This commit is contained in:
parent
d4b0da50d0
commit
cba1abad68
|
@ -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
|
||||||
|
AND p.`code` = c.postcode
|
||||||
|
WHERE c.id = vSelf
|
||||||
|
ORDER BY (c.city SOUNDS LIKE t.`name`) DESC
|
||||||
|
LIMIT 1;
|
||||||
|
|
||||||
|
RETURN vGeoFk;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -0,0 +1,25 @@
|
||||||
|
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
|
||||||
|
AND p.`code` = s.postCode
|
||||||
|
WHERE s.id = vSelf
|
||||||
|
ORDER BY (s.city SOUNDS LIKE t.`name`) DESC
|
||||||
|
LIMIT 1;
|
||||||
|
|
||||||
|
RETURN vGeoFk;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -6,6 +6,7 @@ BEGIN
|
||||||
DECLARE vIsEqualizated BOOL;
|
DECLARE vIsEqualizated BOOL;
|
||||||
|
|
||||||
SET NEW.editorFk = account.myUser_getId();
|
SET NEW.editorFk = account.myUser_getId();
|
||||||
|
SET NEW.geoFk = address_getGeo(NEW.id);
|
||||||
|
|
||||||
IF (NEW.phone <> '') THEN
|
IF (NEW.phone <> '') THEN
|
||||||
CALL pbx.phone_isValid(NEW.phone);
|
CALL pbx.phone_isValid(NEW.phone);
|
||||||
|
|
|
@ -3,7 +3,6 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`address_beforeUpdate`
|
||||||
BEFORE UPDATE ON `address`
|
BEFORE UPDATE ON `address`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
SET NEW.editorFk = account.myUser_getId();
|
SET NEW.editorFk = account.myUser_getId();
|
||||||
|
|
||||||
IF !(NEW.phone <=> OLD.phone) AND (NEW.phone <> '') THEN
|
IF !(NEW.phone <=> OLD.phone) AND (NEW.phone <> '') THEN
|
||||||
|
@ -14,5 +13,10 @@ BEGIN
|
||||||
CALL pbx.phone_isValid(NEW.mobile);
|
CALL pbx.phone_isValid(NEW.mobile);
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
|
IF NOT (NEW.provinceFk <=> OLD.provinceFk)
|
||||||
|
OR (NEW.postalCode <=> OLD.postalCode) THEN
|
||||||
|
|
||||||
|
SET NEW.geoFk = address_getGeo(NEW.id);
|
||||||
|
END IF;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -3,8 +3,10 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`client_beforeInsert`
|
||||||
BEFORE INSERT ON `client`
|
BEFORE INSERT ON `client`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
SET NEW.editorFk = account.myUser_getId();
|
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
|
IF (NEW.phone <> '') THEN
|
||||||
CALL pbx.phone_isValid(NEW.phone);
|
CALL pbx.phone_isValid(NEW.phone);
|
||||||
|
@ -13,9 +15,5 @@ BEGIN
|
||||||
IF (NEW.mobile <> '') THEN
|
IF (NEW.mobile <> '') THEN
|
||||||
CALL pbx.phone_isValid(NEW.mobile);
|
CALL pbx.phone_isValid(NEW.mobile);
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
SET NEW.accountingAccount = 4300000000 + NEW.id;
|
|
||||||
|
|
||||||
SET NEW.lastSalesPersonFk = NEW.salesPersonFk;
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -72,5 +72,11 @@ BEGIN
|
||||||
IF NOT (NEW.businessTypeFk <=> OLD.businessTypeFk) AND (NEW.businessTypeFk = 'individual' OR OLD.businessTypeFk = 'individual') THEN
|
IF NOT (NEW.businessTypeFk <=> OLD.businessTypeFk) AND (NEW.businessTypeFk = 'individual' OR OLD.businessTypeFk = 'individual') THEN
|
||||||
SET NEW.isTaxDataChecked = 0;
|
SET NEW.isTaxDataChecked = 0;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
|
IF NOT (NEW.provinceFk <=> OLD.provinceFk)
|
||||||
|
OR (NEW.postcode <=> OLD.postcode) THEN
|
||||||
|
|
||||||
|
SET NEW.geoFk = client_getGeo(NEW.id);
|
||||||
|
END IF;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -4,5 +4,6 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`supplier_beforeInsert`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
SET NEW.editorFk = account.myUser_getId();
|
SET NEW.editorFk = account.myUser_getId();
|
||||||
|
SET NEW.geoFk = supplier_getGeo(NEW.id);
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -40,5 +40,10 @@ BEGIN
|
||||||
SET NEW.isPayMethodChecked = FALSE;
|
SET NEW.isPayMethodChecked = FALSE;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
|
IF NOT (NEW.provinceFk <=> OLD.provinceFk)
|
||||||
|
OR (NEW.postcode <=> OLD.postcode) THEN
|
||||||
|
|
||||||
|
SET NEW.geoFk = client_getGeo(NEW.id);
|
||||||
|
END IF;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -8,13 +8,13 @@ ALTER TABLE vn.supplier
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tSupplierGeo
|
CREATE OR REPLACE TEMPORARY TABLE tSupplierGeo
|
||||||
(PRIMARY KEY (id))
|
(PRIMARY KEY (id))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT sa.supplierFk id, p.geoFk
|
SELECT s.id, p.geoFk
|
||||||
FROM supplierAddress sa
|
FROM supplier s
|
||||||
JOIN town t ON t.provinceFk = sa.provinceFk
|
JOIN town t ON t.provinceFk = s.provinceFk
|
||||||
JOIN postCode p ON p.townFk = t.id
|
JOIN postCode p ON p.townFk = t.id
|
||||||
AND p.`code` = sa.postalCode
|
AND p.`code` = s.postCode
|
||||||
GROUP BY sa.supplierFk
|
GROUP BY s.id
|
||||||
ORDER BY (sa.city SOUNDS LIKE t.`name`) DESC;
|
ORDER BY (s.city SOUNDS LIKE t.`name`) DESC;
|
||||||
|
|
||||||
UPDATE supplier s
|
UPDATE supplier s
|
||||||
JOIN tSupplierGeo tsg ON tsg.id = s.id
|
JOIN tSupplierGeo tsg ON tsg.id = s.id
|
||||||
|
|
Loading…
Reference in New Issue