mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
98 lines
3.8 KiB
PHP
98 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Jobs\Commands\V2;
|
|
|
|
use App\Classes\Modules\KeyValuePairs\DataTransferObjects\KeyValuePairObject;
|
|
use App\Classes\Modules\KeyValuePairs\Services\CreatesKeyValuePair;
|
|
use App\Classes\Modules\KeyValuePairs\Services\UpdatesKeyValuePair;
|
|
use App\Classes\ValueObjects\Constants\KVPKey;
|
|
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;
|
|
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
|
|
|
class ProcessSalesDepositByWalletRefundEntryV2CommandJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
/** @var array */
|
|
private $details;
|
|
|
|
/**
|
|
* ProcessSalesDepositByWalletRefundEntryV2CommandJob constructor.
|
|
* @param array $details
|
|
*/
|
|
public function __construct(array $details)
|
|
{
|
|
$this->details = $details;
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
Log::info(Carbon::now() . ': Start job - Processing single record from 01DRF - Sales Deposit by Wallet [AR REFUND ENTRY] Import.');
|
|
$start = new Carbon();
|
|
|
|
$docNo = $this->details['docno'] ?? null;
|
|
$debtorCode = $this->details['debtorcode'] ?? null;
|
|
$docDate = $this->details['docdate'] ?? null;
|
|
$description = $this->details['description'] ?? null;
|
|
$deptNo = $this->details['deptno'] ?? null;
|
|
$paymentMethod = $this->details['paymentmethod'] ?? null;
|
|
$knockOffDocType = $this->details['knockoffdoctype'] ?? null;
|
|
$knockOffDocNo = $this->details['knockoffdocno'] ?? null;
|
|
$knockOffAmt = $this->details['knockoffamt'] ?? null;
|
|
|
|
Log::info("Processing Sales Deposit By Wallet [Refund Entry] Report:", [
|
|
'DocNo' => $docNo,
|
|
'DebtorCode' => $debtorCode,
|
|
'DocDate' => $docDate,
|
|
'Description' => $description,
|
|
'DeptNo' => $deptNo,
|
|
'PaymentMethod' => $paymentMethod,
|
|
'KnockOffDocType' => $knockOffDocType,
|
|
'KnockOffDocNo' => $knockOffDocNo,
|
|
'KnockOffAmt' => $knockOffAmt,
|
|
]);
|
|
|
|
$transaction = Transaction::where('bill_no', $description)->first();
|
|
if($transaction){
|
|
if($docNo != "" && $docNo != "<<New>>"){
|
|
$this->updateOrCreateKeyValuePair($transaction, KVPKey::AUTOCOUNT_DOCNO_SALES_DEPOSIT_BY_WALLET_REFUND, $docNo);
|
|
}
|
|
// if($docDate){
|
|
// $this->updateOrCreateKeyValuePair($transaction, KVPKey::AUTOCOUNT_DOCDATE_REFUND, is_numeric($docDate) ? $this->convertDocDateToString($docDate) : $docDate);
|
|
// }
|
|
}
|
|
|
|
$end = new Carbon();
|
|
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
|
|
Log::info(Carbon::now() . ': End job - Processing single record from 01DRF - Sales Deposit by Wallet [AR REFUND ENTRY] 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);
|
|
}
|
|
}
|
|
|
|
private function convertDocDateToString($value, $format = 'm/d/Y') {
|
|
if (is_numeric($value)) {
|
|
return Carbon::instance(Date::excelToDateTimeObject($value))->format($format);
|
|
}
|
|
|
|
return Carbon::parse($value)->format($format);
|
|
}
|
|
}
|