feat: refs #8298 add priceOptimum and packagesDiscountFactor to zone and client tables
This commit is contained in:
parent
2572182a89
commit
1816b6de67
|
@ -0,0 +1,8 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` EVENT `vn`.`client_setPackagesDiscountFactor`
|
||||
ON SCHEDULE EVERY 1 DAY
|
||||
STARTS '2024-10-18 03:00:00.000'
|
||||
ON COMPLETION PRESERVE
|
||||
ENABLE
|
||||
DO CALL client_setPackagesDiscountFactor()$$
|
||||
DELIMITER ;
|
|
@ -231,7 +231,23 @@ BEGIN
|
|||
SELECT tcc.warehouseFK,
|
||||
tcc.itemFk,
|
||||
c2.id,
|
||||
z.inflation * ROUND(ic.cm3delivery * (IFNULL(zo.price,5000) - IFNULL(zo.bonus,0)) / (1000 * vc.standardFlowerBox) , 4) cost
|
||||
z.inflation
|
||||
* ROUND(
|
||||
ic.cm3delivery
|
||||
* (
|
||||
(
|
||||
zo.price
|
||||
- (
|
||||
(zo.price - zo.priceOptimum)
|
||||
* c.packagesDiscountFactor
|
||||
)
|
||||
)
|
||||
- IFNULL(zo.bonus, 0)
|
||||
)
|
||||
/ (1000 * vc.standardFlowerBox),
|
||||
4
|
||||
) cost
|
||||
|
||||
FROM tmp.ticketComponentCalculate tcc
|
||||
JOIN item i ON i.id = tcc.itemFk
|
||||
JOIN tmp.zoneOption zo ON zo.zoneFk = vZoneFk
|
||||
|
@ -239,6 +255,7 @@ BEGIN
|
|||
JOIN agencyMode am ON am.id = z.agencyModeFk
|
||||
JOIN vn.volumeConfig vc
|
||||
JOIN vn.component c2 ON c2.code = 'delivery'
|
||||
JOIN `client` c on c.id = vClientFk
|
||||
LEFT JOIN itemCost ic ON ic.warehouseFk = tcc.warehouseFk
|
||||
AND ic.itemFk = tcc.itemFk
|
||||
HAVING cost <> 0;
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
DELIMITER $$
|
||||
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost`
|
||||
PROCEDURE `vn`.`client_setPackagesDiscountFactor`()
|
||||
BEGIN
|
||||
/**
|
||||
* Set the discount factor for the packages of the clients.
|
||||
*/
|
||||
UPDATE client c
|
||||
JOIN (
|
||||
SELECT t.clientFk,
|
||||
LEAST((
|
||||
SUM(t.packages) / COUNT(DISTINCT DATE(t.shipped))
|
||||
) / cc.packagesOptimum, 1) discountFactor
|
||||
FROM ticket t
|
||||
JOIN clientConfig cc ON TRUE
|
||||
WHERE t.shipped > util.VN_CURDATE() - INTERVAL cc.monthsToCalcOptimumPrice MONTH
|
||||
AND t.packages
|
||||
GROUP BY t.clientFk
|
||||
) ca ON c.id = ca.clientFk
|
||||
SET c.packagesDiscountFactor = ca.discountFactor;
|
||||
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
|
@ -9,7 +9,7 @@ BEGIN
|
|||
* @return tmp.zoneOption(zoneFk, hour, travelingDays, price, bonus, specificity) The computed options
|
||||
*/
|
||||
DECLARE vHour TIME DEFAULT TIME(util.VN_NOW());
|
||||
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tLandings;
|
||||
CREATE TEMPORARY TABLE tLandings
|
||||
(INDEX (eventFk))
|
||||
|
@ -30,6 +30,7 @@ BEGIN
|
|||
TIME(IFNULL(e.`hour`, z.`hour`)) `hour`,
|
||||
l.travelingDays,
|
||||
IFNULL(e.price, z.price) price,
|
||||
IFNULL(e.priceOptimum, z.priceOptimum) priceOptimum,
|
||||
IFNULL(e.bonus, z.bonus) bonus,
|
||||
l.landed,
|
||||
vShipped shipped
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
ALTER TABLE `vn`.`zoneEvent`
|
||||
ADD COLUMN `priceOptimum` DECIMAL(10,2) NOT NULL COMMENT 'Precio mínimo que puede pagar un bulto'
|
||||
AFTER `price`,
|
||||
ADD CONSTRAINT `ck_zoneEvent_priceOptimum`
|
||||
CHECK (priceOptimum <= price)
|
|
@ -0,0 +1,5 @@
|
|||
ALTER TABLE `vn`.`zone`
|
||||
ADD COLUMN `priceOptimum` DECIMAL(10,2) NOT NULL COMMENT 'Precio mínimo que puede pagar un bulto'
|
||||
AFTER `price`,
|
||||
ADD CONSTRAINT `ck_zone_priceOptimum`
|
||||
CHECK (priceOptimum <= price)
|
|
@ -0,0 +1,2 @@
|
|||
UPDATE `vn`.`zone`
|
||||
SET `priceOptimum` = `price`;
|
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE `vn`.`client`
|
||||
ADD COLUMN `packagesDiscountFactor` DECIMAL(4,3) NOT NULL DEFAULT 1.000
|
||||
COMMENT 'Factor (1-0) que pondera el precio final entre priceOptimum (mejor) y price (peor)';
|
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE `vn`.`clientConfig`
|
||||
ADD COLUMN `packagesOptimum` INT UNSIGNED NOT NULL DEFAULT 20 COMMENT 'Numero de bultos por cliente/dia para conseguir el precio optimo',
|
||||
ADD COLUMN `monthsToCalcOptimumPrice` TINYINT UNSIGNED NOT NULL DEFAULT 3 COMMENT 'Número de meses a usar para el cálculo de client.packagesDiscountFactor';
|
|
@ -250,5 +250,6 @@
|
|||
"Holidays to past days not available": "Holidays to past days not available",
|
||||
"Price cannot be blank": "Price cannot be blank",
|
||||
"There are tickets to be invoiced": "There are tickets to be invoiced",
|
||||
"The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent"
|
||||
"The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent",
|
||||
"CONSTRAINT `ck_zoneEvent_priceOptimum` failed for `vn`.`zoneEvent`": "CONSTRAINT `ck_zoneEvent_priceOptimum` failed for `vn`.`zoneEvent`"
|
||||
}
|
|
@ -42,6 +42,9 @@
|
|||
"price": {
|
||||
"type": "number"
|
||||
},
|
||||
"priceOptimum": {
|
||||
"type": "number"
|
||||
},
|
||||
"bonus": {
|
||||
"type": "number"
|
||||
},
|
||||
|
|
|
@ -28,6 +28,9 @@
|
|||
"price": {
|
||||
"type": "number"
|
||||
},
|
||||
"priceOptimum": {
|
||||
"type": "number"
|
||||
},
|
||||
"bonus": {
|
||||
"type": "number"
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue