7863-devToTest_2434 #2852

Merged
alexm merged 129 commits from 7863-devToTest_2434 into test 2024-08-13 06:50:25 +00:00
1 changed files with 12 additions and 25 deletions
Showing only changes of commit 50e2c03d3e - Show all commits

View File

@ -1,40 +1,28 @@
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,
vDated DATE, vShipped DATE,
vDepartment INT vDepartmentFk INT
) )
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 vDepartment Departamento del trabajador * @param vDepartmentFk Id de departamento
* @return Un select * @return Un select
*/ */
CALL zone_getPostalCode(vSelf); CALL zone_getPostalCode(vSelf);
WITH notHasTicket AS ( WITH clientWithTicket AS (
SELECT id SELECT clientFk
FROM vn.client
WHERE id NOT IN (
SELECT clientFk
FROM vn.ticket
WHERE landed BETWEEN vDated AND util.dayEnd(vDated)
)
),
hasTicketShippedToday AS (
SELECT clientFk,
IF (COUNT(*) > 0, TRUE, FALSE) hasTicketShipped
FROM vn.ticket FROM vn.ticket
WHERE shipped BETWEEN vDated AND util.dayEnd(vDated) WHERE shipped BETWEEN vShipped AND util.dayEnd(vShipped)
GROUP BY clientFk
) )
SELECT c.id clientFk, SELECT c.id,
c.name, c.name,
c.phone, c.phone,
bt.description, bt.description,
@ -42,12 +30,12 @@ BEGIN
u.name username, u.name username,
aai.invoiced, aai.invoiced,
cnb.lastShipped, cnb.lastShipped,
ht.hasTicketShipped cwt.clientFk
FROM vn.client c FROM vn.client c
JOIN vn.worker w ON w.id = c.salesPersonFk JOIN vn.worker w ON w.id = c.salesPersonFk
JOIN vn.workerDepartment wd ON wd.workerFk = w.id JOIN vn.workerDepartment wd ON wd.workerFk = w.id
JOIN vn.department d ON d.id = wd.departmentFk JOIN vn.department d ON d.id = wd.departmentFk
JOIN notHasTicket ON notHasTicket.id = c.id LEFT JOIN clientWithTicket cwt ON cwt.clientFk = 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
JOIN vn.postCode pc ON pc.code = a.postalCode JOIN vn.postCode pc ON pc.code = a.postalCode
@ -58,12 +46,11 @@ 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 AND d.id = vDepartmentFk
GROUP BY c.id; GROUP BY c.id;
DROP TEMPORARY TABLE tmp.zoneNodes; DROP TEMPORARY TABLE tmp.zoneNodes;