mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-25 15:34:02 +00:00
127 lines
4.4 KiB
PHP
127 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Jobs;
|
|
|
|
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMObject;
|
|
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 Transaction */
|
|
private $transaction;
|
|
|
|
/** @var UpdatePerfexCRMObject */
|
|
private $updatePerfexCRMObject;
|
|
|
|
/** @var */
|
|
private $nextJob;
|
|
|
|
/**
|
|
* UpdatePerfexCRMPrelude constructor.
|
|
* @param Transaction $transaction
|
|
* @param UpdatePerfexCRMObject $updatePerfexCRMObject
|
|
* @param $nextJob
|
|
*/
|
|
public function __construct(Transaction $transaction, UpdatePerfexCRMObject $updatePerfexCRMObject, $nextJob)
|
|
{
|
|
$this->transaction = $transaction;
|
|
$this->updatePerfexCRMObject = $updatePerfexCRMObject;
|
|
$this->nextJob = $nextJob;
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
// //dd(json_encode($supplier));
|
|
// // if($this->transaction->payment_method == PaymentMethodType::CASH)
|
|
// $supplier = (App()->make(FetchesCompany::class))->execute(['id' => $this->transaction->receiver]);
|
|
// $purchaseOrder = $booking->transactions()
|
|
// ->where('type', TransactionType::PURCHASE_ORDER)
|
|
// ->complete()
|
|
// ->first();
|
|
|
|
$serviceTypeName = $this->transaction->owner->company->services()->where('id', $this->transaction->owner->service_id)->first()->name;
|
|
$booking = $this->transaction->booking;
|
|
$bank = $booking->bank;
|
|
$bankDetails = $this->transaction->owner->service_id == 4 ?
|
|
[
|
|
'1688_username' => $bank->account_no,
|
|
'1688_password' => $bank->holder_name,
|
|
'payment_pin' => $bank->bank_branch,
|
|
]:
|
|
[
|
|
'id' => $bank->id,
|
|
'type' => $bank->type,
|
|
'reference' => $bank->reference,
|
|
'bank_name' => $bank->bank_name,
|
|
'bank_branch' => $bank->bank_branch,
|
|
'holder_name' => $bank->holder_name,
|
|
'account_no' => $bank->account_no,
|
|
'country_id' => $bank->country_id,
|
|
'default' => $bank->default,
|
|
'status' => $bank->status,
|
|
];
|
|
$data = [
|
|
'amount' => number_format($this->transaction->amount, 2, '.', ''),
|
|
'currency' => $this->transaction->currency_id == 1 ? "MYR" : "CNY",
|
|
'service_type' => $serviceTypeName,
|
|
'bank_details' => $bankDetails,
|
|
'link_transfer' => config('app.url').'/transfer/'.$this->transaction->owner->marking,
|
|
'link_payments' => config('app.url').'/payments',
|
|
'link_autocount_or' => 'https://docs.google.com/spreadsheets/d/1Q3rJBGQ9Bo04HZp5WR9zbLp7pIW2kfDYsabxG7JON-4/edit#gid=2013983170',
|
|
];
|
|
|
|
|
|
$result = $this->replacePlaceholders($this->updatePerfexCRMObject->getTasks(), $data);
|
|
$this->updatePerfexCRMObject->setTasks($result);
|
|
|
|
//cief todo: cleanup
|
|
// // Do some work here
|
|
// $result = 'some result';
|
|
|
|
// // Return the result
|
|
// return $result;
|
|
|
|
// dd(json_encode($this->updatePerfexCRMObject->getTasks()));
|
|
// return $this->updatePerfexCRMObject;
|
|
$this->nextJob::dispatch($this->updatePerfexCRMObject);
|
|
}
|
|
|
|
// public function then($callback)
|
|
// {
|
|
// $result = $this->result;
|
|
|
|
// dd(json_encode($result));
|
|
// // Execute the callback with the result
|
|
// $callback($result);
|
|
// }
|
|
|
|
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;
|
|
}
|
|
|
|
}
|