3. srv / modelo / Venta.php

1<?php
2
3require_once __DIR__ . "/../../lib/php/ProblemDetails.php";
4require_once __DIR__ . "/DetalleDeVenta.php";
5
6class Venta
7{
8
9 public int $id;
10 public bool $enCaptura;
11 /** @var DetalleDeVenta[] */
12 public array $detalles;
13
14 public function __construct(
15 bool $enCaptura = false,
16 array $detalles = [],
17 int $id = 0
18 ) {
19 $this->id = $id;
20 $this->enCaptura = $enCaptura;
21 $this->detalles = $detalles;
22 }
23
24 public function valida()
25 {
26 foreach ($this->detalles as $detalle) {
27 if (!($detalle instanceof DetalleDeVenta))
28 throw new ProblemDetails(
29 status: ProblemDetails::BadRequest,
30 type: "/error/detalledeventaincorrecto.html",
31 title: "Tipo incorrecto para un etalle de venta.",
32 );
33 $detalle->valida();
34 }
35 }
36}
37
skip_previous skip_next