2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
2016-01-06 21:46:11 +01:00
|
|
|
|
2017-01-03 20:48:40 +01:00
|
|
|
use App\Models\Client;
|
|
|
|
|
2016-05-01 21:30:39 +02:00
|
|
|
class UpdateInvoiceRequest extends InvoiceRequest
|
2016-01-06 21:46:11 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function authorize()
|
|
|
|
{
|
2016-05-01 21:30:39 +02:00
|
|
|
return $this->user()->can('edit', $this->entity());
|
2016-01-06 21:46:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
2016-05-01 21:30:39 +02:00
|
|
|
$invoiceId = $this->entity()->id;
|
2016-08-13 21:19:37 +02:00
|
|
|
|
2016-01-06 21:46:11 +01:00
|
|
|
$rules = [
|
2017-02-21 14:27:04 +01:00
|
|
|
'client' => 'required',
|
2016-02-09 22:51:08 +01:00
|
|
|
'invoice_items' => 'valid_invoice_items',
|
2016-05-01 21:30:39 +02:00
|
|
|
'invoice_number' => 'required|unique:invoices,invoice_number,' . $invoiceId . ',id,account_id,' . $this->user()->account_id,
|
2016-01-06 21:46:11 +01:00
|
|
|
'discount' => 'positive',
|
2016-08-28 12:14:28 +02:00
|
|
|
'invoice_date' => 'required',
|
2016-08-15 21:57:05 +02:00
|
|
|
//'due_date' => 'date',
|
|
|
|
//'start_date' => 'date',
|
|
|
|
//'end_date' => 'date',
|
2016-01-06 21:46:11 +01:00
|
|
|
];
|
|
|
|
|
2017-01-03 20:48:40 +01: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 21:30:39 +02:00
|
|
|
/* There's a problem parsing the dates
|
|
|
|
if (Request::get('is_recurring') && Request::get('start_date') && Request::get('end_date')) {
|
|
|
|
$rules['end_date'] = 'after' . Request::get('start_date');
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2016-01-06 21:46:11 +01:00
|
|
|
return $rules;
|
|
|
|
}
|
|
|
|
}
|