2020-09-23 02:46:35 +02:00
|
|
|
<?php
|
2020-10-22 08:46:02 +02:00
|
|
|
/**
|
|
|
|
* 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)
|
2020-10-22 08:46:02 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-10-22 08:46:02 +02:00
|
|
|
*/
|
|
|
|
|
2020-09-23 02:46:35 +02:00
|
|
|
namespace App\Http\Requests\Expense;
|
|
|
|
|
2020-11-25 15:19:52 +01:00
|
|
|
use App\Http\Requests\Request;
|
2023-11-03 01:07:05 +01:00
|
|
|
use Illuminate\Validation\Rule;
|
2020-09-23 02:46:35 +02:00
|
|
|
|
2020-10-22 08:46:02 +02:00
|
|
|
class BulkExpenseRequest extends Request
|
2020-09-23 02:46:35 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function authorize()
|
|
|
|
{
|
2023-11-03 01:07:05 +01:00
|
|
|
return true;
|
2020-09-23 02:46:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
2023-11-03 01:07:05 +01:00
|
|
|
/** @var \App\Models\User $user */
|
|
|
|
$user = auth()->user();
|
|
|
|
|
|
|
|
return [
|
|
|
|
'ids' => ['required','bail','array', Rule::exists('expenses', 'id')->where('company_id', $user->company()->id)],
|
|
|
|
'category_id' => ['sometimes', 'bail', Rule::exists('expense_categories', 'id')->where('company_id', $user->company()->id)],
|
|
|
|
'action' => 'in:archive,restore,delete,bulk_categorize',
|
|
|
|
];
|
|
|
|
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-11-03 01:07:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function prepareForValidation()
|
|
|
|
{
|
|
|
|
$input = $this->all();
|
|
|
|
|
|
|
|
if (isset($input['ids'])) {
|
|
|
|
$input['ids'] = $this->transformKeys($input['ids']);
|
|
|
|
}
|
2020-09-23 02:46:35 +02:00
|
|
|
|
2023-11-03 01:07:05 +01:00
|
|
|
if (isset($input['category_id'])) {
|
|
|
|
$input['category_id'] = $this->transformKeys($input['category_id']);
|
2020-09-23 02:46:35 +02:00
|
|
|
}
|
|
|
|
|
2023-11-03 01:07:05 +01:00
|
|
|
$this->replace($input);
|
2020-09-23 02:46:35 +02:00
|
|
|
}
|
|
|
|
}
|