5342-monitor.tickets_isFragile #1393

Merged
vicent merged 10 commits from 5342-monitor.tickets_isFragile into dev 2023-03-24 07:10:42 +00:00
4 changed files with 29 additions and 44 deletions
Showing only changes of commit d276c7b611 - Show all commits

View File

@ -0,0 +1,5 @@
ALTER TABLE `vn`.`itemType` ADD isFragile tinyint(1) NULL;
ALTER TABLE `vn`.`itemType` MODIFY COLUMN isFragile tinyint(1) DEFAULT 0 NOT NULL;
UPDATE `vn`.`itemType`
SET isFragile = 1
WHERE code IN ('ZKA', 'ZKE');

View File

@ -1,35 +0,0 @@
DROP PROCEDURE IF EXISTS `vn`.`sale_getWarnings`;
DELIMITER $$
$$
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`sale_getWarnings`()
BEGIN
/**
* Calcula las advertencias de cada venta para un conjunto de tickets.
*
* @table tmp.sale_getWarnings(ticketFk) Identificadores de los tickets a calcular
* @return tmp.sale_warnings
*/
DROP TEMPORARY TABLE IF EXISTS tmp.sale_warnings;
CREATE TEMPORARY TABLE tmp.sale_warnings (
ticketFk INT(11),
saleFk INT(11),
isFragile INTEGER(1) DEFAULT 0,
PRIMARY KEY (ticketFk, saleFk)
) ENGINE = MEMORY;
-- Frágil
INSERT INTO tmp.sale_warnings(ticketFk, saleFk, isFragile)
SELECT tt.ticketFk, s.id, TRUE
FROM tmp.sale_getWarnings tt
LEFT JOIN sale s ON s.ticketFk = tt.ticketFk
LEFT JOIN item i ON i.id = s.itemFk
LEFT JOIN itemType it ON it.id = i.typeFk
LEFT JOIN itemCategory ic ON ic.id = it.categoryFk
LEFT JOIN agencyMode am ON am.id = tt.agencyModeFk
LEFT JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk
WHERE dm.code IN ('AGENCY', 'DELIVERY')
AND (ic.code = 'plant' OR it.code IN ('ZKA', 'ZKE'));
END$$
DELIMITER ;

View File

@ -11,7 +11,26 @@ BEGIN
* @table tmp.sale_getWarnings(ticketFk) Identificadores de los tickets a calcular
* @return tmp.ticket_warnings
*/
CALL sale_getWarnings();
DROP TEMPORARY TABLE IF EXISTS tmp.sale_warnings;
CREATE TEMPORARY TABLE tmp.sale_warnings (
ticketFk INT(11),
saleFk INT(11),
isFragile INTEGER(1) DEFAULT 0,
PRIMARY KEY (ticketFk, saleFk)
) ENGINE = MEMORY;
-- Frágil
INSERT INTO tmp.sale_warnings(ticketFk, saleFk, isFragile)
SELECT tt.ticketFk, s.id, TRUE
FROM tmp.sale_getWarnings tt
LEFT JOIN sale s ON s.ticketFk = tt.ticketFk
LEFT JOIN item i ON i.id = s.itemFk
LEFT JOIN itemType it ON it.id = i.typeFk
LEFT JOIN itemCategory ic ON ic.id = it.categoryFk
LEFT JOIN agencyMode am ON am.id = tt.agencyModeFk
LEFT JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk
WHERE dm.code IN ('AGENCY')
AND (ic.code = 'plant' OR it.isFragile);
DROP TEMPORARY TABLE IF EXISTS tmp.ticket_warnings;
CREATE TEMPORARY TABLE tmp.ticket_warnings
@ -19,17 +38,10 @@ BEGIN
ENGINE = MEMORY
SELECT
sw.ticketFk,
MAX(sw.isFragile) AS isFragile,
0 AS totalWarnings
MAX(sw.isFragile) AS isFragile
FROM tmp.sale_warnings sw
GROUP BY sw.ticketFk;
UPDATE tmp.ticket_warnings tw
SET tw.totalWarnings =
(
(tw.isFragile)
);
DROP TEMPORARY TABLE
tmp.sale_warnings;
END$$

View File

@ -402,6 +402,9 @@ module.exports = Self => {
tmp.filter,
tmp.ticket_problems,
tmp.sale_getProblems,
tmp.sale_warnings,
tmp.sale_getWarnings,
tmp.ticket_warnings,
tmp.risk`);
const sql = ParameterizedSQL.join(stmts, ';');