refs #7531 Modify zone_getAddresses #2675
|
@ -1,7 +1,8 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getAddresses`(
|
||||
vSelf INT,
|
||||
vLanded DATE
|
||||
vDated DATE,
|
||||
vDepartment INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
|
@ -12,6 +13,7 @@ BEGIN
|
|||
*
|
||||
* @param vSelf Id de zona
|
||||
* @param vDated Fecha de entrega
|
||||
* @param vDepartment Departamento del trabajador
|
||||
* @return Un select
|
||||
*/
|
||||
CALL zone_getPostalCode(vSelf);
|
||||
|
@ -22,34 +24,47 @@ BEGIN
|
|||
WHERE id NOT IN (
|
||||
ivanm marked this conversation as resolved
|
||||
SELECT clientFk
|
||||
FROM vn.ticket
|
||||
WHERE landed BETWEEN vLanded AND util.dayEnd(vLanded)
|
||||
WHERE landed BETWEEN vDated AND util.dayEnd(vDated)
|
||||
)
|
||||
),
|
||||
hasTicketShippedToday AS (
|
||||
ivanm marked this conversation as resolved
guillermo
commented
hasTickets (today no es correcte perque li pots pasar una altra fetxa que no siga hui) hasTickets (today no es correcte perque li pots pasar una altra fetxa que no siga hui)
|
||||
SELECT clientFk,
|
||||
ivanm marked this conversation as resolved
guillermo
commented
Aço queda mes net aixina:
Aço queda mes net aixina:
```
SELECT DISTINCT clientFk
FROM vn.ticket
WHERE shipped BETWEEN vDated AND util.dayEnd(vDated)
```
|
||||
IF (COUNT(*) > 0, TRUE, FALSE) hasTicketShipped
|
||||
FROM vn.ticket
|
||||
WHERE shipped BETWEEN vDated AND util.dayEnd(vDated)
|
||||
ivanm marked this conversation as resolved
guillermo
commented
Si li preguntares i volia per shipped ok Si li preguntares i volia per shipped ok
|
||||
GROUP BY clientFk
|
||||
)
|
||||
SELECT c.id clientFk,
|
||||
c.name,
|
||||
c.phone,
|
||||
bt.description,
|
||||
c.salesPersonFk,
|
||||
u.name username,
|
||||
aai.invoiced,
|
||||
cnb.lastShipped
|
||||
FROM vn.client c
|
||||
JOIN notHasTicket ON notHasTicket.id = c.id
|
||||
LEFT JOIN account.`user` u ON u.id = c.salesPersonFk
|
||||
JOIN vn.`address` a ON a.clientFk = c.id
|
||||
JOIN vn.postCode pc ON pc.code = a.postalCode
|
||||
JOIN vn.town t ON t.id = pc.townFk AND t.provinceFk = a.provinceFk
|
||||
JOIN vn.zoneGeo zg ON zg.name = a.postalCode
|
||||
JOIN tmp.zoneNodes zn ON zn.geoFk = pc.geoFk
|
||||
LEFT JOIN bs.clientNewBorn cnb ON cnb.clientFk = c.id
|
||||
LEFT JOIN vn.annualAverageInvoiced aai ON aai.clientFk = c.id
|
||||
JOIN vn.clientType ct ON ct.code = c.typeFk
|
||||
JOIN vn.businessType bt ON bt.code = c.businessTypeFk
|
||||
WHERE a.isActive
|
||||
AND c.isActive
|
||||
AND ct.code = 'normal'
|
||||
AND bt.code <> 'worker'
|
||||
GROUP BY c.id;
|
||||
c.name,
|
||||
c.phone,
|
||||
bt.description,
|
||||
c.salesPersonFk,
|
||||
u.name username,
|
||||
aai.invoiced,
|
||||
cnb.lastShipped,
|
||||
ht.hasTicketShipped
|
||||
ivanm marked this conversation as resolved
guillermo
commented
IF(ht.clientFk, TRUE, FALSE) hasTicket IF(ht.clientFk, TRUE, FALSE) hasTicket
|
||||
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
|
||||
LEFT JOIN account.`user` u ON u.id = c.salesPersonFk
|
||||
JOIN vn.`address` a ON a.clientFk = c.id
|
||||
JOIN vn.postCode pc ON pc.code = a.postalCode
|
||||
JOIN vn.town t ON t.id = pc.townFk AND t.provinceFk = a.provinceFk
|
||||
JOIN vn.zoneGeo zg ON zg.name = a.postalCode
|
||||
JOIN tmp.zoneNodes zn ON zn.geoFk = pc.geoFk
|
||||
LEFT JOIN bs.clientNewBorn cnb ON cnb.clientFk = c.id
|
||||
LEFT JOIN vn.annualAverageInvoiced aai ON aai.clientFk = c.id
|
||||
JOIN vn.clientType ct ON ct.code = c.typeFk
|
||||
JOIN vn.businessType bt ON bt.code = c.businessTypeFk
|
||||
LEFT JOIN hasTicketShippedToday ht ON ht.clientFk = c.id
|
||||
WHERE a.isActive
|
||||
AND c.isActive
|
||||
AND ct.code = 'normal'
|
||||
AND bt.code <> 'worker'
|
||||
AND d.id = vDepartment
|
||||
GROUP BY c.id;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.zoneNodes;
|
||||
END$$
|
||||
|
|
Loading…
Reference in New Issue
notHasTicket crec que te sobra