7489-testToMaster #2515
|
@ -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(
|
|
@ -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 ;
|
|
@ -22,13 +22,14 @@ BEGIN
|
|||
CALL buyUltimate(vWarehouseFk, vDated);
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||
SELECT vSelf saleFk, MOD(vQuantity, bu.`grouping`) hasProblem
|
||||
FROM tmp.buyUltimate bu
|
||||
JOIN buy b ON b.id = bu.buyFk
|
||||
WHERE bu.itemFk = vItemFk;
|
||||
SELECT vSelf saleFk, MOD(vQuantity, bu.`grouping`) hasProblem
|
||||
FROM tmp.buyUltimate bu
|
||||
JOIN buy b ON b.id = bu.buyFk
|
||||
WHERE bu.itemFk = vItemFk;
|
||||
|
||||
CALL sale_setProblem('hasRounding');
|
||||
|
||||
DROP TEMPORARY TABLE tmp.ticket;
|
||||
DROP TEMPORARY TABLE tmp.buyUltimate;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -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;
|
||||
|
||||
CALL ticket_setProblem('isFreezed');
|
||||
|
||||
DROP TEMPORARY TABLE tmp.ticket;
|
||||
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('hasTicketRequest');
|
||||
END$$
|
||||
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 $$
|
||||
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;
|
||||
UPDATE tmp.ticket t
|
||||
JOIN ticketRequest tr ON tr.ticketFk = t.ticketFk
|
||||
SET t.hasProblem = TRUE
|
||||
WHERE tr.isOK IS NULL;
|
||||
|
||||
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;
|
||||
|
||||
CALL ticket_setProblem('hasTicketRequest');
|
||||
|
||||
DROP TEMPORARY TABLE tmp.ticket;
|
||||
END$$
|
||||
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
|
||||
/**
|
||||
* Actualiza los problemas para los tickets con riesgo
|
||||
* Actualiza los problema de riesgo para un ticket en concreto
|
||||
*
|
||||
* @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');
|
||||
|
||||
DROP TEMPORARY TABLE tmp.ticket;
|
||||
DROP TEMPORARY TABLE tmp.buyUltimate;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -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 ;
|
|
@ -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
|
||||
(INDEX(ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT vSelf ticketFk, ticket_isTooLittle(vSelf);
|
||||
SELECT vSelf ticketFk, ticket_isTooLittle(vSelf) hasProblem;
|
||||
|
||||
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
|
||||
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');
|
||||
|
||||
|
|
|
@ -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
|
||||
WHERE s.itemFk = vItemFk
|
||||
AND t.shipped >= util.midnight()
|
||||
GROUP BY 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
|
||||
)SELECT ticketFk, ticket_isTooLittle(ticketFk) hasProblem
|
||||
FROM tickets;
|
||||
|
||||
CALL ticket_setProblem('isTooLittle');
|
||||
|
||||
|
|
|
@ -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 ;
|
||||
|
|
Loading…
Reference in New Issue