From 8b20bfc0a6baa12d59b9097bd181cda1b6a46bda Mon Sep 17 00:00:00 2001 From: Dillon Date: Fri, 4 Aug 2023 14:45:01 +0800 Subject: [PATCH 01/52] Minor logging update --- .../PerfexCRM/Processors/CreatePerfexCRMInvoiceProcessor.php | 1 - .../PerfexCRM/Processors/FetchPerfexCRMInvoiceProcessor.php | 3 +-- .../Modules/PerfexCRM/Services/UpdatesPerfexCRMInvoice.php | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/app/Classes/Modules/PerfexCRM/Processors/CreatePerfexCRMInvoiceProcessor.php b/app/Classes/Modules/PerfexCRM/Processors/CreatePerfexCRMInvoiceProcessor.php index 2bd95920..ca2c4069 100644 --- a/app/Classes/Modules/PerfexCRM/Processors/CreatePerfexCRMInvoiceProcessor.php +++ b/app/Classes/Modules/PerfexCRM/Processors/CreatePerfexCRMInvoiceProcessor.php @@ -120,7 +120,6 @@ class CreatePerfexCRMInvoiceProcessor $bookingMarking = $transaction->owner->marking; $serviceTypeName = $transaction->owner->company->services()->where('id', $transaction->owner->service_id)->first()->name; $projectName = 'Exchange | '.$serviceTypeName.' | '.$bookingMarking; - Log::error('CreatePerfexCRMInvoiceProcessor debug:'.json_encode($transaction)); Log::error('$projectName: '.$projectName); return $email; } diff --git a/app/Classes/Modules/PerfexCRM/Processors/FetchPerfexCRMInvoiceProcessor.php b/app/Classes/Modules/PerfexCRM/Processors/FetchPerfexCRMInvoiceProcessor.php index ddf0ee55..f9ffced9 100644 --- a/app/Classes/Modules/PerfexCRM/Processors/FetchPerfexCRMInvoiceProcessor.php +++ b/app/Classes/Modules/PerfexCRM/Processors/FetchPerfexCRMInvoiceProcessor.php @@ -56,13 +56,12 @@ class FetchPerfexCRMInvoiceProcessor $number = 'EXC-'.$number; $invoice = $this->fetchesPerfexCRMInvoice->execute($customer->userid,"INV-", $number); - Log::error(json_encode('FetchPerfexCRMInvoiceProcessor debug $number: '.$number)); if(is_null($invoice)){ $result = $this->createPerfexCRMInvoiceProcessor->execute($transaction, null, null, $fetchPerfexCRMInvoiceObject->getIsPaid()); if ($result) { $invoiceId = $result->payload['id']; } else { - $log['message'] = 'FetchPerfexCRMInvoiceProcessor failed'; + $log['message'] = 'FetchPerfexCRMInvoiceProcessor failed for transaction > bill_no: '.$number; Helper::debugLogger($log); } } diff --git a/app/Classes/Modules/PerfexCRM/Services/UpdatesPerfexCRMInvoice.php b/app/Classes/Modules/PerfexCRM/Services/UpdatesPerfexCRMInvoice.php index 1ade5453..9adb9460 100644 --- a/app/Classes/Modules/PerfexCRM/Services/UpdatesPerfexCRMInvoice.php +++ b/app/Classes/Modules/PerfexCRM/Services/UpdatesPerfexCRMInvoice.php @@ -64,7 +64,6 @@ class UpdatesPerfexCRMInvoice return null; } }catch(\Exception $exception){ - dd(json_encode($exception)); throw new MalformedRequestException('Unable to get correct response from Perfex CRM server: ' . $exception->getMessage()); } } From ba2fcb1d6f66862b685c39c36ab4230834353301 Mon Sep 17 00:00:00 2001 From: Dillon Date: Fri, 4 Aug 2023 23:17:26 +0800 Subject: [PATCH 02/52] Some code syntax fixes + remove comments --- app/Classes/Jobs/UpdatePerfexCRM.php | 17 +++--- .../FetchPerfexCRMInvoiceObject.php | 14 +---- .../CreatePerfexCRMInvoiceProcessor.php | 20 ------- .../FetchPerfexCRMInvoiceProcessor.php | 2 +- .../Processors/UpdatePerfexCRMProcessor.php | 24 +++++--- .../Services/CreatesPerfexCRMTask.php | 60 ++++++------------- 6 files changed, 45 insertions(+), 92 deletions(-) diff --git a/app/Classes/Jobs/UpdatePerfexCRM.php b/app/Classes/Jobs/UpdatePerfexCRM.php index 93f536c5..83e91df4 100644 --- a/app/Classes/Jobs/UpdatePerfexCRM.php +++ b/app/Classes/Jobs/UpdatePerfexCRM.php @@ -26,28 +26,28 @@ class UpdatePerfexCRM implements ShouldQueue private $transaction; /** @var Boolean|null */ - private $shouldCreateInvoice; + private $shouldCreateInvoiceWithPayment; /** * @param UpdatePerfexCRMObject $updatePerfexCRMObject * @param $transaction - * @param bool|null $shouldCreateInvoice + * @param bool|null $shouldCreateInvoiceWithPayment */ - public function __construct(UpdatePerfexCRMObject $updatePerfexCRMObject, $transaction, ?bool $shouldCreateInvoice = false) + public function __construct(UpdatePerfexCRMObject $updatePerfexCRMObject, $transaction, ?bool $shouldCreateInvoiceWithPayment = false) { $this->updatePerfexCRMObject = $updatePerfexCRMObject; $this->transaction = $transaction; - $this->shouldCreateInvoice = $shouldCreateInvoice; + $this->shouldCreateInvoiceWithPayment = $shouldCreateInvoiceWithPayment; } public function handle() { //To use invoice as a reference to decide whether more tasks should be created - $this->updatePerfexCRMObject->setInvoiceId($this->getInvoiceId()); + $this->updatePerfexCRMObject->setInvoiceId($this->getInvoiceIdOrCreateInvoice()); $result = (App()->make(UpdatePerfexCRMProcessor::class))->execute($this->updatePerfexCRMObject); - if($this->transaction != null && $this->shouldCreateInvoice){ + if($this->transaction != null && $this->shouldCreateInvoiceWithPayment){ $updatePerfexCRMInvoiceObject = new UpdatePerfexCRMInvoiceObject( $this->updatePerfexCRMObject->getContactEmail(), $this->updatePerfexCRMObject->getProjectName(), @@ -59,12 +59,11 @@ class UpdatePerfexCRM implements ShouldQueue } } - private function getInvoiceId(){ + private function getInvoiceIdOrCreateInvoice(){ if($this->transaction != null){ $fetchPerfexCRMInvoiceObject = new FetchPerfexCRMInvoiceObject( $this->updatePerfexCRMObject->getContactEmail(), - $this->transaction, - true + $this->transaction ); $invoiceId = (App()->make(FetchPerfexCRMInvoiceProcessor::class))->execute($fetchPerfexCRMInvoiceObject); return $invoiceId; diff --git a/app/Classes/Modules/PerfexCRM/DataTransferObjects/FetchPerfexCRMInvoiceObject.php b/app/Classes/Modules/PerfexCRM/DataTransferObjects/FetchPerfexCRMInvoiceObject.php index cbb85a3e..56c5a01d 100644 --- a/app/Classes/Modules/PerfexCRM/DataTransferObjects/FetchPerfexCRMInvoiceObject.php +++ b/app/Classes/Modules/PerfexCRM/DataTransferObjects/FetchPerfexCRMInvoiceObject.php @@ -13,15 +13,11 @@ class FetchPerfexCRMInvoiceObject implements DataTransferObject /** @var Transaction */ private $transaction; - /** @var bool */ - private $isPaid; - - public function __construct(string $email, Transaction $transaction, bool $isPaid) + public function __construct(string $email, Transaction $transaction) { $this->email = $email; $this->transaction = $transaction; - $this->isPaid = $isPaid; } /** @@ -39,12 +35,4 @@ class FetchPerfexCRMInvoiceObject implements DataTransferObject { return $this->transaction; } - - /** - * @return bool - */ - public function getIsPaid(): bool - { - return $this->isPaid; - } } diff --git a/app/Classes/Modules/PerfexCRM/Processors/CreatePerfexCRMInvoiceProcessor.php b/app/Classes/Modules/PerfexCRM/Processors/CreatePerfexCRMInvoiceProcessor.php index ca2c4069..2b6a557d 100644 --- a/app/Classes/Modules/PerfexCRM/Processors/CreatePerfexCRMInvoiceProcessor.php +++ b/app/Classes/Modules/PerfexCRM/Processors/CreatePerfexCRMInvoiceProcessor.php @@ -228,26 +228,6 @@ class CreatePerfexCRMInvoiceProcessor ); $result = $this->createsPerfexCRMInvoice->execute($invoicePerfexCRMObject); - - //cief todo: When invoices need to be regenerated, need to ensure payment do not get double created - - // if(!is_null($result)) - // { - // if($result->payload['id']){ - // $invoicePaymentPerfexCRMObject = new InvoicePaymentPerfexCRMObject( - // $result->payload['id'], - // $total, - // $date, - // 1, - // "", - // "" - // ); - // $this->createsPerfexCRMInvoicePayment->execute($invoicePaymentPerfexCRMObject); - // } - // } - //else: logs will record the following: - //"status":false,"error":{"number":"The Invoice number is already in use"},"message":"

The Invoice number is already in use<\/p>"} - return $result; } } diff --git a/app/Classes/Modules/PerfexCRM/Processors/FetchPerfexCRMInvoiceProcessor.php b/app/Classes/Modules/PerfexCRM/Processors/FetchPerfexCRMInvoiceProcessor.php index f9ffced9..28ee70a7 100644 --- a/app/Classes/Modules/PerfexCRM/Processors/FetchPerfexCRMInvoiceProcessor.php +++ b/app/Classes/Modules/PerfexCRM/Processors/FetchPerfexCRMInvoiceProcessor.php @@ -57,7 +57,7 @@ class FetchPerfexCRMInvoiceProcessor $number = 'EXC-'.$number; $invoice = $this->fetchesPerfexCRMInvoice->execute($customer->userid,"INV-", $number); if(is_null($invoice)){ - $result = $this->createPerfexCRMInvoiceProcessor->execute($transaction, null, null, $fetchPerfexCRMInvoiceObject->getIsPaid()); + $result = $this->createPerfexCRMInvoiceProcessor->execute($transaction, null, null); if ($result) { $invoiceId = $result->payload['id']; } else { diff --git a/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php b/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php index 2971e3c8..5552edd9 100644 --- a/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php +++ b/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php @@ -15,8 +15,8 @@ use App\Classes\Modules\PerfexCRM\Services\UpdatesPerfexCRMTask; use App\Classes\Modules\PerfexCRM\Services\UpdatesPerfexCRMCustomer; use App\Classes\Modules\PerfexCRM\Services\UpdatesPerfexCRMProject; use App\Classes\Modules\PerfexCRM\DataTransferObjects\CustomerContactObject; -use App\Classes\Exceptions\MalformedRequestException; use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMObject; +use App\Classes\Modules\PerfexCRM\DataTransferObjects\CreateTaskPerfexCRMObject; use App\Classes\ValueObjects\Constants\PerfexCRMTaskStatus; use App\Classes\ValueObjects\Constants\PerfexCRMProjectStatus; use Illuminate\Support\Facades\Http; @@ -219,13 +219,23 @@ class UpdatePerfexCRMProcessor } } else{ - $result = $this->createsPerfexCRMTask->execute($taskName, $tasks[$count]['description'], '', $milestoneId, $projectId, $tasks[$count]['reference'], $tasks[$count]['on_task_completion'], $tasks[$count]['department'], $taskStatus, $tasks[$count]['priority'], $tasks[$count]['duedate'], $updatePerfexCRMObject->getInvoiceId()); + $createTaskPerfexCRMObject = new CreateTaskPerfexCRMObject( + "", + $taskName, + $tasks[$count]['description'], + "", + $projectId, + $milestoneId, + $tasks[$count]['reference'], + $tasks[$count]['on_task_completion'], + $taskStatus, + $tasks[$count]['department'], + $tasks[$count]['priority'], + $tasks[$count]['duedate'], + $updatePerfexCRMObject->getInvoiceId() + ); + $result = $this->createsPerfexCRMTask->execute($createTaskPerfexCRMObject); } - - //cief todo: to evaluate if this is still needed - // if(is_null($result)){ - // break; //Breaking the rest of the tasks in array assuming that they are all created as a batch previously - // } } } diff --git a/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMTask.php b/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMTask.php index ace2aa00..feb8f9c8 100644 --- a/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMTask.php +++ b/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMTask.php @@ -6,70 +6,46 @@ use Illuminate\Support\Facades\Http; use App\Classes\Exceptions\MalformedRequestException; use Illuminate\Support\Facades\Log; use App\Classes\ValueObjects\Constants\PerfexCRMCustomFields; +use App\Classes\Modules\PerfexCRM\DataTransferObjects\CreateTaskPerfexCRMObject; class CreatesPerfexCRMTask { /** - * @param string $taskName - * @param string $taskDescription - * @param string $leadId - * @param string $milestoneId - * @param string $projectId - * @param string $reference - * @param string $on_task_completion - * @param string $department - * @param string $status - * @param string $priority - * @param string $duedate - * @param int $invoiceId + * @param CreateTaskPerfexCRMObject $createTaskPerfexCRMObject * @return null|object * @throws MalformedRequestException */ - public function execute(string $taskName, string $taskDescription, string $leadId, string $milestoneId, string $projectId, string $reference, string $on_task_completion, string $department, string $status, string $priority, string $duedate, int $invoiceId) { + public function execute(CreateTaskPerfexCRMObject $createTaskPerfexCRMObject) { try{ $custom_fields = []; - if($department != ""){ + if($createTaskPerfexCRMObject->getDepartment() != ""){ $custom_fields = [ "tasks" => [ - PerfexCRMCustomFields::TASKS_DEPARTMENT => $department + PerfexCRMCustomFields::TASKS_DEPARTMENT => $createTaskPerfexCRMObject->getDepartment() ] ]; } $data = [ - 'name' => $taskName, - 'description' => $taskDescription, - 'milestone' => $milestoneId, + 'name' => $createTaskPerfexCRMObject->getName(), + 'description' => $createTaskPerfexCRMObject->getDescription(), + 'milestone' => $createTaskPerfexCRMObject->getMilestoneId(), 'startdate' => date('Y-m-d'), 'rel_type' => 'project', - 'rel_id' => $projectId, - 'status' => $status, + 'rel_id' => $createTaskPerfexCRMObject->getProjectId(), + 'status' => $createTaskPerfexCRMObject->getStatus(), 'is_system_created' => 1, - 'reference' => $reference, - 'on_task_completion' => $on_task_completion, + 'reference' => $createTaskPerfexCRMObject->getReference(), + 'on_task_completion' => $createTaskPerfexCRMObject->getOnTaskCompletion(), 'custom_fields' => $custom_fields, - 'priority' => $priority, - 'duedate' => date('Y-m-d', strtotime('+' . $duedate . ' days')), - 'invoice_id' => $invoiceId, + 'priority' => $createTaskPerfexCRMObject->getPriority(), + 'duedate' => date('Y-m-d', strtotime('+' . $createTaskPerfexCRMObject->getDuedate() . ' days')), + 'invoice_id' => $createTaskPerfexCRMObject->getInvoiceId(), ]; - if($leadId != '') { - $data = [ - 'name' => $taskName, - 'description' => $taskDescription, - 'milestone' => $milestoneId, - 'startdate' => date('Y-m-d'), - 'rel_type' => 'lead', - 'rel_id' => $leadId, - 'status' => $status, - 'is_system_created' => 1, - 'reference' => $reference, - 'on_task_completion' => $on_task_completion, - 'custom_fields' => $custom_fields, - 'priority' => $priority, - 'duedate' => date('Y-m-d', strtotime('+' . $duedate . ' days')), - 'invoice_id' => 0 - ]; + if($createTaskPerfexCRMObject->getLeadId() != '') { + $data['rel_type'] = 'lead'; + $data['rel_id'] = $createTaskPerfexCRMObject->getLeadId(); } $response = Http::asForm()->withHeaders([ From fd3aacd2c069957e21410b47f2195f7e56b888bc Mon Sep 17 00:00:00 2001 From: Dillon Date: Sat, 5 Aug 2023 00:13:21 +0800 Subject: [PATCH 03/52] Fix error from production logs --- app/Classes/Jobs/UpdatePerfexCRM.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/Classes/Jobs/UpdatePerfexCRM.php b/app/Classes/Jobs/UpdatePerfexCRM.php index 83e91df4..65d40126 100644 --- a/app/Classes/Jobs/UpdatePerfexCRM.php +++ b/app/Classes/Jobs/UpdatePerfexCRM.php @@ -26,28 +26,30 @@ class UpdatePerfexCRM implements ShouldQueue private $transaction; /** @var Boolean|null */ - private $shouldCreateInvoiceWithPayment; + private $shouldCreateInvoice; /** * @param UpdatePerfexCRMObject $updatePerfexCRMObject * @param $transaction - * @param bool|null $shouldCreateInvoiceWithPayment + * @param bool|null $shouldCreateInvoice */ - public function __construct(UpdatePerfexCRMObject $updatePerfexCRMObject, $transaction, ?bool $shouldCreateInvoiceWithPayment = false) + public function __construct(UpdatePerfexCRMObject $updatePerfexCRMObject, $transaction, ?bool $shouldCreateInvoice = false) { $this->updatePerfexCRMObject = $updatePerfexCRMObject; $this->transaction = $transaction; - $this->shouldCreateInvoiceWithPayment = $shouldCreateInvoiceWithPayment; + $this->shouldCreateInvoice = $shouldCreateInvoice; } public function handle() { //To use invoice as a reference to decide whether more tasks should be created - $this->updatePerfexCRMObject->setInvoiceId($this->getInvoiceIdOrCreateInvoice()); + if($this->transaction != null && $this->shouldCreateInvoice){ + $this->updatePerfexCRMObject->setInvoiceId($this->getInvoiceIdOrCreateInvoice()); + } $result = (App()->make(UpdatePerfexCRMProcessor::class))->execute($this->updatePerfexCRMObject); - if($this->transaction != null && $this->shouldCreateInvoiceWithPayment){ + if($this->transaction != null && $this->shouldCreateInvoice){ $updatePerfexCRMInvoiceObject = new UpdatePerfexCRMInvoiceObject( $this->updatePerfexCRMObject->getContactEmail(), $this->updatePerfexCRMObject->getProjectName(), From edfec118fe943ad4bc339614e592eb0c60cabe2c Mon Sep 17 00:00:00 2001 From: Dillon Date: Sat, 5 Aug 2023 00:36:18 +0800 Subject: [PATCH 04/52] Fix error from production logs --- app/Classes/Jobs/UpdatePerfexCRM.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Classes/Jobs/UpdatePerfexCRM.php b/app/Classes/Jobs/UpdatePerfexCRM.php index 65d40126..cbb65228 100644 --- a/app/Classes/Jobs/UpdatePerfexCRM.php +++ b/app/Classes/Jobs/UpdatePerfexCRM.php @@ -14,6 +14,7 @@ use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMInvoiceObje use App\Classes\Modules\PerfexCRM\DataTransferObjects\FetchPerfexCRMInvoiceObject; use Illuminate\Support\Facades\Log; use PhpOffice\PhpSpreadsheet\Calculation\Logical\Boolean; +use App\Classes\ValueObjects\Constants\TransactionType; class UpdatePerfexCRM implements ShouldQueue { @@ -44,7 +45,7 @@ class UpdatePerfexCRM implements ShouldQueue public function handle() { //To use invoice as a reference to decide whether more tasks should be created - if($this->transaction != null && $this->shouldCreateInvoice){ + if($this->transaction != null && $this->transaction->type === TransactionType::PAYMENT){ $this->updatePerfexCRMObject->setInvoiceId($this->getInvoiceIdOrCreateInvoice()); } From bea8180e200a0b04ba5d89c4dfc091bebe51067c Mon Sep 17 00:00:00 2001 From: Dillon Date: Sat, 5 Aug 2023 00:44:11 +0800 Subject: [PATCH 05/52] Fix error from production logs --- app/Classes/Jobs/UpdatePerfexCRM.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/Classes/Jobs/UpdatePerfexCRM.php b/app/Classes/Jobs/UpdatePerfexCRM.php index cbb65228..9f598c34 100644 --- a/app/Classes/Jobs/UpdatePerfexCRM.php +++ b/app/Classes/Jobs/UpdatePerfexCRM.php @@ -45,9 +45,7 @@ class UpdatePerfexCRM implements ShouldQueue public function handle() { //To use invoice as a reference to decide whether more tasks should be created - if($this->transaction != null && $this->transaction->type === TransactionType::PAYMENT){ - $this->updatePerfexCRMObject->setInvoiceId($this->getInvoiceIdOrCreateInvoice()); - } + $this->updatePerfexCRMObject->setInvoiceId($this->getInvoiceIdOrCreateInvoice()); $result = (App()->make(UpdatePerfexCRMProcessor::class))->execute($this->updatePerfexCRMObject); if($this->transaction != null && $this->shouldCreateInvoice){ @@ -63,7 +61,7 @@ class UpdatePerfexCRM implements ShouldQueue } private function getInvoiceIdOrCreateInvoice(){ - if($this->transaction != null){ + if($this->transaction != null && $this->transaction->type !== TransactionType::PURCHASE_ORDER){ $fetchPerfexCRMInvoiceObject = new FetchPerfexCRMInvoiceObject( $this->updatePerfexCRMObject->getContactEmail(), $this->transaction From 818672bbf5ca54af837e2ef03bfcccbd0d46c8e8 Mon Sep 17 00:00:00 2001 From: Dillon Date: Sat, 5 Aug 2023 01:31:15 +0800 Subject: [PATCH 06/52] Fix error from production logs --- app/Classes/Jobs/UpdatePerfexCRM.php | 2 +- app/Classes/Jobs/UpdatePerfexCRMInvoice.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Classes/Jobs/UpdatePerfexCRM.php b/app/Classes/Jobs/UpdatePerfexCRM.php index 9f598c34..51ec264f 100644 --- a/app/Classes/Jobs/UpdatePerfexCRM.php +++ b/app/Classes/Jobs/UpdatePerfexCRM.php @@ -61,7 +61,7 @@ class UpdatePerfexCRM implements ShouldQueue } private function getInvoiceIdOrCreateInvoice(){ - if($this->transaction != null && $this->transaction->type !== TransactionType::PURCHASE_ORDER){ + if($this->transaction != null){ $fetchPerfexCRMInvoiceObject = new FetchPerfexCRMInvoiceObject( $this->updatePerfexCRMObject->getContactEmail(), $this->transaction diff --git a/app/Classes/Jobs/UpdatePerfexCRMInvoice.php b/app/Classes/Jobs/UpdatePerfexCRMInvoice.php index e9094f84..422dabb3 100644 --- a/app/Classes/Jobs/UpdatePerfexCRMInvoice.php +++ b/app/Classes/Jobs/UpdatePerfexCRMInvoice.php @@ -60,7 +60,7 @@ class UpdatePerfexCRMInvoice implements ShouldQueue Log::error(json_encode('UpdatePerfexCRMInvoice debug $number: '.$number)); if(is_null($invoice)){ - $result = (App()->make(CreatePerfexCRMInvoiceProcessor::class))->execute($transaction, null, null, $this->updatePerfexCRMInvoiceObject->getIsPaid()); + $result = (App()->make(CreatePerfexCRMInvoiceProcessor::class))->execute($transaction, null, null); if ($result) { $invoiceId = $result->payload['id']; } else { From 96aed6b8f4949b4c8ce4dc29bad48efd15763103 Mon Sep 17 00:00:00 2001 From: Dillon Date: Sat, 5 Aug 2023 02:48:11 +0800 Subject: [PATCH 07/52] Fix error from production logs --- .../Processors/CreatePerfexCRMTaskProcessor.php | 15 +-------------- .../Processors/UpdatePerfexCRMProcessor.php | 11 ++++++++--- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/app/Classes/Modules/PerfexCRM/Processors/CreatePerfexCRMTaskProcessor.php b/app/Classes/Modules/PerfexCRM/Processors/CreatePerfexCRMTaskProcessor.php index 4aa5a089..efd6df0e 100644 --- a/app/Classes/Modules/PerfexCRM/Processors/CreatePerfexCRMTaskProcessor.php +++ b/app/Classes/Modules/PerfexCRM/Processors/CreatePerfexCRMTaskProcessor.php @@ -25,20 +25,7 @@ class CreatePerfexCRMTaskProcessor * @throws \App\Classes\Exceptions\MalformedRequestException */ public function execute(CreateTaskPerfexCRMObject $createTaskPerfexCRMObject) { - $this->createsPerfexCRMTask->execute( - $createTaskPerfexCRMObject->getName(), - $createTaskPerfexCRMObject->getDescription(), - $createTaskPerfexCRMObject->getLeadId(), - $createTaskPerfexCRMObject->getMilestoneId(), - $createTaskPerfexCRMObject->getProjectId(), - $createTaskPerfexCRMObject->getReference(), - $createTaskPerfexCRMObject->getOnTaskCompletion(), - $createTaskPerfexCRMObject->getDepartment(), - $createTaskPerfexCRMObject->getStatus(), - $createTaskPerfexCRMObject->getPriority(), - $createTaskPerfexCRMObject->getDuedate(), - $createTaskPerfexCRMObject->getInvoiceId(), - ); + $this->createsPerfexCRMTask->execute($createTaskPerfexCRMObject); return true; } diff --git a/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php b/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php index 5552edd9..1852eb72 100644 --- a/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php +++ b/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php @@ -203,10 +203,15 @@ class UpdatePerfexCRMProcessor } // Get existing or create task - $taskName = $tasks[$count]['name'];; + $taskName = $tasks[$count]['name']; + $taskReference = $tasks[$count]['reference']; + $taskOnTaskCompletion = $tasks[$count]['on_task_completion']; if($updatePerfexCRMObject->getInvoiceId() != 0){ $taskName = $taskName." (".$updatePerfexCRMObject->getInvoiceId().")"; + $taskReference = $taskReference."_".$updatePerfexCRMObject->getInvoiceId(); + $taskOnTaskCompletion = $taskOnTaskCompletion."_".$updatePerfexCRMObject->getInvoiceId(); } + $result = $this->fetchesPerfexCRMTask->execute($taskName, $milestoneId, 'project', $projectId, $updatePerfexCRMObject->getInvoiceId()); // Log::info("UpdatePerfexCRMProcessor task: ".json_encode($taskStatus)." , ".json_encode($result)); @@ -226,8 +231,8 @@ class UpdatePerfexCRMProcessor "", $projectId, $milestoneId, - $tasks[$count]['reference'], - $tasks[$count]['on_task_completion'], + $taskReference, + $taskOnTaskCompletion, $taskStatus, $tasks[$count]['department'], $tasks[$count]['priority'], From 0d2ecffd8ca7f07483dc8e786b9a4e3fe808d1d9 Mon Sep 17 00:00:00 2001 From: Dillon Date: Sat, 5 Aug 2023 03:16:27 +0800 Subject: [PATCH 08/52] Fix error from production logs --- .../Processors/TransactionToPerfexCRMProcessorV2.php | 12 ++++++------ .../Processors/UpdatePerfexCRMProcessor.php | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/Classes/Modules/PerfexCRM/Processors/TransactionToPerfexCRMProcessorV2.php b/app/Classes/Modules/PerfexCRM/Processors/TransactionToPerfexCRMProcessorV2.php index 7ec712c6..bc747720 100644 --- a/app/Classes/Modules/PerfexCRM/Processors/TransactionToPerfexCRMProcessorV2.php +++ b/app/Classes/Modules/PerfexCRM/Processors/TransactionToPerfexCRMProcessorV2.php @@ -162,12 +162,12 @@ class TransactionToPerfexCRMProcessorV2 $tasks = array_merge($tasks, $this->payment1688Tasks()); } - if ($model->owner->service_id === 1 || $model->owner->service_id === 3) { - $purchaseOrder = $model->booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->complete()->first(); - if(is_null($purchaseOrder)){ - $tasks = array_merge($tasks, $this->purchaseOrderTasks()); - } - } + // if ($model->owner->service_id === 1 || $model->owner->service_id === 3) { + // $purchaseOrder = $model->booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->complete()->first(); + // if(is_null($purchaseOrder)){ + // $tasks = array_merge($tasks, $this->purchaseOrderTasks()); + // } + // } return $tasks; } diff --git a/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php b/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php index 1852eb72..127b712f 100644 --- a/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php +++ b/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php @@ -209,7 +209,9 @@ class UpdatePerfexCRMProcessor if($updatePerfexCRMObject->getInvoiceId() != 0){ $taskName = $taskName." (".$updatePerfexCRMObject->getInvoiceId().")"; $taskReference = $taskReference."_".$updatePerfexCRMObject->getInvoiceId(); - $taskOnTaskCompletion = $taskOnTaskCompletion."_".$updatePerfexCRMObject->getInvoiceId(); + if($taskOnTaskCompletion){ + $taskOnTaskCompletion = $taskOnTaskCompletion."_".$updatePerfexCRMObject->getInvoiceId(); + } } $result = $this->fetchesPerfexCRMTask->execute($taskName, $milestoneId, 'project', $projectId, $updatePerfexCRMObject->getInvoiceId()); From 3be1854fce50680fba178a8f0e738aad2dab7aeb Mon Sep 17 00:00:00 2001 From: Dillon Date: Sat, 5 Aug 2023 20:39:04 +0800 Subject: [PATCH 09/52] Fix error from production logs --- app/Classes/Jobs/CreatePerfexCRMInvoice.php | 14 ++------------ app/Classes/Jobs/UpdatePerfexCRMInvoice.php | 2 +- .../Processors/CreatePerfexCRMInvoiceProcessor.php | 13 +++---------- .../Processors/FetchPerfexCRMInvoiceProcessor.php | 2 +- 4 files changed, 7 insertions(+), 24 deletions(-) diff --git a/app/Classes/Jobs/CreatePerfexCRMInvoice.php b/app/Classes/Jobs/CreatePerfexCRMInvoice.php index a6905be4..7246dc79 100644 --- a/app/Classes/Jobs/CreatePerfexCRMInvoice.php +++ b/app/Classes/Jobs/CreatePerfexCRMInvoice.php @@ -16,27 +16,17 @@ class CreatePerfexCRMInvoice implements ShouldQueue /** @var $transaction*/ private $transaction; - /** @var $purchaseOrder*/ - private $purchaseOrder; - - /** @var $supplier*/ - private $supplier; - /** * CreatePerfexCRMInvoice constructor. * @param $transaction - * @param $purchaseOrder - * @param $supplier */ - public function __construct($transaction, $purchaseOrder, $supplier) + public function __construct($transaction) { $this->transaction = $transaction; - $this->purchaseOrder = $purchaseOrder; - $this->supplier = $supplier; } public function handle() { - (App()->make(CreatePerfexCRMInvoiceProcessor::class))->execute($this->transaction, $this->purchaseOrder, $this->supplier); + (App()->make(CreatePerfexCRMInvoiceProcessor::class))->execute($this->transaction); } } diff --git a/app/Classes/Jobs/UpdatePerfexCRMInvoice.php b/app/Classes/Jobs/UpdatePerfexCRMInvoice.php index 422dabb3..26131bca 100644 --- a/app/Classes/Jobs/UpdatePerfexCRMInvoice.php +++ b/app/Classes/Jobs/UpdatePerfexCRMInvoice.php @@ -60,7 +60,7 @@ class UpdatePerfexCRMInvoice implements ShouldQueue Log::error(json_encode('UpdatePerfexCRMInvoice debug $number: '.$number)); if(is_null($invoice)){ - $result = (App()->make(CreatePerfexCRMInvoiceProcessor::class))->execute($transaction, null, null); + $result = (App()->make(CreatePerfexCRMInvoiceProcessor::class))->execute($transaction); if ($result) { $invoiceId = $result->payload['id']; } else { diff --git a/app/Classes/Modules/PerfexCRM/Processors/CreatePerfexCRMInvoiceProcessor.php b/app/Classes/Modules/PerfexCRM/Processors/CreatePerfexCRMInvoiceProcessor.php index 2b6a557d..4edb2ef5 100644 --- a/app/Classes/Modules/PerfexCRM/Processors/CreatePerfexCRMInvoiceProcessor.php +++ b/app/Classes/Modules/PerfexCRM/Processors/CreatePerfexCRMInvoiceProcessor.php @@ -59,23 +59,16 @@ class CreatePerfexCRMInvoiceProcessor /** * @param $transaction - * @param $purchaseOrder - * @param $supplier * @return null|object * @throws \App\Classes\Exceptions\MalformedRequestException */ - public function execute($transaction, $purchaseOrder, $supplier) { + public function execute($transaction) { $booking = $transaction->booking; - - if(is_null($supplier)){ - $supplier = $this->fetchesCompany->execute(['id' => $transaction->receiver]); - } - if(is_null($purchaseOrder)){ - $purchaseOrder = $booking->transactions() + $supplier = $this->fetchesCompany->execute(['id' => $transaction->receiver]); + $purchaseOrder = $booking->transactions() ->where('type', TransactionType::PURCHASE_ORDER) ->complete() ->first(); - } $clientId = ""; $number = $transaction->bill_no; diff --git a/app/Classes/Modules/PerfexCRM/Processors/FetchPerfexCRMInvoiceProcessor.php b/app/Classes/Modules/PerfexCRM/Processors/FetchPerfexCRMInvoiceProcessor.php index 28ee70a7..4c8ee9bf 100644 --- a/app/Classes/Modules/PerfexCRM/Processors/FetchPerfexCRMInvoiceProcessor.php +++ b/app/Classes/Modules/PerfexCRM/Processors/FetchPerfexCRMInvoiceProcessor.php @@ -57,7 +57,7 @@ class FetchPerfexCRMInvoiceProcessor $number = 'EXC-'.$number; $invoice = $this->fetchesPerfexCRMInvoice->execute($customer->userid,"INV-", $number); if(is_null($invoice)){ - $result = $this->createPerfexCRMInvoiceProcessor->execute($transaction, null, null); + $result = $this->createPerfexCRMInvoiceProcessor->execute($transaction); if ($result) { $invoiceId = $result->payload['id']; } else { From 79affd81f92588d44e3ee28ea21b6a40b90ae6fd Mon Sep 17 00:00:00 2001 From: Dillon Date: Sat, 5 Aug 2023 21:01:21 +0800 Subject: [PATCH 10/52] Fix error from production logs --- .../Processors/UpdatePerfexCRMProcessor.php | 3 +- .../ValueObjects/Constants/PerfexCRMTasks.php | 96 ++++++++++++------- 2 files changed, 66 insertions(+), 33 deletions(-) diff --git a/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php b/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php index 127b712f..4355956a 100644 --- a/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php +++ b/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php @@ -206,7 +206,8 @@ class UpdatePerfexCRMProcessor $taskName = $tasks[$count]['name']; $taskReference = $tasks[$count]['reference']; $taskOnTaskCompletion = $tasks[$count]['on_task_completion']; - if($updatePerfexCRMObject->getInvoiceId() != 0){ + $taskIsAllowMultiple = $tasks[$count]['is_allow_multiple']; + if($updatePerfexCRMObject->getInvoiceId() != 0 && $taskIsAllowMultiple){ $taskName = $taskName." (".$updatePerfexCRMObject->getInvoiceId().")"; $taskReference = $taskReference."_".$updatePerfexCRMObject->getInvoiceId(); if($taskOnTaskCompletion){ diff --git a/app/Classes/ValueObjects/Constants/PerfexCRMTasks.php b/app/Classes/ValueObjects/Constants/PerfexCRMTasks.php index 4129f2a8..c0bc66d7 100644 --- a/app/Classes/ValueObjects/Constants/PerfexCRMTasks.php +++ b/app/Classes/ValueObjects/Constants/PerfexCRMTasks.php @@ -13,7 +13,8 @@ class PerfexCRMTasks 'department' => '', 'status' => PerfexCRMTaskStatus::COMPLETED, 'priority' => PerfexCRMTaskPriority::DEFAULT, - 'duedate' => 0 + 'duedate' => 0, + 'is_allow_multiple' => false ]; public const TASK_1_DAY_TRANSFER_1 = [ @@ -27,7 +28,8 @@ class PerfexCRMTasks 'department' => 'Accounts', 'status' => PerfexCRMTaskStatus::IN_PROGRESS, 'priority' => PerfexCRMTaskPriority::HIGH, - 'duedate' => 0 + 'duedate' => 0, + 'is_allow_multiple' => false ]; public const TASK_1_DAY_TRANSFER_2 = [ 'name' => 'Approve Payment', @@ -47,7 +49,8 @@ class PerfexCRMTasks 'department' => 'Accounts', 'status' => PerfexCRMTaskStatus::IN_PROGRESS, 'priority' => PerfexCRMTaskPriority::HIGH, - 'duedate' => 0 + 'duedate' => 0, + 'is_allow_multiple' => true ]; public const TASK_1_DAY_TRANSFER_3 = [ 'name' => 'Issue Exchange Autocount Invoince', @@ -65,7 +68,8 @@ class PerfexCRMTasks 'department' => 'Accounts', 'status' => '', 'priority' => PerfexCRMTaskPriority::MEDIUM, - 'duedate' => 1 + 'duedate' => 1, + 'is_allow_multiple' => false ]; public const TASK_1_DAY_TRANSFER_3_1 = [ 'name' => 'Issue Exchange Autocount OR', @@ -76,7 +80,8 @@ class PerfexCRMTasks 'department' => 'Accounts', 'status' => '', 'priority' => PerfexCRMTaskPriority::DEFAULT, - 'duedate' => 0 + 'duedate' => 0, + 'is_allow_multiple' => false ]; public const TASK_1_DAY_TRANSFER_4 = [ 'name' => 'Knockoff Invoice', @@ -94,7 +99,8 @@ class PerfexCRMTasks 'department' => 'Accounts', 'status' => '', 'priority' => PerfexCRMTaskPriority::MEDIUM, - 'duedate' => 1 + 'duedate' => 1, + 'is_allow_multiple' => false ]; public const TASK_1_DAY_TRANSFER_5 = [ 'name' => 'Order Placed in White Form', @@ -114,7 +120,8 @@ class PerfexCRMTasks 'department' => 'Operations', 'status' => '', 'priority' => PerfexCRMTaskPriority::HIGH, - 'duedate' => 0 + 'duedate' => 0, + 'is_allow_multiple' => true ]; public const TASK_1_DAY_TRANSFER_6 = [ 'name' => 'Upload China Bank Slip', @@ -132,7 +139,8 @@ class PerfexCRMTasks 'department' => 'Operations', 'status' => '', 'priority' => PerfexCRMTaskPriority::MEDIUM, - 'duedate' => 1 + 'duedate' => 1, + 'is_allow_multiple' => true ]; public const TASK_3_DAY_TRANSFER_1 = [ @@ -151,7 +159,8 @@ class PerfexCRMTasks 'department' => 'Accounts', 'status' => PerfexCRMTaskStatus::IN_PROGRESS, 'priority' => PerfexCRMTaskPriority::HIGH, - 'duedate' => 0 + 'duedate' => 0, + 'is_allow_multiple' => false ]; public const TASK_3_DAY_TRANSFER_2 = [ 'name' => 'Approve Payment', @@ -164,7 +173,8 @@ class PerfexCRMTasks 'department' => 'Accounts', 'status' => PerfexCRMTaskStatus::IN_PROGRESS, 'priority' => PerfexCRMTaskPriority::HIGH, - 'duedate' => 0 + 'duedate' => 0, + 'is_allow_multiple' => true ]; public const TASK_3_DAY_TRANSFER_3 = [ 'name' => 'Issue Exchange Autocount Invoince', @@ -182,7 +192,8 @@ class PerfexCRMTasks 'department' => 'Accounts', 'status' => '', 'priority' => PerfexCRMTaskPriority::MEDIUM, - 'duedate' => 1 + 'duedate' => 1, + 'is_allow_multiple' => false ]; public const TASK_3_DAY_TRANSFER_3_1 = [ 'name' => 'Issue Exchange Autocount OR', @@ -193,7 +204,8 @@ class PerfexCRMTasks 'department' => 'Accounts', 'status' => '', 'priority' => PerfexCRMTaskPriority::DEFAULT, - 'duedate' => 0 + 'duedate' => 0, + 'is_allow_multiple' => false ]; public const TASK_3_DAY_TRANSFER_4 = [ 'name' => 'Knockoff Invoice', @@ -211,7 +223,8 @@ class PerfexCRMTasks 'department' => 'Accounts', 'status' => '', 'priority' => PerfexCRMTaskPriority::MEDIUM, - 'duedate' => 1 + 'duedate' => 1, + 'is_allow_multiple' => false ]; public const TASK_3_DAY_TRANSFER_5 = [ 'name' => 'Order Placed in White Form', @@ -231,7 +244,8 @@ class PerfexCRMTasks 'department' => 'Operations', 'status' => '', 'priority' => PerfexCRMTaskPriority::HIGH, - 'duedate' => 0 + 'duedate' => 0, + 'is_allow_multiple' => true ]; public const TASK_3_DAY_TRANSFER_6 = [ 'name' => 'Upload China Bank Slip', @@ -249,7 +263,8 @@ class PerfexCRMTasks 'department' => 'Operations', 'status' => '', 'priority' => PerfexCRMTaskPriority::MEDIUM, - 'duedate' => 1 + 'duedate' => 1, + 'is_allow_multiple' => true ]; @@ -270,7 +285,8 @@ class PerfexCRMTasks 'department' => 'Accounts', 'status' => PerfexCRMTaskStatus::IN_PROGRESS, 'priority' => PerfexCRMTaskPriority::HIGH, - 'duedate' => 0 + 'duedate' => 0, + 'is_allow_multiple' => false ]; public const TASK_1688_PAYMENT_2 = [ 'name' => 'Approve Payment', @@ -290,7 +306,8 @@ class PerfexCRMTasks 'department' => 'Accounts', 'status' => PerfexCRMTaskStatus::IN_PROGRESS, 'priority' => PerfexCRMTaskPriority::HIGH, - 'duedate' => 0 + 'duedate' => 0, + 'is_allow_multiple' => false ]; public const TASK_1688_PAYMENT_3 = [ 'name' => 'Issue Exchange Autocount Invoice', @@ -308,7 +325,8 @@ class PerfexCRMTasks 'department' => 'Accounts', 'status' => '', 'priority' => PerfexCRMTaskPriority::MEDIUM, - 'duedate' => 1 + 'duedate' => 1, + 'is_allow_multiple' => false ]; public const TASK_1688_PAYMENT_3_1 = [ 'name' => 'Issue Exchange Autocount OR', @@ -320,7 +338,8 @@ class PerfexCRMTasks 'department' => 'Accounts', 'status' => '', 'priority' => PerfexCRMTaskPriority::DEFAULT, - 'duedate' => 0 + 'duedate' => 0, + 'is_allow_multiple' => false ]; public const TASK_1688_PAYMENT_4 = [ 'name' => 'Knockoff Invoice', @@ -338,7 +357,8 @@ class PerfexCRMTasks 'department' => 'Accounts', 'status' => '', 'priority' => PerfexCRMTaskPriority::MEDIUM, - 'duedate' => 1 + 'duedate' => 1, + 'is_allow_multiple' => false ]; public const TASK_1688_PAYMENT_5 = [ 'name' => 'Order Placed in White Form', @@ -357,7 +377,8 @@ class PerfexCRMTasks 'department' => 'Operations', 'status' => '', 'priority' => PerfexCRMTaskPriority::HIGH, - 'duedate' => 0 + 'duedate' => 0, + 'is_allow_multiple' => false ]; public const TASK_1688_PAYMENT_6 = [ 'name' => 'Send White Form to Operation Department', @@ -375,7 +396,8 @@ class PerfexCRMTasks 'department' => 'Operations', 'status' => '', 'priority' => PerfexCRMTaskPriority::DEFAULT, - 'duedate' => 0 + 'duedate' => 0, + 'is_allow_multiple' => false ]; public const TASK_1688_PAYMENT_7 = [ 'name' => 'Authorize Customer\'s 1688 Account', @@ -395,7 +417,8 @@ class PerfexCRMTasks 'department' => 'Operations', 'status' => '', 'priority' => PerfexCRMTaskPriority::HIGH, - 'duedate' => 1 + 'duedate' => 1, + 'is_allow_multiple' => true ]; public const TASK_1688_PAYMENT_8 = [ 'name' => 'Make Payment for Customer 1688 Order', @@ -410,7 +433,8 @@ class PerfexCRMTasks 'department' => 'Operations', 'status' => '', 'priority' => PerfexCRMTaskPriority::HIGH, - 'duedate' => 1 + 'duedate' => 1, + 'is_allow_multiple' => true ]; public const TASK_1688_PAYMENT_9 = [ 'name' => 'Upload China Bank Slip', @@ -422,7 +446,8 @@ class PerfexCRMTasks 'department' => 'Operations', 'status' => '', 'priority' => PerfexCRMTaskPriority::MEDIUM, - 'duedate' => 1 + 'duedate' => 1, + 'is_allow_multiple' => true ]; public const TASK_1688_PAYMENT_10 = [ 'name' => 'Upload 1688 Purchase Order PDF', @@ -434,7 +459,8 @@ class PerfexCRMTasks 'department' => 'Operations', 'status' => '', 'priority' => PerfexCRMTaskPriority::MEDIUM, - 'duedate' => 1 + 'duedate' => 1, + 'is_allow_multiple' => true ]; public const TASK_1688_PAYMENT_11 = [ 'name' => 'Fill Up Purchase Order', @@ -446,7 +472,8 @@ class PerfexCRMTasks 'department' => 'Operations', 'status' => '', 'priority' => PerfexCRMTaskPriority::LOW, - 'duedate' => 7 + 'duedate' => 7, + 'is_allow_multiple' => false ]; public const TASK_1688_PAYMENT_12 = [ 'name' => 'Approve Purchase Order', @@ -458,7 +485,8 @@ class PerfexCRMTasks 'department' => 'Operations', 'status' => '', 'priority' => PerfexCRMTaskPriority::LOW, - 'duedate' => 1 + 'duedate' => 1, + 'is_allow_multiple' => false ]; public const TASK_1688_PAYMENT_13 = [ 'name' => 'Complete Order bookkeeping', @@ -476,7 +504,8 @@ class PerfexCRMTasks 'department' => 'Operations', 'status' => '', 'priority' => PerfexCRMTaskPriority::DEFAULT, - 'duedate' => 0 + 'duedate' => 0, + 'is_allow_multiple' => false ]; @@ -497,7 +526,8 @@ class PerfexCRMTasks 'department' => 'Operations', 'status' => PerfexCRMTaskStatus::IN_PROGRESS, 'priority' => PerfexCRMTaskPriority::LOW, - 'duedate' => 1 + 'duedate' => 1, + 'is_allow_multiple' => false ]; public const TASK_PURCHASE_ORDER_2 = [ @@ -510,7 +540,8 @@ class PerfexCRMTasks 'department' => 'Accounts', 'status' => '', 'priority' => PerfexCRMTaskPriority::DEFAULT, - 'duedate' => 0 + 'duedate' => 0, + 'is_allow_multiple' => false ]; @@ -530,6 +561,7 @@ class PerfexCRMTasks 'department' => 'Operations', 'status' => PerfexCRMTaskStatus::IN_PROGRESS, 'priority' => PerfexCRMTaskPriority::DEFAULT, - 'duedate' => 0 + 'duedate' => 0, + 'is_allow_multiple' => false ]; } From 21c4508647dfd84b2ff83d7af95dfab5957b160f Mon Sep 17 00:00:00 2001 From: Dillon Date: Sat, 5 Aug 2023 21:20:56 +0800 Subject: [PATCH 11/52] Fix error from production logs --- .../Processors/UpdatePerfexCRMProcessor.php | 3 +- .../ValueObjects/Constants/PerfexCRMTasks.php | 96 ++++++++++++------- 2 files changed, 66 insertions(+), 33 deletions(-) diff --git a/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php b/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php index 4355956a..51e04388 100644 --- a/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php +++ b/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php @@ -207,10 +207,11 @@ class UpdatePerfexCRMProcessor $taskReference = $tasks[$count]['reference']; $taskOnTaskCompletion = $tasks[$count]['on_task_completion']; $taskIsAllowMultiple = $tasks[$count]['is_allow_multiple']; + $taskIsOnTaskCompletionUpdate = $tasks[$count]['is_on_task_completion_update']; if($updatePerfexCRMObject->getInvoiceId() != 0 && $taskIsAllowMultiple){ $taskName = $taskName." (".$updatePerfexCRMObject->getInvoiceId().")"; $taskReference = $taskReference."_".$updatePerfexCRMObject->getInvoiceId(); - if($taskOnTaskCompletion){ + if($taskOnTaskCompletion && $taskIsOnTaskCompletionUpdate){ $taskOnTaskCompletion = $taskOnTaskCompletion."_".$updatePerfexCRMObject->getInvoiceId(); } } diff --git a/app/Classes/ValueObjects/Constants/PerfexCRMTasks.php b/app/Classes/ValueObjects/Constants/PerfexCRMTasks.php index c0bc66d7..1d26c9d3 100644 --- a/app/Classes/ValueObjects/Constants/PerfexCRMTasks.php +++ b/app/Classes/ValueObjects/Constants/PerfexCRMTasks.php @@ -14,7 +14,8 @@ class PerfexCRMTasks 'status' => PerfexCRMTaskStatus::COMPLETED, 'priority' => PerfexCRMTaskPriority::DEFAULT, 'duedate' => 0, - 'is_allow_multiple' => false + 'is_allow_multiple' => false, + 'is_on_task_completion_update' => false ]; public const TASK_1_DAY_TRANSFER_1 = [ @@ -29,7 +30,8 @@ class PerfexCRMTasks 'status' => PerfexCRMTaskStatus::IN_PROGRESS, 'priority' => PerfexCRMTaskPriority::HIGH, 'duedate' => 0, - 'is_allow_multiple' => false + 'is_allow_multiple' => false, + 'is_on_task_completion_update' => false ]; public const TASK_1_DAY_TRANSFER_2 = [ 'name' => 'Approve Payment', @@ -50,7 +52,8 @@ class PerfexCRMTasks 'status' => PerfexCRMTaskStatus::IN_PROGRESS, 'priority' => PerfexCRMTaskPriority::HIGH, 'duedate' => 0, - 'is_allow_multiple' => true + 'is_allow_multiple' => true, + 'is_on_task_completion_update' => true ]; public const TASK_1_DAY_TRANSFER_3 = [ 'name' => 'Issue Exchange Autocount Invoince', @@ -69,7 +72,8 @@ class PerfexCRMTasks 'status' => '', 'priority' => PerfexCRMTaskPriority::MEDIUM, 'duedate' => 1, - 'is_allow_multiple' => false + 'is_allow_multiple' => false, + 'is_on_task_completion_update' => false ]; public const TASK_1_DAY_TRANSFER_3_1 = [ 'name' => 'Issue Exchange Autocount OR', @@ -81,7 +85,8 @@ class PerfexCRMTasks 'status' => '', 'priority' => PerfexCRMTaskPriority::DEFAULT, 'duedate' => 0, - 'is_allow_multiple' => false + 'is_allow_multiple' => false, + 'is_on_task_completion_update' => false ]; public const TASK_1_DAY_TRANSFER_4 = [ 'name' => 'Knockoff Invoice', @@ -100,7 +105,8 @@ class PerfexCRMTasks 'status' => '', 'priority' => PerfexCRMTaskPriority::MEDIUM, 'duedate' => 1, - 'is_allow_multiple' => false + 'is_allow_multiple' => false, + 'is_on_task_completion_update' => false ]; public const TASK_1_DAY_TRANSFER_5 = [ 'name' => 'Order Placed in White Form', @@ -121,7 +127,8 @@ class PerfexCRMTasks 'status' => '', 'priority' => PerfexCRMTaskPriority::HIGH, 'duedate' => 0, - 'is_allow_multiple' => true + 'is_allow_multiple' => true, + 'is_on_task_completion_update' => true ]; public const TASK_1_DAY_TRANSFER_6 = [ 'name' => 'Upload China Bank Slip', @@ -140,7 +147,8 @@ class PerfexCRMTasks 'status' => '', 'priority' => PerfexCRMTaskPriority::MEDIUM, 'duedate' => 1, - 'is_allow_multiple' => true + 'is_allow_multiple' => true, + 'is_on_task_completion_update' => true ]; public const TASK_3_DAY_TRANSFER_1 = [ @@ -160,7 +168,8 @@ class PerfexCRMTasks 'status' => PerfexCRMTaskStatus::IN_PROGRESS, 'priority' => PerfexCRMTaskPriority::HIGH, 'duedate' => 0, - 'is_allow_multiple' => false + 'is_allow_multiple' => false, + 'is_on_task_completion_update' => false ]; public const TASK_3_DAY_TRANSFER_2 = [ 'name' => 'Approve Payment', @@ -174,7 +183,8 @@ class PerfexCRMTasks 'status' => PerfexCRMTaskStatus::IN_PROGRESS, 'priority' => PerfexCRMTaskPriority::HIGH, 'duedate' => 0, - 'is_allow_multiple' => true + 'is_allow_multiple' => true, + 'is_on_task_completion_update' => true ]; public const TASK_3_DAY_TRANSFER_3 = [ 'name' => 'Issue Exchange Autocount Invoince', @@ -193,7 +203,8 @@ class PerfexCRMTasks 'status' => '', 'priority' => PerfexCRMTaskPriority::MEDIUM, 'duedate' => 1, - 'is_allow_multiple' => false + 'is_allow_multiple' => false, + 'is_on_task_completion_update' => false ]; public const TASK_3_DAY_TRANSFER_3_1 = [ 'name' => 'Issue Exchange Autocount OR', @@ -205,7 +216,8 @@ class PerfexCRMTasks 'status' => '', 'priority' => PerfexCRMTaskPriority::DEFAULT, 'duedate' => 0, - 'is_allow_multiple' => false + 'is_allow_multiple' => false, + 'is_on_task_completion_update' => false ]; public const TASK_3_DAY_TRANSFER_4 = [ 'name' => 'Knockoff Invoice', @@ -224,7 +236,8 @@ class PerfexCRMTasks 'status' => '', 'priority' => PerfexCRMTaskPriority::MEDIUM, 'duedate' => 1, - 'is_allow_multiple' => false + 'is_allow_multiple' => false, + 'is_on_task_completion_update' => false ]; public const TASK_3_DAY_TRANSFER_5 = [ 'name' => 'Order Placed in White Form', @@ -245,7 +258,8 @@ class PerfexCRMTasks 'status' => '', 'priority' => PerfexCRMTaskPriority::HIGH, 'duedate' => 0, - 'is_allow_multiple' => true + 'is_allow_multiple' => true, + 'is_on_task_completion_update' => true ]; public const TASK_3_DAY_TRANSFER_6 = [ 'name' => 'Upload China Bank Slip', @@ -264,7 +278,8 @@ class PerfexCRMTasks 'status' => '', 'priority' => PerfexCRMTaskPriority::MEDIUM, 'duedate' => 1, - 'is_allow_multiple' => true + 'is_allow_multiple' => true, + 'is_on_task_completion_update' => true ]; @@ -286,7 +301,8 @@ class PerfexCRMTasks 'status' => PerfexCRMTaskStatus::IN_PROGRESS, 'priority' => PerfexCRMTaskPriority::HIGH, 'duedate' => 0, - 'is_allow_multiple' => false + 'is_allow_multiple' => false, + 'is_on_task_completion_update' => false ]; public const TASK_1688_PAYMENT_2 = [ 'name' => 'Approve Payment', @@ -307,7 +323,8 @@ class PerfexCRMTasks 'status' => PerfexCRMTaskStatus::IN_PROGRESS, 'priority' => PerfexCRMTaskPriority::HIGH, 'duedate' => 0, - 'is_allow_multiple' => false + 'is_allow_multiple' => false, + 'is_on_task_completion_update' => false ]; public const TASK_1688_PAYMENT_3 = [ 'name' => 'Issue Exchange Autocount Invoice', @@ -326,7 +343,8 @@ class PerfexCRMTasks 'status' => '', 'priority' => PerfexCRMTaskPriority::MEDIUM, 'duedate' => 1, - 'is_allow_multiple' => false + 'is_allow_multiple' => false, + 'is_on_task_completion_update' => false ]; public const TASK_1688_PAYMENT_3_1 = [ 'name' => 'Issue Exchange Autocount OR', @@ -339,7 +357,8 @@ class PerfexCRMTasks 'status' => '', 'priority' => PerfexCRMTaskPriority::DEFAULT, 'duedate' => 0, - 'is_allow_multiple' => false + 'is_allow_multiple' => false, + 'is_on_task_completion_update' => false ]; public const TASK_1688_PAYMENT_4 = [ 'name' => 'Knockoff Invoice', @@ -358,7 +377,8 @@ class PerfexCRMTasks 'status' => '', 'priority' => PerfexCRMTaskPriority::MEDIUM, 'duedate' => 1, - 'is_allow_multiple' => false + 'is_allow_multiple' => false, + 'is_on_task_completion_update' => false ]; public const TASK_1688_PAYMENT_5 = [ 'name' => 'Order Placed in White Form', @@ -378,7 +398,8 @@ class PerfexCRMTasks 'status' => '', 'priority' => PerfexCRMTaskPriority::HIGH, 'duedate' => 0, - 'is_allow_multiple' => false + 'is_allow_multiple' => false, + 'is_on_task_completion_update' => false ]; public const TASK_1688_PAYMENT_6 = [ 'name' => 'Send White Form to Operation Department', @@ -397,7 +418,8 @@ class PerfexCRMTasks 'status' => '', 'priority' => PerfexCRMTaskPriority::DEFAULT, 'duedate' => 0, - 'is_allow_multiple' => false + 'is_allow_multiple' => false, + 'is_on_task_completion_update' => false ]; public const TASK_1688_PAYMENT_7 = [ 'name' => 'Authorize Customer\'s 1688 Account', @@ -418,7 +440,8 @@ class PerfexCRMTasks 'status' => '', 'priority' => PerfexCRMTaskPriority::HIGH, 'duedate' => 1, - 'is_allow_multiple' => true + 'is_allow_multiple' => true, + 'is_on_task_completion_update' => true ]; public const TASK_1688_PAYMENT_8 = [ 'name' => 'Make Payment for Customer 1688 Order', @@ -434,7 +457,8 @@ class PerfexCRMTasks 'status' => '', 'priority' => PerfexCRMTaskPriority::HIGH, 'duedate' => 1, - 'is_allow_multiple' => true + 'is_allow_multiple' => true, + 'is_on_task_completion_update' => true ]; public const TASK_1688_PAYMENT_9 = [ 'name' => 'Upload China Bank Slip', @@ -447,7 +471,8 @@ class PerfexCRMTasks 'status' => '', 'priority' => PerfexCRMTaskPriority::MEDIUM, 'duedate' => 1, - 'is_allow_multiple' => true + 'is_allow_multiple' => true, + 'is_on_task_completion_update' => true ]; public const TASK_1688_PAYMENT_10 = [ 'name' => 'Upload 1688 Purchase Order PDF', @@ -460,7 +485,8 @@ class PerfexCRMTasks 'status' => '', 'priority' => PerfexCRMTaskPriority::MEDIUM, 'duedate' => 1, - 'is_allow_multiple' => true + 'is_allow_multiple' => true, + 'is_on_task_completion_update' => false ]; public const TASK_1688_PAYMENT_11 = [ 'name' => 'Fill Up Purchase Order', @@ -473,7 +499,8 @@ class PerfexCRMTasks 'status' => '', 'priority' => PerfexCRMTaskPriority::LOW, 'duedate' => 7, - 'is_allow_multiple' => false + 'is_allow_multiple' => false, + 'is_on_task_completion_update' => false ]; public const TASK_1688_PAYMENT_12 = [ 'name' => 'Approve Purchase Order', @@ -486,7 +513,8 @@ class PerfexCRMTasks 'status' => '', 'priority' => PerfexCRMTaskPriority::LOW, 'duedate' => 1, - 'is_allow_multiple' => false + 'is_allow_multiple' => false, + 'is_on_task_completion_update' => false ]; public const TASK_1688_PAYMENT_13 = [ 'name' => 'Complete Order bookkeeping', @@ -505,7 +533,8 @@ class PerfexCRMTasks 'status' => '', 'priority' => PerfexCRMTaskPriority::DEFAULT, 'duedate' => 0, - 'is_allow_multiple' => false + 'is_allow_multiple' => false, + 'is_on_task_completion_update' => false ]; @@ -527,7 +556,8 @@ class PerfexCRMTasks 'status' => PerfexCRMTaskStatus::IN_PROGRESS, 'priority' => PerfexCRMTaskPriority::LOW, 'duedate' => 1, - 'is_allow_multiple' => false + 'is_allow_multiple' => false, + 'is_on_task_completion_update' => false ]; public const TASK_PURCHASE_ORDER_2 = [ @@ -541,7 +571,8 @@ class PerfexCRMTasks 'status' => '', 'priority' => PerfexCRMTaskPriority::DEFAULT, 'duedate' => 0, - 'is_allow_multiple' => false + 'is_allow_multiple' => false, + 'is_on_task_completion_update' => false ]; @@ -562,6 +593,7 @@ class PerfexCRMTasks 'status' => PerfexCRMTaskStatus::IN_PROGRESS, 'priority' => PerfexCRMTaskPriority::DEFAULT, 'duedate' => 0, - 'is_allow_multiple' => false + 'is_allow_multiple' => false, + 'is_on_task_completion_update' => false ]; } From e2930acd018d1d936a2ebe1ce8a1febc7423ccc9 Mon Sep 17 00:00:00 2001 From: Dillon Date: Sun, 6 Aug 2023 12:14:23 +0800 Subject: [PATCH 12/52] Enabled back previously disabled function meant for CRM task creation --- .../Processors/TransactionToPerfexCRMProcessorV2.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/Classes/Modules/PerfexCRM/Processors/TransactionToPerfexCRMProcessorV2.php b/app/Classes/Modules/PerfexCRM/Processors/TransactionToPerfexCRMProcessorV2.php index bc747720..7ec712c6 100644 --- a/app/Classes/Modules/PerfexCRM/Processors/TransactionToPerfexCRMProcessorV2.php +++ b/app/Classes/Modules/PerfexCRM/Processors/TransactionToPerfexCRMProcessorV2.php @@ -162,12 +162,12 @@ class TransactionToPerfexCRMProcessorV2 $tasks = array_merge($tasks, $this->payment1688Tasks()); } - // if ($model->owner->service_id === 1 || $model->owner->service_id === 3) { - // $purchaseOrder = $model->booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->complete()->first(); - // if(is_null($purchaseOrder)){ - // $tasks = array_merge($tasks, $this->purchaseOrderTasks()); - // } - // } + if ($model->owner->service_id === 1 || $model->owner->service_id === 3) { + $purchaseOrder = $model->booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->complete()->first(); + if(is_null($purchaseOrder)){ + $tasks = array_merge($tasks, $this->purchaseOrderTasks()); + } + } return $tasks; } From 0e67cacf80f7572d293a05dc768d8e86231c40dd Mon Sep 17 00:00:00 2001 From: edmondlang Date: Tue, 8 Aug 2023 19:14:56 +0800 Subject: [PATCH 13/52] make refunded booking expired status --- app/Console/Commands/DeleteOrderCommand.php | 79 +++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 app/Console/Commands/DeleteOrderCommand.php diff --git a/app/Console/Commands/DeleteOrderCommand.php b/app/Console/Commands/DeleteOrderCommand.php new file mode 100644 index 00000000..a4702ff0 --- /dev/null +++ b/app/Console/Commands/DeleteOrderCommand.php @@ -0,0 +1,79 @@ +argument('bookings_reference'); + $bookings_reference = explode(',', $bookings_reference); + + $start = new Carbon(); + $this->logOutput('Process started'); + + foreach ($bookings_reference as $reference) { + $booking = Booking::where('marking', $reference)->first(); + + if (!$booking) { + $this->logOutput('Booking not found: ' . $reference); + } else { + $booking->status = ApprovalStatus::EXPIRED; + $booking->save(); + $this->logOutput('Booking deleted: ' . $reference); + } + } + + $end = new Carbon(); + $elapsedTime = $start->diff($end)->format('%H:%I:%S'); + + $this->logOutput('Process ended. ElapsedTime: ' . $elapsedTime); + } + + public function logOutput($text) + { + if (is_array($text)) { + $text = implode(', ', $text); + } + + $this->info(Carbon::now() . ' : ' . $text); + + $filePath = storage_path('logs/delete-orders.log'); + $textToAppend = Carbon::now()->format('[Y-m-d H:i:s]') . ' ' . $text . PHP_EOL; + file_put_contents($filePath, $textToAppend, FILE_APPEND); + } +} From 2cf2c27051a32043595bcc445698c1624c9dea4a Mon Sep 17 00:00:00 2001 From: Dillon Date: Tue, 8 Aug 2023 23:10:36 +0800 Subject: [PATCH 14/52] Debugging --- .../Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php b/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php index 51e04388..9093321e 100644 --- a/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php +++ b/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php @@ -217,7 +217,7 @@ class UpdatePerfexCRMProcessor } $result = $this->fetchesPerfexCRMTask->execute($taskName, $milestoneId, 'project', $projectId, $updatePerfexCRMObject->getInvoiceId()); - // Log::info("UpdatePerfexCRMProcessor task: ".json_encode($taskStatus)." , ".json_encode($result)); + Log::error("UpdatePerfexCRMProcessor task: ".$taskName." , ".json_encode($result)); if(isset($result->payload)){ //&& $result->payload[0]['status'] == PerfexCRMTaskStatus::NOT_STARTED From 497ec941738a2a687cd18b65c8a80c5e02e20b0b Mon Sep 17 00:00:00 2001 From: Dillon Date: Tue, 8 Aug 2023 23:15:58 +0800 Subject: [PATCH 15/52] Debugging --- .../Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php b/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php index 9093321e..fbf64be8 100644 --- a/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php +++ b/app/Classes/Modules/PerfexCRM/Processors/UpdatePerfexCRMProcessor.php @@ -217,7 +217,8 @@ class UpdatePerfexCRMProcessor } $result = $this->fetchesPerfexCRMTask->execute($taskName, $milestoneId, 'project', $projectId, $updatePerfexCRMObject->getInvoiceId()); - Log::error("UpdatePerfexCRMProcessor task: ".$taskName." , ".json_encode($result)); + // Log::error("UpdatePerfexCRMProcessor task: ".$taskName." , ".json_encode($result)); + Log::error("UpdatePerfexCRMProcessor task: ".$taskName); if(isset($result->payload)){ //&& $result->payload[0]['status'] == PerfexCRMTaskStatus::NOT_STARTED From 0b597b473ee0a67dfd48cc546daacfa7acad1ae9 Mon Sep 17 00:00:00 2001 From: Dillon Date: Wed, 9 Aug 2023 01:41:02 +0800 Subject: [PATCH 16/52] Debugging --- .../PerfexCRM/Processors/TransactionToPerfexCRMProcessorV2.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Classes/Modules/PerfexCRM/Processors/TransactionToPerfexCRMProcessorV2.php b/app/Classes/Modules/PerfexCRM/Processors/TransactionToPerfexCRMProcessorV2.php index 7ec712c6..8494f61e 100644 --- a/app/Classes/Modules/PerfexCRM/Processors/TransactionToPerfexCRMProcessorV2.php +++ b/app/Classes/Modules/PerfexCRM/Processors/TransactionToPerfexCRMProcessorV2.php @@ -24,6 +24,8 @@ class TransactionToPerfexCRMProcessorV2 $projectName = 'Exchange | ' . $bookingInfo['serviceTypeName'] . ' | ' . $bookingInfo['bookingMarking']; $tasks = $this->defineTasks($model, $status); + Log::error("TransactionToPerfexCRMProcessorV2 status: ".$status." - for project name: ".$projectName); + if(count($tasks) > 0) { $updatePerfexCRMObject = new UpdatePerfexCRMObject( $bookingInfo['companyName'], From d7932c488ad34bf4d950cebe267157eaec364d5b Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 12:38:11 +0800 Subject: [PATCH 17/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 115 +++++++++---------- 1 file changed, 52 insertions(+), 63 deletions(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index ca45e766..f75cbeed 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -1,21 +1,20 @@ @extends('layouts.base_pdf') + @section('inner_content')


{{ $transaction->bill_no }}
+ +
- - - CIEF WORLDWIDE SDN BHD - - + CIEF WORLDWIDE SDN BHD (1134596-M)
No. 72-3, Jalan Jalil 1,
The Earth Bukit Jalil,
@@ -23,14 +22,8 @@ Tel: 03-8082 1252
-
- - Invoice - -
- +
Invoice
EI#: {{ $transaction->bill_no }}
-
Ref# {{ $po_order_transaction->booking->marking }}
Date: {{ $supplier->segments->whereIn('id', [23])->first() ? \Carbon\Carbon::now() : $po_order_transaction->booking->created_at }}
 
@@ -38,37 +31,34 @@
- - Bill To - + Bill To
-
- {{ $supplier->name }} -
+
{{ $supplier->name }}
+ @php + $billingAddress = $supplier->addresses()->where('billing', '=', true)->first(); + @endphp
- @php - $billingAddress = $supplier->addresses()->where('billing', '=', true)->first(); - @endphp {{ $billingAddress->street_one }} - {{ $billingAddress->street_two }} , + {{ $billingAddress->street_two }}, {{ $billingAddress->district()->first()->name }}, {{ $billingAddress->postcode }} {{ $billingAddress->state()->first()->name }}, {{ $billingAddress->country()->first()->name }}
-
- Phone: {{ $supplier->contacts()->first()->phone }} -
+
Phone: {{ $supplier->contacts()->first()->phone }}


+ + + @@ -81,11 +71,8 @@ @php - $subtotal = 0; - $voucher_redemption = isset($voucher_redemption) ? $voucher_redemption : null; - - $voucherDiscount = $voucher_redemption ? $voucher_redemption->value * -1 : 0; - $currencyRate = $transaction->currency_rate; + $subtotal = calculateSubtotal($po_order_transaction, $transaction->currency_rate); + $voucherDiscount = getVoucherDiscount($voucher_redemption); @endphp @foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail) @@ -93,19 +80,8 @@ - - + + @endforeach @@ -124,19 +100,9 @@ - + @endif - - - - - @if($transaction->tax > 0) @@ -149,19 +115,42 @@
No
{{ $transaction_detail->product_code }} {{ $transaction_detail->product_name }} {{ $transaction_detail->quantity }} - @php - $unitPrice = $transaction_detail->price / $currencyRate; - @endphp - {{ number_format($unitPrice, 2) }} - - @php - $itemTotal = $unitPrice * $transaction_detail->quantity; - $subtotal += $itemTotal; - @endphp - {{ number_format($itemTotal, 2) }} - {{ number_format($transaction_detail->price / $transaction->currency_rate, 2) }}{{ number_format(($transaction_detail->price / $transaction->currency_rate) * $transaction_detail->quantity, 2) }}
Voucher ({{ $voucher_redemption->voucher->code }})-{{ $voucherDiscount }}-{{ number_format($voucherDiscount, 2) }}
Adjustment - @php - $adjustment = $transaction->amount - $subtotal; - @endphp - {{ number_format($adjustment, 2) }} -
Total @php - $total = $subtotal + $transaction->service_charge + $transaction->tax + $voucherDiscount; + $total = calculateTotalInvoice($subtotal, $transaction->service_charge, $transaction->tax, $voucherDiscount); @endphp {{ number_format($total, 2) }}
- - - - - - -
This is generated by computer. No signature required.Page {PAGENO} of {nbpg}
-
+
+
+ Note: All items purchased are subject to our Terms & Conditions. Please refer to our official website for more information. +
+

