From f34333f4c981454f45dc6513db4c574cff37a39b Mon Sep 17 00:00:00 2001 From: Dillon Date: Wed, 2 Aug 2023 20:44:37 +0800 Subject: [PATCH] Minor rewrite --- app/Classes/Jobs/UpdatePerfexCRM.php | 32 +++++++++---------- .../UpdatePerfexCRMObject.php | 2 +- .../CreatePerfexCRMInvoiceV2Processor.php | 6 ++-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/Classes/Jobs/UpdatePerfexCRM.php b/app/Classes/Jobs/UpdatePerfexCRM.php index 77e19b64..27357552 100644 --- a/app/Classes/Jobs/UpdatePerfexCRM.php +++ b/app/Classes/Jobs/UpdatePerfexCRM.php @@ -42,22 +42,9 @@ class UpdatePerfexCRM implements ShouldQueue public function handle() { - $invoiceId = 0; - //To use invoice as a reference to decide whether more tasks should be created - if($this->transaction != null){ - $updatePerfexCRMInvoiceObject = new UpdatePerfexCRMInvoiceObject( - $this->updatePerfexCRMObject->getContactEmail(), - $this->updatePerfexCRMObject->getProjectName(), - '', - $this->transaction, - true - ); - // UpdatePerfexCRMInvoice::dispatch($updatePerfexCRMInvoiceObject); - $invoiceId = (App()->make(CreatePerfexCRMInvoiceV2Processor::class))->execute($updatePerfexCRMInvoiceObject); - } + $this->updatePerfexCRMObject->setInvoiceId($this->getInvoiceId()); - $this->updatePerfexCRMObject->setInvoiceId($invoiceId); $result = (App()->make(UpdatePerfexCRMProcessor::class))->execute($this->updatePerfexCRMObject); if($this->transaction != null && $this->shouldCreateInvoice){ $updatePerfexCRMInvoiceObject = new UpdatePerfexCRMInvoiceObject( @@ -67,9 +54,22 @@ class UpdatePerfexCRM implements ShouldQueue $this->transaction, true ); - UpdatePerfexCRMInvoice::dispatch($updatePerfexCRMInvoiceObject); - } } + + private function getInvoiceId(){ + if($this->transaction != null){ + $updatePerfexCRMInvoiceObject = new UpdatePerfexCRMInvoiceObject( + $this->updatePerfexCRMObject->getContactEmail(), + $this->updatePerfexCRMObject->getProjectName(), + '', + $this->transaction, + true + ); + $invoiceId = (App()->make(CreatePerfexCRMInvoiceV2Processor::class))->execute($updatePerfexCRMInvoiceObject); + return $invoiceId; + } + return 0; + } } diff --git a/app/Classes/Modules/PerfexCRM/DataTransferObjects/UpdatePerfexCRMObject.php b/app/Classes/Modules/PerfexCRM/DataTransferObjects/UpdatePerfexCRMObject.php index cec82ee5..96bbc8bd 100644 --- a/app/Classes/Modules/PerfexCRM/DataTransferObjects/UpdatePerfexCRMObject.php +++ b/app/Classes/Modules/PerfexCRM/DataTransferObjects/UpdatePerfexCRMObject.php @@ -35,7 +35,7 @@ class UpdatePerfexCRMObject implements DataTransferObject private $tasks; /** @var int */ - private $invoiceId; + private $invoiceId = 0; public function __construct(string $companyName, string $companyReference, string $contactName, string $contactEmail, string $bookingMarking, string $projectName, int $projectStatus, int $invoiceId, array $milestoneNames, array $tasks) diff --git a/app/Classes/Modules/PerfexCRM/Processors/CreatePerfexCRMInvoiceV2Processor.php b/app/Classes/Modules/PerfexCRM/Processors/CreatePerfexCRMInvoiceV2Processor.php index df73bd61..08c74133 100644 --- a/app/Classes/Modules/PerfexCRM/Processors/CreatePerfexCRMInvoiceV2Processor.php +++ b/app/Classes/Modules/PerfexCRM/Processors/CreatePerfexCRMInvoiceV2Processor.php @@ -39,13 +39,13 @@ class CreatePerfexCRMInvoiceV2Processor public function execute(UpdatePerfexCRMInvoiceObject $updatePerfexCRMInvoiceObject) { + //invoiceId to be returned - fetch or create + $invoiceId = 0; + //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-";