invoiceninja/app/Http/Requests/CreatePaymentRequest.php

45 lines
1.2 KiB
PHP
Raw Normal View History

2017-01-30 21:40:43 +02:00
<?php
namespace App\Http\Requests;
2015-10-28 21:22:07 +02:00
use App\Models\Invoice;
2016-05-01 14:31:10 +03:00
class CreatePaymentRequest extends PaymentRequest
2015-10-28 21:22:07 +02:00
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
2016-05-01 14:31:10 +03:00
return $this->user()->can('create', ENTITY_PAYMENT);
2015-10-28 21:22:07 +02: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 22:03:59 +03:00
$rules = [
2016-06-02 22:03:59 +03:00
'client' => 'required', // TODO: change to client_id once views are updated
'invoice' => 'required', // TODO: change to invoice_id once views are updated
2016-08-28 17:19:33 +03:00
'amount' => "required|numeric|between:0.01,{$invoice->balance}",
2016-08-25 17:31:36 +03:00
'payment_date' => 'required',
];
2015-10-28 21:22:07 +02:00
2017-01-30 18:05:31 +02:00
if (! empty($input['payment_type_id']) && $input['payment_type_id'] == PAYMENT_TYPE_CREDIT) {
2015-10-28 21:22:07 +02:00
$rules['payment_type_id'] = 'has_credit:'.$input['client'].','.$input['amount'];
}
return $rules;
}
}