Merge pull request 'refs #7531 Modify zone_getAddresses' (!2675) from 7531-Modify-zone_getAddresses into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #2675 Reviewed-by: Guillermo Bonet <guillermo@verdnatura.es>
This commit is contained in:
commit
bcf08db6d6
|
@ -1,55 +1,57 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zone_getAddresses`(
|
||||
vSelf INT,
|
||||
vLanded DATE
|
||||
vShipped DATE,
|
||||
vDepartmentFk INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Devuelve un listado de todos los clientes activos
|
||||
* con consignatarios a los que se les puede
|
||||
* vender producto para esa zona y no tiene un ticket
|
||||
* para ese día.
|
||||
* vender producto para esa zona.
|
||||
*
|
||||
* @param vSelf Id de zona
|
||||
* @param vDated Fecha de entrega
|
||||
* @param vShipped Fecha de envio
|
||||
* @param vDepartmentFk Id de departamento
|
||||
* @return Un select
|
||||
*/
|
||||
CALL zone_getPostalCode(vSelf);
|
||||
|
||||
WITH notHasTicket AS (
|
||||
SELECT id
|
||||
FROM vn.client
|
||||
WHERE id NOT IN (
|
||||
SELECT clientFk
|
||||
FROM vn.ticket
|
||||
WHERE landed BETWEEN vLanded AND util.dayEnd(vLanded)
|
||||
)
|
||||
WITH clientWithTicket AS (
|
||||
SELECT clientFk
|
||||
FROM vn.ticket
|
||||
WHERE shipped BETWEEN vShipped AND util.dayEnd(vShipped)
|
||||
)
|
||||
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;
|
||||
SELECT c.id,
|
||||
c.name,
|
||||
c.phone,
|
||||
bt.description,
|
||||
c.salesPersonFk,
|
||||
u.name username,
|
||||
aai.invoiced,
|
||||
cnb.lastShipped,
|
||||
cwt.clientFk
|
||||
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
|
||||
LEFT JOIN clientWithTicket cwt ON cwt.clientFk = 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'
|
||||
AND (d.id = vDepartmentFk OR NOT vDepartmentFk)
|
||||
GROUP BY c.id;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.zoneNodes;
|
||||
END$$
|
||||
|
|
Loading…
Reference in New Issue