make category types extendible
This commit is contained in:
parent
09dde2847f
commit
c074be895f
@ -11,9 +11,11 @@ use App\Jobs\Setting\CreateCategory;
|
|||||||
use App\Jobs\Setting\DeleteCategory;
|
use App\Jobs\Setting\DeleteCategory;
|
||||||
use App\Jobs\Setting\UpdateCategory;
|
use App\Jobs\Setting\UpdateCategory;
|
||||||
use App\Models\Setting\Category;
|
use App\Models\Setting\Category;
|
||||||
|
use App\Traits\Categories as Helper;
|
||||||
|
|
||||||
class Categories extends Controller
|
class Categories extends Controller
|
||||||
{
|
{
|
||||||
|
use Helper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
@ -26,12 +28,7 @@ class Categories extends Controller
|
|||||||
|
|
||||||
$transfer_id = Category::transfer();
|
$transfer_id = Category::transfer();
|
||||||
|
|
||||||
$types = collect([
|
$types = $this->getCategoryTypes();
|
||||||
'expense' => trans_choice('general.expenses', 1),
|
|
||||||
'income' => trans_choice('general.incomes', 1),
|
|
||||||
'item' => trans_choice('general.items', 1),
|
|
||||||
'other' => trans_choice('general.others', 1),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return $this->response('settings.categories.index', compact('categories', 'types', 'transfer_id'));
|
return $this->response('settings.categories.index', compact('categories', 'types', 'transfer_id'));
|
||||||
}
|
}
|
||||||
@ -53,12 +50,7 @@ class Categories extends Controller
|
|||||||
*/
|
*/
|
||||||
public function create()
|
public function create()
|
||||||
{
|
{
|
||||||
$types = [
|
$types = $this->getCategoryTypes();
|
||||||
'expense' => trans_choice('general.expenses', 1),
|
|
||||||
'income' => trans_choice('general.incomes', 1),
|
|
||||||
'item' => trans_choice('general.items', 1),
|
|
||||||
'other' => trans_choice('general.others', 1),
|
|
||||||
];
|
|
||||||
|
|
||||||
return view('settings.categories.create', compact('types'));
|
return view('settings.categories.create', compact('types'));
|
||||||
}
|
}
|
||||||
@ -128,12 +120,7 @@ class Categories extends Controller
|
|||||||
*/
|
*/
|
||||||
public function edit(Category $category)
|
public function edit(Category $category)
|
||||||
{
|
{
|
||||||
$types = [
|
$types = $this->getCategoryTypes();
|
||||||
'expense' => trans_choice('general.expenses', 1),
|
|
||||||
'income' => trans_choice('general.incomes', 1),
|
|
||||||
'item' => trans_choice('general.items', 1),
|
|
||||||
'other' => trans_choice('general.others', 1),
|
|
||||||
];
|
|
||||||
|
|
||||||
$type_disabled = (Category::where('type', $category->type)->count() == 1) ?: false;
|
$type_disabled = (Category::where('type', $category->type)->count() == 1) ?: false;
|
||||||
|
|
||||||
|
28
app/Traits/Categories.php
Normal file
28
app/Traits/Categories.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Traits;
|
||||||
|
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
trait Categories
|
||||||
|
{
|
||||||
|
public function getCategoryTypes()
|
||||||
|
{
|
||||||
|
$types = [];
|
||||||
|
$configs = config('type.category');
|
||||||
|
|
||||||
|
foreach ($configs as $type => $attr) {
|
||||||
|
$plural_type = Str::plural($type);
|
||||||
|
|
||||||
|
$name = $attr['translation']['prefix'] . '.' . $plural_type;
|
||||||
|
|
||||||
|
if (!empty($attr['alias'])) {
|
||||||
|
$name = $attr['alias'] . '::' . $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
$types[$type] = trans_choice($name, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $types;
|
||||||
|
}
|
||||||
|
}
|
119
config/type.php
119
config/type.php
@ -6,86 +6,115 @@ return [
|
|||||||
|
|
||||||
// Documents
|
// Documents
|
||||||
Document::INVOICE_TYPE => [
|
Document::INVOICE_TYPE => [
|
||||||
'alias' => '', // core empty but module write own alias
|
'alias' => '', // core empty but module write own alias
|
||||||
'group' => 'sales', // controller folder name for permission and route
|
'group' => 'sales', // controller folder name for permission and route
|
||||||
'route' => [
|
'route' => [
|
||||||
'prefix' => 'invoices', // core use with group + prefix, module ex. estimates
|
'prefix' => 'invoices', // core use with group + prefix, module ex. estimates
|
||||||
'parameter' => 'invoice', // sales/invoices/{parameter}/edit
|
'parameter' => 'invoice', // sales/invoices/{parameter}/edit
|
||||||
//'create' => 'invoices.create', // if you change route, you can write full path
|
//'create' => 'invoices.create', // if you change route, you can write full path
|
||||||
],
|
],
|
||||||
'permission' => [
|
'permission' => [
|
||||||
'prefix' => 'invoices', // this controller file name.
|
'prefix' => 'invoices', // this controller file name.
|
||||||
//'create' => 'create-sales-invoices', // if you change action permission key, you can write full permission
|
//'create' => 'create-sales-invoices', // if you change action permission key, you can write full permission
|
||||||
],
|
],
|
||||||
'translation' => [
|
'translation' => [
|
||||||
'prefix' => 'invoices', // this translation file name.
|
'prefix' => 'invoices', // this translation file name.
|
||||||
'add_contact' => 'general.customers', //
|
'add_contact' => 'general.customers', //
|
||||||
'issued_at' => 'invoices.invoice_date',
|
'issued_at' => 'invoices.invoice_date',
|
||||||
'due_at' => 'invoices.due_date',
|
'due_at' => 'invoices.due_date',
|
||||||
],
|
],
|
||||||
'category_type' => 'income',
|
'category_type' => 'income',
|
||||||
'transaction_type' => 'income',
|
'transaction_type' => 'income',
|
||||||
'contact_type' => 'customer', // use contact type
|
'contact_type' => 'customer', // use contact type
|
||||||
'hide' => [], // for document items
|
'hide' => [], // for document items
|
||||||
'class' => [],
|
'class' => [],
|
||||||
],
|
],
|
||||||
|
|
||||||
Document::BILL_TYPE => [
|
Document::BILL_TYPE => [
|
||||||
'alias' => '',
|
'alias' => '',
|
||||||
'group' => 'purchases',
|
'group' => 'purchases',
|
||||||
'route' => [
|
'route' => [
|
||||||
'prefix' => 'bills',
|
'prefix' => 'bills',
|
||||||
'parameter' => 'bill',
|
'parameter' => 'bill',
|
||||||
//'create' => 'bilss.create',
|
//'create' => 'bilss.create',
|
||||||
],
|
],
|
||||||
'permission' => [
|
'permission' => [
|
||||||
'prefix' => 'bills',
|
'prefix' => 'bills',
|
||||||
//'create' => 'create-purchases-bills',
|
//'create' => 'create-purchases-bills',
|
||||||
],
|
],
|
||||||
'translation' => [
|
'translation' => [
|
||||||
'prefix' => 'bills',
|
'prefix' => 'bills',
|
||||||
'issued_at' => 'bills.bill_date',
|
'issued_at' => 'bills.bill_date',
|
||||||
'due_at' => 'bills.due_date',
|
'due_at' => 'bills.due_date',
|
||||||
],
|
],
|
||||||
'category_type' => 'expense',
|
'category_type' => 'expense',
|
||||||
'transaction_type' => 'expense',
|
'transaction_type' => 'expense',
|
||||||
'contact_type' => 'vendor',
|
'contact_type' => 'vendor',
|
||||||
'hide' => [],
|
'hide' => [],
|
||||||
],
|
],
|
||||||
|
|
||||||
// Contacts
|
// Contacts
|
||||||
'customer' => [
|
'customer' => [
|
||||||
'group' => 'sales',
|
'group' => 'sales',
|
||||||
'permission' => [
|
'permission' => [
|
||||||
'prefix' => 'customers',
|
'prefix' => 'customers',
|
||||||
//'create' => 'create-sales-customers',
|
//'create' => 'create-sales-customers',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
'vendor' => [
|
'vendor' => [
|
||||||
'group' => 'purchases',
|
'group' => 'purchases',
|
||||||
'permission' => [
|
'permission' => [
|
||||||
'prefix' => 'vendors',
|
'prefix' => 'vendors',
|
||||||
//'create' => 'create-purchases-vendors',
|
//'create' => 'create-purchases-vendors',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
// Transactions
|
// Transactions
|
||||||
'income' => [
|
'income' => [
|
||||||
'group' => 'sales',
|
'group' => 'sales',
|
||||||
'permission' => [
|
'permission' => [
|
||||||
'prefix' => 'revenues',
|
'prefix' => 'revenues',
|
||||||
//'create' => 'create-sales-revenues',
|
//'create' => 'create-sales-revenues',
|
||||||
],
|
],
|
||||||
'contact_type' => 'customer',
|
'contact_type' => 'customer',
|
||||||
],
|
],
|
||||||
|
|
||||||
'expense' => [
|
'expense' => [
|
||||||
'group' => 'purchases',
|
'group' => 'purchases',
|
||||||
'permission' => [
|
'permission' => [
|
||||||
'prefix' => 'payments',
|
'prefix' => 'payments',
|
||||||
//'create' => 'create-purchases-payments',
|
//'create' => 'create-purchases-payments',
|
||||||
],
|
],
|
||||||
'contact_type' => 'vendor',
|
'contact_type' => 'vendor',
|
||||||
],
|
],
|
||||||
|
|
||||||
|
// Categories
|
||||||
|
'category' => [
|
||||||
|
'income' => [
|
||||||
|
'alias' => '',
|
||||||
|
'translation' => [
|
||||||
|
'prefix' => 'general',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'expense' => [
|
||||||
|
'alias' => '',
|
||||||
|
'translation' => [
|
||||||
|
'prefix' => 'general',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'item' => [
|
||||||
|
'alias' => '',
|
||||||
|
'translation' => [
|
||||||
|
'prefix' => 'general',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'other' => [
|
||||||
|
'alias' => '',
|
||||||
|
'translation' => [
|
||||||
|
'prefix' => 'general',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user