1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Merge pull request #8822 from turbo124/v5-develop

Prevent duplicate tax names
This commit is contained in:
David Bomba 2023-09-21 13:56:15 +10:00 committed by GitHub
commit fd5d519dda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 7 deletions

View File

@ -22,14 +22,20 @@ class StoreTaxRateRequest extends Request
*/
public function authorize() : bool
{
return auth()->user()->isAdmin();
/** @var \App\Models\User $user */
$user = auth()->user();
return $user->isAdmin();
}
public function rules()
{
/** @var \App\Models\User $user */
$user = auth()->user();
return [
//'name' => 'required',
'name' => 'required|unique:tax_rates,name,null,null,company_id,'.auth()->user()->companyId().',deleted_at,NULL',
'name' => 'required|unique:tax_rates,name,null,null,company_id,'.$user->companyId().',deleted_at,NULL',
'rate' => 'required|numeric',
];
}

View File

@ -23,17 +23,25 @@ class UpdateTaxRateRequest extends Request
*/
public function authorize() : bool
{
return auth()->user()->isAdmin();
/** @var \App\Models\User $user */
$user = auth()->user();
return $user->isAdmin();
}
public function rules()
{
/** @var \App\Models\User $user */
$user = auth()->user();
$rules = [];
$rules['rate'] = 'numeric';
$rules['rate'] = 'required|numeric';
if ($this->number) {
$rules['number'] = Rule::unique('tax_rates')->where('company_id', auth()->user()->company()->id)->ignore($this->tax_rate->id);
if ($this->name) {
$rules['name'] = Rule::unique('tax_rates')->where('company_id', auth()->user()->company()->id)->ignore($this->tax_rate->id);
}
return $rules;