8032-devToTest_2440 #3009
|
@ -1,5 +1,3 @@
|
||||||
|
|
||||||
|
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_canAdvance`(vDateFuture DATE, vDateToAdvance DATE, vWarehouseFk INT)
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_canAdvance`(vDateFuture DATE, vDateToAdvance DATE, vWarehouseFk INT)
|
||||||
BEGIN
|
BEGIN
|
||||||
|
@ -10,82 +8,90 @@ BEGIN
|
||||||
* @param vDateToAdvance Fecha a cuando se quiere adelantar.
|
* @param vDateToAdvance Fecha a cuando se quiere adelantar.
|
||||||
* @param vWarehouseFk Almacén
|
* @param vWarehouseFk Almacén
|
||||||
*/
|
*/
|
||||||
DECLARE vDateInventory DATE;
|
|
||||||
|
|
||||||
SELECT inventoried INTO vDateInventory FROM config;
|
CALL item_getStock(vWarehouseFk, vDateToAdvance, NULL);
|
||||||
|
CALL item_getMinacum(
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tStock
|
vWarehouseFk,
|
||||||
(itemFk INT PRIMARY KEY, amount INT)
|
vDateToAdvance,
|
||||||
ENGINE = MEMORY;
|
DATEDIFF(DATE_SUB(vDateFuture, INTERVAL 1 DAY), vDateToAdvance),
|
||||||
|
NULL
|
||||||
INSERT INTO tStock(itemFk, amount)
|
);
|
||||||
SELECT itemFk, SUM(quantity) amount FROM
|
|
||||||
(
|
|
||||||
SELECT itemFk, quantity
|
|
||||||
FROM itemTicketOut
|
|
||||||
WHERE shipped >= vDateInventory
|
|
||||||
AND shipped < vDateFuture
|
|
||||||
AND warehouseFk = vWarehouseFk
|
|
||||||
UNION ALL
|
|
||||||
SELECT itemFk, quantity
|
|
||||||
FROM itemEntryIn
|
|
||||||
WHERE landed >= vDateInventory
|
|
||||||
AND landed < vDateFuture
|
|
||||||
AND isVirtualStock = FALSE
|
|
||||||
AND warehouseInFk = vWarehouseFk
|
|
||||||
UNION ALL
|
|
||||||
SELECT itemFk, quantity
|
|
||||||
FROM itemEntryOut
|
|
||||||
WHERE shipped >= vDateInventory
|
|
||||||
AND shipped < vDateFuture
|
|
||||||
AND warehouseOutFk = vWarehouseFk
|
|
||||||
) t
|
|
||||||
GROUP BY itemFk HAVING amount != 0;
|
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.filter
|
CREATE OR REPLACE TEMPORARY TABLE tmp.filter
|
||||||
(INDEX (id))
|
(INDEX (id))
|
||||||
SELECT dest.*,
|
SELECT origin.ticketFk futureId,
|
||||||
origin.*,
|
dest.ticketFk id,
|
||||||
IFNULL(dest.nickname, origin.nickname) nickname,
|
dest.state,
|
||||||
|
origin.futureState,
|
||||||
|
origin.futureIpt,
|
||||||
|
dest.ipt,
|
||||||
|
origin.workerFk,
|
||||||
|
origin.futureLiters,
|
||||||
|
origin.futureLines,
|
||||||
|
dest.shipped,
|
||||||
|
origin.shipped futureShipped,
|
||||||
|
dest.totalWithVat,
|
||||||
|
origin.totalWithVat futureTotalWithVat,
|
||||||
|
dest.agency,
|
||||||
|
dest.agencyModeFk,
|
||||||
|
origin.futureAgency,
|
||||||
|
origin.agencyModeFk futureAgencyModeFk,
|
||||||
|
dest.lines,
|
||||||
|
dest.liters,
|
||||||
|
origin.futureLines - origin.hasStock AS notMovableLines,
|
||||||
(origin.futureLines = origin.hasStock) AS isFullMovable,
|
(origin.futureLines = origin.hasStock) AS isFullMovable,
|
||||||
origin.futureLines - origin.hasStock AS notMovableLines
|
dest.zoneFk,
|
||||||
|
origin.futureZoneFk,
|
||||||
|
origin.futureZoneName,
|
||||||
|
origin.classColor futureClassColor,
|
||||||
|
dest.classColor,
|
||||||
|
origin.clientFk futureClientFk,
|
||||||
|
origin.addressFk futureAddressFk,
|
||||||
|
origin.warehouseFk futureWarehouseFk,
|
||||||
|
origin.companyFk futureCompanyFk,
|
||||||
|
IFNULL(dest.nickname, origin.nickname) nickname,
|
||||||
|
dest.landed,
|
||||||
|
dest.preparation
|
||||||
FROM (
|
FROM (
|
||||||
SELECT s.ticketFk futureId,
|
SELECT s.ticketFk,
|
||||||
t.workerFk,
|
c.salesPersonFk workerFk,
|
||||||
t.shipped futureShipped,
|
t.shipped,
|
||||||
t.totalWithVat futureTotalWithVat,
|
t.totalWithVat,
|
||||||
st.name futureState,
|
st.name futureState,
|
||||||
t.addressFk futureAddressFk,
|
|
||||||
am.name futureAgency,
|
am.name futureAgency,
|
||||||
count(s.id) futureLines,
|
count(s.id) futureLines,
|
||||||
GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) futureIpt,
|
GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) futureIpt,
|
||||||
CAST(SUM(litros) AS DECIMAL(10,0)) futureLiters,
|
CAST(SUM(litros) AS DECIMAL(10,0)) futureLiters,
|
||||||
SUM((s.quantity <= IFNULL(tst.amount,0))) hasStock,
|
SUM(s.quantity <= (IFNULL(il.stock,0) + IFNULL(im.amount, 0))) hasStock,
|
||||||
st.classColor futureClassColor,
|
z.id futureZoneFk,
|
||||||
(
|
z.name futureZoneName,
|
||||||
count(s.id) -
|
st.classColor,
|
||||||
SUM((s.quantity <= IFNULL(tst.amount,0)))
|
t.clientFk,
|
||||||
) notMovableLines,
|
t.nickname,
|
||||||
(
|
t.addressFk,
|
||||||
count(s.id) =
|
t.warehouseFk,
|
||||||
SUM((s.quantity <= IFNULL(tst.amount,0)))
|
t.companyFk,
|
||||||
) isFullMovable
|
t.agencyModeFk
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
|
JOIN client c ON c.id = t.clientFk
|
||||||
JOIN sale s ON s.ticketFk = t.id
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
JOIN saleVolume sv ON sv.saleFk = s.id
|
JOIN saleVolume sv ON sv.saleFk = s.id
|
||||||
JOIN item i ON i.id = s.itemFk
|
JOIN item i ON i.id = s.itemFk
|
||||||
JOIN ticketState ts ON ts.ticketFk = t.id
|
JOIN ticketState ts ON ts.ticketFk = t.id
|
||||||
JOIN `state` st ON st.id = ts.stateFk
|
JOIN `state` st ON st.id = ts.stateFk
|
||||||
JOIN agencyMode am ON t.agencyModeFk = am.id
|
JOIN agencyMode am ON t.agencyModeFk = am.id
|
||||||
|
JOIN `zone` z ON t.zoneFk = z.id
|
||||||
|
LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk
|
||||||
LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk
|
LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk
|
||||||
LEFT JOIN tStock tst ON tst.itemFk = i.id
|
LEFT JOIN tmp.itemMinacum im ON im.itemFk = i.id
|
||||||
|
AND im.warehouseFk = vWarehouseFk
|
||||||
|
LEFT JOIN tmp.itemList il ON il.itemFk = i.id
|
||||||
WHERE t.shipped BETWEEN vDateFuture AND util.dayend(vDateFuture)
|
WHERE t.shipped BETWEEN vDateFuture AND util.dayend(vDateFuture)
|
||||||
AND t.warehouseFk = vWarehouseFk
|
AND t.warehouseFk = vWarehouseFk
|
||||||
GROUP BY t.id
|
GROUP BY t.id
|
||||||
) origin
|
) origin
|
||||||
JOIN (
|
LEFT JOIN (
|
||||||
SELECT t.id,
|
SELECT t.id ticketFk,
|
||||||
t.addressFk,
|
|
||||||
st.name state,
|
st.name state,
|
||||||
GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) ipt,
|
GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) ipt,
|
||||||
t.shipped,
|
t.shipped,
|
||||||
|
@ -94,9 +100,17 @@ BEGIN
|
||||||
CAST(SUM(litros) AS DECIMAL(10,0)) liters,
|
CAST(SUM(litros) AS DECIMAL(10,0)) liters,
|
||||||
CAST(COUNT(*) AS DECIMAL(10,0)) `lines`,
|
CAST(COUNT(*) AS DECIMAL(10,0)) `lines`,
|
||||||
st.classColor,
|
st.classColor,
|
||||||
CONCAT_WS(':',
|
t.clientFk,
|
||||||
COALESCE(HOUR(t.shipped), HOUR(zc.hour), HOUR(z.hour)),
|
t.nickname,
|
||||||
COALESCE(MINUTE(t.shipped), MINUTE(zc.hour), MINUTE(z.hour))
|
t.addressFk,
|
||||||
|
t.zoneFk,
|
||||||
|
t.warehouseFk,
|
||||||
|
t.companyFk,
|
||||||
|
t.landed,
|
||||||
|
t.agencyModeFk,
|
||||||
|
SEC_TO_TIME(
|
||||||
|
COALESCE(HOUR(t.shipped), HOUR(zc.hour), HOUR(z.hour)) * 3600 +
|
||||||
|
COALESCE(MINUTE(t.shipped), MINUTE(zc.hour), MINUTE(z.hour)) * 60
|
||||||
) preparation
|
) preparation
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
JOIN sale s ON s.ticketFk = t.id
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
|
@ -105,17 +119,19 @@ BEGIN
|
||||||
JOIN ticketState ts ON ts.ticketFk = t.id
|
JOIN ticketState ts ON ts.ticketFk = t.id
|
||||||
JOIN `state` st ON st.id = ts.stateFk
|
JOIN `state` st ON st.id = ts.stateFk
|
||||||
JOIN agencyMode am ON t.agencyModeFk = am.id
|
JOIN agencyMode am ON t.agencyModeFk = am.id
|
||||||
JOIN ticketCanAdvanceConfig
|
|
||||||
LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk
|
LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk
|
||||||
LEFT JOIN `zone` z ON z.id = t.zoneFk
|
LEFT JOIN `zone` z ON z.id = t.zoneFk
|
||||||
LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk
|
LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk
|
||||||
|
JOIN ticketCanAdvanceConfig tc
|
||||||
WHERE t.shipped BETWEEN vDateToAdvance AND util.dayend(vDateToAdvance)
|
WHERE t.shipped BETWEEN vDateToAdvance AND util.dayend(vDateToAdvance)
|
||||||
AND t.warehouseFk = vWarehouseFk
|
AND t.warehouseFk = vWarehouseFk
|
||||||
AND st.order <= destinationOrder
|
AND st.order <= tc.destinationOrder
|
||||||
GROUP BY t.id
|
GROUP BY t.id
|
||||||
) dest ON dest.addressFk = origin.futureAddressFk
|
) dest ON dest.addressFk = origin.addressFk
|
||||||
WHERE origin.hasStock;
|
WHERE origin.hasStock;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE tStock;
|
DROP TEMPORARY TABLE IF EXISTS
|
||||||
|
tmp.itemList,
|
||||||
|
tmp.itemMinacum;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
-- Place your SQL code here
|
-- Place your SQL code here
|
||||||
CREATE TABLE IF NOT EXISTS vn.ticketCanAdvanceConfig (
|
CREATE TABLE IF NOT EXISTS vn.ticketCanAdvanceConfig (
|
||||||
id INT NOT NULL unsigned PRIMARY KEY,
|
id int(10) unsigned NOT NULL,
|
||||||
destinationOrder INT NULL,
|
destinationOrder INT NULL,
|
||||||
CONSTRAINT ticketCanAdvanceConfig_PK PRIMARY KEY (id)
|
PRIMARY KEY (`id`),
|
||||||
)
|
CONSTRAINT `ticketCanAdvanceConfig_check` CHECK (`id` = 1)
|
||||||
ENGINE=InnoDB
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;
|
||||||
DEFAULT CHARSET=utf8mb3
|
|
||||||
COLLATE=utf8mb3_unicode_ci;
|
|
||||||
|
|
||||||
INSERT INTO vn.ticketCanAdvanceConfig
|
INSERT INTO vn.ticketCanAdvanceConfig SET id =1, destinationOrder = 5;
|
||||||
SET destinationOrder = 5;
|
|
Loading…
Reference in New Issue