1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Http/Requests/CreatePaymentRequest.php

42 lines
981 B
PHP
Raw Normal View History

2015-10-28 20:22:07 +01:00
<?php namespace app\Http\Requests;
use App\Http\Requests\Request;
use Illuminate\Validation\Factory;
use App\Models\Invoice;
class CreatePaymentRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$input = $this->input();
2015-12-31 12:31:50 +01:00
$invoice = Invoice::scope($input['invoice'])->firstOrFail();
2015-10-28 20:22:07 +01:00
$rules = array(
'client' => 'required',
'invoice' => 'required',
2015-12-31 12:31:50 +01:00
'amount' => 'required|less_than:{$invoice->balance}|positive',
2015-10-28 20:22:07 +01:00
);
if ($input['payment_type_id'] == PAYMENT_TYPE_CREDIT) {
$rules['payment_type_id'] = 'has_credit:'.$input['client'].','.$input['amount'];
}
return $rules;
}
}