From 5d79d5808a63a24f6e82afa2af2b062596ddcbd9 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Mon, 27 Feb 2023 16:17:47 +0800 Subject: [PATCH] delete duplicated invoice for order marking 165005587 only --- routes/web.php | 48 ++++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/routes/web.php b/routes/web.php index 3e4c4a19..a2e35cf9 100644 --- a/routes/web.php +++ b/routes/web.php @@ -869,38 +869,30 @@ Route::get('/invoices/delete-duplicated', function(Request $request){ $order = $packingList->owner; $order_marking = $order->reference; - $duplicatedShipingInvoice = $packingList->transactions->where('type', TransactionType::SHIPPING_INVOICE); + // delete for order_marking 165005587 only + if ($order_marking == 165005587) { + $duplicatedShipingInvoice = $packingList->transactions->where('type', TransactionType::SHIPPING_INVOICE); - if (sizeof($duplicatedShipingInvoice)) { - $paidShippingInvoice = $duplicatedShipingInvoice->where('status', ApprovalStatus::COMPLETED); + if (sizeof($duplicatedShipingInvoice)) { + $paidShippingInvoice = $duplicatedShipingInvoice->where('status', ApprovalStatus::COMPLETED); - if (sizeof($paidShippingInvoice)) { - // if packing list have any paid invoices, delete all the unpaid - - 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->orderByDesc('created_at')->first()->id ) { - if ($invoice->id != $duplicatedShipingInvoice->sortByDesc('created_at')->first()->id ) { - // delete this invoice - $invoice->delete(); - dump('Deleted invoice id -' . $invoice->id); + if (sizeof($paidShippingInvoice)) { + // if packing list have any paid invoices, delete all the unpaid + + 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); + } } } } } -}); - -Route::get('/invoices/suspend-invoices', function(Request $request){ - // $pendingPayment = Transaction::where('type', TransactionType::SHIPPING_INVOICE)->where('status', ApprovalStatus::APPROVED)->get(); - $pendingPayment = Transaction::where('type', TransactionType::SHIPPING_INVOICE)->where('status', 5)->get(); - - foreach ($pendingPayment as $invoice) { - $invoice->status = ApprovalStatus::EXPIRED; - $invoice->save(); - } }); \ No newline at end of file