update regenerate invoice

This commit is contained in:
edmondlang
2023-11-09 10:07:13 +08:00
parent 9b46981593
commit fc2bdb4ff0
+9 -1
View File
@@ -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();