+
+ Please transfer the payment to:
+ Bank: Maybank Berhad
+ Account Name: CIEF Worldwide Sdn Bhd
+ Account No: 564892103405
+
@endsection + +@php + function calculateSubtotal($po_order_transaction, $currencyRate) { + $subtotal = 0; + foreach ($po_order_transaction->transactionDetails as $transaction_detail) { + $unitPrice = $transaction_detail->price / $currencyRate; + $itemTotal = $unitPrice * $transaction_detail->quantity; + $subtotal += $itemTotal; + } + return $subtotal; + } + + function getVoucherDiscount($voucher_redemption) { + return $voucher_redemption ? $voucher_redemption->value * -1 : 0; + } + + function calculateTotalInvoice($subtotal, $service_charge, $tax, $voucherDiscount) { + return $subtotal + $service_charge + $tax + $voucherDiscount; + } +@endphp From 7e553e39f7f4bc3e1d9df74ea3705d085001041e Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 12:48:47 +0800 Subject: [PATCH 18/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index f75cbeed..2356033a 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -136,21 +136,25 @@ @endsection @php + if (!extension_loaded('bcmath')) { + throw new Exception('BCMath extension is not loaded.'); + } function calculateSubtotal($po_order_transaction, $currencyRate) { - $subtotal = 0; + $subtotal = "0"; foreach ($po_order_transaction->transactionDetails as $transaction_detail) { - $unitPrice = $transaction_detail->price / $currencyRate; - $itemTotal = $unitPrice * $transaction_detail->quantity; - $subtotal += $itemTotal; + $unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 2); + $itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 2); + $subtotal = bcadd($subtotal, $itemTotal, 2); } return $subtotal; } function getVoucherDiscount($voucher_redemption) { - return $voucher_redemption ? $voucher_redemption->value * -1 : 0; + return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; } function calculateTotalInvoice($subtotal, $service_charge, $tax, $voucherDiscount) { - return $subtotal + $service_charge + $tax + $voucherDiscount; + return bcadd(bcadd(bcadd($subtotal, $service_charge, 2), $tax, 2), $voucherDiscount, 2); } + @endphp From 6f5606c036d201c7fdd16f7c47319992b579290b Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 12:55:13 +0800 Subject: [PATCH 19/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 2356033a..b8eff2b5 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -75,13 +75,22 @@ $voucherDiscount = getVoucherDiscount($voucher_redemption); @endphp @foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail) + @php + $unitPrice = $transaction_detail->price / $transaction->currency_rate; + $itemTotal = $unitPrice * $transaction_detail->quantity; + $subtotal += $itemTotal; + @endphp {{ $key + 1 }} {{ $transaction_detail->product_code }} {{ $transaction_detail->product_name }} {{ $transaction_detail->quantity }} - {{ number_format($transaction_detail->price / $transaction->currency_rate, 2) }} - {{ number_format(($transaction_detail->price / $transaction->currency_rate) * $transaction_detail->quantity, 2) }} + + {{ number_format($unitPrice, 2) }} + + + {{ number_format($itemTotal, 2) }} + @endforeach From 7757e3d7e2c89bb0a90771cac129131b34ce43ee Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 12:58:29 +0800 Subject: [PATCH 20/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index b8eff2b5..944f6ee7 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -76,17 +76,17 @@ @endphp @foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail) @php - $unitPrice = $transaction_detail->price / $transaction->currency_rate; - $itemTotal = $unitPrice * $transaction_detail->quantity; - $subtotal += $itemTotal; + $exactUnitPrice = $transaction_detail->price / $transaction->currency_rate; + $itemTotal = $exactUnitPrice * $transaction_detail->quantity; @endphp + {{ $key + 1 }} {{ $transaction_detail->product_code }} {{ $transaction_detail->product_name }} {{ $transaction_detail->quantity }} - {{ number_format($unitPrice, 2) }} + {{ number_format($exactUnitPrice, 2) }} {{ number_format($itemTotal, 2) }} From 23b67290acdcad469ae969521c124813484c3573 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 13:00:13 +0800 Subject: [PATCH 21/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 944f6ee7..2356033a 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -75,22 +75,13 @@ $voucherDiscount = getVoucherDiscount($voucher_redemption); @endphp @foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail) - @php - $exactUnitPrice = $transaction_detail->price / $transaction->currency_rate; - $itemTotal = $exactUnitPrice * $transaction_detail->quantity; - @endphp - {{ $key + 1 }} {{ $transaction_detail->product_code }} {{ $transaction_detail->product_name }} {{ $transaction_detail->quantity }} - - {{ number_format($exactUnitPrice, 2) }} - - - {{ number_format($itemTotal, 2) }} - + {{ number_format($transaction_detail->price / $transaction->currency_rate, 2) }} + {{ number_format(($transaction_detail->price / $transaction->currency_rate) * $transaction_detail->quantity, 2) }} @endforeach From ead3bb9a013fea2aea730746ba03062613098ed9 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 13:04:12 +0800 Subject: [PATCH 22/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 2356033a..5ade5f0e 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -75,13 +75,22 @@ $voucherDiscount = getVoucherDiscount($voucher_redemption); @endphp @foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail) + @php + $exactUnitPrice = bcdiv($transaction_detail->price, $transaction->currency_rate, 5); // Using 5 decimal places for precision + $itemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 2); // Multiplication, result rounded to 2 decimal places + @endphp {{ $key + 1 }} {{ $transaction_detail->product_code }} {{ $transaction_detail->product_name }} {{ $transaction_detail->quantity }} - {{ number_format($transaction_detail->price / $transaction->currency_rate, 2) }} - {{ number_format(($transaction_detail->price / $transaction->currency_rate) * $transaction_detail->quantity, 2) }} + + {{ number_format($exactUnitPrice, 2) }} + + + + {{ $itemTotal }} + @endforeach From c985ad48586543b29362aa24af2978a2c1ec1a48 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 13:11:46 +0800 Subject: [PATCH 23/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 5ade5f0e..cf87c66b 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -71,13 +71,14 @@ @php - $subtotal = calculateSubtotal($po_order_transaction, $transaction->currency_rate); - $voucherDiscount = getVoucherDiscount($voucher_redemption); + $subtotal = 0; // Initialize to zero + $voucherDiscount = getVoucherDiscount($voucher_redemption); // Get the voucher discount (if any) @endphp @foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail) @php $exactUnitPrice = bcdiv($transaction_detail->price, $transaction->currency_rate, 5); // Using 5 decimal places for precision $itemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 2); // Multiplication, result rounded to 2 decimal places + $subtotal = bcadd($subtotal, $itemTotal, 2); // Accumulate each itemTotal into the subtotal @endphp {{ $key + 1 }} @@ -145,13 +146,10 @@ @endsection @php - if (!extension_loaded('bcmath')) { - throw new Exception('BCMath extension is not loaded.'); - } function calculateSubtotal($po_order_transaction, $currencyRate) { $subtotal = "0"; foreach ($po_order_transaction->transactionDetails as $transaction_detail) { - $unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 2); + $unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5); $itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 2); $subtotal = bcadd($subtotal, $itemTotal, 2); } @@ -165,5 +163,4 @@ function calculateTotalInvoice($subtotal, $service_charge, $tax, $voucherDiscount) { return bcadd(bcadd(bcadd($subtotal, $service_charge, 2), $tax, 2), $voucherDiscount, 2); } - @endphp From 4ac98cdd972a86ff146c6773362383ab7aa67c34 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 14:20:12 +0800 Subject: [PATCH 24/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 47 ++++++++------------ 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index cf87c66b..0d39923a 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -1,6 +1,7 @@ @extends('layouts.base_pdf') @section('inner_content') +


