salix/db/versions/11346-yellowPhormium/01-client.sql

27 lines
954 B
MySQL
Raw Permalink Normal View History

2024-11-14 07:24:42 +00:00
ALTER TABLE vn.client
2024-11-14 08:00:19 +00:00
CHANGE hasDailyInvoice hasDailyInvoice tinyint(1) DEFAULT 0 NOT NULL
COMMENT 'Indica si el cliente requiere facturación diaria por defecto se copiará lo que tenga country.hasDailyInvoice'
AFTER recommendedCredit,
ADD geoFk int(11) DEFAULT NULL NULL AFTER hasDailyInvoice,
ADD CONSTRAINT client_zoneGeo_FK FOREIGN KEY (geoFk)
REFERENCES vn.zoneGeo(id) ON DELETE RESTRICT ON UPDATE CASCADE;
2024-11-18 11:53:36 +00:00
CREATE OR REPLACE TEMPORARY TABLE tmp.tClientGeo
2024-11-14 08:00:19 +00:00
(PRIMARY KEY (id))
ENGINE = MEMORY
SELECT c.id, p.geoFk
2024-11-18 11:56:37 +00:00
FROM vn.client c
JOIN vn.town t ON t.provinceFk = c.provinceFk
JOIN vn.postCode p ON p.townFk = t.id
AND (p.code = c.postcode OR c.postcode IS NULL)
2024-11-18 12:09:33 +00:00
JOIN vn.zoneGeo zg ON zg.id = p.geoFk
2024-11-14 08:00:19 +00:00
GROUP BY c.id
2024-11-18 09:52:41 +00:00
ORDER BY (c.city SOUNDS LIKE t.`name`) DESC,
(p.code = c.postcode) DESC;
2024-11-14 08:00:19 +00:00
2024-11-18 11:56:37 +00:00
UPDATE vn.client c
2024-11-18 11:53:36 +00:00
JOIN tmp.tClientGeo tcg ON tcg.id = c.id
2024-11-14 08:00:19 +00:00
SET c.geoFk = tcg.geoFk;
2024-11-18 11:53:36 +00:00
DROP TEMPORARY TABLE tmp.tClientGeo;