diff --git a/db/routines/vn/procedures/sale_getBoxPickingList.sql b/db/routines/vn/procedures/sale_getBoxPickingList.sql index 7466eb9be..8d16d556b 100644 --- a/db/routines/vn/procedures/sale_getBoxPickingList.sql +++ b/db/routines/vn/procedures/sale_getBoxPickingList.sql @@ -19,21 +19,20 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.sale (saleFk INT PRIMARY KEY) - SELECT - s.ticketFk, - s.id saleFk, - s.itemFk, - s.concept, - s.quantity, - MAKETIME(pb.HH,pb.mm,0) etd, - pb.routeFk, - FLOOR(s.quantity / IF(i.isBoxPickingMode, ish.packing, i.packingOut)) stickers, - IF(i.isBoxPickingMode, ish.packing, i.packingOut) packing, - b.packagingFk + SELECT s.ticketFk, + s.id saleFk, + s.itemFk, + s.concept, + s.quantity, + MAKETIME(pb.HH,pb.mm,0) etd, + pb.routeFk, + FLOOR(s.quantity / IF(i.isBoxPickingMode, ish.packing, i.packingOut)) stickers, + IF(i.isBoxPickingMode, ish.packing, i.packingOut) packing, + IF(pa.isPackageReturnable, pc.defaultBigPackageFk, b.packagingFk) FROM sale s JOIN item i ON i.id = s.itemFk JOIN itemShelving ish ON ish.itemFk = s.itemFk - LEFT JOIN ( SELECT iss.itemShelvingFk, + LEFT JOIN ( SELECT iss.itemShelvingFk, s.itemFk, SUM(iss.quantity) reserve FROM itemShelvingSale iss @@ -52,6 +51,8 @@ BEGIN LEFT JOIN ticketState ts ON ts.ticketFk = s.ticketFk LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = vWarehouseFk LEFT JOIN buy b ON b.id = lb.buy_id + LEFT JOIN packaging pa ON pa.id = b.packagingFk + JOIN packagingConfig pc WHERE IF(i.isBoxPickingMode, ish.packing, i.packingOut) <= LEAST(s.quantity, ish.visible - IFNULL(tISS.reserve,0)) AND NOT pb.problem diff --git a/db/routines/vn/procedures/ticket_close.sql b/db/routines/vn/procedures/ticket_close.sql index 47d748ddf..7f52e81a7 100644 --- a/db/routines/vn/procedures/ticket_close.sql +++ b/db/routines/vn/procedures/ticket_close.sql @@ -44,14 +44,14 @@ BEGIN t.shipped, IFNULL(a.hasDailyInvoice, co.hasDailyInvoice), w.isManaged, - c.hasToInvoice + c.hasToInvoice INTO vClientFk, vIsTaxDataChecked, vCompanyFk, vShipped, vHasDailyInvoice, vWithPackage, - vHasToInvoice + vHasToInvoice FROM ticket t JOIN `client` c ON c.id = t.clientFk JOIN province p ON p.id = c.provinceFk @@ -64,8 +64,12 @@ BEGIN (SELECT vCurTicketFk, p.id, COUNT(*) FROM expedition e JOIN packaging p ON p.id = e.packagingFk + JOIN ticket t ON t.id = e.ticketFk + LEFT JOIN agencyMode am ON am.id = t.agencyModeFk + LEFT JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk WHERE e.ticketFk = vCurTicketFk AND p.isPackageReturnable AND vWithPackage + AND NOT dm.`code`= 'PICKUP' GROUP BY p.itemFk); -- No retornables o no catalogados