mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Prevent duplicate payment terms
This commit is contained in:
parent
2c41361cae
commit
552b72a4bc
@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\CreatePaymentTermAPIRequest;
|
||||
use App\Http\Requests\CreatePaymentTermRequest;
|
||||
use App\Http\Requests\PaymentTermRequest;
|
||||
use App\Http\Requests\UpdatePaymentTermRequest;
|
||||
use App\Libraries\Utils;
|
||||
@ -110,7 +110,7 @@ class PaymentTermApiController extends BaseAPIController
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function store(CreatePaymentTermAPIRequest $request)
|
||||
public function store(CreatePaymentTermRequest $request)
|
||||
{
|
||||
|
||||
$paymentTerm = PaymentTerm::createNew();
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\CreatePaymentTermRequest;
|
||||
use App\Http\Requests\UpdatePaymentTermRequest;
|
||||
use App\Models\PaymentTerm;
|
||||
use App\Services\PaymentTermService;
|
||||
use Auth;
|
||||
@ -84,7 +86,7 @@ class PaymentTermController extends BaseController
|
||||
/**
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store()
|
||||
public function store(CreatePaymentTermRequest $request)
|
||||
{
|
||||
return $this->save();
|
||||
}
|
||||
@ -94,7 +96,7 @@ class PaymentTermController extends BaseController
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update($publicId)
|
||||
public function update(UpdatePaymentTermRequest $request, $publicId)
|
||||
{
|
||||
return $this->save($publicId);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ namespace App\Http\Requests;
|
||||
|
||||
use App\Models\Invoice;
|
||||
|
||||
class CreatePaymentTermAPIRequest extends Request
|
||||
class CreatePaymentTermRequest extends PaymentTermRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
@ -27,7 +27,8 @@ class CreatePaymentTermAPIRequest extends Request
|
||||
{
|
||||
|
||||
$rules = [
|
||||
'num_days' => 'required|numeric|unique:payment_terms',
|
||||
'num_days' => 'required|numeric|unique:payment_terms,num_days,,id,account_id,' . $this->user()->account_id . ',deleted_at,NULL'
|
||||
. '|unique:payment_terms,num_days,,id,account_id,0,deleted_at,NULL',
|
||||
];
|
||||
|
||||
|
@ -2,16 +2,41 @@
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
class UpdatePaymentTermRequest extends EntityRequest
|
||||
use App\Models\Invoice;
|
||||
|
||||
class UpdatePaymentTermRequest extends PaymentTermRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
||||
public function authorize()
|
||||
{
|
||||
return $this->entity() && $this->user()->can('edit', $this->entity());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [];
|
||||
if (! $this->entity()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$paymentTermId = $this->entity()->id;
|
||||
|
||||
$rules = [
|
||||
'num_days' => 'required|numeric|unique:payment_terms,num_days,' . $paymentTermId . ',id,account_id,' . $this->user()->account_id . ',deleted_at,NULL'
|
||||
. '|unique:payment_terms,num_days,' . $paymentTermId . ',id,account_id,0,deleted_at,NULL',
|
||||
];
|
||||
|
||||
|
||||
return $rules;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user