2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`wrongEqualizatedClient`()
|
2024-01-15 11:31:03 +00:00
|
|
|
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 ;
|