1 | <?php |
2 | |
3 | require_once __DIR__ . "/../lib/php/ejecutaServicio.php"; |
4 | require_once __DIR__ . "/../lib/php/ProblemDetails.php"; |
5 | require_once __DIR__ . "/modelo/DetalleDeVenta.php"; |
6 | require_once __DIR__ . "/bd/ventaEnCapturaBusca.php"; |
7 | |
8 | ejecutaServicio(function () { |
9 | $modelo = ventaEnCapturaBusca(); |
10 | if ($modelo === false) |
11 | throw new ProblemDetails( |
12 | status: ProblemDetails::BadRequest, |
13 | type: "/error/ventaencapturanoencontrada.html", |
14 | title: "Venta en captura no encontrada.", |
15 | detail: "No se encontró ninguna venta en captura.", |
16 | ); |
17 | $detalles = $modelo->detalles; |
18 | $productoIds = []; |
19 | foreach ($detalles as $detalle) { |
20 | $id = $detalle->producto->id; |
21 | $productoIds[$id] = true; |
22 | } |
23 | $renderDetalles = ""; |
24 | foreach ($detalles as $detalle) { |
25 | $producto = $detalle->producto; |
26 | $prodId = htmlentities($producto->id); |
27 | $prodNombre = htmlentities($producto->nombre); |
28 | $precio = htmlentities("$" . number_format($detalle->precio, 2)); |
29 | $cantidad = htmlentities(number_format($detalle->cantidad, 2)); |
30 | $renderDetalles .= |
31 | "<dt>$prodNombre</dt> |
32 | <dd> |
33 | <a href= 'modifica.html?prodId=$prodId'>Modificar o eliminar</a> |
34 | </dd> |
35 | <dd> |
36 | <dl> |
37 | <dt>Cantidad</dt> |
38 | <dd>$cantidad</dd> |
39 | <dt>Precio</dt> |
40 | <dd>$precio</dd> |
41 | </dl> |
42 | </dd>"; |
43 | } |
44 | $modelo->detalles = []; |
45 | return [ |
46 | "folio" => ["value" => $modelo->id], |
47 | "detalles" => ["innerHTML" => $renderDetalles] |
48 | ]; |
49 | }); |
50 | |