7965-unifyProblems #2990
|
@ -1085,12 +1085,12 @@ INSERT INTO `vn`.`sale`(`id`, `itemFk`, `ticketFk`, `concept`, `quantity`, `pric
|
|||
(5, 1, 2, 'Ranged weapon longbow 200cm', 1, 110.33, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 'hasComponentLack'),
|
||||
(6, 1, 3, 'Ranged weapon longbow 200cm', 1, 110.33, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 'hasComponentLack'),
|
||||
(7, 2, 11, 'Melee weapon combat fist 15cm', 15, 7.74, 0, 0, 0, util.VN_CURDATE(), NULL),
|
||||
(8, 4, 11, 'Melee weapon heavy shield 100cm', 10, 1.79, 0, 0, 0, util.VN_CURDATE(), NULL),
|
||||
(8, 4, 11, 'Melee weapon heavy shield 100cm', 10, 1.79, 0, 0, 0, util.VN_CURDATE(), 'hasItemLost,hasRounding'),
|
||||
(9, 1, 16, 'Ranged weapon longbow 200cm', 1, 103.49, 0, 0, 0, util.VN_CURDATE(), NULL),
|
||||
(10, 2, 16, 'Melee weapon combat fist 15cm', 10, 7.09, 0, 0, 0, util.VN_CURDATE(), NULL),
|
||||
(11, 1, 16, 'Ranged weapon longbow 200cm', 1, 103.49, 0, 0, 0, util.VN_CURDATE(), NULL),
|
||||
(12, 4, 16, 'Melee weapon heavy shield 100cm', 20, 1.71, 0, 0, 0, util.VN_CURDATE(), NULL),
|
||||
(13, 2, 8, 'Melee weapon combat fist 15cm', 10, 7.08, 0, 0, 0, util.VN_CURDATE(), NULL),
|
||||
(12, 4, 16, 'Melee weapon heavy shield 100cm', 20, 1.71, 0, 0, 0, util.VN_CURDATE(), NULL),
|
||||
(13, 2, 8, 'Melee weapon combat fist 15cm', 10, 7.08, 0, 0, 0, util.VN_CURDATE(), 'hasItemLost'),
|
||||
(14, 1, 8, 'Ranged weapon longbow 200cm', 2, 103.49, 0, 0, 0, util.VN_CURDATE(), NULL),
|
||||
(15, 1, 19, 'Ranged weapon longbow 200cm', 1, 103.49, 0, 0, 0, util.VN_CURDATE(), NULL),
|
||||
(16, 2, 20, 'Melee weapon combat fist 15cm', 20, 7.07, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'),
|
||||
|
@ -1101,25 +1101,25 @@ INSERT INTO `vn`.`sale`(`id`, `itemFk`, `ticketFk`, `concept`, `quantity`, `pric
|
|||
(21, 1, 6, 'Ranged weapon longbow 200cm', 1, 8.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 'hasComponentLack'),
|
||||
(22, 1, 7, 'Ranged weapon longbow 200cm', 1, 8.07, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'),
|
||||
(23, 1, 9, 'Ranged weapon longbow 200cm', 1, 8.07, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'),
|
||||
(24, 1, 10, 'Ranged weapon longbow 200cm', 1, 8.07, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'),
|
||||
(25, 4, 12, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'),
|
||||
(26, 4, 13, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'),
|
||||
(27, 4, 14, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'),
|
||||
(28, 4, 15, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'),
|
||||
(29, 4, 17, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'),
|
||||
(30, 4, 18, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'),
|
||||
(31, 2, 23, 'Melee weapon combat fist 15cm', -5, 7.08, 0, 0, 0, util.VN_CURDATE(), NULL),
|
||||
(24, 1, 10, 'Ranged weapon longbow 200cm', 1, 8.07, 0, 0, 0, util.VN_CURDATE(), 'hasItemShortage,hasComponentLack'),
|
||||
(25, 4, 12, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack,hasItemLost'),
|
||||
(26, 4, 13, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack,hasItemLost'),
|
||||
(27, 4, 14, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasItemShortage,hasComponentLack,hasItemLost'),
|
||||
(28, 4, 15, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack,hasItemLost'),
|
||||
(29, 4, 17, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasItemShortage,hasComponentLack'),
|
||||
(30, 4, 18, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasItemShortage,hasComponentLack'),
|
||||
(31, 2, 23, 'Melee weapon combat fist 15cm', -5, 7.08, 0, 0, 0, util.VN_CURDATE(), 'hasRounding'),
|
||||
(32, 1, 24, 'Ranged weapon longbow 200cm', -1, 8.07, 0, 0, 0, util.VN_CURDATE(), NULL),
|
||||
(33, 5, 14, 'Ranged weapon pistol 9mm', 50, 1.79, 0, 0, 0, util.VN_CURDATE(), NULL),
|
||||
(34, 4, 28, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'),
|
||||
(35, 4, 29, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'),
|
||||
(34, 4, 28, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack,hasItemLost'),
|
||||
(35, 4, 29, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack,hasItemLost'),
|
||||
(37, 4, 31, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), NULL),
|
||||
(36, 4, 30, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'),
|
||||
(36, 4, 30, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack,hasItemLost'),
|
||||
(38, 2, 32, 'Melee weapon combat fist 15cm', 30, 7.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH), 'hasComponentLack'),
|
||||
(39, 1, 32, 'Ranged weapon longbow 200cm', 2, 103.49, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'),
|
||||
(40, 2, 34, 'Melee weapon combat fist 15cm', 10.00, 3.91, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'),
|
||||
(41, 2, 35, 'Melee weapon combat fist 15cm', 8.00, 3.01, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack'),
|
||||
(42, 2, 36, 'Melee weapon combat fist 15cm', 6.00, 2.50, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack');
|
||||
(40, 2, 34, 'Melee weapon combat fist 15cm', 10.00, 3.91, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack,hasItemLost'),
|
||||
(41, 2, 35, 'Melee weapon combat fist 15cm', 8.00, 3.01, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack,hasRounding,hasItemLost'),
|
||||
(42, 2, 36, 'Melee weapon combat fist 15cm', 6.00, 2.50, 0, 0, 0, util.VN_CURDATE(), 'hasComponentLack,hasRounding,hasItemLost');
|
||||
|
||||
INSERT INTO `vn`.`saleComponent`(`saleFk`, `componentFk`, `value`)
|
||||
VALUES
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`prepareTicketList`(vStartingDate DATETIME, vEndingDate DATETIME)
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`prepareTicketList`(
|
||||
vStartingDate DATETIME,
|
||||
vEndingDate DATETIME
|
||||
)
|
||||
BEGIN
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.productionTicket;
|
||||
CREATE TEMPORARY TABLE tmp.productionTicket
|
||||
(PRIMARY KEY (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT t.id ticketFk, t.clientFk
|
||||
SELECT t.id ticketFk
|
||||
FROM ticket t
|
||||
JOIN alertLevel al ON al.code = 'DELIVERED'
|
||||
LEFT JOIN ticketState ts ON ts.ticketFk = t.id
|
||||
JOIN client c ON c.id = t.clientFk
|
||||
|
||||
WHERE c.typeFk IN ('normal','handMaking','internalUse')
|
||||
AND (
|
||||
t.shipped BETWEEN util.VN_CURDATE() AND vEndingDate
|
||||
|
|
|
@ -24,24 +24,31 @@ proc: BEGIN
|
|||
CALL prepareTicketList(util.yesterday(), vEndingDate);
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||
SELECT * FROM tmp.productionTicket;
|
||||
|
||||
CALL prepareClientList();
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale_getProblems
|
||||
(INDEX (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT tt.ticketFk, tt.clientFk, t.warehouseFk, t.shipped
|
||||
FROM tmp.productionTicket tt
|
||||
JOIN ticket t ON t.id = tt.ticketFk;
|
||||
SELECT ticketFk
|
||||
FROM tmp.productionTicket;
|
||||
|
||||
CALL ticket_getProblems(vIsTodayRelative);
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.productionBuffer
|
||||
(PRIMARY KEY(ticketFk), previaParking VARCHAR(255))
|
||||
ENGINE = MEMORY
|
||||
WITH saleProblemsDescription AS(
|
||||
SELECT s.ticketFk,
|
||||
LEFT(CONCAT('F: ', GROUP_CONCAT(CONCAT(i.id, ' ', i.longName) SEPARATOR ', ')), 250) itemShortage,
|
||||
LEFT(CONCAT('R: ', GROUP_CONCAT(CONCAT(i2.id, ' ', i2.longName) SEPARATOR ', ')), 250) itemDelay,
|
||||
LEFT(CONCAT('I: ', GROUP_CONCAT(CONCAT(i3.id, ' ', i3.longName) SEPARATOR ', ')), 250) itemLost
|
||||
FROM tmp.saleProblems sp
|
||||
JOIN vn.sale s ON s.id = sp.saleFk
|
||||
LEFT JOIN vn.item i ON i.id = s.itemFk AND sp.hasItemShortage
|
||||
LEFT JOIN vn.item i2 ON i2.id = s.itemFk AND sp.hasItemDelay
|
||||
LEFT JOIN vn.item i3 ON i3.id = s.itemFk AND sp.hasItemLost
|
||||
WHERE hasItemShortage OR hasItemDelay OR hasItemLost
|
||||
GROUP BY s.ticketFk
|
||||
)
|
||||
SELECT tt.ticketFk,
|
||||
tt.clientFk,
|
||||
t.clientFk,
|
||||
t.warehouseFk,
|
||||
t.nickname,
|
||||
t.packages,
|
||||
|
@ -59,7 +66,17 @@ proc: BEGIN
|
|||
0 `lines`,
|
||||
CAST( 0 AS DECIMAL(5,2)) m3,
|
||||
CAST( 0 AS DECIMAL(5,2)) preparationRate,
|
||||
"" problem,
|
||||
TRIM(CAST(CONCAT( IFNULL(sp.itemShortage, ''),
|
||||
IFNULL(sp.itemDelay, ''),
|
||||
IFNULL(sp.itemLost, ''),
|
||||
IF(tpr.isFreezed, ' CONGELADO',''),
|
||||
IF(tpr.hasHighRisk, ' RIESGO',''),
|
||||
IF(tpr.hasTicketRequest, ' COD 100',''),
|
||||
IF(tpr.isTaxDataChecked, '',' FICHA INCOMPLETA'),
|
||||
IF(tpr.hasComponentLack, ' COMPONENTES', ''),
|
||||
IF(HOUR(util.VN_NOW()) < IF(HOUR(t.shipped), HOUR(t.shipped), COALESCE(HOUR(zc.hour),HOUR(z.hour)))
|
||||
AND tpr.isTooLittle, ' PEQUEÑO', '')
|
||||
) AS char(255))) problem,
|
||||
IFNULL(tls.state,2) state,
|
||||
w.code workerCode,
|
||||
DATE(t.shipped) shipped,
|
||||
|
@ -79,29 +96,31 @@ proc: BEGIN
|
|||
ag.isOwn,
|
||||
rm.bufferFk
|
||||
FROM tmp.productionTicket tt
|
||||
JOIN ticket t ON tt.ticketFk = t.id
|
||||
JOIN alertLevel al ON al.code = 'FREE'
|
||||
LEFT JOIN ticketStateToday tst ON tst.ticketFk = t.id
|
||||
LEFT JOIN `state` st ON st.id = tst.state
|
||||
LEFT JOIN client c ON c.id = t.clientFk
|
||||
LEFT JOIN worker wk ON wk.id = c.salesPersonFk
|
||||
JOIN address a ON a.id = t.addressFk
|
||||
LEFT JOIN province p ON p.id = a.provinceFk
|
||||
JOIN agencyMode am ON am.id = t.agencyModeFk
|
||||
JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk
|
||||
JOIN agency ag ON ag.id = am.agencyFk
|
||||
LEFT JOIN ticketState tls ON tls.ticketFk = tt.ticketFk
|
||||
LEFT JOIN ticketLastUpdated tlu ON tlu.ticketFk = tt.ticketFk
|
||||
LEFT JOIN worker w ON w.id = tls.userFk
|
||||
LEFT JOIN routesMonitor rm ON rm.routeFk = t.routeFk
|
||||
LEFT JOIN `zone` z ON z.id = t.zoneFk
|
||||
LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk
|
||||
JOIN vn.ticket t ON tt.ticketFk = t.id
|
||||
JOIN vn.alertLevel al ON al.code = 'FREE'
|
||||
LEFT JOIN vn.ticketStateToday tst ON tst.ticketFk = t.id
|
||||
LEFT JOIN vn.`state` st ON st.id = tst.state
|
||||
LEFT JOIN vn.client c ON c.id = t.clientFk
|
||||
LEFT JOIN vn.worker wk ON wk.id = c.salesPersonFk
|
||||
JOIN vn.address a ON a.id = t.addressFk
|
||||
LEFT JOIN vn.province p ON p.id = a.provinceFk
|
||||
JOIN vn.agencyMode am ON am.id = t.agencyModeFk
|
||||
JOIN vn.deliveryMethod dm ON dm.id = am.deliveryMethodFk
|
||||
JOIN vn.agency ag ON ag.id = am.agencyFk
|
||||
LEFT JOIN vn.ticketState tls ON tls.ticketFk = tt.ticketFk
|
||||
LEFT JOIN vn.ticketLastUpdated tlu ON tlu.ticketFk = tt.ticketFk
|
||||
LEFT JOIN vn.worker w ON w.id = tls.userFk
|
||||
LEFT JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk
|
||||
LEFT JOIN vn.`zone` z ON z.id = t.zoneFk
|
||||
LEFT JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk
|
||||
AND DATE(t.shipped) = zc.dated
|
||||
LEFT JOIN ticketParking tp ON tp.ticketFk = t.id
|
||||
LEFT JOIN parking pk ON pk.id = tp.parkingFk
|
||||
LEFT JOIN vn.ticketParking tp ON tp.ticketFk = t.id
|
||||
LEFT JOIN vn.parking pk ON pk.id = tp.parkingFk
|
||||
LEFT JOIN tmp.ticketProblems tpr ON tpr.ticketFk = tt.ticketFk
|
||||
LEFT JOIN saleProblemsDescription sp ON sp.ticketFk = tt.ticketFk
|
||||
WHERE t.warehouseFk = vWarehouseFk
|
||||
AND dm.code IN ('AGENCY', 'DELIVERY', 'PICKUP');
|
||||
|
||||
|
||||
UPDATE tmp.productionBuffer pb
|
||||
JOIN (
|
||||
SELECT pb.ticketFk, GROUP_CONCAT(p.code) previaParking
|
||||
|
@ -121,19 +140,6 @@ proc: BEGIN
|
|||
ADD COLUMN `collectionV` INT,
|
||||
ADD COLUMN `collectionN` INT;
|
||||
|
||||
UPDATE tmp.productionBuffer pb
|
||||
JOIN tmp.ticket_problems tp ON tp.ticketFk = pb.ticketFk
|
||||
SET pb.problem = TRIM(CAST(CONCAT( IFNULL(tp.itemShortage, ''),
|
||||
IFNULL(tp.itemDelay, ''),
|
||||
IFNULL(tp.itemLost, ''),
|
||||
IF(tp.isFreezed, ' CONGELADO',''),
|
||||
IF(tp.hasHighRisk, ' RIESGO',''),
|
||||
IF(tp.hasTicketRequest, ' COD 100',''),
|
||||
IF(tp.isTaxDataChecked, '',' FICHA INCOMPLETA'),
|
||||
IF(tp.hasComponentLack, ' COMPONENTES', ''),
|
||||
IF(HOUR(util.VN_NOW()) < pb.HH AND tp.isTooLittle, ' PEQUEÑO', '')
|
||||
) AS char(255)));
|
||||
|
||||
-- Clientes Nuevos o Recuperados
|
||||
UPDATE tmp.productionBuffer pb
|
||||
LEFT JOIN bs.clientNewBorn cnb ON cnb.clientFk = pb.clientFk
|
||||
|
@ -278,7 +284,8 @@ proc: BEGIN
|
|||
DROP TEMPORARY TABLE
|
||||
tmp.productionTicket,
|
||||
tmp.ticket,
|
||||
tmp.ticket_problems,
|
||||
tmp.ticketProblems,
|
||||
tmp.saleProblems,
|
||||
tmp.ticketWithPrevia,
|
||||
tItemShelvingStock,
|
||||
tItemPackingType;
|
||||
|
|
|
@ -1,86 +1,42 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`sale_getProblems`(
|
||||
vIsTodayRelative tinyint(1)
|
||||
vIsTodayRelative TINYINT(1)
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Calcula los problemas de cada venta para un conjunto de tickets.
|
||||
* Calcula los problemas para un conjunto de sale
|
||||
*
|
||||
* @param vIsTodayRelative Indica si se calcula el disponible como si todo saliera hoy
|
||||
jgallego marked this conversation as resolved
Outdated
|
||||
* @table tmp.sale_getProblems(ticketFk, clientFk, warehouseFk, shipped) Tickets a calcular
|
||||
* @return tmp.sale_problems
|
||||
* @table tmp.sale(saleFk) Identificadores de los sale a calcular
|
||||
* @return tmp.saleProblems
|
||||
*/
|
||||
DECLARE vWarehouseFk INT;
|
||||
DECLARE vWarehouseFk INT;
|
||||
DECLARE vDate DATE;
|
||||
DECLARE vAvailableCache INT;
|
||||
DECLARE vAvailableCache INT;
|
||||
DECLARE vVisibleCache INT;
|
||||
DECLARE vDone BOOL;
|
||||
DECLARE vCursor CURSOR FOR
|
||||
SELECT DISTINCT warehouseFk, IF(vIsTodayRelative, util.VN_CURDATE(), DATE(shipped))
|
||||
FROM tmp.sale_getProblems
|
||||
WHERE shipped BETWEEN util.VN_CURDATE()
|
||||
AND util.dayEnd(util.VN_CURDATE() + INTERVAL IF(vIsTodayRelative, 9.9, 1.9) DAY);
|
||||
DECLARE vCursor CURSOR FOR
|
||||
SELECT t.warehouseFk, IF(vIsTodayRelative, util.VN_CURDATE(), DATE(t.shipped)) dated
|
||||
FROM tmp.sale ts
|
||||
JOIN sale s ON s.id = ts.saleFk
|
||||
JOIN ticket t ON t.id = s.ticketFk
|
||||
WHERE t.shipped BETWEEN util.VN_CURDATE()
|
||||
jgallego marked this conversation as resolved
jgallego
commented
confirma si açò es lo mateix que gastar dayend confirma si açò es lo mateix que gastar dayend
jgallego
commented
Açò no has contestat ni has modificat. Açò no has contestat ni has modificat.
carlosap
commented
util.dayEnd(util.VN_CURDATE() + INTERVAL IF(vIsTodayRelative, 9.9, 1.9) DAY) no és igual que gastar dayEnd, el que està fent es sumar 9 ó 1 día segons el paràmetro vIsTodayRelative. És com està ara en producció. Entenc que podem simplificar-ho, no entenc perqué 9.9 / 1.9 i no 9 / 1, però és com està en producció util.dayEnd(util.VN_CURDATE() + INTERVAL IF(vIsTodayRelative, 9.9, 1.9) DAY) no és igual que gastar dayEnd, el que està fent es sumar 9 ó 1 día segons el paràmetro vIsTodayRelative. És com està ara en producció. Entenc que podem simplificar-ho, no entenc perqué 9.9 / 1.9 i no 9 / 1, però és com està en producció
|
||||
AND util.dayEnd(util.VN_CURDATE() + INTERVAL IF(vIsTodayRelative, 9.9, 1.9) DAY)
|
||||
GROUP BY warehouseFk, dated;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale_problems (
|
||||
ticketFk INT(11),
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.saleProblems(
|
||||
saleFk INT(11),
|
||||
isFreezed INTEGER(1) DEFAULT 0,
|
||||
risk DECIMAL(10,1) DEFAULT 0,
|
||||
hasRisk TINYINT(1) DEFAULT 0,
|
||||
hasHighRisk TINYINT(1) DEFAULT 0,
|
||||
hasTicketRequest INTEGER(1) DEFAULT 0,
|
||||
itemShortage VARCHAR(255),
|
||||
isTaxDataChecked INTEGER(1) DEFAULT 1,
|
||||
itemDelay VARCHAR(255),
|
||||
itemLost VARCHAR(255),
|
||||
hasComponentLack INTEGER(1),
|
||||
hasRounding VARCHAR(255),
|
||||
isTooLittle BOOL DEFAULT FALSE,
|
||||
isVip BOOL DEFAULT FALSE,
|
||||
PRIMARY KEY (ticketFk, saleFk)
|
||||
); -- No memory
|
||||
hasItemShortage BOOL DEFAULT FALSE,
|
||||
hasItemLost BOOL DEFAULT FALSE,
|
||||
hasComponentLack BOOL DEFAULT FALSE,
|
||||
hasItemDelay BOOL DEFAULT FALSE,
|
||||
hasRounding BOOL DEFAULT FALSE,
|
||||
PRIMARY KEY (saleFk)
|
||||
) ENGINE = MEMORY;
|
||||
|
||||
INSERT INTO tmp.sale_problems(ticketFk,
|
||||
saleFk,
|
||||
isFreezed,
|
||||
risk,
|
||||
hasRisk,
|
||||
hasHighRisk,
|
||||
hasTicketRequest,
|
||||
isTaxDataChecked,
|
||||
hasComponentLack,
|
||||
isTooLittle)
|
||||
SELECT sgp.ticketFk,
|
||||
s.id,
|
||||
IF(FIND_IN_SET('isFreezed', t.problem), TRUE, FALSE) isFreezed,
|
||||
t.risk,
|
||||
IF(FIND_IN_SET('hasRisk', t.problem), TRUE, FALSE) hasRisk,
|
||||
IF(FIND_IN_SET('hasHighRisk', t.problem), TRUE, FALSE) hasHighRisk,
|
||||
IF(FIND_IN_SET('hasTicketRequest', t.problem), TRUE, FALSE) hasTicketRequest,
|
||||
IF(FIND_IN_SET('isTaxDataChecked', t.problem), FALSE, TRUE) isTaxDataChecked,
|
||||
IF(FIND_IN_SET('hasComponentLack', s.problem), TRUE, FALSE) hasComponentLack,
|
||||
IF(FIND_IN_SET('isTooLittle', t.problem)
|
||||
AND util.VN_NOW() < (util.VN_CURDATE() + INTERVAL HOUR(zc.`hour`) HOUR) + INTERVAL MINUTE(zc.`hour`) MINUTE,
|
||||
TRUE, FALSE) isTooLittle
|
||||
FROM tmp.sale_getProblems sgp
|
||||
JOIN ticket t ON t.id = sgp.ticketFk
|
||||
LEFT JOIN sale s ON s.ticketFk = t.id
|
||||
LEFT JOIN item i ON i.id = s.itemFk
|
||||
LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk
|
||||
AND zc.dated = util.VN_CURDATE()
|
||||
WHERE s.problem <> '' OR t.problem <> '' OR t.risk
|
||||
GROUP BY t.id, s.id;
|
||||
|
||||
INSERT INTO tmp.sale_problems(ticketFk, isVip)
|
||||
SELECT sgp.ticketFk, TRUE
|
||||
FROM tmp.sale_getProblems sgp
|
||||
JOIN client c ON c.id = sgp.clientFk
|
||||
WHERE c.businessTypeFk = 'VIP'
|
||||
ON DUPLICATE KEY UPDATE isVIP = TRUE;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tItemShelvingStock_byWarehouse
|
||||
CREATE OR REPLACE TEMPORARY TABLE tItemShelving
|
||||
(INDEX (itemFk, warehouseFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT ish.itemFk itemFk,
|
||||
|
@ -92,6 +48,14 @@ BEGIN
|
|||
JOIN sector s ON s.id = p.sectorFk
|
||||
GROUP BY ish.itemFk, s.warehouseFk;
|
||||
|
||||
-- Componentes: Algún componente obligatorio no se ha calcualdo
|
||||
INSERT INTO tmp.saleProblems(saleFk, hasComponentLack)
|
||||
SELECT s.id, TRUE
|
||||
FROM tmp.sale ts
|
||||
JOIN sale s ON s.id = ts.saleFk
|
||||
WHERE FIND_IN_SET('hasComponentLack', s.problem)
|
||||
GROUP BY s.id;
|
||||
|
||||
-- Disponible, faltas, inventario y retrasos
|
||||
OPEN vCursor;
|
||||
l: LOOP
|
||||
|
@ -104,130 +68,112 @@ BEGIN
|
|||
|
||||
-- Disponible: no va a haber suficiente producto para preparar todos los pedidos
|
||||
CALL cache.available_refresh(vAvailableCache, FALSE, vWarehouseFk, vDate);
|
||||
|
||||
-- Faltas: visible, disponible y ubicado son menores que la cantidad vendida
|
||||
|
||||
-- Faltas: visible, disponible y ubicado son menores que la cantidad vendida
|
||||
CALL cache.visible_refresh(vVisibleCache, FALSE, vWarehouseFk);
|
||||
|
||||
INSERT INTO tmp.sale_problems(ticketFk, itemShortage, saleFk)
|
||||
SELECT ticketFk, problem, saleFk
|
||||
FROM (
|
||||
SELECT sgp.ticketFk,
|
||||
LEFT(CONCAT('F: ', GROUP_CONCAT(i.id, ' ', i.longName, ' ')), 250) problem,
|
||||
s.id saleFk
|
||||
FROM tmp.sale_getProblems sgp
|
||||
JOIN ticket t ON t.id = sgp.ticketFk
|
||||
JOIN sale s ON s.ticketFk = t.id
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
JOIN itemCategory ic ON ic.id = it.categoryFk
|
||||
LEFT JOIN cache.visible v ON v.item_id = i.id
|
||||
AND v.calc_id = vVisibleCache
|
||||
LEFT JOIN cache.available av ON av.item_id = i.id
|
||||
AND av.calc_id = vAvailableCache
|
||||
LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id
|
||||
AND issw.warehouseFk = t.warehouseFk
|
||||
WHERE IFNULL(v.visible, 0) < s.quantity
|
||||
AND IFNULL(av.available, 0) < 0
|
||||
AND IFNULL(issw.visible, 0) < s.quantity
|
||||
AND NOT s.isPicked
|
||||
AND NOT s.reserved
|
||||
AND ic.merchandise
|
||||
AND IF(vIsTodayRelative, TRUE, DATE(t.shipped) = vDate)
|
||||
AND NOT i.generic
|
||||
AND util.VN_CURDATE() = vDate
|
||||
AND t.warehouseFk = vWarehouseFk
|
||||
GROUP BY sgp.ticketFk) sub
|
||||
ON DUPLICATE KEY UPDATE itemShortage = sub.problem, saleFk = sub.saleFk;
|
||||
|
||||
-- Inventario: Visible suficiente, pero ubicado menor a la cantidad vendida
|
||||
INSERT INTO tmp.sale_problems(ticketFk, itemLost, saleFk)
|
||||
SELECT ticketFk, problem, saleFk
|
||||
FROM (
|
||||
SELECT sgp.ticketFk,
|
||||
LEFT(GROUP_CONCAT('I: ', i.id, ' ', i.longName, ' '), 250) problem,
|
||||
s.id saleFk
|
||||
FROM tmp.sale_getProblems sgp
|
||||
JOIN ticket t ON t.id = sgp.ticketFk
|
||||
JOIN sale s ON s.ticketFk = t.id
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
JOIN itemCategory ic ON ic.id = it.categoryFk
|
||||
LEFT JOIN cache.visible v ON v.item_id = s.itemFk
|
||||
AND v.calc_id = vVisibleCache
|
||||
LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id
|
||||
AND issw.warehouseFk = t.warehouseFk
|
||||
WHERE IFNULL(v.visible, 0) >= s.quantity
|
||||
AND IFNULL(issw.visible, 0) < s.quantity
|
||||
AND s.quantity > 0
|
||||
AND NOT s.isPicked
|
||||
AND NOT s.reserved
|
||||
AND ic.merchandise
|
||||
AND IF(vIsTodayRelative, TRUE, DATE(t.shipped) = vDate)
|
||||
AND NOT i.generic
|
||||
AND util.VN_CURDATE() = vDate
|
||||
AND t.warehouseFk = vWarehouseFk
|
||||
GROUP BY sgp.ticketFk
|
||||
) sub
|
||||
ON DUPLICATE KEY UPDATE itemLost = sub.problem, saleFk = sub.saleFk;
|
||||
|
||||
-- Retraso: Disponible suficiente, pero no visible ni ubicado
|
||||
INSERT INTO tmp.sale_problems(ticketFk, itemDelay, saleFk)
|
||||
SELECT ticketFk, problem, saleFk
|
||||
FROM (
|
||||
SELECT sgp.ticketFk,
|
||||
LEFT(GROUP_CONCAT('R: ', i.id, ' ', i.longName, ' '), 250) problem,
|
||||
s.id saleFk
|
||||
FROM tmp.sale_getProblems sgp
|
||||
JOIN ticket t ON t.id = sgp.ticketFk
|
||||
JOIN sale s ON s.ticketFk = t.id
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
JOIN itemCategory ic ON ic.id = it.categoryFk
|
||||
LEFT JOIN cache.visible v ON v.item_id = s.itemFk
|
||||
AND v.calc_id = vVisibleCache
|
||||
LEFT JOIN cache.available av ON av.item_id = i.id
|
||||
AND av.calc_id = vAvailableCache
|
||||
LEFT JOIN tItemShelvingStock_byWarehouse issw ON issw.itemFk = i.id
|
||||
AND issw.warehouseFk = t.warehouseFk
|
||||
WHERE IFNULL(v.visible, 0) < s.quantity
|
||||
AND IFNULL(av.available, 0) >= 0
|
||||
AND IFNULL(issw.visible, 0) < s.quantity
|
||||
AND s.quantity > 0
|
||||
AND NOT s.isPicked
|
||||
AND NOT s.reserved
|
||||
AND ic.merchandise
|
||||
AND IF(vIsTodayRelative, TRUE, DATE(t.shipped) = vDate)
|
||||
AND NOT i.generic
|
||||
AND util.VN_CURDATE() = vDate
|
||||
AND t.warehouseFk = vWarehouseFk
|
||||
GROUP BY sgp.ticketFk
|
||||
) sub
|
||||
ON DUPLICATE KEY UPDATE itemDelay = sub.problem, saleFk = sub.saleFk;
|
||||
INSERT INTO tmp.saleProblems(saleFk, hasItemShortage)
|
||||
SELECT s.id, TRUE
|
||||
FROM tmp.sale ts
|
||||
JOIN sale s ON s.id = ts.saleFk
|
||||
JOIN ticket t ON t.id = s.ticketFk
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
jgallego marked this conversation as resolved
Outdated
jgallego
commented
ja posats canvia el IFNULL que en la convencio ja no esta acceptat ja posats canvia el IFNULL que en la convencio ja no esta acceptat
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
JOIN itemCategory ic ON ic.id = it.categoryFk
|
||||
LEFT JOIN cache.visible v ON v.item_id = i.id
|
||||
AND v.calc_id = vVisibleCache
|
||||
LEFT JOIN cache.available av ON av.item_id = i.id
|
||||
AND av.calc_id = vAvailableCache
|
||||
LEFT JOIN tItemShelving tis ON tis.itemFk = i.id
|
||||
AND tis.warehouseFk = t.warehouseFk
|
||||
WHERE (s.quantity > v.visible OR (s.quantity > 0 AND v.visible IS NULL))
|
||||
AND (av.available < 0 OR av.available IS NULL)
|
||||
AND (s.quantity > tis.visible OR tis.visible IS NULL)
|
||||
AND NOT s.isPicked
|
||||
AND NOT s.reserved
|
||||
AND ic.merchandise
|
||||
AND IF(vIsTodayRelative, TRUE, DATE(t.shipped) = vDate)
|
||||
AND NOT i.generic
|
||||
AND util.VN_CURDATE() = vDate
|
||||
AND t.warehouseFk = vWarehouseFk
|
||||
GROUP BY s.id
|
||||
ON DUPLICATE KEY UPDATE hasItemShortage = TRUE;
|
||||
|
||||
-- Redondeo: cantidad incorrecta con respecto al grouping
|
||||
-- Inventario: Visible suficiente, pero ubicado menor a la cantidad vendida
|
||||
INSERT INTO tmp.saleProblems(saleFk, hasItemLost)
|
||||
SELECT s.id, TRUE
|
||||
FROM tmp.sale ts
|
||||
JOIN sale s ON s.id = ts.saleFk
|
||||
JOIN ticket t ON t.id = s.ticketFk
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
JOIN itemCategory ic ON ic.id = it.categoryFk
|
||||
LEFT JOIN cache.visible v ON v.item_id = s.itemFk
|
||||
AND v.calc_id = vVisibleCache
|
||||
LEFT JOIN tItemShelving tis ON tis.itemFk = i.id
|
||||
AND tis.warehouseFk = t.warehouseFk
|
||||
WHERE (v.visible >= s.quantity OR v.visible IS NULL)
|
||||
AND (s.quantity > tis.visible AND tis.visible IS NOT NULL)
|
||||
AND s.quantity > 0
|
||||
AND NOT s.isPicked
|
||||
AND NOT s.reserved
|
||||
AND ic.merchandise
|
||||
AND IF(vIsTodayRelative, TRUE, DATE(t.shipped) = vDate)
|
||||
AND NOT i.generic
|
||||
AND util.VN_CURDATE() = vDate
|
||||
AND t.warehouseFk = vWarehouseFk
|
||||
GROUP BY s.id
|
||||
ON DUPLICATE KEY UPDATE hasItemLost = TRUE;
|
||||
|
||||
-- Retraso: Disponible suficiente, pero no visible ni ubicado
|
||||
INSERT INTO tmp.saleProblems(saleFk, hasItemDelay)
|
||||
SELECT s.id, TRUE
|
||||
FROM tmp.sale ts
|
||||
JOIN sale s ON s.id = ts.saleFk
|
||||
JOIN ticket t ON t.id = s.ticketFk
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
JOIN itemCategory ic ON ic.id = it.categoryFk
|
||||
LEFT JOIN cache.visible v ON v.item_id = s.itemFk
|
||||
AND v.calc_id = vVisibleCache
|
||||
LEFT JOIN cache.available av ON av.item_id = i.id
|
||||
AND av.calc_id = vAvailableCache
|
||||
LEFT JOIN tItemShelving tis ON tis.itemFk = i.id
|
||||
AND tis.warehouseFk = t.warehouseFk
|
||||
WHERE (s.quantity > v.visible AND v.visible IS NULL)
|
||||
AND (av.available >= 0 OR av.available IS NULL)
|
||||
AND (s.quantity > tis.visible AND tis.visible IS NOT NULL)
|
||||
AND s.quantity > 0
|
||||
AND NOT s.isPicked
|
||||
AND NOT s.reserved
|
||||
AND ic.merchandise
|
||||
AND IF(vIsTodayRelative, TRUE, DATE(t.shipped) = vDate)
|
||||
AND NOT i.generic
|
||||
AND util.VN_CURDATE() = vDate
|
||||
AND t.warehouseFk = vWarehouseFk
|
||||
GROUP BY s.id
|
||||
ON DUPLICATE KEY UPDATE hasItemDelay = TRUE;
|
||||
|
||||
-- Redondeo: cantidad incorrecta con respecto al grouping
|
||||
CALL buy_getUltimate(NULL, vWarehouseFk, vDate);
|
||||
INSERT INTO tmp.sale_problems(ticketFk, hasRounding, saleFk)
|
||||
SELECT ticketFk, problem, saleFk
|
||||
FROM (
|
||||
SELECT sgp.ticketFk,
|
||||
s.id saleFk,
|
||||
LEFT(GROUP_CONCAT('RE: ',i.id, ' ', IFNULL(i.longName,'') SEPARATOR ', '), 250) problem
|
||||
FROM tmp.sale_getProblems sgp
|
||||
JOIN ticket t ON t.id = sgp.ticketFk
|
||||
AND t.warehouseFk = vWarehouseFk
|
||||
JOIN sale s ON s.ticketFk = sgp.ticketFk
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
|
||||
JOIN buy b ON b.id = bu.buyFk
|
||||
WHERE MOD(s.quantity, b.`grouping`)
|
||||
GROUP BY sgp.ticketFk
|
||||
)sub
|
||||
ON DUPLICATE KEY UPDATE hasRounding = sub.problem, saleFk = sub.saleFk;
|
||||
|
||||
INSERT INTO tmp.saleProblems(saleFk, hasRounding)
|
||||
SELECT s.id, TRUE
|
||||
FROM tmp.sale ts
|
||||
JOIN sale s ON s.id = ts.saleFk
|
||||
JOIN ticket t ON t.id = s.ticketFk
|
||||
AND t.warehouseFk = vWarehouseFk
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
|
||||
JOIN buy b ON b.id = bu.buyFk
|
||||
WHERE MOD(s.quantity, b.`grouping`)
|
||||
GROUP BY s.id
|
||||
ON DUPLICATE KEY UPDATE hasRounding = TRUE;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.buyUltimate;
|
||||
END LOOP;
|
||||
CLOSE vCursor;
|
||||
|
||||
DROP TEMPORARY TABLE tItemShelvingStock_byWarehouse;
|
||||
DROP TEMPORARY TABLE tItemShelving;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`sale_getProblemsByTicket`(IN vTicketFk INT, IN vIsTodayRelative TINYINT(1))
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`sale_getProblemsByTicket`(
|
||||
IN vTicketFk INT,
|
||||
IN vIsTodayRelative TINYINT(1)
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Calcula los problemas de cada venta
|
||||
* para un conjunto de tickets.
|
||||
* Calcula los problemas de cada venta para un tickets.
|
||||
*
|
||||
* @return Problems result
|
||||
*/
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale_getProblems
|
||||
(INDEX (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT t.id ticketFk, t.clientFk, t.warehouseFk, t.shipped
|
||||
FROM ticket t
|
||||
WHERE t.id = vTicketFk;
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
||||
(INDEX (saleFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT id saleFk FROM sale WHERE ticketFk = vTicketFk;
|
||||
|
||||
CALL sale_getProblems(vIsTodayRelative);
|
||||
CALL sale_getProblems(vIsTodayRelative);
|
||||
|
||||
SELECT * FROM tmp.sale_problems;
|
||||
SELECT * FROM tmp.saleProblems;
|
||||
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.sale_getProblems,
|
||||
tmp.sale_problems;
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.saleProblems,
|
||||
tmp.sale;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -1,53 +1,109 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_getProblems`(
|
||||
vIsTodayRelative tinyint(1)
|
||||
vIsTodayRelative TINYINT(1)
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Calcula los problemas para un conjunto de tickets.
|
||||
* Agrupados por ticket
|
||||
*
|
||||
* @table tmp.sale_getProblems(ticketFk, clientFk, warehouseFk, shipped) Identificadores de los tickets a calcular
|
||||
* @return tmp.ticket_problems
|
||||
* @param vIsTodayRelative Indica si se calcula el disponible como si todo saliera hoy
|
||||
jgallego marked this conversation as resolved
Outdated
jgallego
commented
vIsTodayRelative falta descripcio vIsTodayRelative falta descripcio
|
||||
* @table tmp.ticket(ticketFk) Identificadores de los tickets a calcular
|
||||
* @return tmp.ticketProblems, tmp.saleProblems
|
||||
*/
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale (
|
||||
saleFk INT(11),
|
||||
PRIMARY KEY (saleFk)
|
||||
) ENGINE = MEMORY
|
||||
SELECT DISTINCT s.id saleFk
|
||||
FROM tmp.ticket tt
|
||||
JOIN ticket t ON t.id = tt.ticketFk
|
||||
JOIN sale s ON s.ticketFk = t.id
|
||||
GROUP BY s.id;
|
||||
|
||||
CALL sale_getProblems(vIsTodayRelative);
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket_problems
|
||||
(PRIMARY KEY (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT ticketFk,
|
||||
MAX(isFreezed) isFreezed,
|
||||
MAX(risk) risk,
|
||||
MAX(hasRisk) hasRisk,
|
||||
MAX(hasHighRisk) hasHighRisk,
|
||||
MAX(hasTicketRequest) hasTicketRequest,
|
||||
MAX(itemShortage) itemShortage,
|
||||
MIN(isTaxDataChecked) isTaxDataChecked,
|
||||
MAX(hasComponentLack) hasComponentLack,
|
||||
MAX(isTooLittle) isTooLittle,
|
||||
MAX(itemDelay) itemDelay,
|
||||
MAX(hasRounding) hasRounding,
|
||||
MAX(itemLost) itemLost,
|
||||
MAX(isVip) isVip,
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketProblems (
|
||||
ticketFk INT(11),
|
||||
isFreezed BOOL DEFAULT FALSE,
|
||||
risk DECIMAL(10,1) DEFAULT 0,
|
||||
hasRisk BOOL DEFAULT FALSE,
|
||||
hasHighRisk BOOL DEFAULT FALSE,
|
||||
hasTicketRequest BOOL DEFAULT FALSE,
|
||||
isTaxDataChecked BOOL DEFAULT FALSE,
|
||||
isTooLittle BOOL DEFAULT FALSE,
|
||||
isVip BOOL DEFAULT FALSE,
|
||||
hasItemShortage BOOL DEFAULT FALSE,
|
||||
hasItemDelay BOOL DEFAULT FALSE,
|
||||
hasItemLost BOOL DEFAULT FALSE,
|
||||
hasComponentLack BOOL DEFAULT FALSE,
|
||||
hasRounding BOOL DEFAULT FALSE,
|
||||
PRIMARY KEY (ticketFk)
|
||||
) ENGINE = MEMORY
|
||||
WITH hasItemShortage AS(
|
||||
SELECT s.ticketFk
|
||||
FROM tmp.saleProblems sp
|
||||
JOIN vn.sale s ON s.id = sp.saleFk
|
||||
WHERE sp.hasItemShortage
|
||||
GROUP BY s.ticketFk
|
||||
),hasItemLost AS(
|
||||
SELECT s.ticketFk
|
||||
FROM tmp.saleProblems sp
|
||||
JOIN vn.sale s ON s.id = sp.saleFk
|
||||
WHERE sp.hasItemLost
|
||||
GROUP BY s.ticketFk
|
||||
),hasRounding AS(
|
||||
SELECT s.ticketFk
|
||||
FROM tmp.saleProblems sp
|
||||
JOIN vn.sale s ON s.id = sp.saleFk
|
||||
WHERE sp.hasRounding
|
||||
GROUP BY s.ticketFk
|
||||
), hasItemDelay AS(
|
||||
SELECT s.ticketFk
|
||||
FROM tmp.saleProblems sp
|
||||
JOIN vn.sale s ON s.id = sp.saleFk
|
||||
WHERE sp.hasItemDelay
|
||||
GROUP BY s.ticketFk
|
||||
), hasComponentLack AS(
|
||||
SELECT s.ticketFk
|
||||
FROM tmp.saleProblems sp
|
||||
JOIN vn.sale s ON s.id = sp.saleFk
|
||||
WHERE sp.hasComponentLack
|
||||
GROUP BY s.ticketFk
|
||||
)SELECT tt.ticketFk,
|
||||
FIND_IN_SET('isFreezed', t.problem) > 0 isFreezed,
|
||||
t.risk,
|
||||
FIND_IN_SET('hasRisk', t.problem) > 0 hasRisk,
|
||||
FIND_IN_SET('hasHighRisk', t.problem) > 0 hasHighRisk,
|
||||
jgallego marked this conversation as resolved
Outdated
jgallego
commented
es posible que el if sobre si true es true, asignau directament no? es posible que el if sobre si true es true, asignau directament no?
|
||||
FIND_IN_SET('hasTicketRequest', t.problem) > 0 hasTicketRequest,
|
||||
FIND_IN_SET('isTaxDataChecked', t.problem) > 0 isTaxDataChecked,
|
||||
FIND_IN_SET('isTooLittle', t.problem) > 0
|
||||
AND util.VN_NOW() < (util.VN_CURDATE() +
|
||||
INTERVAL HOUR(zc.`hour`) HOUR) +
|
||||
INTERVAL MINUTE(zc.`hour`) MINUTE isTooLittle,
|
||||
c.businessTypeFk = 'VIP' isVip,
|
||||
NOT (his.ticketFk IS NULL) hasItemShortage,
|
||||
NOT (hid.ticketFk IS NULL) hasItemDelay,
|
||||
NOT (hil.ticketFk IS NULL) hasItemLost,
|
||||
NOT (hcl.ticketFk IS NULL) hasComponentLack,
|
||||
jgallego marked this conversation as resolved
Outdated
jgallego
commented
aci pots posar NOT i la comparacio aci pots posar NOT i la comparacio
|
||||
NOT (hr.ticketFk IS NULL) hasRounding,
|
||||
0 totalProblems
|
||||
FROM tmp.sale_problems
|
||||
GROUP BY ticketFk;
|
||||
FROM tmp.ticket tt
|
||||
JOIN vn.ticket t ON t.id = tt.ticketFk
|
||||
JOIN vn.client c ON c.id = t.clientFk
|
||||
LEFT JOIN hasItemShortage his ON his.ticketFk = t.id
|
||||
LEFT JOIN hasItemLost hil ON hil.ticketFk = t.id
|
||||
LEFT JOIN hasRounding hr ON hr.ticketFk = t.id
|
||||
LEFT JOIN hasItemDelay hid ON hid.ticketFk = t.id
|
||||
LEFT JOIN hasComponentLack hcl ON hcl.ticketFk = t.id
|
||||
LEFT JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk
|
||||
AND zc.dated = util.VN_CURDATE()
|
||||
GROUP BY t.id;
|
||||
|
||||
UPDATE tmp.ticket_problems
|
||||
SET totalProblems = (
|
||||
(isFreezed) +
|
||||
(hasHighRisk) +
|
||||
(hasTicketRequest) +
|
||||
(!isTaxDataChecked) +
|
||||
(hasComponentLack) +
|
||||
(itemDelay IS NOT NULL) +
|
||||
(isTooLittle) +
|
||||
(itemLost IS NOT NULL) +
|
||||
(hasRounding IS NOT NULL) +
|
||||
(itemShortage IS NOT NULL) +
|
||||
(isVip)
|
||||
);
|
||||
UPDATE tmp.ticketProblems
|
||||
SET totalProblems = isFreezed + hasHighRisk + hasTicketRequest +
|
||||
isTaxDataChecked + hasComponentLack + hasItemDelay +
|
||||
isTooLittle + hasItemLost + hasRounding + hasItemShortage + isVip;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.sale_problems;
|
||||
DROP TEMPORARY TABLE tmp.sale;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
-- Place your SQL code here
|
||||
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
|
||||
VALUES ('Ticket','getTicketProblems','READ','ALLOW','ROLE','employee');
|
|
@ -270,10 +270,10 @@ module.exports = Self => {
|
|||
stmts.push(`SET SESSION optimizer_search_depth = @_optimizer_search_depth`);
|
||||
|
||||
stmt = new ParameterizedSQL(`
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale_getProblems
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||
(INDEX (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT f.id ticketFk, f.clientFk, f.warehouseFk, f.shipped
|
||||
SELECT f.id ticketFk
|
||||
FROM tmp.filter f
|
||||
LEFT JOIN alertLevel al ON al.id = f.alertLevel
|
||||
WHERE (al.code = 'FREE' OR f.alertLevel IS NULL)
|
||||
|
@ -294,7 +294,7 @@ module.exports = Self => {
|
|||
stmts.push('CALL ticket_getWarnings()');
|
||||
|
||||
stmt = new ParameterizedSQL(`
|
||||
UPDATE tmp.ticket_problems
|
||||
UPDATE tmp.ticketProblems
|
||||
SET risk = IF(hasRisk, risk, 0)
|
||||
`);
|
||||
stmts.push(stmt);
|
||||
|
@ -302,7 +302,7 @@ module.exports = Self => {
|
|||
stmt = new ParameterizedSQL(`
|
||||
SELECT *
|
||||
FROM tmp.filter f
|
||||
LEFT JOIN tmp.ticket_problems tp ON tp.ticketFk = f.id
|
||||
LEFT JOIN tmp.ticketProblems tp ON tp.ticketFk = f.id
|
||||
LEFT JOIN tmp.ticket_warnings tw ON tw.ticketFk = f.id
|
||||
`);
|
||||
stmts.push(stmt);
|
||||
|
@ -319,8 +319,8 @@ module.exports = Self => {
|
|||
{'tp.hasRisk': true},
|
||||
{'tp.hasTicketRequest': true},
|
||||
{'tp.hasComponentLack': true},
|
||||
{'tp.isTaxDataChecked': false},
|
||||
{'tp.itemShortage': {neq: null}},
|
||||
{'tp.isTaxDataChecked': true},
|
||||
{'tp.hasItemShortage': true},
|
||||
{'tp.isTooLittle': true}
|
||||
]};
|
||||
} else if (hasProblems === false) {
|
||||
|
@ -329,8 +329,8 @@ module.exports = Self => {
|
|||
{'tp.hasRisk': false},
|
||||
{'tp.hasTicketRequest': false},
|
||||
{'tp.hasComponentLack': false},
|
||||
{'tp.isTaxDataChecked': true},
|
||||
{'tp.itemShortage': null},
|
||||
{'tp.isTaxDataChecked': false},
|
||||
{'tp.hasItemShortage': false},
|
||||
{'tp.isTooLittle': false}
|
||||
]};
|
||||
}
|
||||
|
@ -404,9 +404,9 @@ module.exports = Self => {
|
|||
|
||||
stmts.push(`
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.ticket,
|
||||
tmp.filter,
|
||||
tmp.ticket_problems,
|
||||
tmp.sale_getProblems,
|
||||
tmp.ticketProblems,
|
||||
tmp.sale_getWarnings,
|
||||
tmp.ticket_warnings
|
||||
`);
|
||||
|
|
|
@ -68,7 +68,7 @@ describe('SalesMonitor salesFilter()', () => {
|
|||
const filter = {};
|
||||
const result = await models.SalesMonitor.salesFilter(ctx, filter, options);
|
||||
|
||||
expect(result.length).toEqual(4);
|
||||
expect(result.length).toEqual(5);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
|
|
|
@ -302,21 +302,17 @@ module.exports = Self => {
|
|||
stmts.push(stmt);
|
||||
|
||||
stmt = new ParameterizedSQL(`
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale_getProblems
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||
(INDEX (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT f.id ticketFk, f.clientFk, f.warehouseFk, f.shipped
|
||||
FROM tmp.filter f
|
||||
LEFT JOIN alertLevel al ON al.id = f.alertLevel
|
||||
WHERE (al.code = 'FREE' OR f.alertLevel IS NULL)
|
||||
AND f.shipped >= ?
|
||||
`, [date]);
|
||||
SELECT f.id ticketFk
|
||||
FROM tmp.filter f`);
|
||||
jgallego
commented
ací que lleves el where no se dir si esta be o no, asegurat tu. ací que lleves el where no se dir si esta be o no, asegurat tu.
carlosap
commented
Ja porta els filtros de fecha y estado la taula tmp.filter Ja porta els filtros de fecha y estado la taula tmp.filter
|
||||
|
||||
stmts.push(stmt);
|
||||
stmts.push('CALL ticket_getProblems(FALSE)');
|
||||
|
||||
stmt = new ParameterizedSQL(`
|
||||
UPDATE tmp.ticket_problems
|
||||
UPDATE tmp.ticketProblems
|
||||
SET risk = IF(hasRisk, risk, 0)
|
||||
`);
|
||||
stmts.push(stmt);
|
||||
|
@ -324,43 +320,19 @@ module.exports = Self => {
|
|||
stmt = new ParameterizedSQL(`
|
||||
SELECT f.*, tp.*
|
||||
FROM tmp.filter f
|
||||
LEFT JOIN tmp.ticket_problems tp ON tp.ticketFk = f.id
|
||||
LEFT JOIN tmp.ticketProblems tp ON tp.ticketFk = f.id
|
||||
`);
|
||||
|
||||
if (args.problems != undefined && (!args.from && !args.to))
|
||||
throw new UserError('Choose a date range or days forward');
|
||||
|
||||
let condition;
|
||||
let hasProblem;
|
||||
let range;
|
||||
let hasWhere;
|
||||
switch (args.problems) {
|
||||
case true:
|
||||
condition = `or`;
|
||||
hasProblem = true;
|
||||
range = {neq: null};
|
||||
hasWhere = true;
|
||||
break;
|
||||
|
||||
case false:
|
||||
condition = `and`;
|
||||
hasProblem = null;
|
||||
range = null;
|
||||
hasWhere = true;
|
||||
break;
|
||||
if (typeof args.problems == 'boolean') {
|
||||
let condition = 0;
|
||||
if (args.problems)
|
||||
condition = {neq: condition};
|
||||
stmt.merge(conn.makeWhere({'tp.totalProblems': condition}));
|
||||
}
|
||||
|
||||
const problems = {[condition]: [
|
||||
{'tp.isFreezed': hasProblem},
|
||||
{'tp.hasRisk': hasProblem},
|
||||
{'tp.hasTicketRequest': hasProblem},
|
||||
{'tp.itemShortage': range},
|
||||
{'tp.hasRounding': hasProblem}
|
||||
]};
|
||||
|
||||
if (hasWhere)
|
||||
stmt.merge(conn.makeWhere(problems));
|
||||
|
||||
if (filter.order) {
|
||||
if (typeof filter.order == 'string') filter.order = [filter.order];
|
||||
const index = filter.order.findIndex(o => o.includes('stateFk'));
|
||||
|
@ -379,8 +351,9 @@ module.exports = Self => {
|
|||
|
||||
stmts.push(
|
||||
`DROP TEMPORARY TABLE
|
||||
tmp.ticket,
|
||||
tmp.filter,
|
||||
tmp.ticket_problems`);
|
||||
tmp.ticketProblems`);
|
||||
|
||||
const sql = ParameterizedSQL.join(stmts, ';');
|
||||
const result = await conn.executeStmt(sql, myOptions);
|
||||
|
|
|
@ -98,14 +98,9 @@ module.exports = Self => {
|
|||
|
||||
for (let sale of sales) {
|
||||
const problems = saleProblems.get(sale.id);
|
||||
const itemStock = itemAvailable.get(sale.itemFk);
|
||||
sale.available = itemStock.available;
|
||||
sale.visible = itemStock.visible;
|
||||
sale.claim = claimedSales.get(sale.id);
|
||||
if (problems) {
|
||||
sale.itemShortage = problems.itemShortage;
|
||||
sale.hasTicketRequest = problems.hasTicketRequest;
|
||||
sale.hasComponentLack = problems.hasComponentLack;
|
||||
for (const problem in problems)
|
||||
sale[problem] = problems[problem];
|
||||
alexm
commented
Podriem ficarli una anidacio Si voleu com esta avisam i la aprove Podriem ficarli una anidacio
`sale.problems[problem]`
Aixina en el front sols hi ha q recorrers ixa propietat encomter de totes les de sale
Si voleu com esta avisam i la aprove
|
||||
}
|
||||
if (salesWithLogs.includes(sale.id))
|
||||
sale.$hasLogs = true;
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
const {buildFilter} = require('vn-loopback/util/filter');
|
||||
|
||||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('getTicketProblems', {
|
||||
description: 'Get problems for a ticket',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The ticket id',
|
||||
http: {source: 'path'}
|
||||
}],
|
||||
returns: {
|
||||
type: ['object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/getTicketProblems`,
|
||||
verb: 'get'
|
||||
}
|
||||
});
|
||||
|
||||
Self.getTicketProblems = async(ctx, id, options) => {
|
||||
const myOptions = {};
|
||||
const stmts = [];
|
||||
const conn = Self.dataSource.connector;
|
||||
let stmt;
|
||||
const ticketId = id;
|
||||
const where = buildFilter(ctx.args, param => {
|
||||
switch (param) {
|
||||
case 'id':
|
||||
return {'t.id': ticketId};
|
||||
}
|
||||
});
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
stmt = new ParameterizedSQL(`
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.filter
|
||||
(INDEX (id))
|
||||
ENGINE = MEMORY
|
||||
SELECT t.id
|
||||
FROM ticket t
|
||||
`);
|
||||
|
||||
stmt.merge(conn.makeWhere(where));
|
||||
stmts.push(stmt);
|
||||
|
||||
stmt = new ParameterizedSQL(`
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||
(INDEX (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT f.id AS ticketFk
|
||||
FROM tmp.filter f
|
||||
`);
|
||||
stmts.push(stmt);
|
||||
|
||||
stmts.push('CALL ticket_getProblems(FALSE)');
|
||||
|
||||
stmt = new ParameterizedSQL(`
|
||||
SELECT f.*, tp.*
|
||||
FROM tmp.filter f
|
||||
LEFT JOIN tmp.ticketProblems tp ON tp.ticketFk = f.id
|
||||
`);
|
||||
const ticketsIndex = stmts.push(stmt) - 1;
|
||||
|
||||
stmts.push(`
|
||||
DROP TEMPORARY TABLE IF EXISTS
|
||||
tmp.filter,
|
||||
tmp.ticket,
|
||||
tmp.ticketProblems
|
||||
`);
|
||||
|
||||
const sql = ParameterizedSQL.join(stmts, ';');
|
||||
const result = await conn.executeStmt(sql, myOptions);
|
||||
|
||||
return result[ticketsIndex];
|
||||
};
|
||||
};
|
|
@ -146,10 +146,10 @@ module.exports = Self => {
|
|||
stmts.push(stmt);
|
||||
|
||||
stmt = new ParameterizedSQL(`
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale_getProblems
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||
(INDEX (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT f.id ticketFk, f.clientFk, f.warehouseFk, f.shipped, f.lines, f.liters
|
||||
SELECT f.id ticketFk
|
||||
FROM tmp.filter f
|
||||
LEFT JOIN alertLevel al ON al.id = f.alertLevel
|
||||
WHERE (al.code = 'FREE' OR f.alertLevel IS NULL)
|
||||
|
@ -159,7 +159,7 @@ module.exports = Self => {
|
|||
stmts.push('CALL ticket_getProblems(FALSE)');
|
||||
|
||||
stmt = new ParameterizedSQL(`
|
||||
UPDATE tmp.ticket_problems
|
||||
UPDATE tmp.ticketProblems
|
||||
SET risk = IF(hasRisk, risk, 0)
|
||||
`);
|
||||
stmts.push(stmt);
|
||||
|
@ -167,7 +167,7 @@ module.exports = Self => {
|
|||
stmt = new ParameterizedSQL(`
|
||||
SELECT f.*, tp.*
|
||||
FROM tmp.filter f
|
||||
LEFT JOIN tmp.ticket_problems tp ON tp.ticketFk = f.id
|
||||
LEFT JOIN tmp.ticketProblems tp ON tp.ticketFk = f.id
|
||||
`);
|
||||
|
||||
if (args.problems != undefined && (!args.originScopeDays && !args.futureScopeDays))
|
||||
|
@ -175,20 +175,17 @@ module.exports = Self => {
|
|||
|
||||
let condition;
|
||||
let hasProblem;
|
||||
let range;
|
||||
let hasWhere;
|
||||
switch (args.problems) {
|
||||
case true:
|
||||
condition = `or`;
|
||||
hasProblem = true;
|
||||
range = {neq: null};
|
||||
hasWhere = true;
|
||||
break;
|
||||
|
||||
case false:
|
||||
condition = `and`;
|
||||
hasProblem = null;
|
||||
range = null;
|
||||
hasWhere = true;
|
||||
break;
|
||||
}
|
||||
|
@ -198,7 +195,7 @@ module.exports = Self => {
|
|||
{'tp.isFreezed': hasProblem},
|
||||
{'tp.hasRisk': hasProblem},
|
||||
{'tp.hasTicketRequest': hasProblem},
|
||||
{'tp.itemShortage': range},
|
||||
{'tp.hasItemShortage': hasProblem},
|
||||
{'tp.hasComponentLack': hasProblem},
|
||||
{'tp.isTooLittle': hasProblem},
|
||||
{'tp.hasRounding': hasProblem}
|
||||
|
@ -216,8 +213,9 @@ module.exports = Self => {
|
|||
|
||||
stmts.push(
|
||||
`DROP TEMPORARY TABLE
|
||||
tmp.ticket,
|
||||
tmp.filter,
|
||||
tmp.ticket_problems`);
|
||||
tmp.ticketProblems`);
|
||||
|
||||
const sql = ParameterizedSQL.join(stmts, ';');
|
||||
const result = await conn.executeStmt(sql, myOptions);
|
||||
|
|
|
@ -42,11 +42,11 @@ describe('ticket filter()', () => {
|
|||
const result = await models.Ticket.filter(ctx, filter, options);
|
||||
|
||||
const hasProblemTicket = result.some(ticket =>
|
||||
ticket.isFreezed === true ||
|
||||
ticket.hasRisk === true ||
|
||||
ticket.hasTicketRequest === true ||
|
||||
(typeof ticket.hasRounding === 'string' && ticket.hasRounding.trim().length > 0) ||
|
||||
(typeof ticket.itemShortage === 'string' && ticket.itemShortage.trim().length > 0)
|
||||
ticket.isFreezed == true ||
|
||||
ticket.hasRisk == true ||
|
||||
ticket.hasTicketRequest == true ||
|
||||
ticket.hasRounding == true ||
|
||||
ticket.hasItemShortage == true
|
||||
);
|
||||
|
||||
expect(hasProblemTicket).toBe(true);
|
||||
|
@ -80,11 +80,11 @@ describe('ticket filter()', () => {
|
|||
const result = await models.Ticket.filter(ctx, filter, options);
|
||||
|
||||
result.forEach(ticket => {
|
||||
expect(ticket.isFreezed).toEqual(null);
|
||||
expect(ticket.hasRisk).toEqual(null);
|
||||
expect(ticket.hasTicketRequest).toEqual(null);
|
||||
expect(ticket.itemShortage).toEqual(null);
|
||||
expect(ticket.hasRounding).toEqual(null);
|
||||
expect(ticket.isFreezed).toEqual(0);
|
||||
expect(ticket.hasRisk).toEqual(0);
|
||||
expect(ticket.hasTicketRequest).toEqual(0);
|
||||
expect(ticket.hasItemShortage).toEqual(0);
|
||||
expect(ticket.hasRounding).toEqual(0);
|
||||
});
|
||||
|
||||
await tx.rollback();
|
||||
|
|
|
@ -15,7 +15,6 @@ describe('ticket getSales()', () => {
|
|||
expect(sales[1].item).toBeDefined();
|
||||
expect(sales[2].item).toBeDefined();
|
||||
expect(sales[3].item).toBeDefined();
|
||||
expect(sales[0].claim).toBeDefined();
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('ticket getTicketProblems()', () => {
|
||||
const ctx = {req: {accessToken: 9}};
|
||||
it('should return the problems of a ticket', async() => {
|
||||
const tx = await models.Ticket.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
const problems = await models.Ticket.getTicketProblems(ctx, 11, options);
|
||||
|
||||
expect(problems[7].totalProblems).toEqual(3);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -46,4 +46,5 @@ module.exports = function(Self) {
|
|||
require('../methods/ticket/docuwareDownload')(Self);
|
||||
require('../methods/ticket/myLastModified')(Self);
|
||||
require('../methods/ticket/setWeight')(Self);
|
||||
require('../methods/ticket/getTicketProblems')(Self);
|
||||
};
|
||||
|
|
falta vIsTodayRelative