2016-05-01 13:31:10 +02:00
|
|
|
<?php namespace App\Http\Requests;
|
2015-10-28 20:22:07 +01:00
|
|
|
|
2016-05-01 21:30:39 +02:00
|
|
|
class CreateInvoiceRequest extends InvoiceRequest
|
2015-10-28 20:22:07 +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('create', ENTITY_INVOICE);
|
2015-10-28 20:22:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
|
|
|
$rules = [
|
2016-05-01 21:30:39 +02:00
|
|
|
'client.contacts' => 'valid_contacts',
|
2015-11-04 08:48:47 +01:00
|
|
|
'invoice_items' => 'valid_invoice_items',
|
2016-05-01 21:30:39 +02:00
|
|
|
'invoice_number' => 'required|unique:invoices,invoice_number,,id,account_id,' . $this->user()->account_id,
|
2015-10-28 20:22:07 +01:00
|
|
|
'discount' => 'positive',
|
|
|
|
];
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2015-10-28 20:22:07 +01:00
|
|
|
return $rules;
|
|
|
|
}
|
|
|
|
}
|