Tax type compound just add once.

This commit is contained in:
Cüneyt Şentürk 2020-12-22 14:47:50 +03:00
parent 1411bd879c
commit 654f7bbb2c
6 changed files with 45 additions and 7 deletions

View File

@ -43,7 +43,13 @@ class Taxes extends Controller
$rand = rand(); $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([ return response()->json([
'success' => true, 'success' => true,

View File

@ -57,7 +57,13 @@ class Taxes extends Controller
'compound' => trans('taxes.compound'), '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'), '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'));
} }
/** /**

View File

@ -23,10 +23,25 @@ class Tax extends FormRequest
*/ */
public function rules() 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 [ return [
'name' => 'required|string', 'name' => 'required|string',
'rate' => 'required|min:0|max:100', 'rate' => 'required|min:0|max:100',
'type' => 'required|string', 'type' => $type,
'enabled' => 'integer|boolean', 'enabled' => 'integer|boolean',
]; ];
} }

View File

@ -933,4 +933,9 @@ table .align-items-center td span.badge {
background: hsla(0,0%,100%,0); background: hsla(0,0%,100%,0);
border: none; border: none;
color: #8898aa; color: #8898aa;
} }
.el-select-dropdown__item.is-disabled {
color: #C0C4CC !important;
cursor: not-allowed !important;
}

View File

@ -21,7 +21,7 @@
{{ Form::textGroup('rate', trans('taxes.rate'), 'percent', ['@input' => 'onChangeTaxRate']) }} {{ 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) }} {{ Form::radioGroup('enabled', trans('general.enabled'), true) }}
</div> </div>

View File

@ -22,7 +22,7 @@
{{ Form::textGroup('rate', trans('taxes.rate'), 'percent', ['@input' => 'onChangeTaxRate']) }} {{ 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) }} {{ Form::radioGroup('enabled', trans('general.enabled'), $tax->enabled) }}
</div> </div>