mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 20:43:56 +00:00
83 lines
4.2 KiB
PHP
83 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use App\Classes\Modules\Transactions\Services\CalculatesBillGroupPaymentAmount;
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class BillGroupResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return array
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
$billGroupPayment = (App()->make(CalculatesBillGroupPaymentAmount::class))->execute($this->resource);
|
|
$bill_refund_amount = $billGroupPayment['bill_refund_amount'];
|
|
$floating_amount = $billGroupPayment['floating_amount'];
|
|
$paid_amount = $billGroupPayment['paid_amount'];
|
|
$outstanding_amount = $billGroupPayment['outstanding_amount'];
|
|
|
|
return [
|
|
'id' => $this->id,
|
|
'reference' => $this->reference,
|
|
'original_amount' => (float) $this->original_amount,
|
|
'original_currency' => new CurrencyResource($this->original_currency),
|
|
'issuer_name' => $this->issuerCompany->name,
|
|
'issuer_id' => $this->issuerCompany->id,
|
|
'amount' => (float) $this->amount,
|
|
'service_charge' => (float) $this->service_charge,
|
|
'currency' => new CurrencyResource($this->currency),
|
|
'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A'),
|
|
'updated_at' => Carbon::parse($this->updated_at)->format('d-m-Y h:i:s A'),
|
|
'currency_rate' => (float) $this->currency_rate,
|
|
'status' => $this->status,
|
|
'groups' => GroupResource::collection($this->groups),
|
|
'bill_refund_amount' => $bill_refund_amount,
|
|
'floating_amount' => $floating_amount,
|
|
'paid_amount' => $paid_amount,
|
|
'outstanding_amount' => $outstanding_amount,
|
|
'payment_history' => $this->transactions->map(function ($transaction) {
|
|
return [
|
|
'id' => $transaction->id,
|
|
'type' => (int) $transaction->type,
|
|
'bill_no' => $transaction->bill_no,
|
|
'payment_method' => (float) $transaction->payment_method,
|
|
'amount' => (double) $transaction->amount,
|
|
'original_amount' => (double) $transaction->original_amount,
|
|
'currency' => new CurrencyResource($transaction->currency),
|
|
'original_currency' => new CurrencyResource($transaction->original_currency),
|
|
'service_charge' => (double) $transaction->service_charge,
|
|
'tax' => (double) $transaction->tax,
|
|
'status' => (int) $transaction->status,
|
|
'statusText' => ApprovalStatus::APPROVAL_STATUS_ID[(int) $transaction->status],
|
|
'documents' => $transaction->documents()->first() ? new DocumentResource($transaction->documents()->first()) : null,
|
|
'updated_at' => Carbon::parse($transaction->updated_at)->format('d-m-Y h:i:s A'),
|
|
];
|
|
}),
|
|
'bill_refunds' => $this->billRefunds->map(function ($transaction) {
|
|
return [
|
|
'id' => $transaction->id,
|
|
'type' => (int) $transaction->type,
|
|
'bill_no' => $transaction->bill_no,
|
|
'payment_method' => (float) $transaction->payment_method,
|
|
'amount' => (double) $transaction->amount,
|
|
'original_amount' => (double) $transaction->original_amount,
|
|
'currency' => new CurrencyResource($transaction->currency),
|
|
'original_currency' => new CurrencyResource($transaction->original_currency),
|
|
'service_charge' => (double) $transaction->service_charge,
|
|
'tax' => (double) $transaction->tax,
|
|
'status' => (int) $transaction->status,
|
|
'statusText' => ApprovalStatus::APPROVAL_STATUS_ID[(int) $transaction->status],
|
|
'updated_at' => Carbon::parse($transaction->updated_at)->format('d-m-Y h:i:s A'),
|
|
];
|
|
}),
|
|
];
|
|
}
|
|
}
|