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`)
|
||||
VALUES
|
||||
(1, 'Diff', 'diff'),
|
||||
(2, 'Recover', 'recover'),
|
||||
(3, 'Mana', 'mana'),
|
||||
(4, 'Reclaim', 'reclaim'),
|
||||
(2, 'Recobro', 'recovery'),
|
||||
(3, 'Maná', 'mana'),
|
||||
(4, 'Reclamación', 'claim'),
|
||||
(5, 'Heritage', 'heritage'),
|
||||
(6, 'Miscellaneous', 'miscellaneous'),
|
||||
(7, 'Freight Pickup', 'freightPickUp');
|
||||
|
|
|
@ -2,9 +2,8 @@ DELIMITER $$
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`claimRatio_add`()
|
||||
BEGIN
|
||||
/*
|
||||
* PAK 2015-11-20
|
||||
* Se trata de añadir a la tabla Greuges todos los
|
||||
* cargos que luego vamos a utilizar para calcular el recobro
|
||||
* Añade a la tabla greuges todos los cargos necesario y
|
||||
* que luego lo utilizamos para calcular el recobro.
|
||||
*/
|
||||
DECLARE vMonthToRefund INT DEFAULT 4;
|
||||
DECLARE vRecoveryGreugeType INT
|
||||
|
@ -61,7 +60,8 @@ BEGIN
|
|||
SELECT c.ticketCreated,
|
||||
c.clientFk,
|
||||
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,
|
||||
s.ticketFk
|
||||
FROM sale s
|
||||
|
@ -134,20 +134,7 @@ BEGIN
|
|||
SET sc.isGreuge = TRUE
|
||||
WHERE sc.componentFk = vDebtComponentType;
|
||||
|
||||
/*
|
||||
* 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(
|
||||
INSERT INTO claimRatio(
|
||||
clientFk,
|
||||
yearSale,
|
||||
claimAmount,
|
||||
|
@ -163,8 +150,8 @@ BEGIN
|
|||
LEFT JOIN (
|
||||
SELECT c.clientFk,
|
||||
ROUND(SUM(-1 * ((c.responsibility - 1) / 4) *
|
||||
s.quantity * s.price * (100 - s.discount)
|
||||
/ 100)) totalClaims
|
||||
s.quantity * s.price * (100 - s.discount)
|
||||
/ 100)) totalClaims
|
||||
FROM sale s
|
||||
JOIN claimEnd ce ON ce.saleFk = s.id
|
||||
JOIN claimDestination cd ON cd.id = ce.claimDestinationFk
|
||||
|
@ -183,16 +170,18 @@ BEGIN
|
|||
FROM greuge
|
||||
WHERE shipped <= util.VN_CURDATE()
|
||||
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) /
|
||||
(IFNULL(cr.yearSale, 0) * vMonthToRefund / 12 ), 3));
|
||||
(IFNULL(cr.yearSale, 0) * vMonthToRefund / 12 ), 3))
|
||||
WHERE cr.dated = util.VN_CURDATE();
|
||||
|
||||
-- Protección neonatos
|
||||
UPDATE claimRatio cr
|
||||
JOIN firstTicketShipped fts ON fts.clientFk = cr.clientFk
|
||||
SET cr.priceIncreasing = 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;
|
||||
END$$
|
||||
|
|
|
@ -2,3 +2,9 @@ UPDATE IGNORE bs.nightTask
|
|||
SET `procedure` = 'claimRatio_add',
|
||||
`schema` = 'vn'
|
||||
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