1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Http/Requests/BankTransaction/MatchBankTransactionRequest.php

61 lines
1.5 KiB
PHP
Raw Normal View History

2022-09-15 05:58:42 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Requests\BankTransaction;
use App\Http\Requests\Request;
use App\Models\BankTransaction;
class MatchBankTransactionRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() : bool
{
return auth()->user()->isAdmin();
}
2022-09-15 06:15:02 +02:00
public function rules()
{
2022-09-22 07:54:58 +02:00
$rules = [
'id' => 'required|bail',
'invoice_ids' => 'nullable|string|sometimes',
'ninja_category_id' => 'nullable|string|sometimes'
2022-09-15 06:15:02 +02:00
];
2022-09-22 07:54:58 +02:00
if(isset($this->vendor_id))
$rules['vendor_id'] = 'bail|required|exists:vendors,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
return $rules;
2022-09-15 06:15:02 +02:00
}
public function prepareForValidation()
{
$input = $this->all();
2022-09-22 08:20:54 +02:00
if(array_key_exists('id', $input))
$input['id'] = $this->decodePrimaryKey($input['id']);
if(array_key_exists('ninja_category_id', $input))
$input['ninja_category_id'] = $this->decodePrimaryKey($input['ninja_category_id']);
2022-09-15 06:15:02 +02:00
$input = $this->decodePrimaryKeys($input);
$this->replace($input);
}
2022-09-15 05:58:42 +02:00
}