@@ -71,14 +72,13 @@ @php - $subtotal = 0; // Initialize to zero - $voucherDiscount = getVoucherDiscount($voucher_redemption); // Get the voucher discount (if any) + $subtotal = 0; @endphp @foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail) @php - $exactUnitPrice = bcdiv($transaction_detail->price, $transaction->currency_rate, 5); // Using 5 decimal places for precision - $itemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 2); // Multiplication, result rounded to 2 decimal places - $subtotal = bcadd($subtotal, $itemTotal, 2); // Accumulate each itemTotal into the subtotal + $exactUnitPrice = bcdiv($transaction_detail->price, $transaction->currency_rate, 5); // Retain precision with 5 decimals + $itemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 5); // Keep precision + $subtotal = bcadd($subtotal, $itemTotal, 5); // Keep precision @endphp {{ $key + 1 }} @@ -88,9 +88,8 @@ {{ number_format($exactUnitPrice, 2) }} - - {{ $itemTotal }} + {{ number_format($itemTotal, 2) }} @endforeach @@ -106,6 +105,11 @@ Service Charges {{ number_format($transaction->service_charge, 2) }} + + @php + $voucherDiscount = getVoucherDiscount($voucher_redemption); + @endphp + @if($voucher_redemption) @@ -113,6 +117,7 @@ -{{ number_format($voucherDiscount, 2) }} @endif + @if($transaction->tax > 0) @@ -120,12 +125,13 @@ {{ number_format($transaction->tax, 2) }} @endif + Total @php - $total = calculateTotalInvoice($subtotal, $transaction->service_charge, $transaction->tax, $voucherDiscount); + $total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); // Keep precision @endphp {{ number_format($total, 2) }} @@ -143,24 +149,9 @@ Account Name: CIEF Worldwide Sdn Bhd
Account No: 564892103405
-@endsection - -@php - function calculateSubtotal($po_order_transaction, $currencyRate) { - $subtotal = "0"; - foreach ($po_order_transaction->transactionDetails as $transaction_detail) { - $unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5); - $itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 2); - $subtotal = bcadd($subtotal, $itemTotal, 2); + @php + function getVoucherDiscount($voucher_redemption) { + return $voucher_redemption ? bcmul($voucher_redemption->value, "-1", 5) : "0"; // Keep precision } - return $subtotal; - } - - function getVoucherDiscount($voucher_redemption) { - return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; - } - - function calculateTotalInvoice($subtotal, $service_charge, $tax, $voucherDiscount) { - return bcadd(bcadd(bcadd($subtotal, $service_charge, 2), $tax, 2), $voucherDiscount, 2); - } -@endphp + @endphp +@endsection From 0e6b1a4b447ad10c47e29459ed2374c3aa3a9727 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 14:30:30 +0800 Subject: [PATCH 25/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 0d39923a..782d0687 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -74,6 +74,7 @@ @php $subtotal = 0; @endphp + @foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail) @php $exactUnitPrice = bcdiv($transaction_detail->price, $transaction->currency_rate, 5); // Retain precision with 5 decimals @@ -95,10 +96,14 @@ @endforeach + @php + $voucherDiscount = getVoucherDiscount($voucher_redemption); + $subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); // Use bcsub to subtract + @endphp Subtotal - {{ number_format($subtotal, 2) }} + {{ number_format($subtotalWithDiscount, 2) }} @@ -106,10 +111,6 @@ {{ number_format($transaction->service_charge, 2) }} - @php - $voucherDiscount = getVoucherDiscount($voucher_redemption); - @endphp - @if($voucher_redemption) From 126a635f06e1cd450ef4e1ceb3a5ac384ae1d02c Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 15:13:11 +0800 Subject: [PATCH 26/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 782d0687..cceccb95 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -77,9 +77,11 @@ @foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail) @php - $exactUnitPrice = bcdiv($transaction_detail->price, $transaction->currency_rate, 5); // Retain precision with 5 decimals - $itemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 5); // Keep precision - $subtotal = bcadd($subtotal, $itemTotal, 5); // Keep precision + $exactUnitPrice = bcdiv($transaction_detail->price, $transaction->currency_rate, 5); + $itemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 5); + $displayedItemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 2); // This is rounded off to 2 decimal places + $displayedTotalAmounts[] = $displayedItemTotal; + $displayedSubtotal = bcadd($displayedSubtotal, $displayedItemTotal, 2); @endphp {{ $key + 1 }} @@ -126,7 +128,16 @@ {{ number_format($transaction->tax, 2) }} @endif - + @php + $displayedTotal = bcadd(bcadd(bcadd($displayedSubtotal, $transaction->service_charge, 2), $transaction->tax, 2), $voucherDiscount, 2); + $expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); + $discrepancy = bcsub($displayedTotal, $expectedTotal, 5); + @endphp + + + Adjustment + {{ number_format($discrepancy, 5) }} + Total From 6abb963b12b471851ab334ee93f40ad633cbe674 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 15:14:59 +0800 Subject: [PATCH 27/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index cceccb95..1c9725a3 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -72,7 +72,8 @@ @php - $subtotal = 0; + $displayedSubtotal = 0; + $displayedTotalAmounts = []; @endphp @foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail) From 5fbe1981ccda23b1e84bdc5935a56d556b8d729d Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 15:19:25 +0800 Subject: [PATCH 28/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 1c9725a3..c33c7b0d 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -72,16 +72,16 @@ @php + $subtotal = calculateSubtotal($po_order_transaction, $transaction->currency_rate); + $voucherDiscount = getVoucherDiscount($voucher_redemption); $displayedSubtotal = 0; - $displayedTotalAmounts = []; @endphp @foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail) @php $exactUnitPrice = bcdiv($transaction_detail->price, $transaction->currency_rate, 5); $itemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 5); - $displayedItemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 2); // This is rounded off to 2 decimal places - $displayedTotalAmounts[] = $displayedItemTotal; + $displayedItemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 2); $displayedSubtotal = bcadd($displayedSubtotal, $displayedItemTotal, 2); @endphp @@ -163,8 +163,18 @@ Account No: 564892103405
@php + function calculateSubtotal($po_order_transaction, $currencyRate) { + $subtotal = "0"; + foreach ($po_order_transaction->transactionDetails as $transaction_detail) { + $unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5); + $itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5); + $subtotal = bcadd($subtotal, $itemTotal, 5); + } + return $subtotal; + } + function getVoucherDiscount($voucher_redemption) { - return $voucher_redemption ? bcmul($voucher_redemption->value, "-1", 5) : "0"; // Keep precision + return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; } @endphp @endsection From 4a87936704b68faedf9a78cdaad6794f28e1fc9c Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 15:23:14 +0800 Subject: [PATCH 29/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index c33c7b0d..6cb6a4b4 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -137,7 +137,7 @@ Adjustment - {{ number_format($discrepancy, 5) }} + {{ number_format(($total - $displayedTotal), 2) }} From 0d1e6b43e4eb418689b891b54accb4208e3c24c8 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 15:24:15 +0800 Subject: [PATCH 30/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 6cb6a4b4..8f3fbe1d 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -133,6 +133,7 @@ $displayedTotal = bcadd(bcadd(bcadd($displayedSubtotal, $transaction->service_charge, 2), $transaction->tax, 2), $voucherDiscount, 2); $expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); $discrepancy = bcsub($displayedTotal, $expectedTotal, 5); + $total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); // Keep precision @endphp @@ -143,9 +144,6 @@ Total - @php - $total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); // Keep precision - @endphp {{ number_format($total, 2) }} From f0affd4bef3491ee0ac672b12460aefbb191c264 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 15:27:49 +0800 Subject: [PATCH 31/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 8f3fbe1d..faef6ecb 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -138,7 +138,7 @@ Adjustment - {{ number_format(($total - $displayedTotal), 2) }} + {{ $total }} - {{ $displayedTotal }} From 406207acf472cfd6d14e8d51b915250c5c4c53fa Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 15:32:00 +0800 Subject: [PATCH 32/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index faef6ecb..6a44eee4 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -138,7 +138,7 @@ Adjustment - {{ $total }} - {{ $displayedTotal }} + {{ number_format($total, 2) }} - {{ number_format($displayedTotal, 2) }} From 10861d9eba708eb74b96af3433e591181eb84561 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 15:34:02 +0800 Subject: [PATCH 33/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 6a44eee4..2baca57f 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -138,7 +138,7 @@ Adjustment - {{ number_format($total, 2) }} - {{ number_format($displayedTotal, 2) }} + {{ round($discrepancy) }} From be427a854d9578a87dd45fcc5065c447472b46b7 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 15:35:05 +0800 Subject: [PATCH 34/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 2baca57f..4dfdb99c 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -138,7 +138,7 @@ Adjustment - {{ round($discrepancy) }} + {{ number_format($discrepancy, 2) }} From 45d7e50e08c14e9375c4115f03416bf7817f268c Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 15:41:22 +0800 Subject: [PATCH 35/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 4dfdb99c..880f9306 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -106,7 +106,7 @@ Subtotal - {{ number_format($subtotalWithDiscount, 2) }} + {{ number_format($subtotal, 2) }} @@ -138,7 +138,7 @@ Adjustment - {{ number_format($discrepancy, 2) }} + {{ number_format(($total - (((float) number_format($subtotal, 2)) + ((float) number_format($transaction->service_charge, 2)) + ((float) number_format($voucherDiscount, 2)) + ((float) number_format($transaction->tax, 2)))), 2) }} From e966c4942670714786cedea4eaaf1435c4d9b1d1 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 15:44:29 +0800 Subject: [PATCH 36/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 880f9306..88ca7547 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -134,11 +134,12 @@ $expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); $discrepancy = bcsub($displayedTotal, $expectedTotal, 5); $total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); // Keep precision + $displayedTotal = (((float) number_format($subtotal, 2)) + ((float) number_format($transaction->service_charge, 2)) + ((float) number_format($voucherDiscount, 2)) + ((float) number_format($transaction->tax, 2))) @endphp Adjustment - {{ number_format(($total - (((float) number_format($subtotal, 2)) + ((float) number_format($transaction->service_charge, 2)) + ((float) number_format($voucherDiscount, 2)) + ((float) number_format($transaction->tax, 2)))), 2) }} + {{ ($total - $displayedTotal) }} From 7e3282302e102140e27bbf7b9c4a092895f6db6e Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 15:48:31 +0800 Subject: [PATCH 37/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 88ca7547..addef480 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -134,7 +134,11 @@ $expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); $discrepancy = bcsub($displayedTotal, $expectedTotal, 5); $total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); // Keep precision - $displayedTotal = (((float) number_format($subtotal, 2)) + ((float) number_format($transaction->service_charge, 2)) + ((float) number_format($voucherDiscount, 2)) + ((float) number_format($transaction->tax, 2))) + $displayedTotal = + ((float) number_format($subtotal, 2)) + + ((float) number_format($transaction->service_charge, 2)) + + ((float) number_format($voucherDiscount, 2)) + + ((float) number_format($transaction->tax, 2)); @endphp From 563937792d1cd4485f28cf69a1a3f0a6039c9eb9 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 15:49:36 +0800 Subject: [PATCH 38/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index addef480..42883bd5 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -143,7 +143,7 @@ Adjustment - {{ ($total - $displayedTotal) }} + {{ $displayedTotal }} From 9d768d4a8c479ad08379a51faeee691fd6bd7f3e Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 15:51:26 +0800 Subject: [PATCH 39/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 42883bd5..d1dfa100 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -134,11 +134,11 @@ $expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); $discrepancy = bcsub($displayedTotal, $expectedTotal, 5); $total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); // Keep precision - $displayedTotal = - ((float) number_format($subtotal, 2)) + - ((float) number_format($transaction->service_charge, 2)) + - ((float) number_format($voucherDiscount, 2)) + - ((float) number_format($transaction->tax, 2)); +// $displayedTotal = +// ((float) number_format($subtotal, 2)) + +// ((float) number_format($transaction->service_charge, 2)) + +// ((float) number_format($voucherDiscount, 2)) + +// ((float) number_format($transaction->tax, 2)); @endphp From 4af66d4c9a7c02c80c8236b7855b36fa22fb591e Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 15:52:19 +0800 Subject: [PATCH 40/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index d1dfa100..0597ae0b 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -143,7 +143,7 @@ Adjustment - {{ $displayedTotal }} + {{ $discrepancy }} From ea2908642a9639f55b9360cc25fad6e54ff87cf3 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 16:00:39 +0800 Subject: [PATCH 41/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 0597ae0b..c775b03a 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -143,7 +143,7 @@ Adjustment - {{ $discrepancy }} + {{ round($discrepancy, 2) }} From f134a9822e5d5250cc72d976b90cc46bca028755 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 16:03:51 +0800 Subject: [PATCH 42/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index c775b03a..fcbea2fc 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -143,7 +143,7 @@ Adjustment - {{ round($discrepancy, 2) }} + {{ ceil($discrepancy, 2) }} From 8d3985b26c7f7dc65daf794c7895433e3add74c7 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 16:05:20 +0800 Subject: [PATCH 43/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index fcbea2fc..03199c1e 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -143,7 +143,7 @@ Adjustment - {{ ceil($discrepancy, 2) }} + {{ round_up($discrepancy, 2) }} @@ -179,5 +179,10 @@ function getVoucherDiscount($voucher_redemption) { return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; } + function round_up ( $value, $precision ) { + $pow = pow ( 10, $precision ); + return ( ceil ( $pow * $value ) + ceil ( $pow * $value - ceil ( $pow * $value ) ) ) / $pow; + } + @endphp @endsection From a912fb88e6303d92f47650c0d1fa5e0294de5302 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 16:07:27 +0800 Subject: [PATCH 44/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 03199c1e..6d44d858 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -143,7 +143,7 @@ Adjustment - {{ round_up($discrepancy, 2) }} + {{ $discrepancy }} From 34399aa34da6ebf5d6b73c7c74622b581a854df5 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 16:19:03 +0800 Subject: [PATCH 45/52] debug invoice pdf --- resources/views/pages/pdfs/invoice.blade.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 6d44d858..b35fe67e 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -143,7 +143,7 @@ Adjustment - {{ $discrepancy }} + {{ roundUp($discrepancy,2) }} @@ -179,10 +179,14 @@ function getVoucherDiscount($voucher_redemption) { return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; } - function round_up ( $value, $precision ) { - $pow = pow ( 10, $precision ); - return ( ceil ( $pow * $value ) + ceil ( $pow * $value - ceil ( $pow * $value ) ) ) / $pow; + function roundUp($number, $decimals) { + $factor = pow(10, $decimals); + if ($number > 0) { + return ceil($number * $factor) / $factor; + } else { + return floor($number * $factor) / $factor; } + } @endphp @endsection From f5121d35dada212612d1f6028f6eb1a4f4d48971 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 16:27:56 +0800 Subject: [PATCH 46/52] debug invoice pdf --- .../views/pages/pdfs/deliver_order.blade.php | 84 ++++++++++++------- resources/views/pages/pdfs/invoice.blade.php | 5 -- .../views/pages/pdfs/purchase_order.blade.php | 84 ++++++++++++------- 3 files changed, 110 insertions(+), 63 deletions(-) diff --git a/resources/views/pages/pdfs/deliver_order.blade.php b/resources/views/pages/pdfs/deliver_order.blade.php index ba30bc68..b58fd066 100644 --- a/resources/views/pages/pdfs/deliver_order.blade.php +++ b/resources/views/pages/pdfs/deliver_order.blade.php @@ -69,6 +69,7 @@

+ @@ -81,34 +82,37 @@ @php - $subtotal = 0; - $voucher_redemption = isset($voucher_redemption) ? $voucher_redemption : null; - $voucherDiscount = $voucher_redemption ? $voucher_redemption->value * -1 : 0; - $currencyRate = $transaction->currency_rate; + $subtotal = calculateSubtotal($po_order_transaction, $transaction->currency_rate); + $voucherDiscount = getVoucherDiscount($voucher_redemption); + $displayedSubtotal = 0; @endphp + @foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail) + @php + $exactUnitPrice = bcdiv($transaction_detail->price, $transaction->currency_rate, 5); + $itemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 5); + $displayedItemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 2); + $displayedSubtotal = bcadd($displayedSubtotal, $displayedItemTotal, 2); + @endphp @endforeach + @php + $voucherDiscount = getVoucherDiscount($voucher_redemption); + $subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); // Use bcsub to subtract + @endphp @@ -117,27 +121,17 @@ - + + @if($voucher_redemption) - + @endif - - - - - + @if($transaction->tax > 0) @@ -145,13 +139,21 @@ @endif + @php + $displayedTotal = bcadd(bcadd(bcadd($displayedSubtotal, $transaction->service_charge, 2), $transaction->tax, 2), $voucherDiscount, 2); + $expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); + $discrepancy = bcsub($displayedTotal, $expectedTotal, 5); + $total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); // Keep precision + @endphp + + + + + @@ -165,4 +167,28 @@
No
{{ $key + 1 }} {{ $transaction_detail->product_code }} {{ $transaction_detail->product_name }} {{ $transaction_detail->quantity }} - @php - $unitPrice = $transaction_detail->price / $currencyRate; - @endphp - {{ number_format($unitPrice, 2) }} + {{ number_format($exactUnitPrice, 2) }} - @php - $itemTotal = $unitPrice * $transaction_detail->quantity; - $subtotal += $itemTotal; - @endphp {{ number_format($itemTotal, 2) }}
Subtotal
Service Charges - {{ number_format($transaction->service_charge, 2) }} - {{ number_format($transaction->service_charge, 2) }}
Voucher ({{ $voucher_redemption->voucher->code }})-{{ $voucherDiscount }}-{{ number_format($voucherDiscount, 2) }}
Adjustment - @php - $adjustment = $transaction->amount - $subtotal; - @endphp - {{ number_format($adjustment, 2) }} -
{{ number_format($transaction->tax, 2) }}
Adjustment{{ roundUp($discrepancy,2) }}
Total - @php - $total = $subtotal + $transaction->service_charge + $transaction->tax + $voucherDiscount; - @endphp {{ number_format($total, 2) }}
+ @php + function calculateSubtotal($po_order_transaction, $currencyRate) { + $subtotal = "0"; + foreach ($po_order_transaction->transactionDetails as $transaction_detail) { + $unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5); + $itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5); + $subtotal = bcadd($subtotal, $itemTotal, 5); + } + return $subtotal; + } + + function getVoucherDiscount($voucher_redemption) { + return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; + } + function roundUp($number, $decimals) { + $factor = pow(10, $decimals); + if ($number > 0) { + return ceil($number * $factor) / $factor; + } else { + return floor($number * $factor) / $factor; + } + } + + @endphp @endsection diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index b35fe67e..066fb971 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -134,11 +134,6 @@ $expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); $discrepancy = bcsub($displayedTotal, $expectedTotal, 5); $total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); // Keep precision -// $displayedTotal = -// ((float) number_format($subtotal, 2)) + -// ((float) number_format($transaction->service_charge, 2)) + -// ((float) number_format($voucherDiscount, 2)) + -// ((float) number_format($transaction->tax, 2)); @endphp diff --git a/resources/views/pages/pdfs/purchase_order.blade.php b/resources/views/pages/pdfs/purchase_order.blade.php index 79841363..220b0ae5 100644 --- a/resources/views/pages/pdfs/purchase_order.blade.php +++ b/resources/views/pages/pdfs/purchase_order.blade.php @@ -77,6 +77,7 @@
+ @@ -89,34 +90,37 @@ @php - $subtotal = 0; - $voucher_redemption = isset($voucher_redemption) ? $voucher_redemption : null; - $voucherDiscount = $voucher_redemption ? $voucher_redemption->value * -1 : 0; - $currencyRate = $transaction->currency_rate; + $subtotal = calculateSubtotal($po_order_transaction, $transaction->currency_rate); + $voucherDiscount = getVoucherDiscount($voucher_redemption); + $displayedSubtotal = 0; @endphp + @foreach ($po_order_transaction->transactionDetails as $key => $transaction_detail) + @php + $exactUnitPrice = bcdiv($transaction_detail->price, $transaction->currency_rate, 5); + $itemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 5); + $displayedItemTotal = bcmul($exactUnitPrice, $transaction_detail->quantity, 2); + $displayedSubtotal = bcadd($displayedSubtotal, $displayedItemTotal, 2); + @endphp @endforeach + @php + $voucherDiscount = getVoucherDiscount($voucher_redemption); + $subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); // Use bcsub to subtract + @endphp @@ -125,27 +129,17 @@ - + + @if($voucher_redemption) - + @endif - - - - - + @if($transaction->tax > 0) @@ -153,13 +147,21 @@ @endif + @php + $displayedTotal = bcadd(bcadd(bcadd($displayedSubtotal, $transaction->service_charge, 2), $transaction->tax, 2), $voucherDiscount, 2); + $expectedTotal = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); + $discrepancy = bcsub($displayedTotal, $expectedTotal, 5); + $total = bcadd(bcadd(bcadd($subtotal, $transaction->service_charge, 5), $transaction->tax, 5), $voucherDiscount, 5); // Keep precision + @endphp + + + + + @@ -173,4 +175,28 @@
No
{{ $key + 1 }} {{ $transaction_detail->product_code }} {{ $transaction_detail->product_name }} {{ $transaction_detail->quantity }} - @php - $unitPrice = $transaction_detail->price / $currencyRate; - @endphp - {{ number_format($unitPrice, 2) }} + {{ number_format($exactUnitPrice, 2) }} - @php - $itemTotal = $unitPrice * $transaction_detail->quantity; - $subtotal += $itemTotal; - @endphp {{ number_format($itemTotal, 2) }}
Subtotal
Service Charges - {{ number_format($transaction->service_charge, 2) }} - {{ number_format($transaction->service_charge, 2) }}
Voucher ({{ $voucher_redemption->voucher->code }})-{{ $voucherDiscount }}-{{ number_format($voucherDiscount, 2) }}
Adjustment - @php - $adjustment = $transaction->amount - $subtotal; - @endphp - {{ number_format($adjustment, 2) }} -
{{ number_format($transaction->tax, 2) }}
Adjustment{{ roundUp($discrepancy,2) }}
Total - @php - $total = $subtotal + $transaction->service_charge + $transaction->tax + $voucherDiscount; - @endphp {{ number_format($total, 2) }}
+ @php + function calculateSubtotal($po_order_transaction, $currencyRate) { + $subtotal = "0"; + foreach ($po_order_transaction->transactionDetails as $transaction_detail) { + $unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5); + $itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5); + $subtotal = bcadd($subtotal, $itemTotal, 5); + } + return $subtotal; + } + + function getVoucherDiscount($voucher_redemption) { + return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; + } + function roundUp($number, $decimals) { + $factor = pow(10, $decimals); + if ($number > 0) { + return ceil($number * $factor) / $factor; + } else { + return floor($number * $factor) / $factor; + } + } + + @endphp @endsection From 69b03f55ad3516832ec2bda4d176bd1fde4877ac Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 16:35:04 +0800 Subject: [PATCH 47/52] debug invoice pdf --- .../CreateInvoiceTransactionProcessor.php | 24 +++++++++++++++++++ .../views/pages/pdfs/deliver_order.blade.php | 23 ------------------ resources/views/pages/pdfs/invoice.blade.php | 24 ------------------- .../views/pages/pdfs/purchase_order.blade.php | 24 ------------------- 4 files changed, 24 insertions(+), 71 deletions(-) diff --git a/app/Classes/Modules/Transactions/Processors/CreateInvoiceTransactionProcessor.php b/app/Classes/Modules/Transactions/Processors/CreateInvoiceTransactionProcessor.php index 7f105dc8..6aab9afd 100644 --- a/app/Classes/Modules/Transactions/Processors/CreateInvoiceTransactionProcessor.php +++ b/app/Classes/Modules/Transactions/Processors/CreateInvoiceTransactionProcessor.php @@ -206,4 +206,28 @@ class CreateInvoiceTransactionProcessor // CreatePerfexCRMInvoice::dispatch($invoice_transaction, $purchaseOrder, $supplier); // } } + + public function calculateSubtotal($po_order_transaction, $currencyRate) { + $subtotal = "0"; + foreach ($po_order_transaction->transactionDetails as $transaction_detail) { + $unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5); + $itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5); + $subtotal = bcadd($subtotal, $itemTotal, 5); + } + return $subtotal; + } + + public function getVoucherDiscount($voucher_redemption) { + return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; + } + + public function roundUp($number, $decimals) + { + $factor = pow(10, $decimals); + if ($number > 0) { + return ceil($number * $factor) / $factor; + } else { + return floor($number * $factor) / $factor; + } + } } diff --git a/resources/views/pages/pdfs/deliver_order.blade.php b/resources/views/pages/pdfs/deliver_order.blade.php index b58fd066..e1676631 100644 --- a/resources/views/pages/pdfs/deliver_order.blade.php +++ b/resources/views/pages/pdfs/deliver_order.blade.php @@ -167,28 +167,5 @@ - @php - function calculateSubtotal($po_order_transaction, $currencyRate) { - $subtotal = "0"; - foreach ($po_order_transaction->transactionDetails as $transaction_detail) { - $unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5); - $itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5); - $subtotal = bcadd($subtotal, $itemTotal, 5); - } - return $subtotal; - } - function getVoucherDiscount($voucher_redemption) { - return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; - } - function roundUp($number, $decimals) { - $factor = pow(10, $decimals); - if ($number > 0) { - return ceil($number * $factor) / $factor; - } else { - return floor($number * $factor) / $factor; - } - } - - @endphp @endsection diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 066fb971..57868e15 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -160,28 +160,4 @@ Account Name: CIEF Worldwide Sdn Bhd
Account No: 564892103405
- @php - function calculateSubtotal($po_order_transaction, $currencyRate) { - $subtotal = "0"; - foreach ($po_order_transaction->transactionDetails as $transaction_detail) { - $unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5); - $itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5); - $subtotal = bcadd($subtotal, $itemTotal, 5); - } - return $subtotal; - } - - function getVoucherDiscount($voucher_redemption) { - return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; - } - function roundUp($number, $decimals) { - $factor = pow(10, $decimals); - if ($number > 0) { - return ceil($number * $factor) / $factor; - } else { - return floor($number * $factor) / $factor; - } - } - - @endphp @endsection diff --git a/resources/views/pages/pdfs/purchase_order.blade.php b/resources/views/pages/pdfs/purchase_order.blade.php index 220b0ae5..93d736a6 100644 --- a/resources/views/pages/pdfs/purchase_order.blade.php +++ b/resources/views/pages/pdfs/purchase_order.blade.php @@ -175,28 +175,4 @@ - @php - function calculateSubtotal($po_order_transaction, $currencyRate) { - $subtotal = "0"; - foreach ($po_order_transaction->transactionDetails as $transaction_detail) { - $unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5); - $itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5); - $subtotal = bcadd($subtotal, $itemTotal, 5); - } - return $subtotal; - } - - function getVoucherDiscount($voucher_redemption) { - return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; - } - function roundUp($number, $decimals) { - $factor = pow(10, $decimals); - if ($number > 0) { - return ceil($number * $factor) / $factor; - } else { - return floor($number * $factor) / $factor; - } - } - - @endphp @endsection From 5528811cc1a0209deba854b43071d85ee5aa90cc Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 17:02:44 +0800 Subject: [PATCH 48/52] debug invoice pdf --- .../CreateInvoiceTransactionProcessor.php | 24 ------------------- resources/views/pages/pdfs/invoice.blade.php | 24 +++++++++++++++++++ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/app/Classes/Modules/Transactions/Processors/CreateInvoiceTransactionProcessor.php b/app/Classes/Modules/Transactions/Processors/CreateInvoiceTransactionProcessor.php index 6aab9afd..7f105dc8 100644 --- a/app/Classes/Modules/Transactions/Processors/CreateInvoiceTransactionProcessor.php +++ b/app/Classes/Modules/Transactions/Processors/CreateInvoiceTransactionProcessor.php @@ -206,28 +206,4 @@ class CreateInvoiceTransactionProcessor // CreatePerfexCRMInvoice::dispatch($invoice_transaction, $purchaseOrder, $supplier); // } } - - public function calculateSubtotal($po_order_transaction, $currencyRate) { - $subtotal = "0"; - foreach ($po_order_transaction->transactionDetails as $transaction_detail) { - $unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5); - $itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5); - $subtotal = bcadd($subtotal, $itemTotal, 5); - } - return $subtotal; - } - - public function getVoucherDiscount($voucher_redemption) { - return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; - } - - public function roundUp($number, $decimals) - { - $factor = pow(10, $decimals); - if ($number > 0) { - return ceil($number * $factor) / $factor; - } else { - return floor($number * $factor) / $factor; - } - } } diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 57868e15..066fb971 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -160,4 +160,28 @@ Account Name: CIEF Worldwide Sdn Bhd
Account No: 564892103405
+ @php + function calculateSubtotal($po_order_transaction, $currencyRate) { + $subtotal = "0"; + foreach ($po_order_transaction->transactionDetails as $transaction_detail) { + $unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5); + $itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5); + $subtotal = bcadd($subtotal, $itemTotal, 5); + } + return $subtotal; + } + + function getVoucherDiscount($voucher_redemption) { + return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; + } + function roundUp($number, $decimals) { + $factor = pow(10, $decimals); + if ($number > 0) { + return ceil($number * $factor) / $factor; + } else { + return floor($number * $factor) / $factor; + } + } + + @endphp @endsection From d6ce7747702a0c44ad47bb2ac96cb4dbfa49f189 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 17:03:21 +0800 Subject: [PATCH 49/52] debug invoice pdf --- .../views/pages/pdfs/deliver_order.blade.php | 23 ++++++++++++++++++ .../views/pages/pdfs/purchase_order.blade.php | 24 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/resources/views/pages/pdfs/deliver_order.blade.php b/resources/views/pages/pdfs/deliver_order.blade.php index e1676631..b58fd066 100644 --- a/resources/views/pages/pdfs/deliver_order.blade.php +++ b/resources/views/pages/pdfs/deliver_order.blade.php @@ -167,5 +167,28 @@ + @php + function calculateSubtotal($po_order_transaction, $currencyRate) { + $subtotal = "0"; + foreach ($po_order_transaction->transactionDetails as $transaction_detail) { + $unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5); + $itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5); + $subtotal = bcadd($subtotal, $itemTotal, 5); + } + return $subtotal; + } + function getVoucherDiscount($voucher_redemption) { + return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; + } + function roundUp($number, $decimals) { + $factor = pow(10, $decimals); + if ($number > 0) { + return ceil($number * $factor) / $factor; + } else { + return floor($number * $factor) / $factor; + } + } + + @endphp @endsection diff --git a/resources/views/pages/pdfs/purchase_order.blade.php b/resources/views/pages/pdfs/purchase_order.blade.php index 93d736a6..220b0ae5 100644 --- a/resources/views/pages/pdfs/purchase_order.blade.php +++ b/resources/views/pages/pdfs/purchase_order.blade.php @@ -175,4 +175,28 @@ + @php + function calculateSubtotal($po_order_transaction, $currencyRate) { + $subtotal = "0"; + foreach ($po_order_transaction->transactionDetails as $transaction_detail) { + $unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5); + $itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5); + $subtotal = bcadd($subtotal, $itemTotal, 5); + } + return $subtotal; + } + + function getVoucherDiscount($voucher_redemption) { + return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; + } + function roundUp($number, $decimals) { + $factor = pow(10, $decimals); + if ($number > 0) { + return ceil($number * $factor) / $factor; + } else { + return floor($number * $factor) / $factor; + } + } + + @endphp @endsection From 14fef7d9839dd6fcb389f419fe3d04f6a67b7dbc Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 17:09:24 +0800 Subject: [PATCH 50/52] debug invoice pdf --- resources/views/pages/pdfs/InvoiceHelpers.php | 24 ++++++++++++++++++ .../views/pages/pdfs/deliver_order.blade.php | 25 +------------------ resources/views/pages/pdfs/invoice.blade.php | 1 + .../views/pages/pdfs/purchase_order.blade.php | 25 +------------------ 4 files changed, 27 insertions(+), 48 deletions(-) create mode 100644 resources/views/pages/pdfs/InvoiceHelpers.php diff --git a/resources/views/pages/pdfs/InvoiceHelpers.php b/resources/views/pages/pdfs/InvoiceHelpers.php new file mode 100644 index 00000000..ae407479 --- /dev/null +++ b/resources/views/pages/pdfs/InvoiceHelpers.php @@ -0,0 +1,24 @@ +transactionDetails as $transaction_detail) { + $unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5); + $itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5); + $subtotal = bcadd($subtotal, $itemTotal, 5); + } + return $subtotal; +} + +function getVoucherDiscount($voucher_redemption) { + return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; +} +function roundUp($number, $decimals) +{ + $factor = pow(10, $decimals); + if ($number > 0) { + return ceil($number * $factor) / $factor; + } else { + return floor($number * $factor) / $factor; + } +} diff --git a/resources/views/pages/pdfs/deliver_order.blade.php b/resources/views/pages/pdfs/deliver_order.blade.php index b58fd066..03e74a8b 100644 --- a/resources/views/pages/pdfs/deliver_order.blade.php +++ b/resources/views/pages/pdfs/deliver_order.blade.php @@ -1,3 +1,4 @@ +@include('InvoiceHelpers') @extends('layouts.base_pdf') @section('inner_content')
@@ -167,28 +168,4 @@ - @php - function calculateSubtotal($po_order_transaction, $currencyRate) { - $subtotal = "0"; - foreach ($po_order_transaction->transactionDetails as $transaction_detail) { - $unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5); - $itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5); - $subtotal = bcadd($subtotal, $itemTotal, 5); - } - return $subtotal; - } - - function getVoucherDiscount($voucher_redemption) { - return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; - } - function roundUp($number, $decimals) { - $factor = pow(10, $decimals); - if ($number > 0) { - return ceil($number * $factor) / $factor; - } else { - return floor($number * $factor) / $factor; - } - } - - @endphp @endsection diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 066fb971..3ff19f19 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -1,3 +1,4 @@ +@include('InvoiceHelpers') @extends('layouts.base_pdf') @section('inner_content') diff --git a/resources/views/pages/pdfs/purchase_order.blade.php b/resources/views/pages/pdfs/purchase_order.blade.php index 220b0ae5..54f81654 100644 --- a/resources/views/pages/pdfs/purchase_order.blade.php +++ b/resources/views/pages/pdfs/purchase_order.blade.php @@ -1,3 +1,4 @@ +@include('InvoiceHelpers') @extends('layouts.base_pdf') @section('inner_content')
@@ -175,28 +176,4 @@ - @php - function calculateSubtotal($po_order_transaction, $currencyRate) { - $subtotal = "0"; - foreach ($po_order_transaction->transactionDetails as $transaction_detail) { - $unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5); - $itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5); - $subtotal = bcadd($subtotal, $itemTotal, 5); - } - return $subtotal; - } - - function getVoucherDiscount($voucher_redemption) { - return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; - } - function roundUp($number, $decimals) { - $factor = pow(10, $decimals); - if ($number > 0) { - return ceil($number * $factor) / $factor; - } else { - return floor($number * $factor) / $factor; - } - } - - @endphp @endsection From 42243d7c231febeb515b8b90946390c4d3796a95 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 17:12:00 +0800 Subject: [PATCH 51/52] debug invoice pdf --- resources/views/pages/pdfs/deliver_order.blade.php | 2 +- resources/views/pages/pdfs/invoice.blade.php | 2 +- resources/views/pages/pdfs/purchase_order.blade.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/views/pages/pdfs/deliver_order.blade.php b/resources/views/pages/pdfs/deliver_order.blade.php index 03e74a8b..75d0d936 100644 --- a/resources/views/pages/pdfs/deliver_order.blade.php +++ b/resources/views/pages/pdfs/deliver_order.blade.php @@ -1,4 +1,4 @@ -@include('InvoiceHelpers') +@include('./InvoiceHelpers') @extends('layouts.base_pdf') @section('inner_content')
diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index 3ff19f19..cc12d8e6 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -1,4 +1,4 @@ -@include('InvoiceHelpers') +@include('./InvoiceHelpers') @extends('layouts.base_pdf') @section('inner_content') diff --git a/resources/views/pages/pdfs/purchase_order.blade.php b/resources/views/pages/pdfs/purchase_order.blade.php index 54f81654..63ab0db6 100644 --- a/resources/views/pages/pdfs/purchase_order.blade.php +++ b/resources/views/pages/pdfs/purchase_order.blade.php @@ -1,4 +1,4 @@ -@include('InvoiceHelpers') +@include('./InvoiceHelpers') @extends('layouts.base_pdf') @section('inner_content')
From 058d7967a207267de1297adb8dbe30d12391e583 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Thu, 10 Aug 2023 17:25:18 +0800 Subject: [PATCH 52/52] debug invoice pdf --- resources/views/pages/pdfs/InvoiceHelpers.php | 24 -------------- .../views/pages/pdfs/deliver_order.blade.php | 33 ++++++++++++++++--- resources/views/pages/pdfs/invoice.blade.php | 1 - .../views/pages/pdfs/purchase_order.blade.php | 33 ++++++++++++++++--- 4 files changed, 56 insertions(+), 35 deletions(-) delete mode 100644 resources/views/pages/pdfs/InvoiceHelpers.php diff --git a/resources/views/pages/pdfs/InvoiceHelpers.php b/resources/views/pages/pdfs/InvoiceHelpers.php deleted file mode 100644 index ae407479..00000000 --- a/resources/views/pages/pdfs/InvoiceHelpers.php +++ /dev/null @@ -1,24 +0,0 @@ -transactionDetails as $transaction_detail) { - $unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5); - $itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5); - $subtotal = bcadd($subtotal, $itemTotal, 5); - } - return $subtotal; -} - -function getVoucherDiscount($voucher_redemption) { - return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; -} -function roundUp($number, $decimals) -{ - $factor = pow(10, $decimals); - if ($number > 0) { - return ceil($number * $factor) / $factor; - } else { - return floor($number * $factor) / $factor; - } -} diff --git a/resources/views/pages/pdfs/deliver_order.blade.php b/resources/views/pages/pdfs/deliver_order.blade.php index 75d0d936..c59cc5a9 100644 --- a/resources/views/pages/pdfs/deliver_order.blade.php +++ b/resources/views/pages/pdfs/deliver_order.blade.php @@ -1,4 +1,3 @@ -@include('./InvoiceHelpers') @extends('layouts.base_pdf') @section('inner_content')
@@ -83,8 +82,8 @@ @php - $subtotal = calculateSubtotal($po_order_transaction, $transaction->currency_rate); - $voucherDiscount = getVoucherDiscount($voucher_redemption); + $subtotal = calculateDoSubtotal($po_order_transaction, $transaction->currency_rate); + $voucherDiscount = getDoVoucherDiscount($voucher_redemption); $displayedSubtotal = 0; @endphp @@ -111,7 +110,7 @@ @php - $voucherDiscount = getVoucherDiscount($voucher_redemption); + $voucherDiscount = getDoVoucherDiscount($voucher_redemption); $subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); // Use bcsub to subtract @endphp @@ -149,7 +148,7 @@ Adjustment - {{ roundUp($discrepancy,2) }} + {{ roundUpDo($discrepancy,2) }} @@ -168,4 +167,28 @@ + @php + function calculateDoSubtotal($po_order_transaction, $currencyRate) { + $subtotal = "0"; + foreach ($po_order_transaction->transactionDetails as $transaction_detail) { + $unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5); + $itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5); + $subtotal = bcadd($subtotal, $itemTotal, 5); + } + return $subtotal; + } + + function getDoVoucherDiscount($voucher_redemption) { + return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; + } + function roundUpDo($number, $decimals) { + $factor = pow(10, $decimals); + if ($number > 0) { + return ceil($number * $factor) / $factor; + } else { + return floor($number * $factor) / $factor; + } + } + + @endphp @endsection diff --git a/resources/views/pages/pdfs/invoice.blade.php b/resources/views/pages/pdfs/invoice.blade.php index cc12d8e6..066fb971 100644 --- a/resources/views/pages/pdfs/invoice.blade.php +++ b/resources/views/pages/pdfs/invoice.blade.php @@ -1,4 +1,3 @@ -@include('./InvoiceHelpers') @extends('layouts.base_pdf') @section('inner_content') diff --git a/resources/views/pages/pdfs/purchase_order.blade.php b/resources/views/pages/pdfs/purchase_order.blade.php index 63ab0db6..e9d1c8fd 100644 --- a/resources/views/pages/pdfs/purchase_order.blade.php +++ b/resources/views/pages/pdfs/purchase_order.blade.php @@ -1,4 +1,3 @@ -@include('./InvoiceHelpers') @extends('layouts.base_pdf') @section('inner_content')
@@ -91,8 +90,8 @@ @php - $subtotal = calculateSubtotal($po_order_transaction, $transaction->currency_rate); - $voucherDiscount = getVoucherDiscount($voucher_redemption); + $subtotal = calculatePoSubtotal($po_order_transaction, $transaction->currency_rate); + $voucherDiscount = getPoVoucherDiscount($voucher_redemption); $displayedSubtotal = 0; @endphp @@ -119,7 +118,7 @@ @php - $voucherDiscount = getVoucherDiscount($voucher_redemption); + $voucherDiscount = getPoVoucherDiscount($voucher_redemption); $subtotalWithDiscount = bcsub($subtotal, $voucherDiscount, 5); // Use bcsub to subtract @endphp @@ -157,7 +156,7 @@ Adjustment - {{ roundUp($discrepancy,2) }} + {{ roundUpPo($discrepancy,2) }} @@ -176,4 +175,28 @@ + @php + function calculatePoSubtotal($po_order_transaction, $currencyRate) { + $subtotal = "0"; + foreach ($po_order_transaction->transactionDetails as $transaction_detail) { + $unitPrice = bcdiv((string)$transaction_detail->price, (string)$currencyRate, 5); + $itemTotal = bcmul($unitPrice, (string)$transaction_detail->quantity, 5); + $subtotal = bcadd($subtotal, $itemTotal, 5); + } + return $subtotal; + } + + function getPoVoucherDiscount($voucher_redemption) { + return $voucher_redemption ? bcmul((string)$voucher_redemption->value, "-1", 2) : "0"; + } + function roundUpPo($number, $decimals) { + $factor = pow(10, $decimals); + if ($number > 0) { + return ceil($number * $factor) / $factor; + } else { + return floor($number * $factor) / $factor; + } + } + + @endphp @endsection