feat: refs #6500 procRefactor8 #2131
|
@ -0,0 +1,8 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`raidUpdate`
|
||||
ON SCHEDULE EVERY 1 DAY
|
||||
STARTS '2017-12-29 00:05:00.000'
|
||||
ON COMPLETION PRESERVE
|
||||
ENABLE
|
||||
DO CALL raidUpdate$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,49 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`creditRecovery`()
|
||||
BEGIN
|
||||
robert marked this conversation as resolved
|
||||
DECLARE EXIT HANDLER FOR SQLSTATE '45000'
|
||||
BEGIN
|
||||
ROLLBACK;
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
UPDATE `client` c
|
||||
JOIN payMethod pm ON pm.id = c.payMethodFk
|
||||
SET c.credit = 0
|
||||
WHERE pm.`code` = 'card';
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tCreditClients;
|
||||
CREATE TEMPORARY TABLE tCreditClients
|
||||
SELECT clientFk, IF (credit > recovery ,credit - recovery,0) newCredit
|
||||
robert marked this conversation as resolved
Outdated
carlosap
commented
Espacios: SELECT clientFk, IF (credit > recovery, credit - recovery, 0) newCredit Espacios: SELECT clientFk, IF (credit > recovery, credit - recovery, 0) newCredit
|
||||
FROM (
|
||||
robert marked this conversation as resolved
Outdated
carlosap
commented
tabulación FROM tabulación FROM
|
||||
SELECT r.clientFk,
|
||||
r.amount recovery,
|
||||
timestampadd(DAY, r.period, sub2.created) deadLine,
|
||||
robert marked this conversation as resolved
Outdated
carlosap
commented
INTERVAL INTERVAL
|
||||
sub2.amount credit
|
||||
FROM recovery r
|
||||
JOIN (
|
||||
SELECT clientFk, amount , created
|
||||
FROM (
|
||||
SELECT * FROM clientCredit
|
||||
robert marked this conversation as resolved
Outdated
carlosap
commented
Especificar campos, eliminar * Especificar campos, eliminar *
|
||||
ORDER BY created DESC
|
||||
LIMIT 10000000000000000000
|
||||
) sub
|
||||
GROUP BY clientFk
|
||||
) sub2 ON sub2.clientFk = r.clientFk
|
||||
WHERE r.finished IS NULL OR r.finished >= util.VN_CURDATE()
|
||||
GROUP BY r.clientFk
|
||||
HAVING deadLine <= util.VN_CURDATE()
|
||||
robert marked this conversation as resolved
Outdated
carlosap
commented
tabulación HAVING tabulación HAVING
|
||||
) sub3
|
||||
WHERE credit > 0;
|
||||
|
||||
UPDATE client c
|
||||
JOIN tCreditClients cc ON cc.clientFk = c.clientFk
|
||||
robert marked this conversation as resolved
Outdated
carlosap
commented
tabulación JOIN y SET tabulación JOIN y SET
|
||||
SET Clientes.Credito = newCredit;
|
||||
|
||||
DROP TEMPORARY TABLE tCreditClients;
|
||||
COMMIT;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,30 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`raidUpdate`()
|
||||
BEGIN
|
||||
|
||||
robert marked this conversation as resolved
Outdated
carlosap
commented
falta descripción falta descripción
|
||||
UPDATE entry e
|
||||
JOIN entryVirtual ev ON ev.entryFk = e.id
|
||||
JOIN travel t ON t.id = e.travelFk
|
||||
JOIN (
|
||||
SELECT *
|
||||
FROM (
|
||||
SELECT id, landed, tt.warehouseInFk, tt.warehouseOutFk
|
||||
FROM travel t
|
||||
JOIN (
|
||||
robert marked this conversation as resolved
Outdated
carlosap
commented
faltan alias en los campos faltan alias en los campos
|
||||
SELECT t.warehouseInFk, t.warehouseOutFk
|
||||
FROM entryVirtual ev
|
||||
JOIN entry e ON e.id = ev.entryFk
|
||||
JOIN travel t ON t.id = e.travelFk
|
||||
GROUP BY t.warehouseInFk, t.warehouseOutFk
|
||||
) tt ON t.warehouseInFk = tt.warehouseInFk AND t.warehouseOutFk = tt.warehouseOutFk
|
||||
|
||||
WHERE shipped > util.VN_CURDATE() AND isDelivered = FALSE
|
||||
ORDER BY t.landed
|
||||
robert marked this conversation as resolved
Outdated
carlosap
commented
isDelivered = FALSE NOT isDelivered Faltan alias isDelivered = FALSE
NOT isDelivered
Faltan alias
|
||||
LIMIT 10000000000000000000
|
||||
) t
|
||||
GROUP BY warehouseInFk, warehouseOutFk
|
||||
) tt ON t.warehouseInFk = tt.warehouseInFk AND t.warehouseOutFk = tt.warehouseOutFk
|
||||
SET e.travelFk = t.id;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,42 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`rateView`()
|
||||
BEGIN
|
||||
|
||||
robert marked this conversation as resolved
Outdated
carlosap
commented
falta descripción falta descripción
|
||||
DECLARE v10Years DATE DEFAULT util.VN_CURDATE() - INTERVAL 10 YEAR;
|
||||
|
||||
SELECT
|
||||
t.year,
|
||||
t.month,
|
||||
pagos.dollars,
|
||||
pagos.changePractical,
|
||||
CAST(SUM(iit.foreignValue ) / SUM(iit.taxableBase) AS DECIMAL(5,4)) cambioTeorico,
|
||||
pagos.changeOfficial
|
||||
FROM invoiceIn ii
|
||||
JOIN time t ON t.dated = ii.issued
|
||||
JOIN invoiceInTax iit ON ii.id = iit.invoiceInFk
|
||||
JOIN
|
||||
(
|
||||
SELECT
|
||||
t.year,
|
||||
t.month,
|
||||
robert marked this conversation as resolved
Outdated
carlosap
commented
faltan alias, no se sabe de que tablas vienen los campos faltan alias, no se sabe de que tablas vienen los campos
|
||||
CAST(SUM(divisa) AS DECIMAL(10,2)) dollars,
|
||||
CAST(SUM(divisa) / SUM(amount) AS DECIMAL(5,4)) changePractical,
|
||||
CAST(rr.value * 0.998 AS DECIMAL(5,4)) changeOfficial
|
||||
FROM payment p
|
||||
JOIN time t ON t.dated = p.received
|
||||
JOIN referenceRate rr ON rr.dated = p.received
|
||||
JOIN currency c ON c.id = rr.currencyFk
|
||||
WHERE divisa
|
||||
AND p.received >= v10Years
|
||||
AND c.code = 'USD'
|
||||
robert marked this conversation as resolved
Outdated
carlosap
commented
En la medida de lo posible no se debe de escribir en español, en este caso el nombre de la subconsulta es totalmente evitable que este en español, traducir En la medida de lo posible no se debe de escribir en español, en este caso el nombre de la subconsulta es totalmente evitable que este en español, traducir
|
||||
GROUP BY t.year, t.month
|
||||
) pagos ON t.year = pagos.year AND t.month = pagos.MONTH
|
||||
JOIN currency c ON c.id = ii.currencyFk
|
||||
WHERE c.code = 'USD'
|
||||
AND ii.issued >= v10Years
|
||||
AND iit.foreignValue
|
||||
AND iit.taxableBase
|
||||
GROUP BY t.year, t.month;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
Loading…
Reference in New Issue
Falta descripción del procedimiento