From 27c7572821c7c1736b645f24922139b41e23b32a Mon Sep 17 00:00:00 2001 From: = Date: Sat, 23 Jan 2021 15:42:27 +1100 Subject: [PATCH] Do not update or create a product if Invoice generated from a task/expense --- app/Jobs/Product/UpdateOrCreateProduct.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/Jobs/Product/UpdateOrCreateProduct.php b/app/Jobs/Product/UpdateOrCreateProduct.php index bba2b15abb05..156159791934 100644 --- a/app/Jobs/Product/UpdateOrCreateProduct.php +++ b/app/Jobs/Product/UpdateOrCreateProduct.php @@ -54,7 +54,18 @@ class UpdateOrCreateProduct implements ShouldQueue public function handle() { MultiDB::setDB($this->company->db); - + + /* + * If the invoice was generated from a Task or Expense then + * we do NOT update the product details this short block we + * check for the presence of a task_id and/or expense_id + */ + $expense_count = count(array_column((array)$this->products, 'expense_id')); + $task_count = count(array_column((array)$this->products, 'task_id')); + + if($task_count >= 1 || $expense_count >= 1) + return; + //only update / create products - not tasks or gateway fees $updateable_products = collect($this->products)->filter(function ($item) { return $item->type_id == 1;