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, ]; } }