-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathCreateAgentSoldApplianceRequest.php
More file actions
61 lines (52 loc) · 1.97 KB
/
Copy pathCreateAgentSoldApplianceRequest.php
File metadata and controls
61 lines (52 loc) · 1.97 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
60
61
<?php
namespace App\Http\Requests;
use App\Models\AgentAssignedAppliances;
use App\Models\ApplianceType;
use Illuminate\Foundation\Http\FormRequest;
class CreateAgentSoldApplianceRequest extends FormRequest {
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool {
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules(): array {
$deviceSerialRules = $this->isShsAppliance()
? ['required', 'string']
: ['nullable', 'string'];
return [
'person_id' => ['required'],
'payment_type' => ['nullable', 'string', 'in:installment,energy_service'],
'down_payment' => ['required_unless:payment_type,energy_service', 'numeric'],
'tenure' => ['required_unless:payment_type,energy_service', 'numeric', 'min:0'],
'first_payment_date' => ['required_unless:payment_type,energy_service'],
'agent_assigned_appliance_id' => ['required'],
'device_serial' => $deviceSerialRules,
'address' => ['nullable', 'array'],
'points' => ['nullable', 'string'],
'minimum_payable_amount' => ['nullable', 'integer', 'min:0'],
'price_per_day' => ['nullable', 'integer', 'min:0'],
];
}
/**
* @return array<string, string>
*/
public function messages(): array {
return [
'device_serial.required' => 'Device serial is required for solar home system sales.',
];
}
private function isShsAppliance(): bool {
$assignedId = $this->input('agent_assigned_appliance_id');
if (!$assignedId) {
return false;
}
$assigned = AgentAssignedAppliances::with('appliance')->find($assignedId);
return $assigned?->appliance?->appliance_type_id === ApplianceType::APPLIANCE_TYPE_SHS;
}
}