7489-testToMaster #2515

Merged
alexm merged 329 commits from 7489-testToMaster into master 2024-05-28 05:30:19 +00:00
21 changed files with 292 additions and 71 deletions
Showing only changes of commit 27e3ae897a - Show all commits

View File

@ -1,16 +1,17 @@
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
/**
* Actualiza el riesgo de los tickets pendientes de un cliente
*
* @param vClientFk Id del cliente
* @param vSelf Id del cliente
*/
DECLARE vHasDebt BOOL;
SELECT COUNT(*) INTO vHasDebt
FROM `client`
WHERE id = vClientFk
WHERE id = vSelf
AND typeFk = 'normal';
IF vHasDebt THEN
@ -21,7 +22,7 @@ BEGIN
WITH ticket AS(
SELECT id ticketFk, DATE(shipped) dated
FROM vn.ticket t
WHERE clientFk = vClientFk
WHERE clientFk = vSelf
AND refFk IS NULL
AND NOT isDeleted
AND totalWithoutVat <> 0
@ -35,11 +36,11 @@ BEGIN
FROM (
SELECT SUM(amount) amount
FROM vn.clientRisk
WHERE clientFk = vClientFk
WHERE clientFk = vSelf
UNION ALL
SELECT -(SUM(amount) / 100) amount
FROM hedera.tpvTransaction t
WHERE clientFk = vClientFk
WHERE clientFk = vSelf
AND receiptFk IS NULL
AND status = 'ok'
) sub
@ -47,14 +48,14 @@ BEGIN
SELECT DATE(t.shipped) dated, SUM(t.totalWithVat)amount
FROM vn.ticket t
JOIN dated d
WHERE t.clientFk = vClientFk
WHERE t.clientFk = vSelf
AND t.refFk IS NULL
AND t.shipped BETWEEN d.started AND d.ended
GROUP BY DATE(t.shipped)
), receipt AS(
SELECT DATE(payed) dated, SUM(amountPaid) amount
FROM vn.receipt
WHERE clientFk = vClientFk
WHERE clientFk = vSelf
AND payed > util.VN_CURDATE()
GROUP BY DATE(payed)
), risk AS(

View File

@ -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 ;

View File

@ -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 ;

View File

@ -30,5 +30,6 @@ BEGIN
CALL sale_setProblem('hasRounding');
DROP TEMPORARY TABLE tmp.ticket;
DROP TEMPORARY TABLE tmp.buyUltimate;
END$$
DELIMITER ;

View File

@ -1,25 +1,18 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getFreezeProblem`(
vClientFk INT
)
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getFreezeProblem`()
proc: BEGIN
/**
* Actualiza los problemas de los ticket de hoy y a fututo cuyo cliente
* se encuentra congelado o deja de estarlo
*
* @param vClientFk Id del cliente
* @table tmp.ticket(ticketFk, hasProblem)
*/
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
(INDEX(ticketFk))
ENGINE = MEMORY
SELECT t.id ticketFk, NOT c.isFreezed hasProblem
FROM ticket t
JOIN client c ON c.id = t.clientFk
WHERE t.shipped >= util.midnight()
AND c.id = vClientFk;
UPDATE tmp.ticket t
JOIN ticket ti ON ti.id = t.ticketFk
JOIN client c ON c.id = ti.clientFk
SET t.hasProblem = TRUE
WHERE c.isFreezed;
CALL ticket_setProblem('isFreezed');
DROP TEMPORARY TABLE tmp.ticket;
CALL ticket_setProblem('hasTicketRequest');
END$$
DELIMITER ;

View File

@ -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 ;

View File

@ -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 ;

View File

@ -1,26 +1,16 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRequestProblem`(
vSelf INT
)
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRequestProblem`()
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
* @param vSelf Id del ticket de la petición de compra
* @table tmp.ticket(ticketFk, hasProblem)
*/
DECLARE vHasProblem BOOL;
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
(INDEX(ticketFk))
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;
UPDATE tmp.ticket t
JOIN ticketRequest tr ON tr.ticketFk = t.ticketFk
SET t.hasProblem = TRUE
WHERE tr.isOK IS NULL;
CALL ticket_setProblem('hasTicketRequest');
DROP TEMPORARY TABLE tmp.ticket;
END$$
DELIMITER ;

View File

@ -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 ;

View File

@ -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 ;

View File

@ -4,7 +4,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getRiskProbl
)
BEGIN
/**
* Actualiza los problemas para los tickets con riesgo
* Actualiza los problema de riesgo para un ticket en concreto
*
* @param vSelf Id del ticket
*/

View File

@ -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 ;

View File

@ -29,5 +29,6 @@ BEGIN
CALL sale_setProblem('hasRounding');
DROP TEMPORARY TABLE tmp.ticket;
DROP TEMPORARY TABLE tmp.buyUltimate;
END$$
DELIMITER ;

View File

@ -1,26 +1,18 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTaxDataCheckedProblem`(
vClientFk INT
)
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_getTaxDataCheckedProblem`()
proc: BEGIN
/**
* Actualiza los problemas de los ticket de hoy y a fututo
* 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, NOT c.isTaxDataChecked hasProblem
FROM ticket t
JOIN client c ON c.id = t.clientFk
WHERE t.shipped >= util.midnight()
AND c.id = vClientFk;
UPDATE tmp.ticket t
JOIN ticket ti ON ti.id = t.ticketFk
JOIN client c ON c.id = ti.clientFk
SET t.hasproblem = TRUE
WHERE c.isTaxDataChecked;
CALL ticket_setProblem('isTaxDataChecked');
DROP TEMPORARY TABLE tmp.ticket;
END$$
DELIMITER ;

View File

@ -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 ;

View File

@ -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 ;

View File

@ -11,7 +11,7 @@ BEGIN
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
(INDEX(ticketFk))
ENGINE = MEMORY
SELECT vSelf ticketFk, ticket_isTooLittle(vSelf);
SELECT vSelf ticketFk, ticket_isTooLittle(vSelf) hasProblem;
CALL ticket_setProblem('isTooLittle');

View File

@ -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 ;

View File

@ -11,8 +11,7 @@ BEGIN
ENGINE = MEMORY
SELECT t.id ticketFk, ticket_isTooLittle(t.id) hasProblem
FROM ticket t
WHERE t.shipped >= util.midnight()
GROUP BY t.id;
WHERE t.shipped >= util.midnight();
CALL ticket_setProblem('isTooLittle');

View File

@ -12,12 +12,15 @@ BEGIN
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
(INDEX(ticketFk))
ENGINE = MEMORY
SELECT t.id ticketFk, ticket_isTooLittle(t.id) hasProblem
FROM ticket t
JOIN sale s ON s.ticketFk = t.id
WITH tickets AS(
SELECT t.id ticketFk
FROM vn.ticket t
JOIN vn.sale s ON s.ticketFk = t.id
WHERE s.itemFk = vItemFk
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');

View File

@ -1,5 +1,5 @@
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
/**
* Actualiza la columna balance de worker.
@ -8,6 +8,6 @@ BEGIN
*/
UPDATE worker
SET balance = IFNULL(balance, 0) + IFNULL(vCredit, 0) - IFNULL(vDebit, 0)
WHERE id = vSelfFk;
WHERE id = vSelf;
END$$
DELIMITER ;