diff --git a/app/Http/Controllers/Modals/Taxes.php b/app/Http/Controllers/Modals/Taxes.php index e407e88f6..0b27b06a3 100644 --- a/app/Http/Controllers/Modals/Taxes.php +++ b/app/Http/Controllers/Modals/Taxes.php @@ -43,7 +43,13 @@ class Taxes extends Controller $rand = rand(); - $html = view('modals.taxes.create', compact('types', 'tax_selector', 'rand'))->render(); + $disable_options = []; + + if ($compound = Tax::compound()->first()) { + $disable_options = ['compound']; + } + + $html = view('modals.taxes.create', compact('types', 'tax_selector', 'disable_options', 'rand'))->render(); return response()->json([ 'success' => true, diff --git a/app/Http/Controllers/Settings/Taxes.php b/app/Http/Controllers/Settings/Taxes.php index 500e32587..f466371c9 100644 --- a/app/Http/Controllers/Settings/Taxes.php +++ b/app/Http/Controllers/Settings/Taxes.php @@ -57,7 +57,13 @@ class Taxes extends Controller 'compound' => trans('taxes.compound'), ]; - return view('settings.taxes.create', compact('types')); + $disable_options = []; + + if ($compound = Tax::compound()->first()) { + $disable_options = ['compound']; + } + + return view('settings.taxes.create', compact('types', 'disable_options')); } /** @@ -105,7 +111,13 @@ class Taxes extends Controller 'compound' => trans('taxes.compound'), ]; - return view('settings.taxes.edit', compact('tax', 'types')); + $disable_options = []; + + if ($tax->type != 'compound' && $compound = Tax::compound()->first()) { + $disable_options = ['compound']; + } + + return view('settings.taxes.edit', compact('tax', 'types', 'disable_options')); } /** diff --git a/app/Http/Requests/Setting/Tax.php b/app/Http/Requests/Setting/Tax.php index 76525ac77..5cbefde6a 100644 --- a/app/Http/Requests/Setting/Tax.php +++ b/app/Http/Requests/Setting/Tax.php @@ -23,10 +23,25 @@ class Tax extends FormRequest */ public function rules() { + // Check if store or update + if ($this->getMethod() == 'PATCH') { + $id = is_numeric($this->tax) ? $this->tax : $this->tax->getAttribute('id'); + } else { + $id = null; + } + + $company_id = $this->request->get('company_id'); + + $type = 'required|string'; + + if (!empty($this->request->get('type')) && $this->request->get('type') == 'compound') { + $type .= '|unique:taxes,NULL,' . $id . ',id,company_id,' . $company_id . ',type,compound,deleted_at,NULL'; + } + return [ 'name' => 'required|string', 'rate' => 'required|min:0|max:100', - 'type' => 'required|string', + 'type' => $type, 'enabled' => 'integer|boolean', ]; } diff --git a/public/css/custom.css b/public/css/custom.css index 27c6ba3fa..471b5fb99 100644 --- a/public/css/custom.css +++ b/public/css/custom.css @@ -933,4 +933,9 @@ table .align-items-center td span.badge { background: hsla(0,0%,100%,0); border: none; color: #8898aa; -} \ No newline at end of file +} + +.el-select-dropdown__item.is-disabled { + color: #C0C4CC !important; + cursor: not-allowed !important; +} diff --git a/resources/views/settings/taxes/create.blade.php b/resources/views/settings/taxes/create.blade.php index 74562046c..1e5992d60 100644 --- a/resources/views/settings/taxes/create.blade.php +++ b/resources/views/settings/taxes/create.blade.php @@ -21,7 +21,7 @@ {{ Form::textGroup('rate', trans('taxes.rate'), 'percent', ['@input' => 'onChangeTaxRate']) }} - {{ Form::selectGroup('type', trans_choice('general.types', 1), 'bars', $types, 'normal') }} + {{ Form::selectGroup('type', trans_choice('general.types', 1), 'bars', $types, 'normal', ['disabledOptions' => $disable_options]) }} {{ Form::radioGroup('enabled', trans('general.enabled'), true) }} diff --git a/resources/views/settings/taxes/edit.blade.php b/resources/views/settings/taxes/edit.blade.php index a32924e96..5af8961e7 100644 --- a/resources/views/settings/taxes/edit.blade.php +++ b/resources/views/settings/taxes/edit.blade.php @@ -22,7 +22,7 @@ {{ Form::textGroup('rate', trans('taxes.rate'), 'percent', ['@input' => 'onChangeTaxRate']) }} - {{ Form::selectGroup('type', trans_choice('general.types', 1), 'bars', $types, $tax->type) }} + {{ Form::selectGroup('type', trans_choice('general.types', 1), 'bars', $types, $tax->type, ['disabledOptions' => $disable_options]) }} {{ Form::radioGroup('enabled', trans('general.enabled'), $tax->enabled) }}