mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
delete duplicated invoice
This commit is contained in:
+18
-21
@@ -869,30 +869,27 @@ Route::get('/invoices/delete-duplicated', function(Request $request){
|
||||
$order = $packingList->owner;
|
||||
$order_marking = $order->reference;
|
||||
|
||||
// delete for order_marking 165005587 only
|
||||
if ($order_marking == 165005587) {
|
||||
$duplicatedShipingInvoice = $packingList->transactions->where('type', TransactionType::SHIPPING_INVOICE);
|
||||
$paidInvoice = $packingList->transactions->where('type', TransactionType::SHIPPING_INVOICE)->where('status', ApprovalStatus::COMPLETED)->get();
|
||||
|
||||
if (sizeof($duplicatedShipingInvoice)) {
|
||||
$paidShippingInvoice = $duplicatedShipingInvoice->where('status', ApprovalStatus::COMPLETED);
|
||||
// check inside packingList has how many unpaid invoice
|
||||
$unpaidInvoices = $packingList->transactions->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [ApprovalStatus::PENDING_SUBMISSION, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED])->sortByDesc('created_at')->get();
|
||||
|
||||
if (sizeof($paidShippingInvoice)) {
|
||||
// if packing list have any paid invoices, delete all the unpaid
|
||||
dump($unpaidInvoices);
|
||||
|
||||
if ($invoice->id != $paidShippingInvoice->id ) {
|
||||
// delete this invoice
|
||||
$invoice->delete();
|
||||
dump('Deleted invoice id -' . $invoice->id);
|
||||
}
|
||||
} else {
|
||||
// if all unpaid, leave the latest one, delete all
|
||||
if ($invoice->id != $duplicatedShipingInvoice->sortByDesc('created_at')->first()->id ) {
|
||||
// delete this invoice
|
||||
$invoice->delete();
|
||||
dump('Deleted invoice id -' . $invoice->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($paidInvoice)) {
|
||||
// delete all other invoice
|
||||
dump($unpaidInvoices);
|
||||
// $unpaidInvoices->delete();
|
||||
continue;
|
||||
}
|
||||
|
||||
// does not have paid invoice, then delete all but the latest
|
||||
$unpaidInvoicesIds = $unpaidInvoices->pluck('id');
|
||||
$latestInvoiceId = array_shift($unpaidInvoicesIds);
|
||||
|
||||
dump($unpaidInvoicesIds);
|
||||
|
||||
// Transaction::whereIn('id', $unpaidInvoicesIds)->delete();
|
||||
// dump(Transaction::whereIn('id', $unpaidInvoicesIds)->get());
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user