refactor: refs #6701 Refactor claim_ratio_routine
This commit is contained in:
parent
883f6f18a3
commit
f0b814c79b
|
@ -831,9 +831,9 @@ INSERT INTO `vn`.`config`(`id`, `mdbServer`, `fakeEmail`, `defaultersMaxAmount`,
|
||||||
INSERT INTO `vn`.`greugeType`(`id`, `name`, `code`)
|
INSERT INTO `vn`.`greugeType`(`id`, `name`, `code`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 'Diff', 'diff'),
|
(1, 'Diff', 'diff'),
|
||||||
(2, 'Recover', 'recover'),
|
(2, 'Recobro', 'recovery'),
|
||||||
(3, 'Mana', 'mana'),
|
(3, 'Maná', 'mana'),
|
||||||
(4, 'Reclaim', 'reclaim'),
|
(4, 'Reclamación', 'claim'),
|
||||||
(5, 'Heritage', 'heritage'),
|
(5, 'Heritage', 'heritage'),
|
||||||
(6, 'Miscellaneous', 'miscellaneous'),
|
(6, 'Miscellaneous', 'miscellaneous'),
|
||||||
(7, 'Freight Pickup', 'freightPickUp');
|
(7, 'Freight Pickup', 'freightPickUp');
|
||||||
|
|
|
@ -2,9 +2,8 @@ DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`claimRatio_add`()
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`claimRatio_add`()
|
||||||
BEGIN
|
BEGIN
|
||||||
/*
|
/*
|
||||||
* PAK 2015-11-20
|
* Añade a la tabla greuges todos los cargos necesario y
|
||||||
* Se trata de añadir a la tabla Greuges todos los
|
* que luego lo utilizamos para calcular el recobro.
|
||||||
* cargos que luego vamos a utilizar para calcular el recobro
|
|
||||||
*/
|
*/
|
||||||
DECLARE vMonthToRefund INT DEFAULT 4;
|
DECLARE vMonthToRefund INT DEFAULT 4;
|
||||||
DECLARE vRecoveryGreugeType INT
|
DECLARE vRecoveryGreugeType INT
|
||||||
|
@ -61,7 +60,8 @@ BEGIN
|
||||||
SELECT c.ticketCreated,
|
SELECT c.ticketCreated,
|
||||||
c.clientFk,
|
c.clientFk,
|
||||||
CONCAT('Claim_mana ', c.id,' : ', s.concept),
|
CONCAT('Claim_mana ', c.id,' : ', s.concept),
|
||||||
ROUND( ((c.responsibility -1)/4) * s.quantity * s.price * (100 - s.discount) / 100, 2),
|
ROUND(((c.responsibility - 1) / 4) * s.quantity *
|
||||||
|
s.price * (100 - s.discount) / 100, 2),
|
||||||
vManaGreugeType,
|
vManaGreugeType,
|
||||||
s.ticketFk
|
s.ticketFk
|
||||||
FROM sale s
|
FROM sale s
|
||||||
|
@ -134,20 +134,7 @@ BEGIN
|
||||||
SET sc.isGreuge = TRUE
|
SET sc.isGreuge = TRUE
|
||||||
WHERE sc.componentFk = vDebtComponentType;
|
WHERE sc.componentFk = vDebtComponentType;
|
||||||
|
|
||||||
/*
|
INSERT INTO claimRatio(
|
||||||
* Recalculamos la ratio de las reclamaciones, que luego
|
|
||||||
* se va a utilizar en el recobro
|
|
||||||
*/
|
|
||||||
REPLACE claimRatio(
|
|
||||||
clientFk,
|
|
||||||
yearSale,
|
|
||||||
claimAmount,
|
|
||||||
claimingRate,
|
|
||||||
priceIncreasing
|
|
||||||
)
|
|
||||||
SELECT id, 0, 0, 0, 0 FROM client;
|
|
||||||
|
|
||||||
REPLACE claimRatio(
|
|
||||||
clientFk,
|
clientFk,
|
||||||
yearSale,
|
yearSale,
|
||||||
claimAmount,
|
claimAmount,
|
||||||
|
@ -183,16 +170,18 @@ BEGIN
|
||||||
FROM greuge
|
FROM greuge
|
||||||
WHERE shipped <= util.VN_CURDATE()
|
WHERE shipped <= util.VN_CURDATE()
|
||||||
GROUP BY clientFk
|
GROUP BY clientFk
|
||||||
) sub ON subg.clientFk = cr.clientFk
|
) sub ON sub.clientFk = cr.clientFk
|
||||||
SET cr.priceIncreasing = GREATEST(0, ROUND(IFNULL(sub.greuge, 0) /
|
SET cr.priceIncreasing = GREATEST(0, ROUND(IFNULL(sub.greuge, 0) /
|
||||||
(IFNULL(cr.yearSale, 0) * vMonthToRefund / 12 ), 3));
|
(IFNULL(cr.yearSale, 0) * vMonthToRefund / 12 ), 3))
|
||||||
|
WHERE cr.dated = util.VN_CURDATE();
|
||||||
|
|
||||||
-- Protección neonatos
|
-- Protección neonatos
|
||||||
UPDATE claimRatio cr
|
UPDATE claimRatio cr
|
||||||
JOIN firstTicketShipped fts ON fts.clientFk = cr.clientFk
|
JOIN firstTicketShipped fts ON fts.clientFk = cr.clientFk
|
||||||
SET cr.priceIncreasing = 0,
|
SET cr.priceIncreasing = 0,
|
||||||
cr.claimingRate = 0
|
cr.claimingRate = 0
|
||||||
WHERE fts.shipped > util.VN_CURDATE() - INTERVAL 1 MONTH;
|
WHERE fts.shipped > util.VN_CURDATE() - INTERVAL 1 MONTH
|
||||||
|
AND cr.dated = util.VN_CURDATE();
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tTicketList;
|
DROP TEMPORARY TABLE tTicketList;
|
||||||
END$$
|
END$$
|
||||||
|
|
|
@ -2,3 +2,9 @@ UPDATE IGNORE bs.nightTask
|
||||||
SET `procedure` = 'claimRatio_add',
|
SET `procedure` = 'claimRatio_add',
|
||||||
`schema` = 'vn'
|
`schema` = 'vn'
|
||||||
WHERE `procedure` = 'claim_ratio_routine';
|
WHERE `procedure` = 'claim_ratio_routine';
|
||||||
|
|
||||||
|
ALTER TABLE vn.claimRatio ADD dated DATE DEFAULT current_timestamp() NOT NULL;
|
||||||
|
ALTER TABLE vn.claimRatio CHANGE dated dated DATE DEFAULT current_timestamp() NOT NULL FIRST;
|
||||||
|
ALTER TABLE vn.claimRatio DROP FOREIGN KEY claimRatio_ibfk_1;
|
||||||
|
ALTER TABLE vn.claimRatio DROP PRIMARY KEY;
|
||||||
|
ALTER TABLE vn.claimRatio ADD CONSTRAINT claimRatio_pk PRIMARY KEY (dated,clientFk);
|
||||||
|
|
Loading…
Reference in New Issue