1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 08:02:40 +01:00
invoiceninja/app/Http/Requests/BankTransaction/ImportBankTransactionsRequest.php

65 lines
2.1 KiB
PHP
Raw Normal View History

2022-10-25 01:25:04 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
2022-10-25 01:25:04 +02:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Requests\BankTransaction;
use App\Http\Requests\Request;
class ImportBankTransactionsRequest extends Request
{
/**
* 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-10-25 01:25:04 +02:00
{
return auth()->user()->isAdmin();
}
public function rules()
{
$rules = [
'transactions' => 'bail|array',
'transactions.*.id' => 'bail|required',
'transactions.*.invoice_ids' => 'nullable|string|sometimes',
'transactions.*.ninja_category_id' => 'nullable|string|sometimes'
];
$rules['transactions.*.vendor_id'] = 'bail|sometimes|exists:vendors,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
return $rules;
}
public function prepareForValidation()
{
$inputs = $this->all();
2024-01-14 05:05:00 +01:00
2023-02-16 02:36:09 +01:00
foreach ($inputs['transactions'] as $key => $input) {
if (array_key_exists('id', $inputs['transactions'][$key])) {
2022-10-25 01:25:04 +02:00
$inputs['transactions'][$key]['id'] = $this->decodePrimaryKey($input['id']);
2023-02-16 02:36:09 +01:00
}
2022-10-25 01:25:04 +02:00
2023-02-16 02:36:09 +01:00
if (array_key_exists('ninja_category_id', $inputs['transactions'][$key]) && strlen($inputs['transactions'][$key]['ninja_category_id']) >= 1) {
2022-10-25 01:25:04 +02:00
$inputs['transactions'][$key]['ninja_category_id'] = $this->decodePrimaryKey($inputs['transactions'][$key]['ninja_category_id']);
2023-02-16 02:36:09 +01:00
}
2022-10-25 01:25:04 +02:00
2023-02-16 02:36:09 +01:00
if (array_key_exists('vendor_id', $inputs['transactions'][$key]) && strlen($inputs['transactions'][$key]['vendor_id']) >= 1) {
2022-10-25 01:25:04 +02:00
$inputs['transactions'][$key]['vendor_id'] = $this->decodePrimaryKey($inputs['transactions'][$key]['vendor_id']);
2023-02-16 02:36:09 +01:00
}
2022-10-25 01:25:04 +02:00
// $input = $this->decodePrimaryKeys($input);
}
$this->replace($inputs);
}
}