From 9b46981593142d4b0ae140bd85eb691ca4adee9f Mon Sep 17 00:00:00 2001 From: edmondlang Date: Thu, 9 Nov 2023 09:43:09 +0800 Subject: [PATCH 1/2] update regenerate documents link --- routes/web.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/web.php b/routes/web.php index 0efe0616..e2cd97fb 100644 --- a/routes/web.php +++ b/routes/web.php @@ -794,8 +794,8 @@ Route::get('/invoice/{marking}/{started_at}/{ended_at}/fix', function($marking, $bookings = $company->bookings() ->where('status', ApprovalStatus::COMPLETED) - ->whereDate('updated_at', '>=', Carbon::parse($started_at)) - ->whereDate('updated_at', '<=', Carbon::parse($ended_at)) + ->whereDate('created_at', '>=', Carbon::parse($started_at)) + ->whereDate('created_at', '<=', Carbon::parse($ended_at)) ->orderBy('id') ->chunk(100, function ($bookings) use (&$processed_invoice) { foreach ($bookings as $booking) { From fc2bdb4ff0afc230c2814de98021ce19483c6ec8 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Thu, 9 Nov 2023 10:07:13 +0800 Subject: [PATCH 2/2] update regenerate invoice --- routes/web.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/routes/web.php b/routes/web.php index e2cd97fb..447d0d72 100644 --- a/routes/web.php +++ b/routes/web.php @@ -821,9 +821,17 @@ Route::get('/invoice/{marking}/{started_at}/{ended_at}/fix', function($marking, // update currentInvoice bill_no to '-deleted-' $currentInvoice = $booking->transactions()->where('type', TransactionType::INVOICE)->first(); - $currentInvoice->bill_no = $currentInvoice->bill_no ."-deleted-" . (string)(Carbon::now()->timestamp); + $currentInvoice->bill_no = $currentInvoice->bill_no ."-deleted-" . Str::random(10); $currentInvoice->save(); + $transactionWithSameBillNo = Transaction::where('bill_no', $firstBillNo)->get(); + if ($transactionWithSameBillNo) { + foreach ($transactionWithSameBillNo as $transaction) { + $transaction->bill_no = $transaction->bill_no . "-deleted-" . Str::random(10); + $transaction->save(); + } + } + $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();