fix duplicated invoices

This commit is contained in:
Omair Saleh
2023-02-28 12:58:18 +08:00
parent d31deeb112
commit e2d1426d19
+12 -2
View File
@@ -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();
}
});