From 3e54b636e0949901be7f3ed1a5902fbd340ebd4c Mon Sep 17 00:00:00 2001 From: edmondlang Date: Wed, 6 Sep 2023 18:08:49 +0800 Subject: [PATCH] fix invoice --- routes/web.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/routes/web.php b/routes/web.php index bbd925ab..25917dd3 100644 --- a/routes/web.php +++ b/routes/web.php @@ -491,7 +491,6 @@ Route::get('/invoice/fix', function(){ Booking::where('status', ApprovalStatus::COMPLETED) ->whereDate('updated_at', '>=', Carbon::parse('01-01-2023')) - ->whereDate('created_at', '<', Carbon::parse('06-09-2023')) ->orderBy('id') ->chunk(100, function ($bookings) use ($processed_invoice){ foreach ($bookings as $booking) { @@ -499,6 +498,13 @@ Route::get('/invoice/fix', function(){ Log::channel('regenerateInvoice')->info('Counter ' . $processed_invoice); $processed_invoice += 1; + if ($booking->transactions()->where('transactions.type', TransactionType::INVOICE) + ->first() + ->created_at + ->greaterThanOrEqualTo(Carbon::parse('2023-09-06'))) { + continue; + } + $booking->transactions()->whereIn('transactions.type', [TransactionType::INVOICE, TransactionType::SUPPLIER_DELIVER])->delete(); $booking->documents()->whereIn('document_type', [DocumentType::INVOICE, DocumentType::PURCHASE_ORDER, DocumentType::DELIVER_ORDER, DocumentType::SUPPLIER_DELIVER_ORDER])->delete(); $booking->status = ApprovalStatus::APPROVED;