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

68 lines
1.7 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:50:45 +02:00
'transactions' => 'bail|array',
'transactions.*.id' => 'bail|required',
'transactions.*.invoice_ids' => 'nullable|string|sometimes',
'transactions.*.ninja_category_id' => 'nullable|string|sometimes'
2022-09-15 06:15:02 +02:00
];
2022-10-24 10:50:45 +02:00
$rules['transactions.*.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-10-24 10:27:40 +02:00
nlog($inputs);
2022-09-15 06:15:02 +02:00
2022-10-24 10:50:45 +02:00
foreach($inputs['transactions'] as $input)
2022-10-24 10:11:37 +02:00
{
2022-10-24 10:25:59 +02:00
nlog($input);
2022-10-24 10:27:40 +02:00
2022-10-24 10:30:15 +02:00
if(isset($input['id']))
2022-10-24 10:11:37 +02:00
$input['id'] = $this->decodePrimaryKey($input['id']);
2022-09-22 08:20:54 +02:00
2022-10-24 10:30:15 +02:00
if(isset($input['ninja_category_id']) && strlen($input['ninja_category_id']) >= 1)
2022-10-24 10:11:37 +02:00
$input['ninja_category_id'] = $this->decodePrimaryKey($input['ninja_category_id']);
2022-09-22 08:20:54 +02:00
2022-10-24 10:31:17 +02:00
// $input = $this->decodePrimaryKeys($input);
2022-10-24 10:11:37 +02:00
}
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
}