1 | <?php |
2 | |
3 | require_once __DIR__ . "/../lib/php/ejecutaServicio.php"; |
4 | require_once __DIR__ . "/../lib/php/devuelveCreated.php"; |
5 | require_once __DIR__ . "/../lib/php/update.php"; |
6 | require_once __DIR__ . "/Bd.php"; |
7 | require_once __DIR__ . "/TABLA_VENTA.php"; |
8 | require_once __DIR__ . "/TABLA_PRODUCTO.php"; |
9 | require_once __DIR__ . "/TABLA_DET_VENTA.php"; |
10 | require_once __DIR__ . "/ventaEnCapturaBusca.php"; |
11 | require_once __DIR__ . "/validaVenta.php"; |
12 | require_once __DIR__ . "/detVentaConsulta.php"; |
13 | require_once __DIR__ . "/ventaEnCapturaAgrega.php"; |
14 | |
15 | ejecutaServicio(function () { |
16 | |
17 | $pdo = Bd::pdo(); |
18 | $pdo->beginTransaction(); |
19 | |
20 | $venta = ventaEnCapturaBusca($pdo); |
21 | validaVenta($venta); |
22 | |
23 | $detalles = detVentaConsulta($pdo, $venta[VENT_ID]); |
24 | |
25 | |
26 | $update = $pdo->prepare( |
27 | "UPDATE PRODUCTO |
28 | SET PROD_EXISTENCIAS = :PROD_EXISTENCIAS |
29 | WHERE PROD_ID = :PROD_ID" |
30 | ); |
31 | foreach ($detalles as $detVenta) { |
32 | $update->execute([ |
33 | ":PROD_ID" => $detVenta[PROD_ID], |
34 | ":PROD_EXISTENCIAS" => $detVenta[PROD_EXISTENCIAS] - $detVenta[DTV_CANTIDAD] |
35 | ]); |
36 | } |
37 | |
38 | update( |
39 | pdo: $pdo, |
40 | table: VENTA, |
41 | set: [VENT_EN_CAPTURA => 0], |
42 | where: [VENT_ID => $venta[VENT_ID]] |
43 | ); |
44 | |
45 | ventaEnCapturaAgrega($pdo); |
46 | $folio = $pdo->lastInsertId(); |
47 | |
48 | $pdo->commit(); |
49 | |
50 | devuelveCreated("/srv/venta-en-captura.php", [ |
51 | "folio" => ["value" => $folio], |
52 | "detalles" => ["innerHTML" => ""] |
53 | ]); |
54 | }); |
55 | |