mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
97 lines
3.2 KiB
PHP
97 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Jobs;
|
|
|
|
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMObject;
|
|
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMInvoiceObject;
|
|
use App\Models\PackingList;
|
|
use App\Models\Transaction;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
class UpdatePerfexCRMPrelude implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
/** @var */
|
|
private $packingList;
|
|
|
|
/** @var */
|
|
private $transaction;
|
|
|
|
/** @var UpdatePerfexCRMObject */
|
|
private $updatePerfexCRMObject;
|
|
|
|
/** @var UpdatePerfexCRM */
|
|
private $nextJob1;
|
|
|
|
/** @var UpdatePerfexCRMInvoice */
|
|
private $nextJob2;
|
|
|
|
/**
|
|
* UpdatePerfexCRMPrelude constructor.
|
|
* @param $packingList
|
|
* @param $transaction
|
|
* @param UpdatePerfexCRMObject $updatePerfexCRMObject
|
|
* @param UpdatePerfexCRM $nextJob1
|
|
* @param UpdatePerfexCRMInvoice $nextJob2
|
|
*/
|
|
public function __construct($packingList, $transaction, UpdatePerfexCRMObject $updatePerfexCRMObject, $nextJob1, $nextJob2)
|
|
{
|
|
$this->packingList = $packingList;
|
|
$this->transaction = $transaction;
|
|
$this->updatePerfexCRMObject = $updatePerfexCRMObject;
|
|
$this->nextJob1 = $nextJob1;
|
|
$this->nextJob2 = $nextJob2;
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
if(is_null($this->packingList)){
|
|
$this->packingList = $this->transaction->owner->owner;
|
|
}
|
|
$amount = 0.00;
|
|
if(!is_null($this->transaction)){
|
|
$amount = $this->transaction->amount;
|
|
}
|
|
$data = [
|
|
'amount' => number_format($amount, 2, '.', ''),
|
|
'link_order' => config('app.url').'/order/show/'.$this->packingList->owner->reference,
|
|
'link_autocount_or' => 'https://docs.google.com/spreadsheets/d/1Q3rJBGQ9Bo04HZp5WR9zbLp7pIW2kfDYsabxG7JON-4/edit#gid=2013983170',
|
|
'link_perfex' => 'https://perfex.cief-malaysia.com/admin/projects/view/89',
|
|
];
|
|
|
|
|
|
$result = $this->replacePlaceholders($this->updatePerfexCRMObject->getTasks(), $data);
|
|
$this->updatePerfexCRMObject->setTasks($result);
|
|
/** @var UpdatePerfexCRM $nextJob1 */
|
|
/** @var UpdatePerfexCRMInvoice $nextJob2 */
|
|
$this->nextJob1::dispatch($this->updatePerfexCRMObject, $this->transaction, $this->nextJob2);
|
|
}
|
|
|
|
function replacePlaceholders($template, $data, $prefix = '')
|
|
{
|
|
foreach ($template as $key => $value) {
|
|
foreach ($data as $dataKey => $dataValue) {
|
|
if (is_array($dataValue)) {
|
|
$template[$key] = $this->replacePlaceholders($template[$key], $dataValue, $dataKey);
|
|
} else {
|
|
if ($prefix != '') {
|
|
$template[$key] = str_replace('{' .$prefix. "." .$dataKey . '}', $dataValue, $template[$key]);
|
|
} else {
|
|
$template[$key] = str_replace('{' . $dataKey . '}', $dataValue, $template[$key]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $template;
|
|
}
|
|
|
|
}
|