diff --git a/app/Abstracts/View/Components/Document.php b/app/Abstracts/View/Components/Document.php index 362599aa1..a9942ac91 100644 --- a/app/Abstracts/View/Components/Document.php +++ b/app/Abstracts/View/Components/Document.php @@ -133,11 +133,43 @@ abstract class Document extends Component return $hide; } - + public function getClassFromConfig($type, $config_key) { $class_key = 'type.' . $type . '.class.' . $config_key; return config($class_key, ''); } + + public function getCategoryFromConfig($type) + { + $category_type = ''; + + // if set config trasnlation config_key + if ($category_type = config('type.' . $type . '.category_type')) { + return $category_type; + } + + switch ($type) { + case 'bill': + case 'expense': + case 'purchase': + $category_type = 'expense'; + break; + case 'item': + $category_type = 'item'; + break; + case 'other': + $category_type = 'other'; + break; + case 'transfer': + $category_type = 'transfer'; + break; + default: + $category_type = 'income'; + break; + } + + return $category_type; + } } diff --git a/app/Abstracts/View/Components/DocumentForm.php b/app/Abstracts/View/Components/DocumentForm.php index 942edab3f..40998a413 100644 --- a/app/Abstracts/View/Components/DocumentForm.php +++ b/app/Abstracts/View/Components/DocumentForm.php @@ -18,6 +18,9 @@ abstract class DocumentForm extends Base public $document; /** Advanced Component Start */ + /** @var string */ + public $categoryType; + /** @var bool */ public $hideRecurring; @@ -192,7 +195,7 @@ abstract class DocumentForm extends Base public function __construct( $type, $document = false, /** Advanced Component Start */ - bool $hideRecurring = false, bool $hideCategory = false, bool $hideAttachment = false, + string $categoryType = '', bool $hideRecurring = false, bool $hideCategory = false, bool $hideAttachment = false, /** Advanced Component End */ /** Company Component Start */ bool $hideLogo = false, bool $hideDocumentTitle = false, bool $hideDocumentSubheading = false, bool $hideCompanyEdit = false, @@ -220,6 +223,7 @@ abstract class DocumentForm extends Base $this->document = $document; /** Advanced Component Start */ + $this->categoryType = $this->getCategoryType($type, $categoryType); $this->hideRecurring = $hideRecurring; $this->hideCategory = $hideCategory; $this->hideAttachment = $hideAttachment; @@ -341,6 +345,22 @@ abstract class DocumentForm extends Base return 'invoices.index'; } + protected function getCategoryType($type, $categoryType) + { + if (!empty($categoryType)) { + return $categoryType; + } + + if ($category_type = config('type.' . $type . '.category_type')) { + return $category_type; + } + + // set default type + $type = Document::INVOICE_TYPE; + + return config('type.' . $type . '.category_type'); + } + protected function getContacts($type, $contacts) { if (!empty($contacts)) { diff --git a/app/View/Components/Documents/Form/Advanced.php b/app/View/Components/Documents/Form/Advanced.php index 800db9b80..c976fc360 100644 --- a/app/View/Components/Documents/Form/Advanced.php +++ b/app/View/Components/Documents/Form/Advanced.php @@ -14,7 +14,7 @@ class Advanced extends Component */ public function render() { - $category_type = $this->getCategoryType(); + $category_type = $this->categoryType; if ($category_type) { $categories = Category::$category_type()->enabled()->orderBy('name')->take(setting('default.select_limit'))->pluck('name', 'id'); @@ -24,31 +24,4 @@ class Advanced extends Component return view('components.documents.form.advanced', compact('categories', 'category_type')); } - - protected function getCategoryType() - { - $type = ''; - - switch ($this->type) { - case 'bill': - case 'expense': - case 'purchase': - $type = 'expense'; - break; - case 'item': - $type = 'item'; - break; - case 'other': - $type = 'other'; - break; - case 'transfer': - $type = 'transfer'; - break; - default: - $type = 'income'; - break; - } - - return $type; - } } diff --git a/config/type.php b/config/type.php index cda42d5bb..bcda981ba 100644 --- a/config/type.php +++ b/config/type.php @@ -23,6 +23,7 @@ return [ 'issued_at' => 'invoices.invoice_date', 'due_at' => 'invoices.due_date', ], + 'category_type' => 'income', 'contact_type' => 'customer', // use contact type 'hide' => [], // for document items 'class' => [], @@ -45,6 +46,7 @@ return [ 'issued_at' => 'bills.bill_date', 'due_at' => 'bills.due_date', ], + 'category_type' => 'expense', 'contact_type' => 'vendor', 'hide' => [], ], diff --git a/resources/views/components/documents/form/advanced.blade.php b/resources/views/components/documents/form/advanced.blade.php index f7727fdba..469bd8101 100644 --- a/resources/views/components/documents/form/advanced.blade.php +++ b/resources/views/components/documents/form/advanced.blade.php @@ -15,7 +15,7 @@