2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
2015-10-28 20:22:07 +01:00
|
|
|
|
2017-01-03 20:48:40 +01:00
|
|
|
use App\Models\Client;
|
|
|
|
|
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-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',
|
2015-10-28 20:22:07 +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');
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2015-10-28 20:22:07 +01:00
|
|
|
return $rules;
|
|
|
|
}
|
|
|
|
}
|