mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
Fix a 504 Endpoint request timed out error at customer payment-and-billing page with storage invoice
This commit is contained in:
+2
-1
@@ -25,6 +25,7 @@ use App\Classes\ValueObjects\Constants\PackingListType;
|
||||
use App\Classes\ValueObjects\Constants\TaxPercentage;
|
||||
use App\Classes\ValueObjects\Constants\TransactionDetailType;
|
||||
use App\Http\Resources\TransactionWithStorageResource;
|
||||
use App\Http\Resources\TransactionForStorageResource;
|
||||
use App\Models\Order;
|
||||
use App\Models\PackingList;
|
||||
use App\Models\Transaction;
|
||||
@@ -379,7 +380,7 @@ class CheckStorageInvoiceTransactionProcessor
|
||||
'currentDate' => $dt2->format('Y-m-d H:i:s'),
|
||||
'cbm' => $cbm,
|
||||
'pricePerCBM' => $pricePerCBM,
|
||||
'storageInvoice' => new TransactionWithStorageResource($storageInvoice)
|
||||
'storageInvoice' => new TransactionForStorageResource($storageInvoice)
|
||||
];
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\Group;
|
||||
use App\Models\PackingList;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\Wallet;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class TransactionForStorageResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$order = null;
|
||||
$groupTransactions = null;
|
||||
$group_payment_attempts = null;
|
||||
$groupPaymentAttemptsFiltered = [];
|
||||
$group_payment_expired = null;
|
||||
$group_payment_history = null;
|
||||
$group_payment_history_query = null;
|
||||
$groupTotalAmount = 0;
|
||||
$payment_history = null;
|
||||
|
||||
if ($this->owner instanceof Transaction) {
|
||||
if ($this->owner) {
|
||||
if ($this->owner->owner) {
|
||||
$order = new OrderResource($this->owner->owner->owner);
|
||||
}
|
||||
}
|
||||
} else if (!($this->owner instanceof Transaction) && !($this->owner instanceof Wallet)) {
|
||||
if ($this->owner) {
|
||||
$order = new OrderResource($this->owner->owner);
|
||||
}
|
||||
|
||||
if($this->groups){
|
||||
$group_payment_attempts = GroupForOrderV2Resource::collection($this->groups->whereNotIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]));
|
||||
$group_payment_expired = GroupForOrderV2Resource::collection($this->groupsWithTrashed->whereIn('status', [ApprovalStatus::EXPIRED]));
|
||||
$group_payment_history_query = $this->groups->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::REJECTED]);
|
||||
$group_payment_history = GroupForOrderV2Resource::collection($group_payment_history_query);
|
||||
}
|
||||
|
||||
} else {
|
||||
$group = Group::where('reference', $this->payment_reference)->first();
|
||||
if ($group) {
|
||||
$groupTransactions = GroupTransactionResource::collection($group->groupTransactions);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$packingListReference = null;
|
||||
if ($this->owner instanceof PackingList) {
|
||||
$packingListReference = $this->owner->reference;
|
||||
}
|
||||
|
||||
$ts = $this->groups->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION])->last();
|
||||
if ($ts && $group_payment_history && $group_payment_attempts) {
|
||||
$paymentTransaction = Transaction::where('payment_reference', $ts->reference)->whereIn('status', [ApprovalStatus::PENDING_SUBMISSION])->first();
|
||||
if($paymentTransaction){
|
||||
$groupTotalAmount = (double) $this->amount;
|
||||
|
||||
foreach ($group_payment_history as $key => $value) {
|
||||
if ($value->id === $ts->id && $value->reference === $ts->reference) {
|
||||
unset($group_payment_history[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($group_payment_attempts as $key => $value) {
|
||||
if ($value->id === $ts->id && $value->reference == $ts->reference) {
|
||||
$groupPaymentAttemptsFiltered[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$payment_history = TransactionResource::collection($this->transactions()
|
||||
->payments()
|
||||
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::COMPLETED, ApprovalStatus::REJECTED])
|
||||
->get());
|
||||
|
||||
//For 'Your Payment Proof' at frontend
|
||||
|
||||
if($group_payment_history_query && count($group_payment_history_query) > 0){
|
||||
if($this->getReferenceForGroupPayment($group_payment_history_query)){
|
||||
foreach ($payment_history as $item) {
|
||||
$item['payment_reference'] = $this->getReferenceForGroupPayment($group_payment_history_query);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
// 'owner_type' => $this->owner_type,
|
||||
'order' => $order,
|
||||
// 'group_transactions' => $groupTransactions,
|
||||
// 'group_reference' => $groupTransactions ? ($group ? $group->reference : null ) : null,
|
||||
// 'groups_payment_attempts' => $groupPaymentAttemptsFiltered,
|
||||
// 'groups_payment_expired' => $group_payment_expired,
|
||||
// 'groups_payment_history' => $group_payment_history,
|
||||
// 'documents' => $groupTransactions ? DocumentResource::collection($this->documents->where('status', ApprovalStatus::PENDING_VERIFICATION)) : DocumentResource::collection($this->documents),
|
||||
// 'type' => (int) $this->type,
|
||||
'bill_no' => $this->bill_no,
|
||||
'amount' => (double) $this->amount,
|
||||
// 'payment_method' => (int) $this->payment_method,
|
||||
// 'payment_reference' => $this->payment_reference,
|
||||
// 'outstanding' => (double) $this->amount - ($this->transactions()->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->sum('amount')),
|
||||
// 'floating' => $group_payment_attempts ? $groupTotalAmount : (double) $this->transactions()->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::PENDING_SUBMISSION, ApprovalStatus::PENDING_VERIFICATION])->sum('amount'),
|
||||
// 'service_charge' => (double) $this->service_charge,
|
||||
// 'tax' => (double) $this->tax,
|
||||
// 'original_amount' => (double) $this->original_amount,
|
||||
// 'currency' => new CurrencyResource($this->currency),
|
||||
// 'original_currency' => new CurrencyResource($this->original_currency),
|
||||
// 'currency_rate' => (double) $this->currency_rate,
|
||||
// 'status' => (int) $this->status,
|
||||
// 'details' => TransactionDetailResource::collection($this->transactionDetails),
|
||||
// 'transactions' => TransactionResource::collection($this->transactions),
|
||||
// 'payment_attempts' => TransactionResource::collection(
|
||||
// $this->transactions()
|
||||
// ->payments()->where('status', ApprovalStatus::PENDING_SUBMISSION)
|
||||
// ->get()
|
||||
// ),
|
||||
// 'payments_expired' => TransactionResource::collection(
|
||||
// $this->transactions()
|
||||
// ->payments()->where('status', ApprovalStatus::EXPIRED)
|
||||
// ->get()
|
||||
// ),
|
||||
// 'payment_history' => $payment_history,
|
||||
// 'remarks' => RemarkResource::collection($this->remarks),
|
||||
// 'packing_list_reference' => $packingListReference,
|
||||
// 'storages' => $this->storages ? $this->storages : null, //from middleware
|
||||
// 'is_waived' => (int) $this->is_waived,
|
||||
// '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'),
|
||||
'created_at' => Carbon::parse($this->created_at)->format('d-m-Y'),
|
||||
// 'is_einvoice_applicable' => Carbon::parse($this->created_at)->isAfter(Carbon::parse(env('E_INVOICE_START_DATE', '2025-07-01 00:00:00'))) && $this->is_einvoice_applicable,
|
||||
];
|
||||
}
|
||||
|
||||
private function getReferenceForGroupPayment($groups){
|
||||
if (is_array($groups) && count($groups) > 0) {
|
||||
$firstGroup = $groups[0];
|
||||
return $firstGroup['reference'];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -52,7 +52,7 @@
|
||||
</div> -->
|
||||
<!-- PDF - INV -->
|
||||
<div class="col-auto" v-if="!isEinvoiceApplicable">
|
||||
<div v-if="item.documents.length && item.documents.some(d => d.document_type === 'SHIPPING_INVOICE' || d.document_type === 'STORAGE_INVOICE')">
|
||||
<div v-if="item.documents && item.documents.length && item.documents.some(d => d.document_type === 'SHIPPING_INVOICE' || d.document_type === 'STORAGE_INVOICE')">
|
||||
<div v-for="doc in item.documents.filter(d => d.document_type === 'SHIPPING_INVOICE' || d.document_type === 'STORAGE_INVOICE')" :key="doc.id">
|
||||
<div v-for="file in doc.files" v-bind:key="file.id" class="col-auto no-padding">
|
||||
<document-file-viewer-component :file="file">
|
||||
@@ -82,7 +82,7 @@
|
||||
|
||||
<!-- PDF - EINV -->
|
||||
<div class="col-auto" v-if="isEinvoiceApplicable">
|
||||
<div v-if="item.documents.length && item.documents.some(d => d.document_type === 'SHIPPING_EINVOICE' || d.document_type === 'STORAGE_EINVOICE')">
|
||||
<div v-if="item.documents && item.documents.length && item.documents.some(d => d.document_type === 'SHIPPING_EINVOICE' || d.document_type === 'STORAGE_EINVOICE')">
|
||||
<div v-for="doc in item.documents.filter(d => d.document_type === 'SHIPPING_EINVOICE' || d.document_type === 'STORAGE_EINVOICE')" :key="doc.id">
|
||||
<div v-for="file in doc.files" v-bind:key="file.id" class="col-auto no-padding">
|
||||
<document-file-viewer-component :file="file">
|
||||
@@ -112,7 +112,7 @@
|
||||
|
||||
<!-- PDF - SO -->
|
||||
<div class="col-auto">
|
||||
<div v-if="item.documents.length && item.documents.some(d => d.document_type === 'SALES_ORDER')">
|
||||
<div v-if="item.documents && item.documents.length && item.documents.some(d => d.document_type === 'SALES_ORDER')">
|
||||
<div v-for="doc in item.documents.filter(d => d.document_type === 'SALES_ORDER')" :key="doc.id">
|
||||
<div v-for="file in doc.files" v-bind:key="file.id" class="col-auto no-padding">
|
||||
<document-file-viewer-component :file="file">
|
||||
|
||||
Reference in New Issue
Block a user