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');