1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 15:42:51 +01:00
invoiceninja/app/Http/Requests/BankTransactionRule/StoreBankTransactionRuleRequest.php

70 lines
2.1 KiB
PHP
Raw Normal View History

2022-11-13 05:12:50 +01:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2024-04-12 06:15:41 +02:00
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
2022-11-13 05:12:50 +01:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Requests\BankTransactionRule;
use App\Http\Requests\Request;
2023-02-16 02:36:09 +01:00
use App\Models\Account;
2023-02-14 23:28:23 +01:00
use App\Models\BankTransactionRule;
2023-02-16 02:36:09 +01:00
use App\Utils\Traits\MakesHash;
2022-11-13 05:12:50 +01:00
class StoreBankTransactionRuleRequest extends Request
{
use MakesHash;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
2024-01-14 05:05:00 +01:00
public function authorize(): bool
2022-11-13 05:12:50 +01:00
{
2024-04-14 23:57:24 +02:00
/** @var \App\Models\User $user */
$user = auth()->user();
return $user->can('create', BankTransactionRule::class) && $user->account->hasFeature(Account::FEATURE_API);
2023-02-16 02:36:09 +01:00
;
2022-11-13 05:12:50 +01:00
}
2024-01-14 05:05:00 +01:00
2022-11-13 05:12:50 +01:00
public function rules()
{
2024-04-14 23:57:24 +02:00
/** @var \App\Models\User $user */
$user = auth()->user();
2022-11-13 05:12:50 +01:00
/* Ensure we have a client name, and that all emails are unique*/
$rules = [
2022-11-13 05:41:34 +01:00
'name' => 'bail|required|string',
'rules' => 'bail|array',
2022-11-23 22:05:08 +01:00
'rules.*.operator' => 'bail|required|nullable',
'rules.*.search_key' => 'bail|required|nullable',
'rules.*.value' => 'bail|required|nullable',
2022-11-13 05:41:34 +01:00
'auto_convert' => 'bail|sometimes|bool',
'matches_on_all' => 'bail|sometimes|bool',
'applies_to' => 'bail|sometimes|string',
2022-11-13 05:12:50 +01:00
];
2024-06-18 12:37:57 +02:00
$rules['category_id'] = 'bail|sometimes|nullable|exists:expense_categories,id,company_id,'.$user->company()->id.',is_deleted,0';
$rules['vendor_id'] = 'bail|sometimes|nullable|exists:vendors,id,company_id,'.$user->company()->id.',is_deleted,0';
$rules['client_id'] = 'bail|sometimes|nullable|exists:clients,id,company_id,'.$user->company()->id.',is_deleted,0';
2022-11-13 05:12:50 +01:00
return $rules;
}
public function prepareForValidation()
{
$input = $this->all();
$input = $this->decodePrimaryKeys($input);
$this->replace($input);
}
}