Merge pull request 'refactor: refs #7486 Optimized procs' (!2564) from 7486-productionControl into test
gitea/salix/pipeline/head This commit looks good Details
gitea/salix/pipeline/pr-master This commit looks good Details

Reviewed-on: #2564
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
This commit is contained in:
Guillermo Bonet 2024-06-10 11:33:10 +00:00
commit 75a529830c
2 changed files with 28 additions and 15 deletions

View File

@ -145,13 +145,19 @@ proc: BEGIN
-- Líneas y volumen por ticket
UPDATE tmp.productionBuffer pb
JOIN (
SELECT tt.ticketFk,
COUNT(*) `lines`,
SUM(sv.volume) m3,
IFNULL(SUM(IF(sv.isPicked, sv.volume, 0)) / SUM(sv.volume), 0) rate
FROM tmp.productionTicket tt
JOIN saleVolume sv ON sv.ticketFk = tt.ticketFk
GROUP BY tt.ticketFk
SELECT tt.ticketFk,
COUNT(*) `lines`,
SUM(s.quantity * ic.cm3delivery / 1000000) m3,
IFNULL(SUM(IF(s.isPicked,
(s.quantity * ic.cm3delivery / 1000000),
0)) / SUM(s.quantity * ic.cm3delivery / 1000000),
0) rate
FROM tmp.productionTicket tt
JOIN sale s ON s.ticketFk = tt.ticketFk
AND s.quantity > 0
JOIN itemCost ic ON ic.itemFk = s.itemFk
AND ic.warehouseFk = vWarehouseFk
GROUP BY tt.ticketFk
) m ON m.ticketFk = pb.ticketFk
SET pb.`lines` = m.`lines`,
pb.m3 = m.m3,
@ -218,6 +224,8 @@ proc: BEGIN
AND ish.visible
GROUP BY ish.itemFk, p.sectorFk;
CREATE INDEX idxItem ON tItemShelvingStock (itemFk);
INSERT INTO tmp.ticketWithPrevia(ticketFk, salesCount)
SELECT pb.ticketFk, COUNT(DISTINCT s.id)
FROM tmp.productionBuffer pb

View File

@ -64,10 +64,15 @@ BEGIN
FROM tmp.sale_getProblems tp
JOIN ticket t ON t.id = tp.ticketFk
JOIN (
SELECT t.addressFk, SUM(sv.litros) litros, t.totalWithoutVat
SELECT t.addressFk,
SUM(ROUND(`ic`.`cm3delivery` * `s`.`quantity` / 1000, 0)) litros,
t.totalWithoutVat
FROM tmp.ticket_list tl
JOIN saleVolume sv ON sv.ticketFk = tl.ticketFk
JOIN ticket t ON t.id = tl.ticketFk
JOIN sale s ON s.ticketFk = t.id
AND s.quantity > 0
JOIN itemCost ic ON ic.itemFk = s.itemFk
AND ic.warehouseFk = t.warehouseFk
JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk
AND zc.dated = util.VN_CURDATE()
JOIN agencyMode am ON am.id = t.agencyModeFk
@ -95,12 +100,12 @@ BEGIN
FROM (
SELECT COUNT(s.id) nComp, tl.ticketFk, s.id saleFk
FROM tmp.ticket_list tl
JOIN vn.sale s ON s.ticketFk = tl.ticketFk
LEFT JOIN vn.saleComponent sc ON sc.saleFk = s.id
LEFT JOIN vn.component c ON c.id = sc.componentFk AND c.isRequired
JOIN vn.ticket t ON t.id = tl.ticketFk
JOIN vn.agencyMode am ON am.id = t.agencyModeFk
JOIN vn.deliveryMethod dm ON dm.id = am.deliveryMethodFk
JOIN sale s ON s.ticketFk = tl.ticketFk
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
LEFT JOIN component c ON c.id = sc.componentFk AND c.isRequired
JOIN ticket t ON t.id = tl.ticketFk
JOIN agencyMode am ON am.id = t.agencyModeFk
JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk
WHERE dm.code IN ('AGENCY','DELIVERY','PICKUP')
AND s.quantity > 0
GROUP BY s.id