ValidatesProposalPricing.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Http\Requests\Concerns;
  3. use Illuminate\Validation\Validator;
  4. trait ValidatesProposalPricing
  5. {
  6. /**
  7. * Validation rules for an optional Pavão/Irrecusável pricing block
  8. * (Matrícula, Aulas, Materiais, Valor Total do Curso), nested under
  9. * $prefix ("pavao"/"irrecusavel"). The block itself is optional — a
  10. * proposal can have Pavão, Irrecusável, both, or neither yet. Sending it
  11. * as `null` means "this proposal doesn't have this modality" (removes an
  12. * existing one); sending an object requires every sub-field.
  13. */
  14. protected function proposalPricingRules(string $prefix, bool $withCondition = false): array
  15. {
  16. $rules = [
  17. $prefix => 'sometimes|nullable|array',
  18. "$prefix.registration_value" => 'nullable|numeric|min:0',
  19. "$prefix.classes_value" => 'nullable|numeric|min:0',
  20. "$prefix.classes_discount_percentage" => 'nullable|numeric|min:0|max:100',
  21. "$prefix.materials" => 'nullable|array',
  22. "$prefix.materials.*.product_id" => "required_with:$prefix.materials|integer|exists:products,id",
  23. "$prefix.materials.*.quantity" => "required_with:$prefix.materials|integer|min:1",
  24. "$prefix.materials.*.price" => "required_with:$prefix.materials|numeric|min:0",
  25. "$prefix.total_value" => 'nullable|numeric|min:0',
  26. "$prefix.total_max_installments" => 'nullable|integer|min:1',
  27. ];
  28. if ($withCondition) {
  29. $rules["$prefix.condition"] = 'nullable|string';
  30. }
  31. return $rules;
  32. }
  33. /**
  34. * For each pricing block actually sent (present and not null), enforce
  35. * that exactly one of "included in course" / "allows installments" is
  36. * selected per section.
  37. */
  38. protected function validateProposalPricingSections(Validator $validator, array $prefixes): void
  39. {
  40. // No longer needed, columns removed. Maintained to avoid breaking dependent code.
  41. }
  42. }