| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace App\Http\Requests;
- use Carbon\CarbonImmutable;
- use Illuminate\Foundation\Http\FormRequest;
- use Illuminate\Validation\Validator;
- class StudentContractRequest extends FormRequest
- {
- public function rules(): array
- {
- return [
- 'student_id' => 'required|exists:students,id',
- 'protocol' => 'sometimes|nullable|string|max:255',
- 'signature_date' => 'sometimes|nullable|date_format:Y-m-d',
- 'end_date' => 'sometimes|nullable|date_format:Y-m-d',
- 'class_package_unit_id' => 'required|exists:class_package_units,id',
- 'class_quantity' => 'sometimes|nullable|integer|min:1',
- 'weekday' => 'sometimes|nullable|integer|min:0|max:6',
- 'start_time' => 'sometimes|nullable|date_format:H:i',
- 'end_time' => 'sometimes|nullable|date_format:H:i',
- 'second_weekday' => 'sometimes|nullable|integer|min:0|max:6',
- 'second_start_time' => 'sometimes|nullable|date_format:H:i',
- 'second_end_time' => 'sometimes|nullable|date_format:H:i',
- 'due_day' => 'sometimes|nullable|integer|min:1|max:31',
- 'tax_register' => 'sometimes|nullable|numeric|min:0',
- 'installments' => 'sometimes|nullable|integer|min:1|max:12',
- 'enrollment_due_date' => 'sometimes|nullable|date_format:Y-m-d',
- 'package_value' => 'sometimes|nullable|numeric|min:0',
- 'package_installments' => 'sometimes|nullable|integer|min:1|max:13',
- 'package_due_date' => 'sometimes|nullable|date_format:Y-m-d',
- 'early_payment_discount' => 'sometimes|nullable|numeric|min:0|max:100',
- 'interest_rate' => 'sometimes|nullable|numeric|min:0',
- 'payment_method' => 'sometimes|nullable|string|in:pix,credit_card,debit_card',
- 'fine_cancelled' => 'sometimes|nullable|numeric|min:0|max:100',
- ];
- }
- public function after(): array
- {
- return [
- function (Validator $validator): void {
- if (
- ! $this->isMethod('POST')
- || ! $this->filled(['signature_date', 'end_date'])
- || $validator->errors()->hasAny(['signature_date', 'end_date'])
- ) {
- return;
- }
- $signatureDate = CarbonImmutable::createFromFormat('!Y-m-d', $this->string('signature_date')->toString());
- $endDate = CarbonImmutable::createFromFormat('!Y-m-d', $this->string('end_date')->toString());
- if ($endDate->greaterThan($signatureDate->addYearNoOverflow())) {
- $validator->errors()->add(
- 'end_date',
- __('validation.student_contract_max_duration'),
- );
- }
- },
- ];
- }
- }
|