refs #6156 new field #1718

Merged
jsegarra merged 13 commits from 6156-advanceTicketsNewField into dev 2024-09-11 10:27:07 +00:00
3 changed files with 98 additions and 223 deletions
Showing only changes of commit 31b04cba75 - Show all commits

View File

@ -1,128 +0,0 @@
CREATE TABLE IF NOT EXISTS `vn`.`ticketCanAdvanceConfig` (
`id` INT auto_increment NULL,
`destinationOrder` INT NULL,
CONSTRAINT `ticketCanAdvanceConfig_PK` PRIMARY KEY (id)
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb3
COLLATE=utf8mb3_unicode_ci;
INSERT INTO `vn`.`ticketCanAdvanceConfig`
SET `destinationOrder` = 5;
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canAdvance`(vDateFuture DATE, vDateToAdvance DATE, vWarehouseFk INT)
BEGIN
/**
* Devuelve los tickets y la cantidad de lineas de venta que se pueden adelantar.
*
* @param vDateFuture Fecha de los tickets que se quieren adelantar.
* @param vDateToAdvance Fecha a cuando se quiere adelantar.
* @param vWarehouseFk Almacén
*/
DECLARE vDateInventory DATE;
SELECT inventoried INTO vDateInventory FROM config;
CREATE OR REPLACE TEMPORARY TABLE tStock
(itemFk INT PRIMARY KEY, amount INT)
ENGINE = MEMORY;
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
(INDEX (id))
SELECT dest.*,
origin.*
FROM (
SELECT s.ticketFk futureId,
t.workerFk,
t.shipped futureShipped,
t.totalWithVat futureTotalWithVat,
st.name futureState,
t.addressFk futureAddressFk,
am.name futureAgency,
count(s.id) futureLines,
GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) futureIpt,
CAST(SUM(litros) AS DECIMAL(10,0)) futureLiters,
SUM((s.quantity <= IFNULL(tst.amount,0))) hasStock,
st.classColor futureClassColor,
(
count(s.id) -
SUM((s.quantity <= IFNULL(tst.amount,0)))
) notMovableLines,
(
count(s.id) =
SUM((s.quantity <= IFNULL(tst.amount,0)))
) isFullMovable
FROM ticket t
JOIN sale s ON s.ticketFk = t.id
JOIN saleVolume sv ON sv.saleFk = s.id
JOIN item i ON i.id = s.itemFk
JOIN ticketState ts ON ts.ticketFk = t.id
JOIN `state` st ON st.id = ts.stateFk
JOIN agencyMode am ON t.agencyModeFk = am.id
LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk
LEFT JOIN tStock tst ON tst.itemFk = i.id
WHERE t.shipped BETWEEN vDateFuture AND util.dayend(vDateFuture)
AND t.warehouseFk = vWarehouseFk
GROUP BY t.id
) origin
JOIN (
SELECT t.id,
t.addressFk,
st.name state,
GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) ipt,
t.shipped,
t.totalWithVat,
am.name agency,
CAST(SUM(litros) AS DECIMAL(10,0)) liters,
CAST(COUNT(*) AS DECIMAL(10,0)) `lines`,
st.classColor,
IF(HOUR(t.shipped),
HOUR(t.shipped),
COALESCE(HOUR(zc.hour),HOUR(z.hour))
) preparation
FROM ticket t
JOIN sale s ON s.ticketFk = t.id
JOIN saleVolume sv ON sv.saleFk = s.id
JOIN item i ON i.id = s.itemFk
JOIN ticketState ts ON ts.ticketFk = t.id
JOIN `state` st ON st.id = ts.stateFk
JOIN agencyMode am ON t.agencyModeFk = am.id
JOIN ticketCanAdvanceConfig
LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk
LEFT JOIN `zone` z ON z.id = t.zoneFk
LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk
WHERE t.shipped BETWEEN vDateToAdvance AND util.dayend(vDateToAdvance)
AND t.warehouseFk = vWarehouseFk
AND st.order <= destinationOrder
GROUP BY t.id
) dest ON dest.addressFk = origin.futureAddressFk
WHERE origin.hasStock != 0;
DROP TEMPORARY TABLE tStock;
END$$
DELIMITER ;

View File

@ -1,5 +1,7 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_canAdvance`(vDateFuture DATE, vDateToAdvance DATE, vWarehouseFk INT)
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canAdvance`(vDateFuture DATE, vDateToAdvance DATE, vWarehouseFk INT)
https://chat.verdnatura.es/group/vn-database?msg=XWo5rMzLLpytj9N2M açò que has posat no es distint?

Este código está hecho de hace 1 año, lo reviso

Este código está hecho de hace 1 año, lo reviso
f70f475223313874abe7e9ea787a4f9e12667db8
BEGIN
/**
* Devuelve los tickets y la cantidad de lineas de venta que se pueden adelantar.
@ -8,91 +10,79 @@ BEGIN
* @param vDateToAdvance Fecha a cuando se quiere adelantar.
* @param vWarehouseFk Almacén
*/
DECLARE vDateInventory DATE;
CALL item_getStock(vWarehouseFk, vDateToAdvance, NULL);
CALL item_getMinacum(
vWarehouseFk,
vDateToAdvance,
DATEDIFF(DATE_SUB(vDateFuture, INTERVAL 1 DAY), vDateToAdvance),
NULL
);
SELECT inventoried INTO vDateInventory FROM config;
CREATE OR REPLACE TEMPORARY TABLE tStock
(itemFk INT PRIMARY KEY, amount INT)
ENGINE = MEMORY;
INSERT INTO tStock(itemFk, amount)
SELECT itemFk, SUM(quantity) amount FROM

esto no me gusta porque esta como repetido de otros procs, o de las vistas entryIn, que lo revise @pablone

esto no me gusta porque esta como repetido de otros procs, o de las vistas entryIn, que lo revise @pablone

commit con las correcciones 92f305b9fd

commit con las correcciones 92f305b9fd5458f13291e8f8ff5b86bdb6e864f5
(
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
(INDEX (id))
SELECT
origin.ticketFk futureId,
dest.ticketFk id,
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,

esta linea on queda?

esta linea on queda?

Este código está hecho de hace 1 año, lo reviso

Este código está hecho de hace 1 año, lo reviso
f9a25617f0eed7ab6e5c6e0a0eba104dd2263e47
(origin.futureLines = origin.hasStock) AS isFullMovable,
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
SELECT dest.*,
origin.*
FROM (
SELECT
s.ticketFk,
c.salesPersonFk workerFk,
t.shipped,
t.totalWithVat,
st.name futureState,
am.name futureAgency,
count(s.id) futureLines,
GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) futureIpt,
CAST(SUM(litros) AS DECIMAL(10,0)) futureLiters,
SUM(s.quantity <= (IFNULL(il.stock,0) + IFNULL(im.amount, 0))) hasStock,
z.id futureZoneFk,
z.name futureZoneName,
st.classColor,
t.clientFk,
t.nickname,
SELECT s.ticketFk futureId,
t.workerFk,
t.shipped futureShipped,
t.totalWithVat futureTotalWithVat,
st.name futureState,
t.addressFk futureAddressFk,
am.name futureAgency,
count(s.id) futureLines,
GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) futureIpt,
CAST(SUM(litros) AS DECIMAL(10,0)) futureLiters,
SUM((s.quantity <= IFNULL(tst.amount,0))) hasStock,
st.classColor futureClassColor,
(
count(s.id) -
SUM((s.quantity <= IFNULL(tst.amount,0)))
) notMovableLines,
(
count(s.id) =
SUM((s.quantity <= IFNULL(tst.amount,0)))
) isFullMovable
FROM ticket t
JOIN sale s ON s.ticketFk = t.id
JOIN saleVolume sv ON sv.saleFk = s.id
JOIN item i ON i.id = s.itemFk
JOIN ticketState ts ON ts.ticketFk = t.id
JOIN `state` st ON st.id = ts.stateFk
JOIN agencyMode am ON t.agencyModeFk = am.id
LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk
LEFT JOIN tStock tst ON tst.itemFk = i.id
WHERE t.shipped BETWEEN vDateFuture AND util.dayend(vDateFuture)
AND t.warehouseFk = vWarehouseFk
GROUP BY t.id
) origin
JOIN (
SELECT t.id,
t.addressFk,
t.warehouseFk,
t.companyFk,
t.agencyModeFk
FROM ticket t
JOIN client c ON c.id = t.clientFk
JOIN sale s ON s.ticketFk = t.id
JOIN saleVolume sv ON sv.saleFk = s.id
JOIN item i ON i.id = s.itemFk
JOIN ticketState ts ON ts.ticketFk = t.id
JOIN state st ON st.id = ts.stateFk
JOIN agencyMode am ON t.agencyModeFk = am.id
JOIN zone z ON t.zoneFk = z.id
LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk
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)
AND t.warehouseFk = vWarehouseFk
GROUP BY t.id
) origin
LEFT JOIN (
SELECT
t.id ticketFk,
st.name state,
GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) ipt,
t.shipped,
@ -101,31 +91,32 @@ BEGIN
CAST(SUM(litros) AS DECIMAL(10,0)) liters,
CAST(COUNT(*) AS DECIMAL(10,0)) `lines`,
st.classColor,
t.clientFk,
t.nickname,
t.addressFk,
t.zoneFk,
t.warehouseFk,
t.companyFk,
t.landed,
t.agencyModeFk
CONCAT_WS(':',
jgallego marked this conversation as resolved Outdated

CONCAT_WS(':',
COALESCE(HOUR(t.shipped), HOUR(zc.hour), HOUR(z.hour)),
COALESCE(MINUTE(t.shipped), MINUTE(zc.hour), MINUTE(z.hour))
) AS preparation

mira a vore si açò es lo mateix es mes compacte

CONCAT_WS(':', COALESCE(HOUR(t.shipped), HOUR(zc.hour), HOUR(z.hour)), COALESCE(MINUTE(t.shipped), MINUTE(zc.hour), MINUTE(z.hour)) ) AS preparation mira a vore si açò es lo mateix es mes compacte
615f57b2e6d5fd2951bee7f5cd9822f61af87ee5
IF(HOUR(t.shipped),
HOUR(t.shipped),
COALESCE(HOUR(zc.hour),HOUR(z.hour))),
IF(MINUTE(t.shipped),
MINUTE(t.shipped),
COALESCE(MINUTE(zc.hour),MINUTE(z.hour)))
) preparation
FROM ticket t
JOIN sale s ON s.ticketFk = t.id
JOIN saleVolume sv ON sv.saleFk = s.id
JOIN item i ON i.id = s.itemFk
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 ticketCanAdvanceConfig
LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk
LEFT JOIN `zone` z ON z.id = t.zoneFk
LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk
WHERE t.shipped BETWEEN vDateToAdvance AND util.dayend(vDateToAdvance)
AND t.warehouseFk = vWarehouseFk
AND st.order <= 5
AND st.order <= destinationOrder
GROUP BY t.id
) dest ON dest.addressFk = origin.addressFk
WHERE origin.hasStock;
) dest ON dest.addressFk = origin.futureAddressFk
WHERE origin.hasStock != 0;
jgallego marked this conversation as resolved Outdated

!= 0 es redundant, a mes en tot cas seria FALSE, jo el deixaria com estava

!= 0 es redundant, a mes en tot cas seria FALSE, jo el deixaria com estava
c407dde7a021c3defe5ca8003758dbf163995159
DROP TEMPORARY TABLE IF EXISTS
tmp.itemList,
tmp.itemMinacum;
DROP TEMPORARY TABLE tStock;
END$$
DELIMITER ;

View File

@ -0,0 +1,12 @@
-- Place your SQL code here
CREATE TABLE IF NOT EXISTS `vn`.`ticketCanAdvanceConfig` (
`id` INT auto_increment NULL,
jgallego marked this conversation as resolved Outdated

copia l'estructura d eles taules config. no deu ser autoincrement i crec que tenen triggers o algo

copia l'estructura d eles taules config. no deu ser autoincrement i crec que tenen triggers o algo

Este código está hecho de hace 1 año, lo reviso

Este código está hecho de hace 1 año, lo reviso

Tienen diferente configuración:
db/versions/11175-pinkChico/00-firstScript.sql
db/versions/11194-orangeOrchid/00-firstScript.sql

Cual aplico?

Tienen diferente configuración: db/versions/11175-pinkChico/00-firstScript.sql db/versions/11194-orangeOrchid/00-firstScript.sql Cual aplico?
773933ca3c32bec8745457afd9e23fb80d96c0fe
`destinationOrder` INT NULL,
CONSTRAINT `ticketCanAdvanceConfig_PK` PRIMARY KEY (id)
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb3
COLLATE=utf8mb3_unicode_ci;
INSERT INTO `vn`.`ticketCanAdvanceConfig`
SET `destinationOrder` = 5;