refactor: refs #7258 Deleted all dependences of vn2008 schema #2362
|
@ -2,22 +2,22 @@ DELIMITER $$
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bi`.`defaulting`(IN `vDate` DATE)
|
||||
BEGIN
|
||||
DECLARE vDone BOOLEAN;
|
||||
DECLARE vClient INT;
|
||||
DECLARE vAmount INT;
|
||||
DECLARE vDued DATE;
|
||||
DECLARE vAmountInvoice DECIMAL(10,2);
|
||||
DECLARE vGraceDays INT;
|
||||
DECLARE vClient INT;
|
||||
DECLARE vAmount INT;
|
||||
DECLARE vDued DATE;
|
||||
DECLARE vAmountInvoice DECIMAL(10,2);
|
||||
DECLARE vGraceDays INT;
|
||||
DECLARE defaulters CURSOR FOR
|
||||
SELECT d.client, d.amount, pm.graceDays
|
||||
FROM bi.defaulters d
|
||||
JOIN vn.client c ON c.id = d.client
|
||||
JOIN vn.payMethod pm ON pm.id = c.pay_met_id
|
||||
WHERE hasChanged AND date = vDate;
|
||||
|
||||
JOIN vn.payMethod pm ON pm.id = c.payMethodFk
|
||||
WHERE hasChanged AND date = vDate;
|
||||
|
||||
DECLARE invoices CURSOR FOR
|
||||
SELECT dued Vencimiento, amount importe FROM vn.invoiceOut
|
||||
WHERE issued >= '2016-01-01' AND clientFk = vClient ORDER BY issued DESC;
|
||||
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||
|
||||
DELETE FROM bi.defaulters WHERE date = vDate;
|
||||
|
@ -27,7 +27,7 @@ BEGIN
|
|||
FROM vn.`client` c
|
||||
LEFT JOIN bi.customerRiskOverdue cro ON c.id = cro.customer_id
|
||||
GROUP BY c.id;
|
||||
|
||||
|
||||
-- marcamos si ha cambiado y heredamos la fecha defaulterSince
|
||||
UPDATE bi.defaulters d
|
||||
LEFT JOIN (
|
||||
|
@ -36,16 +36,16 @@ BEGIN
|
|||
WHERE date <= TIMESTAMPADD(DAY,-1, vDate)
|
||||
ORDER BY date DESC
|
||||
LIMIT 10000000000000000000) t GROUP BY client
|
||||
) yesterday using(client)
|
||||
) yesterday using(client)
|
||||
SET d.hasChanged = (IFNULL(d.amount,0) <> IFNULL(yesterday.amount,0)),
|
||||
d.defaulterSince = yesterday.defaulterSince,
|
||||
d.frozened = yesterday.frozened
|
||||
d.frozened = yesterday.frozened
|
||||
WHERE d.date = vDate ;
|
||||
|
||||
OPEN defaulters;
|
||||
|
||||
OPEN defaulters;
|
||||
defaulters: LOOP
|
||||
SET vDone = FALSE;
|
||||
SET vAmount = 0;
|
||||
SET vAmount = 0;
|
||||
FETCH defaulters INTO vClient,vAmount, vGraceDays;
|
||||
IF vDone THEN
|
||||
LEAVE defaulters;
|
||||
|
@ -61,7 +61,7 @@ BEGIN
|
|||
IF TIMESTAMPADD(DAY, vGraceDays, vDued) <= vDate THEN
|
||||
SET vAmount = vAmount - vAmountInvoice;
|
||||
IF vAmount <= 0 THEN
|
||||
|
||||
|
||||
UPDATE defaulters SET defaulterSince = vDued
|
||||
WHERE client = vClient and date = vDate;
|
||||
|
||||
|
@ -74,20 +74,20 @@ BEGIN
|
|||
END LOOP;
|
||||
CLOSE defaulters;
|
||||
|
||||
DELETE FROM defaulters
|
||||
DELETE FROM defaulters
|
||||
WHERE amount = 0
|
||||
AND hasChanged = FALSE
|
||||
AND `date` = vDate;
|
||||
|
||||
UPDATE defaulters d
|
||||
AND `date` = vDate;
|
||||
|
||||
UPDATE defaulters d
|
||||
JOIN vn.config ON TRUE
|
||||
SET d.frozened = NULL
|
||||
WHERE `date` = vDate
|
||||
AND d.amount <= config.defaultersMaxAmount;
|
||||
|
||||
CALL vn.clientFreeze();
|
||||
|
||||
-- actualizamos defaulting
|
||||
|
||||
CALL vn.clientFreeze();
|
||||
|
||||
-- actualizamos defaulting
|
||||
DELETE FROM bi.defaulting WHERE date = vDate;
|
||||
|
||||
INSERT INTO bi.defaulting(date, amount)
|
||||
|
|
|
@ -58,7 +58,7 @@ BEGIN
|
|||
JOIN vn.address a on a.id = t.addressFk
|
||||
JOIN vn.client c on c.id = a.clientFk
|
||||
JOIN tmp.ticket_list tt on tt.id = t.id
|
||||
JOIN vn.item i on s.itemFk = i.Id_Ticket
|
||||
JOIN vn.item i on s.itemFk = i.id
|
||||
JOIN vn.company co on co.id = t.companyFk
|
||||
LEFT JOIN vn.company co2 on co2.clientFk = c.id
|
||||
JOIN vn.itemType it on it.id = i.typeFk
|
||||
|
|
|
@ -4,7 +4,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`solunionCAP_afterInse
|
|||
FOR EACH ROW
|
||||
BEGIN
|
||||
UPDATE client c
|
||||
JOIN creditClassification cc ON cc.client = c.clientFk
|
||||
JOIN creditClassification cc ON cc.client = c.id
|
||||
JOIN creditInsurance ci ON ci.creditClassification = cc.id
|
||||
SET creditInsurance = ci.credit * 2 WHERE ci.id = NEW.creditInsurance;
|
||||
END$$
|
||||
|
|
|
@ -5,12 +5,12 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`solunionCAP_afterUpda
|
|||
BEGIN
|
||||
IF NEW.dateLeaving IS NOT NULL THEN
|
||||
UPDATE client c
|
||||
JOIN creditClassification cc ON cc.client = c.clientFk
|
||||
JOIN creditClassification cc ON cc.client = c.id
|
||||
JOIN creditInsurance ci ON ci.creditClassification = cc.id
|
||||
SET creditInsurance = ci.credit WHERE ci.id = OLD.creditInsurance;
|
||||
ELSE
|
||||
UPDATE client c
|
||||
JOIN creditClassification cc ON cc.client = c.clientFk
|
||||
JOIN creditClassification cc ON cc.client = c.id
|
||||
JOIN creditInsurance ci ON ci.creditClassification = cc.id
|
||||
SET creditInsurance = ci.credit * 2 WHERE ci.id = OLD.creditInsurance;
|
||||
END IF;
|
||||
|
|
|
@ -4,7 +4,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`solunionCAP_beforeDel
|
|||
FOR EACH ROW
|
||||
BEGIN
|
||||
UPDATE client c
|
||||
JOIN creditClassification cc ON cc.client = c.clientFk
|
||||
JOIN creditClassification cc ON cc.client = c.id
|
||||
JOIN creditInsurance ci ON ci.creditClassification = cc.id
|
||||
SET creditInsurance = ci.credit WHERE ci.id = OLD.creditInsurance;
|
||||
END$$
|
||||
|
|
Loading…
Reference in New Issue