Ingreso de pedididos finalizado
This commit is contained in:
@@ -4,7 +4,7 @@ const config = {
|
||||
port: 3306,
|
||||
user: 'admin',
|
||||
pswd: 'Dx.1706%',
|
||||
db_a: 'TELCOTRONICS',
|
||||
db_a: 'facturacion',
|
||||
debg: false,
|
||||
sock: '/'
|
||||
},
|
||||
|
||||
@@ -114,16 +114,93 @@ controlador.login_test = (req, res) => {
|
||||
});
|
||||
});
|
||||
};
|
||||
controlador.recibe_pedidos = (req, res) => {
|
||||
console.log("Data: "+req.body);
|
||||
req.getConnection((err, conn) => {
|
||||
res.json({sision:"exitosa"});
|
||||
});
|
||||
|
||||
controlador.recibe_pedidos = async (req, res) => {
|
||||
const data = req.query.orden_pedidos;
|
||||
const json = JSON.parse([data]);
|
||||
var pedido = {
|
||||
PedUsoPrdct_Num: "1",
|
||||
PedUsoPrdct_idClient: json.clienteId,
|
||||
PedUsoPrdct_reg: reg_DB(),
|
||||
PedUsoPrdct_estado: json.plataforma,
|
||||
PedUsoPrdct_plataforma: json.plataforma,
|
||||
PedUsoPrdct_usuario: json.user,
|
||||
PedUsoPrdct_valor: json.valor,
|
||||
PedUsoPrdct_iva: json.iva,
|
||||
PedUsoPrdct_origen: json.origen
|
||||
};
|
||||
ingreso_pedido(req,pedido,json.items);
|
||||
//await console.log(await ingreso_pedido(req,pedido));
|
||||
//await ingreso_detalle(req, id_ped, json.items);
|
||||
};
|
||||
|
||||
async function ingreso_pedido(req,pedido_data,items) {
|
||||
var lastInsert = "";
|
||||
req.getConnection((err, conn) => {
|
||||
conn.query('INSERT INTO PedidoUsoProduct set ?', [pedido_data], (err, result) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
//next(res.json(err));
|
||||
return 0;
|
||||
} else {
|
||||
lastInsert = result.insertId;
|
||||
console.log("existe id = "+lastInsert);
|
||||
ingreso_detalle(req, lastInsert, items)
|
||||
//res.json({ sision: "ORDEN INGRESADA" });
|
||||
//res.redirect('/clientes');//redireciona a la ruta inical de la app
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
async function ingreso_detalle(req, id_ped, data) {
|
||||
//console.log("ID Pedido: "+id_ped);
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var items = {
|
||||
PedUsoPrdct_id:id_ped,
|
||||
//PedUsoPrdct_id: 36,
|
||||
PedUsoPrdctDet_codigoProducto: data[i].cod,
|
||||
PedUsoPrdct_cant: data[i].cant,
|
||||
PedUsoPrdct_costo: data[i].precio,
|
||||
PedUsoPrdct_desct: data[i].descuento,
|
||||
//PedUsoPrdct_iva:data[i].iva,
|
||||
PedUsoPrdct_iva:0,
|
||||
PedUsoPrdct_gpPrecios: data[i].gp_precio
|
||||
}
|
||||
//console.log(items);
|
||||
req.getConnection((err, conn) => {
|
||||
conn.query('INSERT INTO PedidoUsoProduct_detalle set ?', [items], (err, result) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
//next(res.json(err));
|
||||
} else {
|
||||
//res.redirect('/clientes');//redireciona a la ruta inical de la app
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
//console.log("ID PEDIDO: " + id_ped);
|
||||
}
|
||||
|
||||
//********* APP-panel control ********//
|
||||
controlador.panel_control = (req, res) => {
|
||||
res.render('panel_control');
|
||||
};
|
||||
|
||||
|
||||
function reg_DB() {
|
||||
// crea un nuevo objeto `Date`
|
||||
var today = new Date();
|
||||
// `getDate()` devuelve el día del mes (del 1 al 31)
|
||||
var day = today.getDate();
|
||||
// `getMonth()` devuelve el mes (de 0 a 11)
|
||||
var month = today.getMonth() + 1;
|
||||
// `getFullYear()` devuelve el año completo
|
||||
var year = today.getFullYear();
|
||||
// muestra la fecha de hoy en formato `MM/DD/YYYY`
|
||||
var hora = today.getHours() + ':' + today.getMinutes() + ':' + today.getSeconds();
|
||||
var fecha = `${year}-${month}-${day} ${hora}`;
|
||||
console.log(fecha);
|
||||
return fecha;
|
||||
}
|
||||
|
||||
module.exports = controlador;
|
||||
|
||||
Reference in New Issue
Block a user