salix/db/routines/vn/procedures/wrongEqualizatedClient.sql

28 lines
719 B
MySQL
Raw Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`wrongEqualizatedClient`()
BEGIN
SELECT clientFk, c.name, c.isActive, c.isTaxDataChecked, count(ie) as num
FROM vn.client c
JOIN
(
SELECT DISTINCT
`a`.`clientFk` ,
a.isEqualizated = 0 as ie
FROM
`vn`.`address` `a`
) sub ON sub.clientFk = c.id
WHERE c.hasToInvoiceByAddress = FALSE
GROUP BY clientFk
HAVING num > 1
UNION ALL
SELECT DISTINCT c.id, c.name, c.isActive, c.isTaxDataChecked,1
FROM
`vn`.`address` `a`
JOIN `vn`.`client` `c` ON `c`.`id` = `a`.`clientFk`
WHERE ABS(a.isEqualizated) <> ABS(c.isEqualizated)
AND c.hasToInvoiceByAddress = FALSE;
END$$
DELIMITER ;