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
|
||||
FROM (
|
||||
SELECT r.clientFk,
|
||||
r.amount recovery,
|
||||
timestampadd(DAY, r.period, sub2.created) deadLine,
|
||||
sub2.amount credit
|
||||
FROM recovery r
|
||||
JOIN (
|
||||
SELECT clientFk, amount , created
|
||||
FROM (
|
||||
SELECT * FROM clientCredit
|
||||
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()
|
||||
) sub3
|
||||
WHERE credit > 0;
|
||||
|
||||
UPDATE client c
|
||||
JOIN tCreditClients cc ON cc.clientFk = c.clientFk
|
||||
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
|
||||
|
||||
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 (
|
||||
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
|
||||
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
|
||||
|
||||
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,
|
||||
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'
|
||||
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