From 2e32ce3059ab0beb28dc8116d05cb8289e9e9414 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Wed, 16 Aug 2023 16:47:11 +0800 Subject: [PATCH] regenerate invoices for 2023 --- app/Classes/Jobs/GenerateInvoice.php | 43 ++++++++++++++++++++++++++++ routes/web.php | 9 ++---- 2 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 app/Classes/Jobs/GenerateInvoice.php diff --git a/app/Classes/Jobs/GenerateInvoice.php b/app/Classes/Jobs/GenerateInvoice.php new file mode 100644 index 00000000..83191e25 --- /dev/null +++ b/app/Classes/Jobs/GenerateInvoice.php @@ -0,0 +1,43 @@ +booking = $booking; + } + + + public function handle() + { + $this->booking->transactions()->whereIn('transactions.type', [TransactionType::INVOICE, TransactionType::SUPPLIER_DELIVER])->delete(); + $this->booking->documents()->whereIn('document_type', [DocumentType::INVOICE, DocumentType::PURCHASE_ORDER, DocumentType::DELIVER_ORDER, DocumentType::SUPPLIER_DELIVER_ORDER])->delete(); + $this->booking->status = ApprovalStatus::APPROVED; + $this->booking->save(); + + (App()->make(CreateInvoiceTransactionProcessor::class))->execute($this->booking); + } +} diff --git a/routes/web.php b/routes/web.php index 324c03a9..ec389475 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,5 +1,6 @@ whereDate('updated_at', '>=', Carbon::parse('01-01-2023'))->get(); foreach($bookings as $booking){ - $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; - $booking->save(); - - (App()->make(CreateInvoiceTransactionProcessor::class))->execute($booking); + GenerateInvoice::dispatch($booking); + return 'Invoice fixing job dispatched.'; } })->name('invoice.fix');