mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
73 lines
3.0 KiB
PHP
73 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Jobs\Commands\V2;
|
|
|
|
|
|
use App\Classes\Modules\Transactions\Processors\CreateShippingEInvoiceDocProcessor;
|
|
use App\Classes\Modules\Transactions\Processors\CreateStorageEInvoiceDocProcessor;
|
|
use App\Classes\ValueObjects\Constants\DocumentType;
|
|
use App\Classes\ValueObjects\Constants\KVPKey;
|
|
use App\Classes\ValueObjects\Constants\TransactionType;
|
|
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\Models\Transaction;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
class ProcessTransactionForEInvoiceV2CommandJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
/** @var Transaction */
|
|
private $transaction;
|
|
|
|
/**
|
|
* ProcessTransactionForEInvoiceV2CommandJob constructor.
|
|
* @param Transaction $transaction
|
|
*/
|
|
public function __construct(Transaction $transaction)
|
|
{
|
|
$this->transaction = $transaction;
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
Log::info(Carbon::now() . ': Start job - Processing single transaction for E-Invoice.');
|
|
$start = new Carbon();
|
|
|
|
$isGenerated = false;
|
|
$companyModule = $this->transaction->owner->owner->companyModule;
|
|
if($companyModule->company->e_invoice === 1){
|
|
$document = $this->transaction->documents()->where('document_type', DocumentType::SHIPPING_EINVOICE)->first();
|
|
$kvp = $this->transaction->attributesKVP()->where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE)->first();
|
|
if(!$document && $kvp && $this->transaction->type == TransactionType::SHIPPING_INVOICE){
|
|
(App()->make(CreateShippingEInvoiceDocProcessor::class))->execute($this->transaction);
|
|
$isGenerated = true;
|
|
}
|
|
else {
|
|
$document2 = $this->transaction->documents()->where('document_type', DocumentType::STORAGE_EINVOICE)->first();
|
|
$kvp2 = $this->transaction->attributesKVP()->where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE)->first();
|
|
if(!$document2 && $kvp2 && $this->transaction->type == TransactionType::STORAGE_INVOICE){
|
|
(App()->make(CreateStorageEInvoiceDocProcessor::class))->execute($this->transaction);
|
|
$isGenerated = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(!$isGenerated){
|
|
Log::info("NO E-Invoice generated for transaction with id: " . $this->transaction->id . ', order: ' . $this->transaction->owner->owner->reference );
|
|
}
|
|
else{
|
|
Log::info("E-Invoice generated for transaction with id: " . $this->transaction->id . ', order: ' . $this->transaction->owner->owner->reference );
|
|
}
|
|
|
|
$end = new Carbon();
|
|
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
|
|
Log::info(Carbon::now() . ': End job - Processing single transaction for E-Invoice. ElapsedTime: ' . $elapsedTime . '.');
|
|
}
|
|
}
|