Add dynamic category type for modules..
This commit is contained in:
parent
7bdbaa973c
commit
381ce21f25
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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)) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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' => [],
|
||||
],
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
<div class="col-sm-6 col-md-6 col-lg-6 col-xl-6">
|
||||
@if (!$hideCategory)
|
||||
{{ Form::selectRemoteAddNewGroup('category_id', trans_choice('general.categories', 1), 'folder', $categories, setting('default.' . $category_type . '_category'), ['required' => 'required', 'path' => route('modals.categories.create') . '?type=' . $category_type, 'remote_action' => route('categories.index'). '?type=' . $category_type], 'col-md-12') }}
|
||||
{{ Form::selectRemoteAddNewGroup('category_id', trans_choice('general.categories', 1), 'folder', $categories, setting('default.' . $categoryType . '_category'), ['required' => 'required', 'path' => route('modals.categories.create') . '?type=' . $categoryType, 'remote_action' => route('categories.index'). '?type=' . $categoryType], 'col-md-12') }}
|
||||
@endif
|
||||
|
||||
@if (!$hideAttachment)
|
||||
|
@ -78,6 +78,7 @@
|
||||
<x-documents.form.advanced
|
||||
type="{{ $type }}"
|
||||
:document="$document"
|
||||
category-type="{{ $categoryType }}"
|
||||
hide-recurring="{{ $hideRecurring }}"
|
||||
hide-category="{{ $hideCategory }}"
|
||||
hide-attachment="{{ $hideAttachment }}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user