-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathCreateServiceRateRequest.php
More file actions
59 lines (55 loc) · 3.3 KB
/
CreateServiceRateRequest.php
File metadata and controls
59 lines (55 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
namespace Fleetbase\FleetOps\Http\Requests;
use Fleetbase\FleetOps\Rules\ComputableAlgo;
use Fleetbase\FleetOps\Support\Utils;
use Fleetbase\Http\Requests\FleetbaseRequest;
use Illuminate\Validation\Rule;
class CreateServiceRateRequest extends FleetbaseRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return request()->session()->has('api_credential');
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'service_name' => [Rule::requiredIf($this->isMethod('POST')), 'string'],
'service_type' => [Rule::requiredIf($this->isMethod('POST')), 'string'],
'service_area' => [Rule::exists('service_areas', 'public_id')->whereNull('deleted_at')],
'zone' => [Rule::exists('zones', 'public_id')->whereNull('deleted_at')],
'rate_calculation_method' => [Rule::requiredIf($this->isMethod('POST')), 'string', 'in:fixed_meter,fixed_rate,per_meter,per_drop,algo'],
'currency' => ['required', 'size:3'],
'base_fee' => ['numeric'],
'per_meter_unit' => ['required_if:rate_calculation_method,per_meter', 'string', 'in:km,m'],
'per_meter_flat_rate_fee' => ['required_if:rate_calculation_method,per_meter', 'numeric'],
'meter_fees' => [Rule::requiredIf(function () {
return in_array($this->input('rate_calculation_method'), ['fixed_meter', 'fixed_rate']);
}), 'array'],
'meter_fees.*.distance' => ['numeric'],
'meter_fees.*.fee' => ['numeric'],
'algorithm' => ['required_if:rate_calculation_method,algo', new ComputableAlgo(), 'string'],
'has_cod_fee' => ['boolean'],
'cod_calculation_method' => [Rule::requiredIf(Utils::isTrue($this->input(['has_cod_fee']))), 'in:percentage,flat'],
'cod_flat_fee' => [Rule::requiredIf($this->input('cod_calculation_method') === 'flat'), 'numeric'],
'cod_percent' => [Rule::requiredIf($this->input('cod_calculation_method') === 'percentage'), 'integer'],
'has_peak_hours_fee' => ['boolean'],
'peak_hours_calculation_method' => [Rule::requiredIf(Utils::isTrue($this->input('has_peak_hours'))), 'in:percentage,flat'],
'peak_hours_flat_fee' => [Rule::requiredIf($this->input('peak_hours_calculation_method') === 'flat'), 'numeric'],
'peak_hours_percent' => [Rule::requiredIf($this->input('peak_hours_calculation_method') === 'percentage'), 'integer'],
'peak_hours_start' => [Rule::requiredIf(Utils::isTrue($this->input('has_peak_hours'))), 'date_format:H:i'],
'peak_hours_end' => [Rule::requiredIf(Utils::isTrue($this->input('has_peak_hours'))), 'date_format:H:i'],
'duration_terms' => ['string'],
'estimated_days' => ['integer'],
];
}
}