1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 13:42:49 +01:00
invoiceninja/app/Http/Requests/BankTransaction/MatchBankTransactionRequest.php

63 lines
1.6 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 = [
2022-10-24 10:18:50 +02:00
'*.id' => 'required|bail',
'*.invoice_ids' => 'nullable|string|sometimes',
'*.ninja_category_id' => 'nullable|string|sometimes'
2022-09-15 06:15:02 +02:00
];
2022-10-24 10:18:50 +02:00
$rules['*.vendor_id'] = 'bail|sometimes|exists:vendors,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
2022-09-22 07:54:58 +02:00
return $rules;
2022-09-15 06:15:02 +02:00
}
public function prepareForValidation()
{
2022-10-24 10:11:37 +02:00
$inputs = $this->all();
2022-09-15 06:15:02 +02:00
2022-10-24 10:11:37 +02:00
foreach($inputs as $input)
{
if(array_key_exists('id', $input))
$input['id'] = $this->decodePrimaryKey($input['id']);
2022-09-22 08:20:54 +02:00
2022-10-24 10:11:37 +02:00
if(array_key_exists('ninja_category_id', $input) && strlen($input['ninja_category_id']) >= 1)
$input['ninja_category_id'] = $this->decodePrimaryKey($input['ninja_category_id']);
2022-09-22 08:20:54 +02:00
2022-10-24 10:11:37 +02:00
$input = $this->decodePrimaryKeys($input);
}
2022-10-24 10:18:50 +02:00
2022-10-24 10:11:37 +02:00
$this->replace($inputs);
2022-09-15 06:15:02 +02:00
}
2022-09-15 05:58:42 +02:00
}