mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
fix duplicated invoices
This commit is contained in:
+12
-2
@@ -871,13 +871,23 @@ dd($duplicatedInvoices);
|
||||
$unpaidInvoices = $packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::PENDING_SUBMISSION, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED])->orderBy('id', 'desc')->get();
|
||||
|
||||
if (count($paidInvoice)) {
|
||||
$packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::PENDING_SUBMISSION, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED])->delete();
|
||||
$packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->where('status', '!=', ApprovalStatus::COMPLETED)->delete();
|
||||
continue;
|
||||
}
|
||||
|
||||
// delete duplicated invoices
|
||||
$unpaidInvoicesIds = $unpaidInvoices->pluck('id')->toArray();
|
||||
array_shift($unpaidInvoicesIds);
|
||||
Transaction::whereIn('id', $unpaidInvoicesIds)->delete();
|
||||
|
||||
// delete expired invoices
|
||||
$packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->where('status', '!=', ApprovalStatus::EXPIRED)->delete();
|
||||
|
||||
// delete suspended invoices
|
||||
$suspendedInvoices = $packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->where('status', '!=', ApprovalStatus::SUSPENDED)->orderBy('id', 'desc')->get();
|
||||
$suspendedInvoicesIds = $suspendedInvoices->pluck('id')->toArray();
|
||||
array_shift($suspendedInvoicesIds);
|
||||
Transaction::whereIn('id', $suspendedInvoicesIds)->delete();
|
||||
|
||||
Transaction::whereIn('id', $unpaidInvoicesIds)->delete();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user