8144-devToTest_2448 #3216

Merged
alexm merged 256 commits from 8144-devToTest_2448 into test 2024-11-19 07:36:04 +00:00
12 changed files with 146 additions and 8 deletions
Showing only changes of commit baadd621e1 - Show all commits

View File

@ -14,9 +14,10 @@ BEGIN
SELECT p.geoFk INTO vGeoFk
FROM address a
JOIN town t ON t.provinceFk = a.provinceFk
JOIN postCode p ON p.townFk = t.id AND p.`code` = a.postalCode
JOIN postCode p ON p.townFk = t.id
WHERE a.id = vSelf
ORDER BY (a.city SOUNDS LIKE t.`name`) DESC
ORDER BY (a.city SOUNDS LIKE t.name) DESC,
(p.code = a.postalCode) DESC
LIMIT 1;
RETURN vGeoFk;

View File

@ -0,0 +1,25 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`client_getGeo`(vSelf INT)
RETURNS int(11)
DETERMINISTIC
BEGIN
/**
* Returns the geo for the passed client.
*
* @param vSelf The address id
* @return The geo id
*/
DECLARE vGeoFk INT;
SELECT p.geoFk INTO vGeoFk
FROM client c
JOIN town t ON t.provinceFk = c.provinceFk
JOIN postCode p ON p.townFk = t.id
WHERE c.id = vSelf
ORDER BY (c.city SOUNDS LIKE t.name) DESC,
(p.code = c.postcode) DESC
LIMIT 1;
RETURN vGeoFk;
END$$
DELIMITER ;

View File

@ -0,0 +1,27 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`supplier_getGeo`(vSelf INT)
RETURNS int(11)
DETERMINISTIC
BEGIN
/**
* Returns the geo for the passed supplier.
*
* @param vSelf The address id
* @return The geo id
*/
DECLARE vGeoFk INT;
SELECT p.geoFk INTO vGeoFk
FROM supplier s
JOIN town t ON t.provinceFk = s.provinceFk
JOIN postCode p ON p.townFk = t.id
LEFT JOIN supplierAddress sad ON sad.supplierFk = s.id
WHERE s.id = vSelf
ORDER BY (s.city SOUNDS LIKE t.name) DESC,
(p.code = s.postCode) DESC,
(p.code = sad.postalCode) DESC
LIMIT 1;
RETURN vGeoFk;
END$$
DELIMITER ;

View File

@ -6,6 +6,7 @@ BEGIN
DECLARE vIsEqualizated BOOL;
SET NEW.editorFk = account.myUser_getId();
SET NEW.geoFk = address_getGeo(NEW.id);
IF (NEW.phone <> '') THEN
CALL pbx.phone_isValid(NEW.phone);

View File

@ -3,7 +3,6 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`address_beforeUpdate`
BEFORE UPDATE ON `address`
FOR EACH ROW
BEGIN
SET NEW.editorFk = account.myUser_getId();
IF !(NEW.phone <=> OLD.phone) AND (NEW.phone <> '') THEN
@ -14,5 +13,10 @@ BEGIN
CALL pbx.phone_isValid(NEW.mobile);
END IF;
IF NOT (NEW.provinceFk <=> OLD.provinceFk)
OR (NEW.postalCode <=> OLD.postalCode) THEN
SET NEW.geoFk = address_getGeo(NEW.id);
END IF;
END$$
DELIMITER ;

View File

@ -3,8 +3,10 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`client_beforeInsert`
BEFORE INSERT ON `client`
FOR EACH ROW
BEGIN
SET NEW.editorFk = account.myUser_getId();
SET NEW.accountingAccount = 4300000000 + NEW.id;
SET NEW.lastSalesPersonFk = NEW.salesPersonFk;
SET NEW.geoFk = client_getGeo(NEW.id);
IF (NEW.phone <> '') THEN
CALL pbx.phone_isValid(NEW.phone);
@ -13,9 +15,5 @@ BEGIN
IF (NEW.mobile <> '') THEN
CALL pbx.phone_isValid(NEW.mobile);
END IF;
SET NEW.accountingAccount = 4300000000 + NEW.id;
SET NEW.lastSalesPersonFk = NEW.salesPersonFk;
END$$
DELIMITER ;

View File

