2022-05-23 01:32:31 +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-05-23 01:32:31 +02:00
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
namespace App\Http\Requests\TaskScheduler;
|
|
|
|
|
|
|
|
use App\Http\Requests\Request;
|
2023-02-20 06:47:30 +01:00
|
|
|
use App\Http\ValidationRules\Scheduler\ValidClientIds;
|
2023-02-22 07:37:16 +01:00
|
|
|
use Illuminate\Validation\Rule;
|
2022-05-23 01:32:31 +02:00
|
|
|
|
2023-01-13 02:43:38 +01:00
|
|
|
class UpdateSchedulerRequest extends Request
|
2022-05-23 01:32:31 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function authorize(): bool
|
|
|
|
{
|
2023-02-22 20:33:38 +01:00
|
|
|
return auth()->user()->isAdmin() && $this->task_scheduler->company_id == auth()->user()->company()->id;
|
2022-05-23 01:32:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function rules(): array
|
|
|
|
{
|
2023-01-13 02:43:38 +01:00
|
|
|
$rules = [
|
2023-03-21 21:30:37 +01:00
|
|
|
'name' => 'bail|sometimes|nullable|string',
|
2023-01-13 02:43:38 +01:00
|
|
|
'is_paused' => 'bail|sometimes|boolean',
|
2023-02-17 11:05:01 +01:00
|
|
|
'frequency_id' => 'bail|sometimes|integer|digits_between:1,12',
|
2023-01-17 09:42:34 +01:00
|
|
|
'next_run' => 'bail|required|date:Y-m-d|after_or_equal:today',
|
|
|
|
'next_run_client' => 'bail|sometimes|date:Y-m-d',
|
2023-01-13 02:43:38 +01:00
|
|
|
'template' => 'bail|required|string',
|
|
|
|
'parameters' => 'bail|array',
|
2023-02-20 06:47:30 +01:00
|
|
|
'parameters.clients' => ['bail','sometimes', 'array', new ValidClientIds()],
|
|
|
|
'parameters.date_range' => 'bail|sometimes|string|in:last7_days,last30_days,last365_days,this_month,last_month,this_quarter,last_quarter,this_year,last_year,custom',
|
|
|
|
'parameters.start_date' => ['bail', 'sometimes', 'date:Y-m-d', 'required_if:parameters.date_rate,custom'],
|
|
|
|
'parameters.end_date' => ['bail', 'sometimes', 'date:Y-m-d', 'required_if:parameters.date_rate,custom', 'after_or_equal:parameters.start_date'],
|
2023-04-14 08:44:04 +02:00
|
|
|
'parameters.entity' => ['bail', 'sometimes', 'string', 'in:invoice,credit,quote,purchase_order'],
|
|
|
|
'parameters.entity_id' => ['bail', 'sometimes', 'string'],
|
|
|
|
'parameters.report_name' => ['bail','sometimes', 'string', 'required_if:template,email_report', 'in:ar_summary_report,ar_detail_report,tax_summary_report,user_sales_report,client_sales_report,client_balance_report,product_sales_report'],
|
|
|
|
'parameters.date_key' => ['bail','sometimes', 'string'],
|
2023-01-13 02:43:38 +01:00
|
|
|
];
|
2022-05-23 21:57:48 +02:00
|
|
|
|
2023-01-13 02:43:38 +01:00
|
|
|
return $rules;
|
2022-05-23 21:57:48 +02:00
|
|
|
}
|
2023-01-17 09:42:34 +01:00
|
|
|
|
|
|
|
public function prepareForValidation()
|
|
|
|
{
|
|
|
|
$input = $this->all();
|
|
|
|
|
2023-02-16 02:36:09 +01:00
|
|
|
if (array_key_exists('next_run', $input) && is_string($input['next_run'])) {
|
2023-01-17 09:42:34 +01:00
|
|
|
$this->merge(['next_run_client' => $input['next_run']]);
|
2023-02-16 02:36:09 +01:00
|
|
|
}
|
2023-01-17 09:42:34 +01:00
|
|
|
|
|
|
|
return $input;
|
|
|
|
}
|
2022-05-23 01:32:31 +02:00
|
|
|
}
|