Merge branch 'dev' of http://git.verdnatura.es/salix into dev

This commit is contained in:
Carlos Jimenez 2018-08-14 14:32:40 +02:00
commit 5cfd5c7605
2 changed files with 23 additions and 13 deletions

View File

@ -1,9 +1,9 @@
USE `vn`;
DROP procedure IF EXISTS `ticketGetFullList`;
DROP procedure IF EXISTS `ticketFilter`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`%` PROCEDURE `ticketGetFullList`()
CREATE DEFINER=`root`@`%` PROCEDURE `ticketFilter`()
BEGIN
/**
* Obtiene un listado de tickets
@ -15,8 +15,8 @@ BEGIN
CALL ticketGetTotal();
CALL ticketGetProblems();
DROP TEMPORARY TABLE IF EXISTS tmp.ticketFullList;
CREATE TEMPORARY TABLE tmp.ticketFullList ENGINE = MEMORY
DROP TEMPORARY TABLE IF EXISTS tmp.ticketFilter;
CREATE TEMPORARY TABLE tmp.ticketFilter ENGINE = MEMORY
SELECT t.*, tt.total, tp.problem
FROM tmp.ticket t
JOIN tmp.ticketTotal tt ON tt.ticketFk = t.ticketFk

View File

@ -24,9 +24,13 @@ module.exports = Self => {
});
Self.filter = async filter => {
let stmt = new ParameterizedSQL(
`DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
CREATE TEMPORARY TABLE tmp.ticket
let stmts = [];
let stmt;
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.ticket');
stmt = new ParameterizedSQL(
`CREATE TEMPORARY TABLE tmp.ticket
(PRIMARY KEY (ticketFk)) ENGINE = MEMORY
SELECT
t.id,
@ -55,14 +59,20 @@ module.exports = Self => {
LEFT JOIN state st ON st.id = ts.stateFk
LEFT JOIN client c ON c.id = t.clientFk
LEFT JOIN worker wk ON wk.id = c.salesPersonFk`);
stmt.merge(Self.buildSuffix(filter, 't'));
stmt.merge(';CALL ticketGetFullList()');
stmt.merge(';SELECT * FROM tmp.ticketFullList tfl');
stmts.push(stmt);
stmts.push('CALL ticketFilter()');
stmt = new ParameterizedSQL(
`SELECT * FROM tmp.ticketFilter tfl`
);
stmt.merge(Self.buildSuffix(filter, 'tfl'));
let rsIndex = stmts.push(stmt) - 1;
let result = await Self.rawStmt(stmt);
let sql = ParameterizedSQL.join(stmts, ';');
let tickets = await Self.rawStmt(sql);
return result[3];
return tickets[rsIndex];
};
};