refs #7531 Modify zone_getAddresses
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Ivan Mas 2024-07-03 17:09:10 +02:00
parent 5500a6f085
commit 4bef3e9107
1 changed files with 41 additions and 26 deletions

View File

@ -1,7 +1,8 @@
DELIMITER $$ DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getAddresses`( CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getAddresses`(
vSelf INT, vSelf INT,
vLanded DATE vDated DATE,
vDepartment INT
) )
BEGIN BEGIN
/** /**
@ -12,6 +13,7 @@ BEGIN
* *
* @param vSelf Id de zona * @param vSelf Id de zona
* @param vDated Fecha de entrega * @param vDated Fecha de entrega
* @param vDepartment Departamento del trabajador
* @return Un select * @return Un select
*/ */
CALL zone_getPostalCode(vSelf); CALL zone_getPostalCode(vSelf);
@ -22,8 +24,15 @@ BEGIN
WHERE id NOT IN ( WHERE id NOT IN (
SELECT clientFk SELECT clientFk
FROM vn.ticket FROM vn.ticket
WHERE landed BETWEEN vLanded AND util.dayEnd(vLanded) WHERE landed BETWEEN vDated AND util.dayEnd(vDated)
) )
),
hasTicketShippedToday AS (
SELECT clientFk,
IF (COUNT(*) > 0, TRUE, FALSE) hasTicketShipped
FROM vn.ticket
WHERE shipped BETWEEN vDated AND util.dayEnd(vDated)
GROUP BY clientFk
) )
SELECT c.id clientFk, SELECT c.id clientFk,
c.name, c.name,
@ -32,8 +41,12 @@ BEGIN
c.salesPersonFk, c.salesPersonFk,
u.name username, u.name username,
aai.invoiced, aai.invoiced,
cnb.lastShipped cnb.lastShipped,
ht.hasTicketShipped
FROM vn.client c FROM vn.client c
JOIN vn.worker w ON w.id = c.salesPersonFk
JOIN vn.workerDepartment wd ON wd.workerFk = w.id
JOIN vn.department d ON d.id = wd.departmentFk
JOIN notHasTicket ON notHasTicket.id = c.id JOIN notHasTicket ON notHasTicket.id = c.id
LEFT JOIN account.`user` u ON u.id = c.salesPersonFk LEFT JOIN account.`user` u ON u.id = c.salesPersonFk
JOIN vn.`address` a ON a.clientFk = c.id JOIN vn.`address` a ON a.clientFk = c.id
@ -45,10 +58,12 @@ BEGIN
LEFT JOIN vn.annualAverageInvoiced aai ON aai.clientFk = c.id LEFT JOIN vn.annualAverageInvoiced aai ON aai.clientFk = c.id
JOIN vn.clientType ct ON ct.code = c.typeFk JOIN vn.clientType ct ON ct.code = c.typeFk
JOIN vn.businessType bt ON bt.code = c.businessTypeFk JOIN vn.businessType bt ON bt.code = c.businessTypeFk
LEFT JOIN hasTicketShippedToday ht ON ht.clientFk = c.id
WHERE a.isActive WHERE a.isActive
AND c.isActive AND c.isActive
AND ct.code = 'normal' AND ct.code = 'normal'
AND bt.code <> 'worker' AND bt.code <> 'worker'
AND d.id = vDepartment
GROUP BY c.id; GROUP BY c.id;
DROP TEMPORARY TABLE tmp.zoneNodes; DROP TEMPORARY TABLE tmp.zoneNodes;