diff --git a/app/Abstracts/View/Components/Transfers/Show.php b/app/Abstracts/View/Components/Transfers/Show.php index fd06b53a9..6c5eef823 100644 --- a/app/Abstracts/View/Components/Transfers/Show.php +++ b/app/Abstracts/View/Components/Transfers/Show.php @@ -4,6 +4,7 @@ namespace App\Abstracts\View\Components\Transfers; use App\Abstracts\View\Component; use App\Traits\ViewComponents; +use App\Utilities\Modules; abstract class Show extends Component { @@ -13,7 +14,9 @@ abstract class Show extends Component public $transfer; - public $template; + public array $payment_methods; + + public string $template; /** * Create a new component instance. @@ -21,10 +24,11 @@ abstract class Show extends Component * @return void */ public function __construct( - $model = false, $transfer = false, string $template = '' + $model = false, $transfer = false, array $payment_methods = [], string $template = '' ) { $this->model = $model; $this->transfer = $this->getTransfer($model, $transfer); + $this->payment_methods = ($payment_methods) ?: Modules::getPaymentMethods('all'); $this->template = ! empty($template) ? $template : setting('transfer.template'); // Set Parent data diff --git a/app/Abstracts/View/Components/Transfers/Template.php b/app/Abstracts/View/Components/Transfers/Template.php index 4e3b161b4..040a42824 100644 --- a/app/Abstracts/View/Components/Transfers/Template.php +++ b/app/Abstracts/View/Components/Transfers/Template.php @@ -4,6 +4,7 @@ namespace App\Abstracts\View\Components\Transfers; use App\Abstracts\View\Component; use App\Traits\ViewComponents; +use App\Utilities\Modules; abstract class Template extends Component { @@ -13,7 +14,9 @@ abstract class Template extends Component public $transfer; - public $template; + public array $payment_methods; + + public string $template; /** * Create a new component instance. @@ -21,10 +24,11 @@ abstract class Template extends Component * @return void */ public function __construct( - $model = false, $transfer = false, string $template = '' + $model = false, $transfer = false, array $payment_methods = [], string $template = '' ) { $this->model = $model; $this->transfer = $this->getTransfer($model, $transfer); + $this->payment_methods = ($payment_methods) ?: Modules::getPaymentMethods('all'); $this->template = ! empty($template) ? $template : setting('transfer.template'); // Set Parent data diff --git a/app/View/Components/Form/Group/Category.php b/app/View/Components/Form/Group/Category.php index 008fc99d1..609ad1ec3 100644 --- a/app/View/Components/Form/Group/Category.php +++ b/app/View/Components/Form/Group/Category.php @@ -22,8 +22,6 @@ class Category extends Form */ public function render() { - $type = $this->type; - if (empty($this->name)) { $this->name = 'category_id'; } @@ -31,18 +29,20 @@ class Category extends Form $this->path = route('modals.categories.create', ['type' => $this->type]); $this->remoteAction = route('categories.index', ['search' => 'type:' . $this->type . ' enabled:1']); - $this->categories = Model::type($type)->enabled()->orderBy('name')->take(setting('default.select_limit'))->get(); + $this->categories = Model::type($this->type)->enabled()->orderBy('name')->take(setting('default.select_limit'))->get(); - if (!empty($model) && $model->category && ! $this->categories->has($model->category_id)) { - $this->categories->put($model->category->id, $model->category->name); - } + $model = $this->getParentData('model'); - if($model = $this->getParentData('model')) { + if (! empty($model)) { $this->selected = $model->category_id; + + if (! $this->categories->has($model->category_id) && ($category = $model->category)) { + $this->categories->put($category->id, $category->name); + } } - if (empty($this->selected) && (in_array($type, ['income', 'expense']))) { - $this->selected = setting('default.' . $type . '_category'); + if (empty($this->selected) && (in_array($this->type, [Model::INCOME_TYPE, Model::EXPENSE_TYPE]))) { + $this->selected = setting('default.' . $this->type . '_category'); } return view('components.form.group.category'); diff --git a/app/View/Components/Form/Group/Contact.php b/app/View/Components/Form/Group/Contact.php index 62e8bc853..e471d73ec 100644 --- a/app/View/Components/Form/Group/Contact.php +++ b/app/View/Components/Form/Group/Contact.php @@ -4,6 +4,7 @@ namespace App\View\Components\Form\Group; use App\Abstracts\View\Components\Form; use App\Models\Common\Contact as Model; +use Illuminate\Support\Str; class Contact extends Form { @@ -26,51 +27,37 @@ class Contact extends Form */ public function render() { - $type = $this->type; + if (empty($this->name)) { + $this->name = 'contact_id'; + } - switch ($type) { - case 'customer': - $this->prepareCustomer(); - break; - case 'vendor': - $this->prepareVendor(); - break; + $this->setRoutes(); + + $this->label = trans_choice('general.' . Str::plural($this->type), 1); + + $this->contacts = Model::type($this->type)->enabled()->orderBy('name')->take(setting('default.select_limit'))->get(); + + $model = $this->getParentData('model'); + + if (! empty($model)) { + $this->selected = $model->contact_id; + + if (! $this->contacts->has($model->contact_id) && ($contact = $model->contact)) { + $this->contacts->put($contact->id, $contact->name); + } } return view($this->view); } - protected function prepareCustomer() + public function setRoutes(): void { - if (empty($this->name)) { - $this->name = 'contact_id'; - } + $alias = config('type.contact.' . $this->type . '.alias'); + $prefix = config('type.contact.' . $this->type . '.route.prefix'); - $this->path = route('modals.customers.create'); - $this->remoteAction = route('customers.index'); - $this->label = trans_choice('general.customers', 1); + $parameters = ['search' => 'enabled:1']; - $this->contacts = Model::customer()->enabled()->orderBy('name')->take(setting('default.select_limit'))->get(); - - if (! empty($model) && $model->customer && ! $this->contacts->has($model->contact_id)) { - $this->contacts->put($model->customer->id, $model->customer->name); - } - } - - protected function prepareVendor() - { - if (empty($this->name)) { - $this->name = 'contact_id'; - } - - $this->path = route('modals.vendors.create'); - $this->remoteAction = route('vendors.index'); - $this->label = trans_choice('general.vendors', 1); - - $this->contacts = Model::vendor()->enabled()->orderBy('name')->take(setting('default.select_limit'))->get(); - - if (! empty($model) && $model->vendor && ! $this->contacts->has($model->contact_id)) { - $this->contacts->put($model->vendor->id, $model->vendor->name); - } + $this->path = ! empty($alias) ? route("{$alias}.modals.{$prefix}.create") : route("modals.{$prefix}.create"); + $this->remoteAction = ! empty($alias) ? route("{$alias}.{$prefix}.index", $parameters) : route("{$prefix}.index", $parameters); } } diff --git a/config/type.php b/config/type.php index 3ed82d195..af729558d 100644 --- a/config/type.php +++ b/config/type.php @@ -41,6 +41,7 @@ return [ // Contacts 'contact' => [ Contact::CUSTOMER_TYPE => [ + 'alias' => '', // core empty but module write own alias 'group' => 'sales', 'route' => [ 'prefix' => 'customers', // core use with group + prefix, module ex. estimates @@ -69,6 +70,7 @@ return [ ], Contact::VENDOR_TYPE => [ + 'alias' => '', // core empty but module write own alias 'group' => 'purchases', 'route' => [ 'prefix' => 'vendors', // core use with group + prefix, module ex. estimates diff --git a/resources/views/banking/accounts/show.blade.php b/resources/views/banking/accounts/show.blade.php index 5bfa87706..de848def5 100644 --- a/resources/views/banking/accounts/show.blade.php +++ b/resources/views/banking/accounts/show.blade.php @@ -3,7 +3,7 @@ {{ $account->name }} - +
@if (! $account->enabled) diff --git a/resources/views/components/contacts/show/content.blade.php b/resources/views/components/contacts/show/content.blade.php index d0f9c7a01..71f09bbbe 100644 --- a/resources/views/components/contacts/show/content.blade.php +++ b/resources/views/components/contacts/show/content.blade.php @@ -162,7 +162,7 @@ - @@ -196,7 +196,7 @@ @foreach($documents as $item) @php $paid = $item->paid; @endphp -