Created
October 2, 2023 13:09
-
-
Save juanchehin/9bc5c6033243f40246a06cc25a3ef8b0 to your computer and use it in GitHub Desktop.
altaVenta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async altaVenta(req: Request, res: Response) { | |
var pIdVendedor = req.params.IdPersona; | |
var pIdCliente = req.body[0]; | |
var pIdEmpleado = req.body[1]; | |
var pLineaVenta = req.body[2]; // productos/servicios | |
var pMontoTotal = req.body[3]; | |
var pIdTipoPago = req.body[4]; | |
// var pFechaVenta = req.body[4]; | |
// var pLineaTipoPago = req.body[2]; | |
// ============================== | |
try { | |
// ====================== Alta Venta =========================================== | |
let sql = `call bsp_alta_venta('${pIdTipoPago}','${pIdEmpleado}','${pIdCliente}','${pMontoTotal}')`; | |
const [result] = await pool.promise().query(sql) | |
console.log('result::: ', result); | |
if(result[0][0].Mensaje != 'Ok') | |
{ | |
logger.error("Error bsp_alta_venta - altaVenta - ventasController"); | |
res.status(404).json({ "error" : "No se pudo confirmar la operacion"}); | |
return; | |
} | |
// ========================== Lineas de venta ======================================= | |
pLineaVenta.forEach(async function (value: any) { | |
let sql2 = `call bsp_alta_linea_venta('${result[0][0].IdVenta}','${value.IdProductoServicio}','${value.precio_venta}','${value.tipo}','${value.cantidad}')`; | |
const [result2] = await pool.promise().query(sql2) | |
console.log('result2::: ', result2); | |
if(result2[0][0].Mensaje != 'Ok') | |
{ | |
logger.error("Error bsp_alta_linea_venta - ventasController"); | |
res.status(404).json({ "error" : "No se pudo confirmar la operacion"}); | |
return; | |
} | |
}); | |
res.json({ Mensaje : 'Ok'}); | |
// ======================= Confirmar transferencia exitosa ========================================== | |
// return result | |
} catch (error) { | |
logger.error("Error funcion altaVenta - ventasController"); | |
res.status(404).json({ "error" : error}); | |
return; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment