mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 12:33:56 +00:00
76 lines
3.4 KiB
PHP
76 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Classes\ValueObjects\Constants\DocumentType;
|
|
use App\Classes\ValueObjects\Constants\KVPKey;
|
|
use App\Classes\ValueObjects\Constants\TransactionType;
|
|
use App\Models\Booking;
|
|
use App\Models\KeyValuePair;
|
|
use App\Models\Transaction;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class GroupResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return array
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
$transfer_fee = $this->morphTransactions()->where('type', TransactionType::TRANSFER_FEE)->first();
|
|
|
|
if ($transfer_fee) {
|
|
$transfer_fee = (float) $transfer_fee->amount;
|
|
} else {
|
|
$transfer_fee = 0;
|
|
}
|
|
|
|
if(!$this->issuerCompany){
|
|
dd($this->id);
|
|
}
|
|
|
|
$ui_payments_complete_currecy_orders_is_locked = ($this->status === 3)
|
|
? KeyValuePair::whereNull('owner_type')->whereNull('owner_id')
|
|
->whereIn('key', [KVPKey::UI_PAYMENTS_COMPLETE_CURRENCY_ORDERS_IS_LOCKED])->where('value', 1)->first()
|
|
: null;
|
|
$ui_payments_open_currecy_orders_is_locked = ($this->status === 0 || $this->status === 1 || $this->status === 2)
|
|
? KeyValuePair::whereNull('owner_type')->whereNull('owner_id')
|
|
->whereIn('key', [KVPKey::UI_PAYMENTS_OPEN_CURRENCY_ORDERS_IS_LOCKED])->where('value', 1)->first()
|
|
: null;
|
|
|
|
return [
|
|
'id' => $this->id,
|
|
'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->amount,
|
|
'currency' => new CurrencyResource($this->currency),
|
|
'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A'),
|
|
'currency_rate' => (float) $this->currency_rate,
|
|
'transfer_fee' => $transfer_fee,
|
|
'transactions' => $this->transactions()->get()->pluck('owner.owner.marking'),
|
|
'complete_transactions' => $this->transactions()->whereHasMorph('owner', [Transaction::class], function($query){
|
|
return $query->whereHas('booking', function($query){
|
|
return $query->whereHas('transactions', function($query){
|
|
return $query->where('type', TransactionType::PURCHASE_ORDER)->where('status', '=', ApprovalStatus::APPROVED);
|
|
});
|
|
});
|
|
})->get()->pluck('owner.owner.marking'),
|
|
'documents' => [
|
|
'currency_order' => new DocumentResource($this->documents()->where('document_type', DocumentType::CURRENCY_VENDOR_ORDER)->first()),
|
|
'purchase_order' => new DocumentResource($this->documents()->where('document_type', DocumentType::BULK_PURCHASE_ORDER)->first())
|
|
],
|
|
'ui_payments_complete_currecy_orders_is_locked' => $ui_payments_complete_currecy_orders_is_locked ? 1 : 0,
|
|
'ui_payments_open_currecy_orders_is_locked' => $ui_payments_open_currecy_orders_is_locked ? 1 : 0,
|
|
];
|
|
}
|
|
}
|