@ -72,5 +72,11 @@ BEGIN
IF NOT (NEW.businessTypeFk <=> OLD.businessTypeFk) AND (NEW.businessTypeFk = 'individual' OR OLD.businessTypeFk = 'individual') THEN
SET NEW.isTaxDataChecked = 0;
END IF;
IF NOT (NEW.provinceFk <=> OLD.provinceFk)
OR (NEW.postcode <=> OLD.postcode) THEN
SET NEW.geoFk = client_getGeo(NEW.id);
END IF;
END$$
DELIMITER ;

View File

@ -4,5 +4,6 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`supplier_beforeInsert`
FOR EACH ROW
BEGIN
SET NEW.editorFk = account.myUser_getId();
SET NEW.geoFk = supplier_getGeo(NEW.id);
END$$
DELIMITER ;

View File

@ -40,5 +40,10 @@ BEGIN
SET NEW.isPayMethodChecked = FALSE;
END IF;
IF NOT (NEW.provinceFk <=> OLD.provinceFk)
OR (NEW.postCode <=> OLD.postCode) THEN
SET NEW.geoFk = supplier_getGeo(NEW.id);
END IF;
END$$
DELIMITER ;

View File

@ -0,0 +1,21 @@
ALTER TABLE vn.address
ADD geoFk int(11) DEFAULT NULL NULL AFTER isLogifloraAllowed,
ADD CONSTRAINT address_zoneGeo_FK FOREIGN KEY (geoFk)
REFERENCES vn.zoneGeo(id) ON DELETE RESTRICT ON UPDATE CASCADE;
CREATE OR REPLACE TEMPORARY TABLE tAddressGeo
(PRIMARY KEY (id))
ENGINE = MEMORY
SELECT a.id, p.geoFk
FROM address a
JOIN town t ON t.provinceFk = a.provinceFk
JOIN postCode p ON p.townFk = t.id
GROUP BY a.id
ORDER BY (a.city SOUNDS LIKE t.`name`) DESC,
(p.code = a.postalCode) DESC;
UPDATE address a
JOIN tAddressGeo tag ON tag.id = a.id
SET a.geoFk = tag.geoFk;
DROP TEMPORARY TABLE tAddressGeo;

View File

@ -0,0 +1,24 @@
ALTER TABLE vn.client
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;
CREATE OR REPLACE TEMPORARY TABLE tClientGeo
(PRIMARY KEY (id))
ENGINE = MEMORY
SELECT c.id, p.geoFk
FROM client c
JOIN town t ON t.provinceFk = c.provinceFk
JOIN postCode p ON p.townFk = t.id
GROUP BY c.id
ORDER BY (c.city SOUNDS LIKE t.`name`) DESC,
(p.code = c.postcode) DESC;
UPDATE client c
JOIN tClientGeo tcg ON tcg.id = c.id
SET c.geoFk = tcg.geoFk;
DROP TEMPORARY TABLE tClientGeo;

View File

@ -0,0 +1,25 @@
ALTER TABLE vn.supplier
CHANGE companySize companySize enum('small','medium','big') CHARACTER SET utf8mb3
COLLATE utf8mb3_general_ci DEFAULT NULL NULL AFTER stamp,
ADD geoFk int(11) DEFAULT NULL NULL AFTER companySize,
ADD CONSTRAINT supplier_zoneGeo_FK FOREIGN KEY (geoFk)
REFERENCES vn.zoneGeo(id) ON DELETE RESTRICT ON UPDATE CASCADE;
CREATE OR REPLACE TEMPORARY TABLE tSupplierGeo
(PRIMARY KEY (id))
ENGINE = MEMORY
SELECT s.id, p.geoFk
FROM supplier s
JOIN town t ON t.provinceFk = s.provinceFk
JOIN postCode p ON p.townFk = t.id
LEFT JOIN supplierAddress sad ON sad.supplierFk = s.id
GROUP BY s.id
ORDER BY (s.city SOUNDS LIKE t.`name`) DESC,
(p.code = s.postCode) DESC,
(p.code = sad.postalCode) DESC;
UPDATE supplier s
JOIN tSupplierGeo tsg ON tsg.id = s.id
SET s.geoFk = tsg.geoFk;
DROP TEMPORARY TABLE tSupplierGeo;