Add dynamic category type for modules..

This commit is contained in:
Cüneyt Şentürk
2021-01-11 16:18:17 +03:00
parent 7bdbaa973c
commit 381ce21f25
6 changed files with 59 additions and 31 deletions

View File

@ -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;
}
}

View File

@ -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)) {