refs #7531 Modify zone_getAddresses #2675
|
@ -1,55 +1,57 @@
|
||||||
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
|
vShipped DATE,
|
||||||
|
vDepartmentFk INT
|
||||||
ivanm marked this conversation as resolved
Outdated
|
|||||||
)
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Devuelve un listado de todos los clientes activos
|
* Devuelve un listado de todos los clientes activos
|
||||||
* con consignatarios a los que se les puede
|
* con consignatarios a los que se les puede
|
||||||
* vender producto para esa zona y no tiene un ticket
|
* vender producto para esa zona.
|
||||||
* para ese día.
|
|
||||||
*
|
*
|
||||||
* @param vSelf Id de zona
|
* @param vSelf Id de zona
|
||||||
* @param vDated Fecha de entrega
|
* @param vShipped Fecha de envio
|
||||||
|
* @param vDepartmentFk Id de departamento
|
||||||
* @return Un select
|
* @return Un select
|
||||||
ivanm marked this conversation as resolved
Outdated
guillermo
commented
vDepartmentFk Id de departamento vDepartmentFk Id de departamento
|
|||||||
*/
|
*/
|
||||||
CALL zone_getPostalCode(vSelf);
|
CALL zone_getPostalCode(vSelf);
|
||||||
|
|
||||||
WITH notHasTicket AS (
|
WITH clientWithTicket AS (
|
||||||
SELECT id
|
SELECT clientFk
|
||||||
FROM vn.client
|
FROM vn.ticket
|
||||||
WHERE id NOT IN (
|
WHERE shipped BETWEEN vShipped AND util.dayEnd(vShipped)
|
||||||
SELECT clientFk
|
|
||||||
FROM vn.ticket
|
|
||||||
WHERE landed BETWEEN vLanded AND util.dayEnd(vLanded)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
ivanm marked this conversation as resolved
guillermo
commented
notHasTicket crec que te sobra notHasTicket crec que te sobra
|
|||||||
SELECT c.id clientFk,
|
SELECT c.id,
|
||||||
c.name,
|
c.name,
|
||||||
c.phone,
|
c.phone,
|
||||||
bt.description,
|
bt.description,
|
||||||
c.salesPersonFk,
|
c.salesPersonFk,
|
||||||
u.name username,
|
u.name username,
|
||||||
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)
|
|||||||
aai.invoiced,
|
aai.invoiced,
|
||||||
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)
```
|
|||||||
cnb.lastShipped
|
cnb.lastShipped,
|
||||||
FROM vn.client c
|
cwt.clientFk
|
||||||
JOIN notHasTicket ON notHasTicket.id = c.id
|
FROM vn.client c
|
||||||
ivanm marked this conversation as resolved
guillermo
commented
Si li preguntares i volia per shipped ok Si li preguntares i volia per shipped ok
|
|||||||
LEFT JOIN account.`user` u ON u.id = c.salesPersonFk
|
JOIN vn.worker w ON w.id = c.salesPersonFk
|
||||||
JOIN vn.`address` a ON a.clientFk = c.id
|
JOIN vn.workerDepartment wd ON wd.workerFk = w.id
|
||||||
JOIN vn.postCode pc ON pc.code = a.postalCode
|
JOIN vn.department d ON d.id = wd.departmentFk
|
||||||
JOIN vn.town t ON t.id = pc.townFk AND t.provinceFk = a.provinceFk
|
LEFT JOIN clientWithTicket cwt ON cwt.clientFk = c.id
|
||||||
JOIN vn.zoneGeo zg ON zg.name = a.postalCode
|
LEFT JOIN account.`user` u ON u.id = c.salesPersonFk
|
||||||
JOIN tmp.zoneNodes zn ON zn.geoFk = pc.geoFk
|
JOIN vn.`address` a ON a.clientFk = c.id
|
||||||
LEFT JOIN bs.clientNewBorn cnb ON cnb.clientFk = c.id
|
JOIN vn.postCode pc ON pc.code = a.postalCode
|
||||||
LEFT JOIN vn.annualAverageInvoiced aai ON aai.clientFk = c.id
|
JOIN vn.town t ON t.id = pc.townFk AND t.provinceFk = a.provinceFk
|
||||||
JOIN vn.clientType ct ON ct.code = c.typeFk
|
JOIN vn.zoneGeo zg ON zg.name = a.postalCode
|
||||||
JOIN vn.businessType bt ON bt.code = c.businessTypeFk
|
JOIN tmp.zoneNodes zn ON zn.geoFk = pc.geoFk
|
||||||
WHERE a.isActive
|
LEFT JOIN bs.clientNewBorn cnb ON cnb.clientFk = c.id
|
||||||
ivanm marked this conversation as resolved
guillermo
commented
IF(ht.clientFk, TRUE, FALSE) hasTicket IF(ht.clientFk, TRUE, FALSE) hasTicket
|
|||||||
AND c.isActive
|
LEFT JOIN vn.annualAverageInvoiced aai ON aai.clientFk = c.id
|
||||||
AND ct.code = 'normal'
|
JOIN vn.clientType ct ON ct.code = c.typeFk
|
||||||
AND bt.code <> 'worker'
|
JOIN vn.businessType bt ON bt.code = c.businessTypeFk
|
||||||
GROUP BY c.id;
|
WHERE a.isActive
|
||||||
|
AND c.isActive
|
||||||
|
AND ct.code = 'normal'
|
||||||
|
AND bt.code <> 'worker'
|
||||||
|
AND (d.id = vDepartmentFk OR NOT vDepartmentFk)
|
||||||
ivanm marked this conversation as resolved
Outdated
guillermo
commented
Soporta que pueda ser null: Soporta que pueda ser null:
`(d.id = vDepartmentFk OR NOT vDepartmentFk)`
ivanm
commented
Cert, també demana els que no tinguen comercial/departament assignat. Ho modifique. Cert, també demana els que no tinguen comercial/departament assignat. Ho modifique.
|
|||||||
|
GROUP BY c.id;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tmp.zoneNodes;
|
DROP TEMPORARY TABLE tmp.zoneNodes;
|
||||||
END$$
|
END$$
|
||||||
|
|
Loading…
Reference in New Issue
vDepartmentFk