B. srv / srvDetalleDeVentaAgrega.php

1<?php
2
3require_once __DIR__ . "/../lib/php/ejecutaServicio.php";
4require_once __DIR__ . "/../lib/php/JsonResponse.php";
5require_once __DIR__ . "/../lib/php/leeEntero.php";
6require_once __DIR__ . "/../lib/php/leeDecimal.php";
7require_once __DIR__ . "/../lib/php/pdFaltaId.php";
8require_once __DIR__ . "/modelo/Producto.php";
9require_once __DIR__ . "/modelo/DetalleDeVenta.php";
10require_once __DIR__ . "/bd/detalleDeVentaAgrega.php";
11
12ejecutaServicio(function () {
13 $id = leeEntero("id");
14 if ($id === null) throw pdFaltaId();
15 $cantidad = leeDecimal("cantidad");
16 if ($cantidad === null)
17 throw new ProblemDetails(
18 status: ProblemDetails::BadRequest,
19 type: "/error/faltacantidad.html",
20 title: "Falta la cantidad."
21 );
22 $producto = new Producto(id: $id);
23 $modelo = new DetalleDeVenta(producto: $producto, cantidad: $cantidad);
24 detalleDeVentaAgrega($modelo);
25 $producto = $modelo->producto;
26 $id = htmlentities($producto->id);
27 return JsonResponse::created("/srv/srvDetalleDeVentaBusca.php?id=$id", [
28 "prodId" => ["value" => $producto->id],
29 "prodNombre" => ["value" => $producto->nombre],
30 "precio" => ["value" => "$" . number_format($modelo->precio, 2)],
31 "cantidad" => ["valueAsNumber" => $modelo->cantidad],
32 ]);
33});
34
skip_previous skip_next