1 | <?php |
2 | |
3 | require_once __DIR__ . "/../../lib/php/ProblemDetails.php"; |
4 | require_once __DIR__ . "/Venta.php"; |
5 | require_once __DIR__ . "/Producto.php"; |
6 | |
7 | class DetalleDeVenta |
8 | { |
9 | |
10 | public ?Venta $venta; |
11 | public ?Producto $producto; |
12 | public float $cantidad; |
13 | public float $precio; |
14 | |
15 | public function __construct( |
16 | float $cantidad = NAN, |
17 | float $precio = NAN, |
18 | ?Producto $producto = null, |
19 | ?Venta $venta = null |
20 | ) { |
21 | $this->cantidad = $cantidad; |
22 | $this->precio = $precio; |
23 | $this->producto = $producto; |
24 | $this->venta = $venta; |
25 | } |
26 | |
27 | public function valida() |
28 | { |
29 | if ($this->producto === null) |
30 | throw new Exception("Detalle de venta sin producto."); |
31 | if (is_nan($this->cantidad)) |
32 | throw new ProblemDetails( |
33 | status: ProblemDetails::BadRequest, |
34 | type: "/error/cantidadincorrecta.html", |
35 | title: "La cantidad no puede ser NAN.", |
36 | ); |
37 | if (is_nan($this->precio)) |
38 | throw new ProblemDetails( |
39 | status: ProblemDetails::BadRequest, |
40 | type: "/error/precioincorrecto.html", |
41 | title: "El precio no puede ser NAN.", |
42 | ); |
43 | } |
44 | } |
45 | |