mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-26 07:54:04 +00:00
132 lines
5.7 KiB
PHP
132 lines
5.7 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Jobs\Commands\V2;
|
|
|
|
use App\Classes\Modules\Accounts\DataTransferObjects\KeyValuePairObject;
|
|
use App\Classes\Modules\Accounts\Services\CreatesKeyValuePair;
|
|
use App\Classes\Modules\Accounts\Services\UpdatesKeyValuePair;
|
|
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\Order;
|
|
use App\Models\Transaction;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
class ProcessSalesInvoiceReportV2CommandJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
/** @var array */
|
|
private $details;
|
|
|
|
/**
|
|
* ProcessSalesInvoiceReportV2CommandJob constructor.
|
|
* @param array $details
|
|
*/
|
|
public function __construct(array $details)
|
|
{
|
|
$this->details = $details;
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
Log::info(Carbon::now() . ': Start job - Processing single record for E-Invoice from Sales Invoice Report Import.');
|
|
$start = new Carbon();
|
|
|
|
$docNo = $this->details['docno'] ?? null;
|
|
$docDate = $this->details['docdate'] ?? null;
|
|
$debtorCode = $this->details['debtorcode'] ?? null;
|
|
$ref = $this->details['ref'] ?? null;
|
|
$shipInfo = $this->details['shipinfo'] ?? null;
|
|
$accNo = $this->details['accno'] ?? null;
|
|
$detailDescription = $this->details['detaildescription'] ?? null;
|
|
$furtherDescription = $this->details['furtherdescription'] ?? null;
|
|
$classification = $this->details['classification'] ?? null;
|
|
$projNo = $this->details['projno'] ?? null;
|
|
$deptNo = $this->details['deptno'] ?? null;
|
|
$qty = $this->details['qty'] ?? null;
|
|
$unitPrice = $this->details['unitprice'] ?? null;
|
|
$taxCode = $this->details['taxcode'] ?? null;
|
|
$taxableAmt = $this->details['taxableamt'] ?? null;
|
|
$taxRate = $this->details['taxrate'] ?? null;
|
|
$submitEinvoice = $this->details['submiteinvoice'] ?? null;
|
|
$consolidatedEinvoice = $this->details['consolidatedeinvoice'] ?? null;
|
|
$eInvoiceValidationLink = $this->details['einvoicevalidationlink'] ?? null;
|
|
|
|
// Log for debugging
|
|
Log::info("Processing Sales Invoice Report:", [
|
|
'DocNo' => $docNo,
|
|
'DocDate' => $docDate,
|
|
'DebtorCode' => $debtorCode,
|
|
'Ref' => $ref,
|
|
'ShipInfo' => $shipInfo,
|
|
'AccNo' => $accNo,
|
|
'DetailDescription' => $detailDescription,
|
|
'FurtherDescription' => $furtherDescription,
|
|
'Classification' => $classification,
|
|
'ProjNo' => $projNo,
|
|
'DeptNo' => $deptNo,
|
|
'Qty' => $qty,
|
|
'UnitPrice' => $unitPrice,
|
|
'TaxCode' => $taxCode,
|
|
'TaxableAmt' => $taxableAmt,
|
|
'TaxRate' => $taxRate,
|
|
'SubmitEinvoice' => $submitEinvoice,
|
|
'ConsolidatedEinvoice' => $consolidatedEinvoice,
|
|
'EInvoiceValidationLink' => $eInvoiceValidationLink,
|
|
]);
|
|
|
|
|
|
// $order = Order::where('reference', $ref)->first();
|
|
// $transactions = $order->transactions()->whereIn('transactions.type', [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE])->get();
|
|
// $matchedTransaction = null;
|
|
// foreach ($transactions as $transaction) {
|
|
// $transactionDetails = $transaction->transactionDetails;
|
|
// foreach ($transactionDetails as $detail) {
|
|
// $detailName = str_replace('<br>', ' ', $detail->name);
|
|
// if (
|
|
// $detailName === $furtherDescription &&
|
|
// $detail->quantity == $qty &&
|
|
// $detail->price == $unitPrice
|
|
// ) {
|
|
// $matchedTransaction = $transaction;
|
|
// break 2;
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
$matchedTransaction = Transaction::where('bill_no', $ref)->first();
|
|
if($matchedTransaction){
|
|
if($docNo != "" && $docNo != "<<New>>"){
|
|
$this->updateOrCreateKeyValuePair($matchedTransaction, KVPKey::AUTOCOUNT_DOCNO_INVOICE, $docNo);
|
|
}
|
|
if($eInvoiceValidationLink){
|
|
$this->updateOrCreateKeyValuePair($matchedTransaction, KVPKey::AUTOCOUNT_EINVOICE_VALIDATION_LINK, $eInvoiceValidationLink);
|
|
}
|
|
}
|
|
|
|
$end = new Carbon();
|
|
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
|
|
Log::info(Carbon::now() . ': End job - Processing single record for E-Invoice from Sales Invoice Report Import. ElapsedTime: ' . $elapsedTime . '.');
|
|
}
|
|
|
|
|
|
private function updateOrCreateKeyValuePair($booking, $key, $value)
|
|
{
|
|
$keyValuePairObject = new KeyValuePairObject($key, $value);
|
|
$metadata = $booking->attributesKVP()->where('key', $key)->first();
|
|
|
|
if ($metadata) {
|
|
(App()->make(UpdatesKeyValuePair::class))->execute($metadata, $keyValuePairObject);
|
|
} else {
|
|
(App()->make(CreatesKeyValuePair::class))->execute($booking, $keyValuePairObject);
|
|
}
|
|
}
|
|
}
|