mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 12:33:56 +00:00
73 lines
2.7 KiB
PHP
73 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\PerfexCRM\Processors;
|
|
|
|
|
|
use App\Classes\Modules\PerfexCRM\Processors\CreatePerfexCRMInvoiceProcessor;
|
|
use App\Classes\Modules\PerfexCRM\Services\FetchesPerfexCRMCustomer;
|
|
use App\Classes\Modules\PerfexCRM\Services\FetchesPerfexCRMInvoice;
|
|
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMInvoiceObject;
|
|
use Illuminate\Support\Facades\Log;
|
|
use App\Classes\General\Helper;
|
|
|
|
class CreatePerfexCRMInvoiceV2Processor
|
|
{
|
|
private $fetchesPerfexCRMCustomer;
|
|
/** @var FetchesPerfexCRMCustomer */
|
|
|
|
/** @var FetchesPerfexCRMInvoice */
|
|
private $fetchesPerfexCRMInvoice;
|
|
|
|
/** @var CreatePerfexCRMInvoiceProcessor */
|
|
private $createPerfexCRMInvoiceProcessor;
|
|
|
|
/**
|
|
*
|
|
* CreatePerfexCRMInvoiceV2Processor constructor.
|
|
* @param FetchesPerfexCRMCustomer $fetchesPerfexCRMCustomer
|
|
* @param FetchesPerfexCRMInvoice $fetchesPerfexCRMInvoice
|
|
* @param CreatePerfexCRMInvoiceProcessor $createPerfexCRMInvoiceProcessor
|
|
*/
|
|
public function __construct(FetchesPerfexCRMCustomer $fetchesPerfexCRMCustomer,
|
|
FetchesPerfexCRMInvoice $fetchesPerfexCRMInvoice,
|
|
CreatePerfexCRMInvoiceProcessor $createPerfexCRMInvoiceProcessor)
|
|
{
|
|
$this->fetchesPerfexCRMCustomer = $fetchesPerfexCRMCustomer;
|
|
$this->fetchesPerfexCRMInvoice = $fetchesPerfexCRMInvoice;
|
|
$this->createPerfexCRMInvoiceProcessor = $createPerfexCRMInvoiceProcessor;
|
|
}
|
|
|
|
public function execute(UpdatePerfexCRMInvoiceObject $updatePerfexCRMInvoiceObject)
|
|
{
|
|
//get the client id
|
|
$customer = $this->fetchesPerfexCRMCustomer->execute($updatePerfexCRMInvoiceObject->getEmail());
|
|
$transaction = $updatePerfexCRMInvoiceObject->getTransaction();
|
|
|
|
//get the invoice id
|
|
$invoiceId = 0;
|
|
|
|
$number = $transaction->bill_no;
|
|
|
|
$prefix = "INV-";
|
|
//This will remove the prefix if prefix already exist in the string
|
|
if (substr($number, 0, strlen($prefix)) == $prefix) {
|
|
$number = substr($number, strlen($prefix));
|
|
}
|
|
|
|
$number = 'EXC-'.$number;
|
|
$invoice = $this->fetchesPerfexCRMInvoice->execute($customer->userid,"INV-", $number);
|
|
Log::error(json_encode('CreatePerfexCRMInvoiceV2Processor debug $number: '.$number));
|
|
if(is_null($invoice)){
|
|
$result = $this->createPerfexCRMInvoiceProcessor->execute($transaction, null, null, $updatePerfexCRMInvoiceObject->getIsPaid());
|
|
if ($result) {
|
|
$invoiceId = $result->payload['id'];
|
|
} else {
|
|
$log['message'] = 'CreatePerfexCRMInvoiceV2Processor CreatePerfexCRMInvoiceProcessor failed';
|
|
Helper::debugLoggerForPerfexCRM($log);
|
|
}
|
|
}
|
|
|
|
return $invoiceId;
|
|
}
|
|
}
|