mirror of
https://gitlab.com/uldvstar/exchange-2.0.git
synced 2026-08-19 04:24:16 +00:00
e3e4b490b0
# Conflicts: # resources/views/partials/header.blade.php # routes/web.php
48 lines
2.2 KiB
PHP
48 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use App\Classes\ValueObjects\Constants\TransactionType;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class TransactionResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return array
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'booking' => new BookingResource($this->booking),
|
|
'type' => (int) $this->type,
|
|
'bill_no' => $this->bill_no,
|
|
'payment_reference' => $this->payment_reference,
|
|
'payment_method' => (float) $this->payment_method,
|
|
'recipient_bank_account' => new BankResource($this->when((int) $this->type === TransactionType::BILL, $this->booking->bank)),
|
|
'issuer_name' => $this->issuerCompany->name,
|
|
'amount' => (double) $this->amount,
|
|
'original_amount' => (double) $this->original_amount,
|
|
'currency' => new CurrencyResource($this->currency),
|
|
'original_currency' => new CurrencyResource($this->original_currency),
|
|
'service_charge' => (double) $this->service_charge,
|
|
'tax' => (double) $this->tax,
|
|
'currency_rate' => (double) $this->currency_rate,
|
|
'status' => (int) $this->status,
|
|
'details' => TransactionDetailResource::collection($this->transactionDetails),
|
|
'documents' => new DocumentResource($this->documents()->first()),
|
|
'customer_booking' => new TransactionResource($this->when((int) $this->type === TransactionType::BILL, $this->booking->transactions()->payments()->complete()->where('original_amount', '=', $this->original_amount)->where('id', '<', $this->id)->orderByDesc('id')->first())),
|
|
'expires_on' => Carbon::parse($this->expires_on)->format('d-m-Y h:i:s A'),
|
|
'updated_at' => Carbon::parse($this->updated_at)->format('d-m-Y h:i:s A'),
|
|
'interval' => [
|
|
'value' => (Carbon::parse($this->created_at)->addDays(3)->gt(Carbon::now()) ) ? '+' : '-' ,
|
|
'duration' => Carbon::parse($this->created_at)->addDays(3)->diff(Carbon::now())->format('%d'),
|
|
],
|
|
];
|
|
}
|
|
}
|