invoiceninja/app/Http/Requests/CreatePaymentRequest.php

51 lines
1.3 KiB
PHP
Raw Permalink 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'])
2017-08-07 09:22:01 +03:00
->withArchived()
->invoices()
->firstOrFail();
2016-06-02 22:03:59 +03:00
$this->merge([
'invoice_id' => $invoice->id,
'client_id' => $invoice->client->id,
]);
$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
2017-08-09 10:57:24 +03:00
'amount' => 'required|numeric',
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;
}
}