fixInvoiceV2CommandObject = $fixInvoiceV2CommandObject; } public function handle() { Log::info(Carbon::now() . ': Start job - Fix invoice.'); $start = new Carbon(); $connection = CompanyConnection::where('invitee_reference', $this->fixInvoiceV2CommandObject->getMarking())->first(); $company_module_id = $connection->invitee->id; $orders = Order::where('company_module_id', $company_module_id)->get(); foreach ($orders as $order){ $invoices = $order->transactions()->where('transactions.type', TransactionType::SHIPPING_INVOICE)->get(); foreach ($invoices as $invoice){ dump($invoice->id); $invoice->documents()->delete(); $transaction_invoice_pdf = LaravelMpdf::loadView('pages.pdfs.shipping_invoice', ['invoice_transaction' => $invoice]); $document_object = new DocumentObject( DocumentType::SHIPPING_INVOICE, [chunk_split('data:application/pdf;base64,'.base64_encode($transaction_invoice_pdf->output()))], '', ApprovalStatus::COMPLETED, 'shipping_invoice' ); /** @var Document $document */ $document = (App()->make(CreatesDocument::class))->execute($invoice, $document_object); (App()->make(CreatesFiles::class))->execute($document, $document_object); } } $end = new Carbon(); $elapsedTime = $start->diff($end)->format('%H:%I:%S'); Log::info(Carbon::now() . ': End job - Fix invoice. ElapsedTime: ' . $elapsedTime . '.'); } }