From 02ef314ed91fda85821d883921c657ee77e1ee92 Mon Sep 17 00:00:00 2001 From: Pako Date: Wed, 2 Oct 2024 07:40:26 +0200 Subject: [PATCH] feat: refs #8030 new field vn.priceDelta.zoneGeoFk --- .../procedures/catalog_componentCalculate.sql | 39 ++++++++++--------- .../11279-turquoiseDendro/00-firstScript.sql | 6 +++ 2 files changed, 27 insertions(+), 18 deletions(-) create mode 100644 db/versions/11279-turquoiseDendro/00-firstScript.sql diff --git a/db/routines/vn/procedures/catalog_componentCalculate.sql b/db/routines/vn/procedures/catalog_componentCalculate.sql index d4ce88ca7..e29e13a8c 100644 --- a/db/routines/vn/procedures/catalog_componentCalculate.sql +++ b/db/routines/vn/procedures/catalog_componentCalculate.sql @@ -29,21 +29,24 @@ BEGIN (INDEX (itemFk)) ENGINE = MEMORY SELECT i.id itemFk, - SUM(IFNULL(pd.absIncreasing,0)) absIncreasing, - SUM(IFNULL(pd.ratIncreasing,0)) ratIncreasing, - pd.warehouseFk - FROM item i - JOIN priceDelta pd - ON pd.itemTypeFk = i.typeFk - AND (pd.minSize IS NULL OR pd.minSize <= i.`size`) - AND (pd.maxSize IS NULL OR pd.maxSize >= i.`size`) - AND (pd.inkFk IS NULL OR pd.inkFk = i.inkFk) - AND (pd.originFk IS NULL OR pd.originFk = i.originFk) - AND (pd.producerFk IS NULL OR pd.producerFk = i.producerFk) - AND (pd.warehouseFk IS NULL OR pd.warehouseFk = vWarehouseFk) - WHERE (pd.fromDated IS NULL OR pd.fromDated <= vShipped) - AND (pd.toDated IS NULL OR pd.toDated >= vShipped) - GROUP BY i.id; + SUM(IFNULL(pd.absIncreasing,0)) absIncreasing, + SUM(IFNULL(pd.ratIncreasing,0)) ratIncreasing, + pd.warehouseFk + FROM item i + JOIN priceDelta pd + ON pd.itemTypeFk = i.typeFk + AND (pd.minSize IS NULL OR pd.minSize <= i.`size`) + AND (pd.maxSize IS NULL OR pd.maxSize >= i.`size`) + AND (pd.inkFk IS NULL OR pd.inkFk = i.inkFk) + AND (pd.originFk IS NULL OR pd.originFk = i.originFk) + AND (pd.producerFk IS NULL OR pd.producerFk = i.producerFk) + AND (pd.warehouseFk IS NULL OR pd.warehouseFk = vWarehouseFk) + LEFT JOIN zoneGeo zg ON zg.id = pd.zoneGeoFk + LEFT JOIN zoneGeo zg2 ON zg2.id = address_getGeo(vAddressFk) + WHERE (pd.fromDated IS NULL OR pd.fromDated <= vShipped) + AND (pd.toDated IS NULL OR pd.toDated >= vShipped) + AND (pd.zoneGeoFk IS NULL OR zg2.lft BETWEEN zg.lft AND zg.rgt) + GROUP BY itemFk; CREATE OR REPLACE TEMPORARY TABLE tSpecialPrice (INDEX (itemFk)) @@ -130,15 +133,15 @@ BEGIN -- Bonus del comprador a un rango de productos INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) - SELECT + SELECT tcb.warehouseFk, tcb.itemFk, c.id, IFNULL(tcb.base * tpd.ratIncreasing / 100,0) + IFNULL(tpd.absIncreasing,0) FROM tmp.ticketComponentBase tcb JOIN component c ON c.code = 'bonus' - JOIN tPriceDelta tpd - ON tpd.itemFk = tcb.itemFk + JOIN tPriceDelta tpd + ON tpd.itemFk = tcb.itemFk AND tpd.warehouseFk = tcb.warehouseFk; -- RECOBRO diff --git a/db/versions/11279-turquoiseDendro/00-firstScript.sql b/db/versions/11279-turquoiseDendro/00-firstScript.sql new file mode 100644 index 000000000..a241e6af2 --- /dev/null +++ b/db/versions/11279-turquoiseDendro/00-firstScript.sql @@ -0,0 +1,6 @@ +-- Place your SQL code here + +ALTER TABLE vn.priceDelta ADD IF NOT EXISTS zoneGeoFk int(11) NULL; + +ALTER TABLE vn.priceDelta ADD CONSTRAINT priceDelta_zoneGeo_FK FOREIGN KEY IF NOT EXISTS (zoneGeoFk) +REFERENCES vn.zoneGeo (`id`) ON DELETE RESTRICT ON UPDATE CASCADE; \ No newline at end of file -- 2.40.1