2022-09-15 13:58:42 +10: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 14:15:02 +10:00
|
|
|
|
|
|
|
|
public function rules()
|
|
|
|
|
{
|
|
|
|
|
|
2022-09-22 15:54:58 +10:00
|
|
|
$rules = [
|
2022-10-24 19:30:15 +11:00
|
|
|
'*.id' => 'bail|required',
|
2022-10-24 19:18:50 +11:00
|
|
|
'*.invoice_ids' => 'nullable|string|sometimes',
|
|
|
|
|
'*.ninja_category_id' => 'nullable|string|sometimes'
|
2022-09-15 14:15:02 +10:00
|
|
|
];
|
|
|
|
|
|
2022-10-24 19:18:50 +11:00
|
|
|
$rules['*.vendor_id'] = 'bail|sometimes|exists:vendors,id,company_id,'.auth()->user()->company()->id.',is_deleted,0';
|
2022-09-22 15:54:58 +10:00
|
|
|
|
|
|
|
|
return $rules;
|
|
|
|
|
|
2022-09-15 14:15:02 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function prepareForValidation()
|
|
|
|
|
{
|
2022-10-24 19:11:37 +11:00
|
|
|
$inputs = $this->all();
|
2022-10-24 19:27:40 +11:00
|
|
|
|
|
|
|
|
nlog($inputs);
|
2022-09-15 14:15:02 +10:00
|
|
|
|
2022-10-24 19:11:37 +11:00
|
|
|
foreach($inputs as $input)
|
|
|
|
|
{
|
2022-10-24 19:25:59 +11:00
|
|
|
nlog($input);
|
2022-10-24 19:27:40 +11:00
|
|
|
|
2022-10-24 19:30:15 +11:00
|
|
|
if(isset($input['id']))
|
2022-10-24 19:11:37 +11:00
|
|
|
$input['id'] = $this->decodePrimaryKey($input['id']);
|
2022-09-22 16:20:54 +10:00
|
|
|
|
2022-10-24 19:30:15 +11:00
|
|
|
if(isset($input['ninja_category_id']) && strlen($input['ninja_category_id']) >= 1)
|
2022-10-24 19:11:37 +11:00
|
|
|
$input['ninja_category_id'] = $this->decodePrimaryKey($input['ninja_category_id']);
|
2022-09-22 16:20:54 +10:00
|
|
|
|
2022-10-24 19:31:17 +11:00
|
|
|
// $input = $this->decodePrimaryKeys($input);
|
2022-10-24 19:11:37 +11:00
|
|
|
}
|
2022-10-24 19:18:50 +11:00
|
|
|
|
2022-10-24 19:11:37 +11:00
|
|
|
$this->replace($inputs);
|
2022-09-15 14:15:02 +10:00
|
|
|
|
|
|
|
|
}
|
2022-09-15 13:58:42 +10:00
|
|
|
}
|