From 0a4e5cd0d6ac3483cd0c8d60ab2b3950adde02a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sat, 9 Jan 2021 18:56:11 +0300 Subject: [PATCH] Config type add hide for Document item columns.. --- app/Abstracts/View/Components/Document.php | 17 +- .../View/Components/DocumentForm.php | 132 +++++----- .../View/Components/DocumentShow.php | 234 +++++++++--------- .../View/Components/DocumentTemplate.php | 132 +++++----- config/type.php | 2 + 5 files changed, 283 insertions(+), 234 deletions(-) diff --git a/app/Abstracts/View/Components/Document.php b/app/Abstracts/View/Components/Document.php index f1b441605..ac4aaa739 100644 --- a/app/Abstracts/View/Components/Document.php +++ b/app/Abstracts/View/Components/Document.php @@ -62,9 +62,7 @@ abstract class Document extends Component return $route; } - $prefix = config("type.' . $type . '.route.prefix"); - - + $prefix = config("type.' . $type . '.route.prefix"); } public function getPermissionFromConfig($type, $config_key, $action) @@ -96,4 +94,17 @@ abstract class Document extends Component return $permission; } + + public function getHideFromConfig($type, $config_key) + { + $hide = false; + + $hides = config('type.' . $type . '.hide'); + + if (!empty($hides) && (in_array($config_key, $hides))) { + $hide = true; + } + + return $hide; + } } diff --git a/app/Abstracts/View/Components/DocumentForm.php b/app/Abstracts/View/Components/DocumentForm.php index 25e704ee4..79a1d9299 100644 --- a/app/Abstracts/View/Components/DocumentForm.php +++ b/app/Abstracts/View/Components/DocumentForm.php @@ -758,6 +758,12 @@ abstract class DocumentForm extends Base return $hideItems; } + $hide = $this->getHideFromConfig($type, 'items'); + + if ($hide) { + return $hide; + } + $hideItems = ($this->getHideName($type, $hideName) & $this->getHideDescription($type, $hideDescription)) ? true : false; return $hideItems; @@ -769,18 +775,19 @@ abstract class DocumentForm extends Base return $hideName; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideName = setting('bill.hide_item_name', $hideName); - break; - default: - $hideName = setting('invoice.hide_item_name', $hideName); - break; + // if you use settting translation + if ($hideName = setting($type . '.hide_item_name', false)) { + return $hideName; } - return $hideName; + $hide = $this->getHideFromConfig($type, 'name'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_item_name', $hideName); } protected function getHideDescription($type, $hideDescription) @@ -789,18 +796,19 @@ abstract class DocumentForm extends Base return $hideDescription; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideDescription = setting('bill.hide_item_description', $hideDescription); - break; - default: - $hideDescription = setting('invoice.hide_item_description', $hideDescription); - break; + // if you use settting translation + if ($hideDescription = setting($type . '.hide_item_description', false)) { + return $hideDescription; } - return $hideDescription; + $hide = $this->getHideFromConfig($type, 'description'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_item_description', $hideDescription); } protected function getHideQuantity($type, $hideQuantity) @@ -809,18 +817,19 @@ abstract class DocumentForm extends Base return $hideQuantity; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideQuantity = setting('bill.hide_quantity', $hideQuantity); - break; - default: - $hideQuantity = setting('invoice.hide_quantity', $hideQuantity); - break; + // if you use settting translation + if ($hideQuantity = setting($type . '.hide_quantity', false)) { + return $hideQuantity; } - return $hideQuantity; + $hide = $this->getHideFromConfig($type, 'quantity'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_quantity', $hideQuantity); } protected function getHidePrice($type, $hidePrice) @@ -829,18 +838,19 @@ abstract class DocumentForm extends Base return $hidePrice; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hidePrice = setting('bill.hide_price', $hidePrice); - break; - default: - $hidePrice = setting('invoice.hide_price', $hidePrice); - break; + // if you use settting translation + if ($hidePrice = setting($type . '.hide_price', false)) { + return $hidePrice; } - return $hidePrice; + $hide = $this->getHideFromConfig($type, 'price'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_price', $hidePrice); } protected function getHideDiscount($type, $hideDiscount) @@ -849,18 +859,19 @@ abstract class DocumentForm extends Base return $hideDiscount; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideDiscount = setting('bill.hide_discount', $hideDiscount); - break; - default: - $hideDiscount = setting('invoice.hide_discount', $hideDiscount); - break; + // if you use settting translation + if ($hideDiscount = setting($type . '.hide_discount', false)) { + return $hideDiscount; } - return $hideDiscount; + $hide = $this->getHideFromConfig($type, 'discount'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_discount', $hideDiscount); } protected function getHideAmount($type, $hideAmount) @@ -869,17 +880,18 @@ abstract class DocumentForm extends Base return $hideAmount; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideAmount = setting('bill.hide_amount', $hideAmount); - break; - default: - $hideAmount = setting('invoice.hide_amount', $hideAmount); - break; + // if you use settting translation + if ($hideAmount = setting($type . '.hide_amount', false)) { + return $hideAmount; } - return $hideAmount; + $hide = $this->getHideFromConfig($type, 'amount'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_amount', $hideAmount); } } diff --git a/app/Abstracts/View/Components/DocumentShow.php b/app/Abstracts/View/Components/DocumentShow.php index 9663d56a5..4c0e582ef 100644 --- a/app/Abstracts/View/Components/DocumentShow.php +++ b/app/Abstracts/View/Components/DocumentShow.php @@ -1317,7 +1317,7 @@ abstract class DocumentShow extends Base } protected function getTextTimelineGetPaidAddPayment($type, $textTimelineGetPaidAddPayment) - { + { if (!empty($textTimelineGetPaidAddPayment)) { return $textTimelineGetPaidAddPayment; } @@ -1331,134 +1331,146 @@ abstract class DocumentShow extends Base return 'invoices.add_payment'; } - protected function getHideItems($type, $hideItems, $hideName, $hideDescription) - { - if (!empty($hideItems)) { - return $hideItems; - } + protected function getHideItems($type, $hideItems, $hideName, $hideDescription) + { + if (!empty($hideItems)) { + return $hideItems; + } - $hideItems = ($this->getHideName($type, $hideName) & $this->getHideDescription($type, $hideDescription)) ? true : false; + $hide = $this->getHideFromConfig($type, 'items'); - return $hideItems; - } + if ($hide) { + return $hide; + } - protected function getHideName($type, $hideName) - { - if (!empty($hideName)) { - return $hideName; - } + $hideItems = ($this->getHideName($type, $hideName) & $this->getHideDescription($type, $hideDescription)) ? true : false; - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideName = setting('bill.hide_item_name', $hideName); - break; - default: - $hideName = setting('invoice.hide_item_name', $hideName); - break; - } + return $hideItems; + } - return $hideName; - } + protected function getHideName($type, $hideName) + { + if (!empty($hideName)) { + return $hideName; + } - protected function getHideDescription($type, $hideDescription) - { - if (!empty($hideDescription)) { - return $hideDescription; - } + // if you use settting translation + if ($hideName = setting($type . '.hide_item_name', false)) { + return $hideName; + } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideDescription = setting('bill.hide_item_description', $hideDescription); - break; - default: - $hideDescription = setting('invoice.hide_item_description', $hideDescription); - break; - } + $hide = $this->getHideFromConfig($type, 'name'); - return $hideDescription; - } + if ($hide) { + return $hide; + } - protected function getHideQuantity($type, $hideQuantity) - { - if (!empty($hideQuantity)) { - return $hideQuantity; - } + // @todo what return value invoice or always false?? + return setting('invoice.hide_item_name', $hideName); + } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideQuantity = setting('bill.hide_quantity', $hideQuantity); - break; - default: - $hideQuantity = setting('invoice.hide_quantity', $hideQuantity); - break; - } + protected function getHideDescription($type, $hideDescription) + { + if (!empty($hideDescription)) { + return $hideDescription; + } - return $hideQuantity; - } + // if you use settting translation + if ($hideDescription = setting($type . '.hide_item_description', false)) { + return $hideDescription; + } - protected function getHidePrice($type, $hidePrice) - { - if (!empty($hidePrice)) { - return $hidePrice; - } + $hide = $this->getHideFromConfig($type, 'description'); - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hidePrice = setting('bill.hide_price', $hidePrice); - break; - default: - $hidePrice = setting('invoice.hide_price', $hidePrice); - break; - } + if ($hide) { + return $hide; + } - return $hidePrice; - } + // @todo what return value invoice or always false?? + return setting('invoice.hide_item_description', $hideDescription); + } - protected function getHideDiscount($type, $hideDiscount) - { - if (!empty($hideDiscount)) { - return $hideDiscount; - } + protected function getHideQuantity($type, $hideQuantity) + { + if (!empty($hideQuantity)) { + return $hideQuantity; + } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideDiscount = setting('bill.hide_discount', $hideDiscount); - break; - default: - $hideDiscount = setting('invoice.hide_discount', $hideDiscount); - break; - } + // if you use settting translation + if ($hideQuantity = setting($type . '.hide_quantity', false)) { + return $hideQuantity; + } - return $hideDiscount; - } + $hide = $this->getHideFromConfig($type, 'quantity'); - protected function getHideAmount($type, $hideAmount) - { - if (!empty($hideAmount)) { - return $hideAmount; - } + if ($hide) { + return $hide; + } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideAmount = setting('bill.hide_amount', $hideAmount); - break; - default: - $hideAmount = setting('invoice.hide_amount', $hideAmount); - break; - } + // @todo what return value invoice or always false?? + return setting('invoice.hide_quantity', $hideQuantity); + } - return $hideAmount; - } + protected function getHidePrice($type, $hidePrice) + { + if (!empty($hidePrice)) { + return $hidePrice; + } + + // if you use settting translation + if ($hidePrice = setting($type . '.hide_price', false)) { + return $hidePrice; + } + + $hide = $this->getHideFromConfig($type, 'price'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_price', $hidePrice); + } + + protected function getHideDiscount($type, $hideDiscount) + { + if (!empty($hideDiscount)) { + return $hideDiscount; + } + + // if you use settting translation + if ($hideDiscount = setting($type . '.hide_discount', false)) { + return $hideDiscount; + } + + $hide = $this->getHideFromConfig($type, 'discount'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_discount', $hideDiscount); + } + + protected function getHideAmount($type, $hideAmount) + { + if (!empty($hideAmount)) { + return $hideAmount; + } + + // if you use settting translation + if ($hideAmount = setting($type . '.hide_amount', false)) { + return $hideAmount; + } + + $hide = $this->getHideFromConfig($type, 'amount'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_amount', $hideAmount); + } } diff --git a/app/Abstracts/View/Components/DocumentTemplate.php b/app/Abstracts/View/Components/DocumentTemplate.php index be651ab39..a7695d584 100644 --- a/app/Abstracts/View/Components/DocumentTemplate.php +++ b/app/Abstracts/View/Components/DocumentTemplate.php @@ -434,6 +434,12 @@ abstract class DocumentTemplate extends Base return $hideItems; } + $hide = $this->getHideFromConfig($type, 'items'); + + if ($hide) { + return $hide; + } + $hideItems = ($this->getHideName($type, $hideName) & $this->getHideDescription($type, $hideDescription)) ? true : false; return $hideItems; @@ -445,18 +451,19 @@ abstract class DocumentTemplate extends Base return $hideName; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideName = setting('bill.hide_item_name', $hideName); - break; - default: - $hideName = setting('invoice.hide_item_name', $hideName); - break; + // if you use settting translation + if ($hideName = setting($type . '.hide_item_name', false)) { + return $hideName; } - return $hideName; + $hide = $this->getHideFromConfig($type, 'name'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_item_name', $hideName); } protected function getHideDescription($type, $hideDescription) @@ -465,18 +472,19 @@ abstract class DocumentTemplate extends Base return $hideDescription; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideDescription = setting('bill.hide_item_description', $hideDescription); - break; - default: - $hideDescription = setting('invoice.hide_item_description', $hideDescription); - break; + // if you use settting translation + if ($hideDescription = setting($type . '.hide_item_description', false)) { + return $hideDescription; } - return $hideDescription; + $hide = $this->getHideFromConfig($type, 'description'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_item_description', $hideDescription); } protected function getHideQuantity($type, $hideQuantity) @@ -485,18 +493,19 @@ abstract class DocumentTemplate extends Base return $hideQuantity; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideQuantity = setting('bill.hide_quantity', $hideQuantity); - break; - default: - $hideQuantity = setting('invoice.hide_quantity', $hideQuantity); - break; + // if you use settting translation + if ($hideQuantity = setting($type . '.hide_quantity', false)) { + return $hideQuantity; } - return $hideQuantity; + $hide = $this->getHideFromConfig($type, 'quantity'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_quantity', $hideQuantity); } protected function getHidePrice($type, $hidePrice) @@ -505,18 +514,19 @@ abstract class DocumentTemplate extends Base return $hidePrice; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hidePrice = setting('bill.hide_price', $hidePrice); - break; - default: - $hidePrice = setting('invoice.hide_price', $hidePrice); - break; + // if you use settting translation + if ($hidePrice = setting($type . '.hide_price', false)) { + return $hidePrice; } - return $hidePrice; + $hide = $this->getHideFromConfig($type, 'price'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_price', $hidePrice); } protected function getHideDiscount($type, $hideDiscount) @@ -525,18 +535,19 @@ abstract class DocumentTemplate extends Base return $hideDiscount; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideDiscount = setting('bill.hide_discount', $hideDiscount); - break; - default: - $hideDiscount = setting('invoice.hide_discount', $hideDiscount); - break; + // if you use settting translation + if ($hideDiscount = setting($type . '.hide_discount', false)) { + return $hideDiscount; } - return $hideDiscount; + $hide = $this->getHideFromConfig($type, 'discount'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_discount', $hideDiscount); } protected function getHideAmount($type, $hideAmount) @@ -545,17 +556,18 @@ abstract class DocumentTemplate extends Base return $hideAmount; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideAmount = setting('bill.hide_amount', $hideAmount); - break; - default: - $hideAmount = setting('invoice.hide_amount', $hideAmount); - break; + // if you use settting translation + if ($hideAmount = setting($type . '.hide_amount', false)) { + return $hideAmount; } - return $hideAmount; + $hide = $this->getHideFromConfig($type, 'amount'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_amount', $hideAmount); } } diff --git a/config/type.php b/config/type.php index 9f4196d7f..be730bfc7 100644 --- a/config/type.php +++ b/config/type.php @@ -24,6 +24,7 @@ return [ 'due_at' => 'invoices.due_date', ], 'contact_type' => 'customer', // use contact type + 'hide' => [], // for document items ], Document::BILL_TYPE => [ @@ -44,6 +45,7 @@ return [ 'due_at' => 'bills.due_date', ], 'contact_type' => 'vendor', + 'hide' => [], ], // Contacts