diff --git a/app/Classes/Jobs/Commands/V2/CreateInvoiceTransactionV2CommandJob.php b/app/Classes/Jobs/Commands/V2/CreateInvoiceTransactionV2CommandJob.php new file mode 100644 index 00000000..08576f16 --- /dev/null +++ b/app/Classes/Jobs/Commands/V2/CreateInvoiceTransactionV2CommandJob.php @@ -0,0 +1,42 @@ +booking = $booking; + } + + public function handle() + { + Log::info(Carbon::now() . ': Start job - Creating invoice for single booking.'); + $start = new Carbon(); + + (App()->make(CreateInvoiceTransactionV2Processor::class))->execute($this->booking); + + $end = new Carbon(); + $elapsedTime = $start->diff($end)->format('%H:%I:%S'); + Log::info(Carbon::now() . ': End job - Creating invoice for single booking. ElapsedTime: ' . $elapsedTime . '.'); + } + +} diff --git a/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php b/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php index 3142441b..ff3f66c2 100644 --- a/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php +++ b/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php @@ -2,6 +2,7 @@ namespace App\Classes\Modules\Exports\Services; +use App\Classes\Jobs\Commands\V2\CreateInvoiceTransactionV2CommandJob; use App\Classes\ValueObjects\Constants\TransactionType; use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Models\Booking; @@ -71,7 +72,7 @@ class ExportsSalesInvoiceReport implements FromQuery, WithHeadings, WithHeadingR 'transactions.voucherRedemption', 'transactions.voucherRedemption.voucher.campaign' ]) - ->where('status', ApprovalStatus::COMPLETED) + // ->where('status', ApprovalStatus::COMPLETED) ->whereHas('transactions', function ($query) use ($startDate, $endDate) { $query->payments() ->complete() @@ -115,6 +116,11 @@ class ExportsSalesInvoiceReport implements FromQuery, WithHeadings, WithHeadingR } $invoiceTransaction = $booking->transactions->where('type', TransactionType::INVOICE)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->first(); + if(!$invoiceTransaction){ + Log::info('ExportsSalesInvoiceReport booking with NO invoice: ' . json_encode($booking)); + // CreateInvoiceTransactionV2CommandJob::dispatch($booking); + return $records; + } $currencyId = $booking->fix_currency_id;