Advertisement
Guest User

Untitled

a guest
Apr 16th, 2017
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. app.post("/commanda", function (req, res) {
  2.     var idCuenta = req.body.idCuenta;
  3.     var idEmpleado = req.body.idEmpleado;
  4.     var fechaRegistro = req.body.fechaRegistro;
  5.     var cuenta_mesero = "C:" + idCuenta + ":E:" + idEmpleado;
  6.     var objects = req.body.objects;
  7.     var element = {};
  8.     //for (var key in objects) {
  9.     asyncloop(Object.keys(objects).length, function (loop) {
  10.         if (objects.hasOwnProperty(Object.keys(objects)[loop.iteration()])) {
  11.             var qProducto = "SELECT descripcionProducto FROM PRODUCTO WHERE idProducto = ? ;";
  12.             var descProducto = '';
  13.             console.log("cantidad in commanda2 : " + objects[Object.keys(objects)[loop.iteration()]].cantidad);
  14.             try {
  15.                 pool.query(qProducto, objects[Object.keys(objects)[loop.iteration()]].idProducto, function (error, results, fields) {
  16.                     if (error) {
  17.                         console.error(error);
  18.                         console.error("Failed with query: " + qProducto);
  19.                         res.status(500).end();
  20.                         loop.break();
  21.                         throw error;
  22.                     } else {
  23.                         console.log("cantidad in commanda4 : " + objects[Object.keys(objects)[loop.iteration()]].cantidad);
  24.                         descProducto = JSON.stringify(results[0].descripcionProducto);
  25.                         element = {
  26.                             idProducto: objects[Object.keys(objects)[loop.iteration()]].idProducto,
  27.                             cantidad: objects[Object.keys(objects)[loop.iteration()]].cantidad,
  28.                             descProducto: descProducto,
  29.                             cuenta_mesero: cuenta_mesero,
  30.                             fechaRegistro: fechaRegistro
  31.                         };
  32.                         imprimirOrden(element);
  33.                         loop.next();
  34.                     }
  35.                 });
  36.             } catch (error) {
  37.                 callback(error);
  38.             }
  39.         }
  40.     }, function () {
  41.         //This is your final callback
  42.         //ALL OBJECTS HANDLED PROPERLY. Maybe put your res.end here instead?
  43.         printer.printVerticalTab();
  44.         res.status(200).end();
  45.     });
  46. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement