From 84ef064e3d585ef6a8692b3027e36b26d49d0657 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 12 Jul 2022 08:22:03 +1000 Subject: [PATCH 1/4] Handle scenario where task has no client --- .../PurchaseOrder/PurchaseOrderService.php | 22 +++++++++++++------ app/Transformers/TaskTransformer.php | 5 ++++- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/Services/PurchaseOrder/PurchaseOrderService.php b/app/Services/PurchaseOrder/PurchaseOrderService.php index b961d9897fdd..c6c1e57d4d90 100644 --- a/app/Services/PurchaseOrder/PurchaseOrderService.php +++ b/app/Services/PurchaseOrder/PurchaseOrderService.php @@ -48,19 +48,27 @@ class PurchaseOrderService public function fillDefaults() { - // $settings = $this->purchase_order->client->getMergedSettings(); - // //TODO implement design, footer, terms + $settings = $this->purchase_order->company->settings; - // /* If client currency differs from the company default currency, then insert the client exchange rate on the model.*/ - // if (!isset($this->purchase_order->exchange_rate) && $this->purchase_order->client->currency()->id != (int)$this->purchase_order->company->settings->currency_id) - // $this->purchase_order->exchange_rate = $this->purchase_order->client->currency()->exchange_rate; + if (! $this->purchase_order->design_id) + $this->purchase_order->design_id = $this->decodePrimaryKey($settings->invoice_design_id); + + if (!isset($this->invoice->footer) || empty($this->invoice->footer)) + $this->purchase_order->footer = $settings->purchase_order_footer; - // if (!isset($this->purchase_order->public_notes)) - // $this->purchase_order->public_notes = $this->purchase_order->client->public_notes; + if (!isset($this->purchase_order->terms) || empty($this->purchase_order->terms)) + $this->purchase_order->terms = $settings->purchase_order_terms; + if (!isset($this->purchase_order->public_notes) || empty($this->purchase_order->public_notes)) + $this->purchase_order->public_notes = $this->purchase_order->vendor->public_notes; + + if($settings->counter_number_applied == 'when_saved'){ + $this->applyNumber()->save(); + } return $this; + } public function triggeredActions($request) diff --git a/app/Transformers/TaskTransformer.php b/app/Transformers/TaskTransformer.php index d498dc44bb4f..33e6f360de70 100644 --- a/app/Transformers/TaskTransformer.php +++ b/app/Transformers/TaskTransformer.php @@ -41,10 +41,13 @@ class TaskTransformer extends EntityTransformer return $this->includeCollection($task->documents, $transformer, Document::class); } - public function includeClient(Task $task): Item + public function includeClient(Task $task): ?Item { $transformer = new ClientTransformer($this->serializer); + if(!$task->client) + return null; + return $this->includeItem($task->client, $transformer, Client::class); } From 63eb2ca524d6296921cc074c53451b86e3453c2e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 12 Jul 2022 08:37:18 +1000 Subject: [PATCH 2/4] Fixes for wrong payment types --- app/Models/PaymentType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/PaymentType.php b/app/Models/PaymentType.php index fe65ec2ff73f..22eb885b787d 100644 --- a/app/Models/PaymentType.php +++ b/app/Models/PaymentType.php @@ -18,7 +18,7 @@ class PaymentType extends StaticModel */ public $timestamps = false; - const CREDIT = 1; + const CREDIT = 32; const ACH = 4; const VISA = 5; const MASTERCARD = 6; From 7157c95ef4e68e5ee69483035df0c138e5c19c35 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 12 Jul 2022 20:47:17 +1000 Subject: [PATCH 3/4] Start recurring invoice on send now --- app/Repositories/BaseRepository.php | 2 +- app/Services/Recurring/RecurringService.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index 68261c0d4fb4..f0afe983f6b7 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -302,7 +302,7 @@ class BaseRepository /* Perform model specific tasks */ if ($model instanceof Invoice) { - if (($state['finished_amount'] != $state['starting_amount']) && ($model->status_id != Invoice::STATUS_DRAFT && $model->status_id != Invoice::STATUS_PAID)) { + if (($state['finished_amount'] != $state['starting_amount']) && ($model->status_id != Invoice::STATUS_DRAFT)) { //10-07-2022 $model->service()->updateStatus()->save(); diff --git a/app/Services/Recurring/RecurringService.php b/app/Services/Recurring/RecurringService.php index 5f4f3c49c1f8..f02173fbcdb6 100644 --- a/app/Services/Recurring/RecurringService.php +++ b/app/Services/Recurring/RecurringService.php @@ -123,8 +123,10 @@ class RecurringService public function sendNow() { - if($this->recurring_entity instanceof RecurringInvoice) + if($this->recurring_entity instanceof RecurringInvoice && $this->recurring_entity->status_id == RecurringInvoice::STATUS_DRAFT){ + $this->start()->save(); SendRecurring::dispatchNow($this->recurring_entity, $this->recurring_entity->company->db); + } return $this->recurring_entity; From 675ccc7b9e4f10b772497c46319919f98e32b57c Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 12 Jul 2022 20:50:50 +1000 Subject: [PATCH 4/4] Add status and client to task transformer --- app/Transformers/TaskTransformer.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/Transformers/TaskTransformer.php b/app/Transformers/TaskTransformer.php index 33e6f360de70..8f67de8e52a9 100644 --- a/app/Transformers/TaskTransformer.php +++ b/app/Transformers/TaskTransformer.php @@ -13,6 +13,8 @@ namespace App\Transformers; use App\Models\Document; use App\Models\Task; +use App\Models\TaskStatus; +use App\Transformers\TaskStatusTransformer; use App\Utils\Traits\MakesHash; use League\Fractal\Resource\Item; @@ -32,6 +34,7 @@ class TaskTransformer extends EntityTransformer */ protected $availableIncludes = [ 'client', + 'status' ]; public function includeDocuments(Task $task) @@ -51,6 +54,17 @@ class TaskTransformer extends EntityTransformer return $this->includeItem($task->client, $transformer, Client::class); } + public function includeStatus(Task $task): ?Item + { + $transformer = new TaskStatusTransformer($this->serializer); + + if(!$task->status) + return null; + + return $this->includeItem($task->status, $transformer, TaskStatus::class); + } + + public function transform(Task $task) { return [