From fc2bdb4ff0afc230c2814de98021ce19483c6ec8 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Thu, 9 Nov 2023 10:07:13 +0800 Subject: [PATCH] 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();