mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-27 00:14:05 +00:00
86 lines
3.3 KiB
PHP
86 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Jobs\Commands\V2;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
|
use App\Classes\Modules\Documents\Services\CreatesDocument;
|
|
use App\Classes\Modules\Documents\Services\CreatesFiles;
|
|
use App\Classes\Modules\Jobs\DataTransferObjects\FixInvoiceV2CommandObject;
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Classes\ValueObjects\Constants\DocumentType;
|
|
use App\Classes\ValueObjects\Constants\TransactionType;
|
|
use App\Models\CompanyConnection;
|
|
use App\Models\Order;
|
|
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class FixInvoiceV2CommandJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
/** @var FixInvoiceV2CommandObject*/
|
|
private $fixInvoiceV2CommandObject;
|
|
|
|
/**
|
|
* FixInvoiceV2CommandJob constructor.
|
|
* @param FixInvoiceV2CommandObject $fixInvoiceV2CommandObject
|
|
*/
|
|
public function __construct(FixInvoiceV2CommandObject $fixInvoiceV2CommandObject)
|
|
{
|
|
$this->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();
|
|
|
|
$view = 'pages.pdfs.shipping_invoice';
|
|
$dateToCompare = Carbon::parse(env('SST_START_DATE', '2024-04-01 00:00:00'));
|
|
$shippingInvoiceTransactionCreatedDate = Carbon::parse($invoice->created_at);
|
|
if ($shippingInvoiceTransactionCreatedDate->isAfter($dateToCompare) && $invoice->tax > 0) {
|
|
$view = 'pages.pdfs.shipping_invoice_sst';
|
|
}
|
|
|
|
$transaction_invoice_pdf = LaravelMpdf::loadView($view, ['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 . '.');
|
|
}
|
|
}
|