invoiceninja/app/Http/Requests/UpdateInvoiceAPIRequest.php

50 lines
1.3 KiB
PHP
Raw Normal View History

2017-01-30 21:40:43 +02:00
<?php
namespace App\Http\Requests;
2016-05-01 22:30:39 +03:00
2017-01-03 21:48:40 +02:00
use App\Models\Client;
2016-05-01 22:30:39 +03:00
class UpdateInvoiceAPIRequest extends InvoiceRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return $this->user()->can('edit', $this->entity());
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
if ($this->action == ACTION_ARCHIVE) {
return [];
}
$invoiceId = $this->entity()->id;
$rules = [
'invoice_items' => 'valid_invoice_items',
'invoice_number' => 'unique:invoices,invoice_number,' . $invoiceId . ',id,account_id,' . $this->user()->account_id,
'discount' => 'positive',
2016-08-15 22:57:05 +03:00
//'invoice_date' => 'date',
//'due_date' => 'date',
//'start_date' => 'date',
//'end_date' => 'date',
2016-05-01 22:30:39 +03:00
];
2017-01-03 21:48:40 +02:00
if ($this->user()->account->client_number_counter) {
$clientId = Client::getPrivateId(request()->input('client')['public_id']);
$rules['client.id_number'] = 'unique:clients,id_number,'.$clientId.',id,account_id,' . $this->user()->account_id;
}
2016-05-01 22:30:39 +03:00
return $rules;
}
}