7489-testToMaster #2515
|
@ -1,16 +1,17 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_risk`(vClientFk INT)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`client_risk`(
|
||||||
|
vSelf INT)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Actualiza el riesgo de los tickets pendientes de un cliente
|
* Actualiza el riesgo de los tickets pendientes de un cliente
|
||||||
*
|
*
|
||||||
* @param vClientFk Id del cliente
|
* @param vSelf Id del cliente
|
||||||
*/
|
*/
|
||||||
DECLARE vHasDebt BOOL;
|
DECLARE vHasDebt BOOL;
|
||||||
|
|
||||||
SELECT COUNT(*) INTO vHasDebt
|
SELECT COUNT(*) INTO vHasDebt
|
||||||
FROM `client`
|
FROM `client`
|
||||||
WHERE id = vClientFk
|
WHERE id = vSelf
|
||||||
AND typeFk = 'normal';
|
AND typeFk = 'normal';
|
||||||
|
|
||||||
IF vHasDebt THEN
|
IF vHasDebt THEN
|
||||||
|
@ -21,7 +22,7 @@ BEGIN
|
||||||
WITH ticket AS(
|
WITH ticket AS(
|
||||||
SELECT id ticketFk, DATE(shipped) dated
|
SELECT id ticketFk, DATE(shipped) dated
|
||||||
FROM vn.ticket t
|
FROM vn.ticket t
|
||||||
WHERE clientFk = vClientFk
|
WHERE clientFk = vSelf
|
||||||
AND refFk IS NULL
|
AND refFk IS NULL
|
||||||
AND NOT isDeleted
|
AND NOT isDeleted
|
||||||
AND totalWithoutVat <> 0
|
AND totalWithoutVat <> 0
|
||||||
|
@ -35,11 +36,11 @@ BEGIN
|
||||||
FROM (
|
FROM (
|
||||||
SELECT SUM(amount) amount
|
SELECT SUM(amount) amount
|
||||||
FROM vn.clientRisk
|
FROM vn.clientRisk
|
||||||
WHERE clientFk = vClientFk
|
WHERE clientFk = vSelf
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT -(SUM(amount) / 100) amount
|
SELECT -(SUM(amount) / 100) amount
|
||||||
FROM hedera.tpvTransaction t
|
FROM hedera.tpvTransaction t
|
||||||
WHERE clientFk = vClientFk
|
WHERE clientFk = vSelf
|
||||||
AND receiptFk IS NULL
|
AND receiptFk IS NULL
|
||||||
AND status = 'ok'
|
AND status = 'ok'
|
||||||
) sub
|
) sub
|
||||||
|
@ -47,14 +48,14 @@ BEGIN
|
||||||
SELECT DATE(t.shipped) dated, SUM(t.totalWithVat)amount
|
SELECT DATE(t.shipped) dated, SUM(t.totalWithVat)amount
|
||||||
FROM vn.ticket t
|
FROM vn.ticket t
|
||||||
JOIN dated d
|
JOIN dated d
|
||||||
WHERE t.clientFk = vClientFk
|
WHERE t.clientFk = vSelf
|
||||||
AND t.refFk IS NULL
|
AND t.refFk IS NULL
|
||||||
AND t.shipped BETWEEN d.started AND d.ended
|
AND t.shipped BETWEEN d.started AND d.ended
|
||||||
GROUP BY DATE(t.shipped)
|
GROUP BY DATE(t.shipped)
|
||||||
), receipt AS(
|
), receipt AS(
|
||||||
SELECT DATE(payed) dated, SUM(amountPaid) amount
|
SELECT DATE(payed) dated, SUM(amountPaid) amount
|
||||||
FROM vn.receipt
|
FROM vn.receipt
|
||||||
WHERE clientFk = vClientFk
|
WHERE clientFk = vSelf
|
||||||
AND payed > util.VN_CURDATE()
|
AND payed > util.VN_CURDATE()
|
||||||
GROUP BY DATE(payed)
|
GROUP BY DATE(payed)
|
||||||
), risk AS(
|
), risk AS(
|
|
@ -0,0 +1,27 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`client_riskAll`()
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Actualiza el riesgo todos los clientes
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
DECLARE vDone BOOL;
|
||||||
|
DECLARE vClientFk INT;
|
||||||
|
|
||||||
|
DECLARE cClients CURSOR FOR
|
||||||
|
SELECT id
|
||||||
|
FROM vn.client;
|
||||||
|
|
||||||
|
DECLARE CONTINUE HANDLER FOR NOT FOUND
|
||||||
|
SET vDone = TRUE;
|
||||||
|
|
||||||
|
OPEN cClients;
|
||||||
|
myLoop: LOOP
|
||||||
|
SET vDone = FALSE;
|
||||||
|
FETCH cClients INTO vClientFk;
|
||||||
|
IF vDone THEN LEAVE myLoop; END IF;
|
||||||
|
CALL vn.client_risk(vClientFk);
|
||||||
|
END LOOP;
|
||||||
|
CLOSE cClients;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1,22 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_getComponentLackProblemAll`()
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Actualiza los problemas para las líneas de ventas que tienen o dejan de tener problemas
|
||||||
|
* con los componentes, verifica que esten o no todos los componenetes obligatorios
|
||||||
|
*
|
||||||
|
* @param vSelf Id del sale
|
||||||
|
*/
|
||||||
|
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
||||||
|
(INDEX(saleFk))
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT s.id saleFk, sale_hasComponentLack(s.id) hasProblem
|
||||||
|
FROM sale s
|
||||||
|
JOIN ticket t ON t.id = s.ticketFk
|
||||||
|
WHERE t.shipped >= util.midnight();
|
||||||
|
|
||||||
|
CALL sale_setProblem('hasComponentLack');
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE tmp.sale;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -30,5 +30,6 @@ BEGIN
|
||||||
CALL sale_setProblem('hasRounding');
|
CALL sale_setProblem('hasRounding');
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tmp.ticket;
|
DROP TEMPORARY TABLE tmp.ticket;
|
||||||
|
DROP TEMPORARY TABLE tmp.buyUltimate;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
|
@ -1,25 +1,18 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getFreezeProblem`(
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getFreezeProblem`()
|
||||||
vClientFk INT
|
|
||||||
)
|
|
||||||
proc: BEGIN
|
proc: BEGIN
|
||||||
/**
|
/**
|
||||||
* Actualiza los problemas de los ticket de hoy y a fututo cuyo cliente
|
* Actualiza los problemas de los ticket de hoy y a fututo cuyo cliente
|
||||||
* se encuentra congelado o deja de estarlo
|
* se encuentra congelado o deja de estarlo
|
||||||
*
|
*
|
||||||
* @param vClientFk Id del cliente
|
* @table tmp.ticket(ticketFk, hasProblem)
|
||||||
*/
|
*/
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
UPDATE tmp.ticket t
|
||||||
(INDEX(ticketFk))
|
JOIN ticket ti ON ti.id = t.ticketFk
|
||||||
ENGINE = MEMORY
|
JOIN client c ON c.id = ti.clientFk
|
||||||
SELECT t.id ticketFk, NOT c.isFreezed hasProblem
|
SET t.hasProblem = TRUE
|
||||||
FROM ticket t
|
WHERE c.isFreezed;
|
||||||
JOIN client c ON c.id = t.clientFk
|
|
||||||
WHERE t.shipped >= util.midnight()
|
|
||||||
AND c.id = vClientFk;
|
|
||||||
|
|
||||||
CALL ticket_setProblem('isFreezed');
|
CALL ticket_setProblem('hasTicketRequest');
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tmp.ticket;
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
|
@ -0,0 +1,19 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getFreezeProblemAll`()
|
||||||
|
proc: BEGIN
|
||||||
|
/**
|
||||||
|
* Actualiza los problemas de los ticket de hoy y a fututo cuyo cliente
|
||||||
|
* se encuentra congelado o deja de estarlo
|
||||||
|
*/
|
||||||
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
|
(INDEX(ticketFk))
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT t.id ticketFk, FALSE hasProblem
|
||||||
|
FROM ticket t
|
||||||
|
WHERE t.shipped >= util.midnight();
|
||||||
|
|
||||||
|
CALL ticket_getFreezeProblem();
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE tmp.ticket;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1,22 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getFreezeProblemByClient`(
|
||||||
|
vClientFk INT
|
||||||
|
)
|
||||||
|
proc: BEGIN
|
||||||
|
/**
|
||||||
|
* Actualiza los problemas de los ticket de hoy y a fututo cuyo cliente
|
||||||
|
* se encuentra congelado o deja de estarlo
|
||||||
|
*/
|
||||||
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
|
(INDEX(ticketFk))
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT t.id ticketFk, FALSE hasProblem
|
||||||
|
FROM ticket t
|
||||||
|
WHERE t.clientFk = vClientFk
|
||||||
|
AND t.shipped >= util.midnight();
|
||||||
|
|
||||||
|
CALL ticket_getFreezeProblem();
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE tmp.ticket;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -1,26 +1,16 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRequestProblem`(
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRequestProblem`()
|
||||||
vSelf INT
|
|
||||||
)
|
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Actualiza los problemas cuando el ticket tiene una petición de compra pendiente o
|
* Actualiza los problemas de tickets que tienen una petición de compra pendiente o
|
||||||
* deja de tenerla
|
* deja de tenerla
|
||||||
* @param vSelf Id del ticket de la petición de compra
|
* @table tmp.ticket(ticketFk, hasProblem)
|
||||||
*/
|
*/
|
||||||
DECLARE vHasProblem BOOL;
|
UPDATE tmp.ticket t
|
||||||
|
JOIN ticketRequest tr ON tr.ticketFk = t.ticketFk
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
SET t.hasProblem = TRUE
|
||||||
(INDEX(ticketFk))
|
WHERE tr.isOK IS NULL;
|
||||||
ENGINE = MEMORY
|
|
||||||
SELECT t.id ticketFk, COUNT(tr.id) hasProblem
|
|
||||||
FROM ticket t
|
|
||||||
LEFT JOIN ticketRequest tr ON tr.ticketFk = t.id
|
|
||||||
WHERE t.id = vSelf
|
|
||||||
AND isOK IS NULL;
|
|
||||||
|
|
||||||
CALL ticket_setProblem('hasTicketRequest');
|
CALL ticket_setProblem('hasTicketRequest');
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tmp.ticket;
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
|
@ -0,0 +1,21 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRequestProblemAll`()
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Actualiza los problemas de tickets pendientes de preparar que tiene una petición
|
||||||
|
* de compra pendiente o deja de tenerla
|
||||||
|
*/
|
||||||
|
DECLARE vHasProblem BOOL;
|
||||||
|
|
||||||
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
|
(INDEX(ticketFk))
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT t.id ticketFk, FALSE hasProblem
|
||||||
|
FROM ticket t
|
||||||
|
WHERE t.shipped >= util.midnight();
|
||||||
|
|
||||||
|
CALL ticket_getRequestProblem();
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE tmp.ticket;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1,24 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRequestProblemByTicket`(
|
||||||
|
vSelf INT
|
||||||
|
)
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Actualiza los problemas de un ticket que tiene una petición de compra pendiente o
|
||||||
|
* deja de tenerla
|
||||||
|
* @param vSelf Id del ticket de la petición de compra
|
||||||
|
*/
|
||||||
|
DECLARE vHasProblem BOOL;
|
||||||
|
|
||||||
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
|
(INDEX(ticketFk))
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT t.id ticketFk, FALSE hasProblem
|
||||||
|
FROM ticket t
|
||||||
|
WHERE t.id = vSelf;
|
||||||
|
|
||||||
|
CALL ticket_getRequestProblem();
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE tmp.ticket;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -4,7 +4,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRiskProbl
|
||||||
)
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Actualiza los problemas para los tickets con riesgo
|
* Actualiza los problema de riesgo para un ticket en concreto
|
||||||
*
|
*
|
||||||
* @param vSelf Id del ticket
|
* @param vSelf Id del ticket
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRiskProblemAll`()
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Actualiza los problema de riesgo para un ticket en concreto
|
||||||
|
*
|
||||||
|
* @param vSelf Id del ticket
|
||||||
|
*/
|
||||||
|
CREATE OR REPLACE TEMPORARY TABLE tRisk
|
||||||
|
(KEY (ticketFk))
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT t.id ticketFk,
|
||||||
|
t.risk > (c.credit + 10) hasRisk,
|
||||||
|
((t.risk - cc.riskTolerance) > (c.credit + 10)) hasHighRisk
|
||||||
|
FROM client c
|
||||||
|
JOIN ticket t ON t.clientFk = c.id
|
||||||
|
JOIN clientConfig cc
|
||||||
|
WHERE t.shipped >= util.midnight();
|
||||||
|
|
||||||
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
|
(KEY (ticketFk))
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT ticketFk, hasRisk hasProblem
|
||||||
|
FROM tRisk;
|
||||||
|
|
||||||
|
CALL ticket_setProblem('hasRisk');
|
||||||
|
DROP TEMPORARY TABLE tmp.ticket;
|
||||||
|
|
||||||
|
CREATE TEMPORARY TABLE tmp.ticket
|
||||||
|
(KEY (ticketFk))
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT ticketFk, hasHighRisk hasProblem
|
||||||
|
FROM tRisk;
|
||||||
|
|
||||||
|
CALL ticket_setProblem('hasHighRisk');
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE tmp.ticket;
|
||||||
|
DROP TEMPORARY TABLE tRisk;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -29,5 +29,6 @@ BEGIN
|
||||||
CALL sale_setProblem('hasRounding');
|
CALL sale_setProblem('hasRounding');
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tmp.ticket;
|
DROP TEMPORARY TABLE tmp.ticket;
|
||||||
|
DROP TEMPORARY TABLE tmp.buyUltimate;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
|
@ -1,26 +1,18 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTaxDataCheckedProblem`(
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTaxDataCheckedProblem`()
|
||||||
vClientFk INT
|
|
||||||
)
|
|
||||||
proc: BEGIN
|
proc: BEGIN
|
||||||
/**
|
/**
|
||||||
* Actualiza los problemas de los ticket de hoy y a fututo
|
* Actualiza los problemas de los ticket de hoy y a fututo
|
||||||
* cuyo cliente tenga o no los datos comprobados
|
* cuyo cliente tenga o no los datos comprobados
|
||||||
*
|
*
|
||||||
* @param vClientFk Id del cliente
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
UPDATE tmp.ticket t
|
||||||
(INDEX(ticketFk))
|
JOIN ticket ti ON ti.id = t.ticketFk
|
||||||
ENGINE = MEMORY
|
JOIN client c ON c.id = ti.clientFk
|
||||||
SELECT t.id ticketFk, NOT c.isTaxDataChecked hasProblem
|
SET t.hasproblem = TRUE
|
||||||
FROM ticket t
|
WHERE c.isTaxDataChecked;
|
||||||
JOIN client c ON c.id = t.clientFk
|
|
||||||
WHERE t.shipped >= util.midnight()
|
|
||||||
AND c.id = vClientFk;
|
|
||||||
|
|
||||||
CALL ticket_setProblem('isTaxDataChecked');
|
CALL ticket_setProblem('isTaxDataChecked');
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tmp.ticket;
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
|
@ -0,0 +1,21 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTaxDataCheckedProblemAll`()
|
||||||
|
proc: BEGIN
|
||||||
|
/**
|
||||||
|
* Actualiza los problemas de los tickets de hoy y a futuro
|
||||||
|
* cuyos clientes tengan o no los datos comprobados
|
||||||
|
*/
|
||||||
|
|
||||||
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
|
(INDEX(ticketFk))
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT t.id ticketFk, FALSE hasProblem
|
||||||
|
FROM ticket t
|
||||||
|
JOIN client c ON c.id = t.clientFk
|
||||||
|
WHERE t.shipped >= util.midnight();
|
||||||
|
|
||||||
|
CALL ticket_getTaxDataCheckedProblem();
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE tmp.ticket;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1,26 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTaxDataCheckedProblemByClient`(
|
||||||
|
vClientFk INT
|
||||||
|
)
|
||||||
|
proc: BEGIN
|
||||||
|
/**
|
||||||
|
* Actualiza los problemas de los ticket de hoy y a futuro
|
||||||
|
* cuyo cliente tenga o no los datos comprobados
|
||||||
|
*
|
||||||
|
* @param vClientFk Id del cliente
|
||||||
|
*/
|
||||||
|
|
||||||
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
|
(INDEX(ticketFk))
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT t.id ticketFk, FALSE hasProblem
|
||||||
|
FROM ticket t
|
||||||
|
JOIN client c ON c.id = t.clientFk
|
||||||
|
WHERE t.shipped >= util.midnight()
|
||||||
|
AND c.id = vClientFk;
|
||||||
|
|
||||||
|
CALL ticket_getTaxDataCheckedProblem();
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE tmp.ticket;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -11,7 +11,7 @@ BEGIN
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
(INDEX(ticketFk))
|
(INDEX(ticketFk))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT vSelf ticketFk, ticket_isTooLittle(vSelf);
|
SELECT vSelf ticketFk, ticket_isTooLittle(vSelf) hasProblem;
|
||||||
|
|
||||||
CALL ticket_setProblem('isTooLittle');
|
CALL ticket_setProblem('isTooLittle');
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTooLittleProblemAll`()
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Actualiza los problemas cuando un ticket es demasiado pequeño o deja de serlo
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
|
(INDEX(ticketFk))
|
||||||
|
ENGINE = MEMORY
|
||||||
|
SELECT id ticketFk, ticket_isTooLittle(id) hasProblem
|
||||||
|
FROM ticket
|
||||||
|
WHERE shipped >= util.midnight();
|
||||||
|
|
||||||
|
CALL ticket_setProblem('isTooLittle');
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE tmp.ticket;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -11,8 +11,7 @@ BEGIN
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT t.id ticketFk, ticket_isTooLittle(t.id) hasProblem
|
SELECT t.id ticketFk, ticket_isTooLittle(t.id) hasProblem
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
WHERE t.shipped >= util.midnight()
|
WHERE t.shipped >= util.midnight();
|
||||||
GROUP BY t.id;
|
|
||||||
|
|
||||||
CALL ticket_setProblem('isTooLittle');
|
CALL ticket_setProblem('isTooLittle');
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,15 @@ BEGIN
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
(INDEX(ticketFk))
|
(INDEX(ticketFk))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT t.id ticketFk, ticket_isTooLittle(t.id) hasProblem
|
WITH tickets AS(
|
||||||
FROM ticket t
|
SELECT t.id ticketFk
|
||||||
JOIN sale s ON s.ticketFk = t.id
|
FROM vn.ticket t
|
||||||
|
JOIN vn.sale s ON s.ticketFk = t.id
|
||||||
WHERE s.itemFk = vItemFk
|
WHERE s.itemFk = vItemFk
|
||||||
AND t.shipped >= util.midnight()
|
AND t.shipped >= util.midnight()
|
||||||
GROUP BY t.id;
|
GROUP BY t.id
|
||||||
|
)SELECT ticketFk, ticket_isTooLittle(ticketFk) hasProblem
|
||||||
|
FROM tickets;
|
||||||
|
|
||||||
CALL ticket_setProblem('isTooLittle');
|
CALL ticket_setProblem('isTooLittle');
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`worker_updateBalance`(vSelfFk INT(11), vCredit DECIMAL(10,2), vDebit DECIMAL(10,2))
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`worker_updateBalance`(vSelf INT(11), vCredit DECIMAL(10,2), vDebit DECIMAL(10,2))
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Actualiza la columna balance de worker.
|
* Actualiza la columna balance de worker.
|
||||||
|
@ -8,6 +8,6 @@ BEGIN
|
||||||
*/
|
*/
|
||||||
UPDATE worker
|
UPDATE worker
|
||||||
SET balance = IFNULL(balance, 0) + IFNULL(vCredit, 0) - IFNULL(vDebit, 0)
|
SET balance = IFNULL(balance, 0) + IFNULL(vCredit, 0) - IFNULL(vDebit, 0)
|
||||||
WHERE id = vSelfFk;
|
WHERE id = vSelf;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
Loading…
Reference in New Issue