delete duplicated invoice for order marking 165005587 only

This commit is contained in:
edmondlang
2023-02-27 16:17:47 +08:00
parent e4464c3eb4
commit 5d79d5808a
+20 -28
View File
@@ -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();
}
});