1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-23 01:41:34 +02:00
invoiceninja/app/Http/Requests/CreatePaymentRequest.php

42 lines
1.1 KiB
PHP
Raw Normal View History

2016-05-01 13:31:10 +02: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();
$invoice = Invoice::scope($input['invoice'])
->invoices()
->firstOrFail();
2016-06-02 21:03:59 +02:00
$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
2016-01-02 21:37:45 +01:00
'amount' => "required|less_than:{$invoice->balance}|positive",
];
2015-10-28 20:22:07 +01:00
2016-06-02 21:03:59 +02: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;
}
}