1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Http/Requests/CreatePaymentRequest.php

50 lines
1.3 KiB
PHP
Raw Normal View History

2017-01-30 20:40:43 +01:00
<?php
namespace App\Http\Requests;
2015-10-28 20:22:07 +01:00
use App\Models\Invoice;
2016-05-01 13:31:10 +02:00
class CreatePaymentRequest extends PaymentRequest
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 13:31:10 +02:00
return $this->user()->can('create', ENTITY_PAYMENT);
2015-10-28 20:22:07 +01:00
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$input = $this->input();
$this->invoice = $invoice = Invoice::scope($input['invoice'])
->invoices()
->firstOrFail();
2016-06-02 21:03:59 +02:00
$this->merge([
'invoice_id' => $invoice->id,
'client_id' => $invoice->client->id,
]);
$rules = [
2016-06-02 21:03:59 +02:00
'client' => 'required', // TODO: change to client_id once views are updated
'invoice' => 'required', // TODO: change to invoice_id once views are updated
2017-03-26 20:31:13 +02:00
'amount' => 'required|numeric|not_in:0',
2016-08-25 16:31:36 +02:00
'payment_date' => 'required',
];
2015-10-28 20:22:07 +01:00
2017-01-30 17:05:31 +01:00
if (! empty($input['payment_type_id']) && $input['payment_type_id'] == PAYMENT_TYPE_CREDIT) {
2015-10-28 20:22:07 +01:00
$rules['payment_type_id'] = 'has_credit:'.$input['client'].','.$input['amount'];
}
return $rules;
}
}