update structure db from production
gitea/salix/dev This commit looks good Details

This commit is contained in:
Bernat 2019-04-05 09:20:22 +02:00
parent 05b23127b4
commit ad830e52fc
25 changed files with 42234 additions and 44789 deletions

View File

@ -1,6 +0,0 @@
INSERT INTO `salix`.`ACL` (`id`,`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (151, 'Department','*','READ','ALLOW','ROLE','employee');
INSERT INTO `salix`.`ACL` (`id`,`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (152, 'Department','*','WRITE','ALLOW','ROLE','hr');
INSERT INTO `salix`.`ACL` (`id`,`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (153, 'Route','*','READ','ALLOW','ROLE','employee');
INSERT INTO `salix`.`ACL` (`id`,`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (154, 'Route','*','WRITE','ALLOW','ROLE','delivery');
INSERT INTO `salix`.`ACL` (`id`,`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (155, 'WorkerCalendar','*','READ','ALLOW','ROLE','hr');
INSERT INTO `salix`.`ACL` (`id`,`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (156, 'WorkerLabour','*','READ','ALLOW','ROLE','hr');

View File

@ -1,12 +0,0 @@
DROP VIEW IF EXISTS `vn`.`absenceType`;
CREATE
ALGORITHM = UNDEFINED
DEFINER = `root`@`%`
SQL SECURITY DEFINER
VIEW `vn`.`absenceType` AS
SELECT
`cs`.`calendar_state_id` AS `id`,
`cs`.`type` AS `name`,
`cs`.`rgb` AS `rgb`
FROM
`postgresql`.`calendar_state` `cs`

View File

@ -1,23 +0,0 @@
/* Ejecutar en prod * /
/* USE `vn2008`;
ALTER TABLE vn2008.department ADD `depth` int DEFAULT 0 NOT NULL;
ALTER TABLE vn2008.department ADD sons int DEFAULT 0 NOT NULL;
USE `vn`;
CREATE
OR REPLACE
VIEW `vn`.`department` AS select
`b`.`department_id` AS `id`,
`b`.`name` AS `name`,
`b`.`father_id` AS `fatherFk`,
`b`.`production` AS `isProduction`,
`b`.`lft` AS `lft`,
`b`.`rgt` AS `rgt`,
`b`.`isSelected` AS `isSelected`,
`b`.`depth` AS `depth`,
`b`.`sons` AS `sons`
from
`vn2008`.`department` `b`; */

View File

@ -1,16 +0,0 @@
DROP VIEW IF EXISTS `vn`.`labourHoliday`;
DROP VIEW IF EXISTS `vn`.`holiday`;
CREATE
OR REPLACE ALGORITHM = UNDEFINED
DEFINER = `root`@`%`
SQL SECURITY DEFINER
VIEW `vn`.`holiday` AS
SELECT
`cl`.`calendar_labour_legend_id` AS `holidayDetailFk`,
`cl`.`calendar_free_id` AS `holidayTypeFk`,
`cl`.`workcenter_id` AS `workCenterFk`,
`cl`.`day` AS `dated`
FROM
`postgresql`.`calendar_labour` `cl`;

View File

@ -1,13 +0,0 @@
DROP VIEW IF EXISTS `vn`.`labourHolidayLegend`;
DROP VIEW IF EXISTS `vn`.`holidayDetail`;
CREATE
OR REPLACE ALGORITHM = UNDEFINED
DEFINER = `root`@`%`
SQL SECURITY DEFINER
VIEW `vn`.`holidayDetail` AS
SELECT
`cll`.`calendar_labour_legend_id` AS `id`,
`cll`.`descripcion` AS `description`
FROM
`postgresql`.`calendar_labour_legend` `cll`;

View File

@ -1,14 +0,0 @@
DROP VIEW IF EXISTS `vn`.`labourHolidayType`;
DROP VIEW IF EXISTS `vn`.`holidayType`;
CREATE
OR REPLACE ALGORITHM = UNDEFINED
DEFINER = `root`@`%`
SQL SECURITY DEFINER
VIEW `vn`.`holidayType` AS
SELECT
`cf`.`calendar_free_id` AS `id`,
`cf`.`type` AS `name`,
`cf`.`rgb` AS `rgb`
FROM
`postgresql`.`calendar_free` `cf`;

View File

@ -1,12 +0,0 @@
CREATE
ALGORITHM = UNDEFINED
DEFINER = `root`@`%`
SQL SECURITY DEFINER
VIEW `account`.`emailUser` AS
SELECT
`u`.`id` AS `userFk`,
CONCAT(`u`.`name`, '@', `mc`.`domain`) AS `email`
FROM
(`account`.`user` `u`
JOIN `account`.`mailConfig` `mc`)

View File

@ -1,86 +0,0 @@
/* Ejecutar en prod * /
/* DROP PROCEDURE IF EXISTS nst.NodeAdd;
DELIMITER $$
$$
CREATE DEFINER=`root`@`%` PROCEDURE `nst`.`nodeAdd`(IN `vScheme` VARCHAR(45), IN `vTable` VARCHAR(45), IN `vParentFk` INT, IN `vChild` VARCHAR(100))
BEGIN
DECLARE vSql TEXT;
DECLARE vTableClone VARCHAR(45);
SET vTableClone = CONCAT(vTable, 'Clone');
CALL util.exec(CONCAT('DROP TEMPORARY TABLE IF EXISTS tmp.', vTableClone));
CALL util.exec(CONCAT(
'CREATE TEMPORARY TABLE tmp.', vTableClone,
' ENGINE = MEMORY'
' SELECT * FROM ', vScheme, '.', vTable
));
-- Check parent childs
SET vSql = sql_printf('
SELECT COUNT(c.id) INTO @childs
FROM %t.%t p
LEFT JOIN %t.%t c ON c.lft BETWEEN p.lft AND p.rgt AND c.id != %v
WHERE p.id = %v',
vScheme, vTable, 'tmp', vTableClone, vParentFk, vParentFk);
SET @qrySql := vSql;
PREPARE stmt FROM @qrySql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- Select left from last child
IF @childs = 0 THEN
SET vSql = sql_printf('SELECT lft INTO @vLeft FROM %t.%t WHERE id = %v', vScheme, vTable, vParentFk);
SET @qrySql := vSql;
ELSE
SET vSql = sql_printf('
SELECT c.rgt INTO @vLeft
FROM %t.%t p
JOIN %t.%t c ON c.lft BETWEEN p.lft AND p.rgt
WHERE p.id = %v
ORDER BY c.lft
DESC LIMIT 1',
vScheme, vTable, 'tmp', vTableClone, vParentFk);
SET @qrySql := vSql;
END IF;
PREPARE stmt FROM @qrySql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- Update right
SET vSql = sql_printf('UPDATE %t.%t SET rgt = rgt + 2 WHERE rgt > %v ORDER BY rgt DESC', vScheme, vTable, @vLeft);
SET @qrySql := vSql;
PREPARE stmt FROM @qrySql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET vSql = sql_printf('UPDATE %t.%t SET lft = lft + 2 WHERE lft > %v ORDER BY lft DESC', vScheme, vTable, @vLeft);
SET @qrySql := vSql;
PREPARE stmt FROM @qrySql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- Escape character
SET vChild = REPLACE(vChild, "'", "\\'");
-- Add child
SET vSql = sql_printf('INSERT INTO %t.%t (name, lft, rgt) VALUES (%v, %v, %v)', vScheme, vTable, vChild, @vLeft + 1, @vLeft + 2);
SET @qrySql := vSql;
PREPARE stmt FROM @qrySql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SELECT id, name, lft, rgt, depth, sons FROM vn.department
WHERE id = LAST_INSERT_ID();
CALL util.exec(CONCAT('DROP TEMPORARY TABLE tmp.', vTableClone));
END$$
DELIMITER ;
*/

View File

@ -1,31 +0,0 @@
/* Ejecutar en prod * /
/* DROP PROCEDURE IF EXISTS nst.nodeRecalc;
DELIMITER $$
$$
CREATE DEFINER=`root`@`%` PROCEDURE `nst`.`nodeRecalc`(IN `vScheme` VARCHAR(45), IN `vTable` VARCHAR(45))
BEGIN
CALL util.exec (sql_printf (
'UPDATE %t.%t d
JOIN (SELECT
node.id,
COUNT(parent.id) - 1 as depth,
cast((node.rgt - node.lft - 1) / 2 as DECIMAL) as sons
FROM
%t.%t AS node,
%t.%t AS parent
WHERE node.lft BETWEEN parent.lft AND parent.rgt
GROUP BY node.id
ORDER BY node.lft) n ON n.id = d.id
SET d.`depth` = n.depth, d.sons = n.sons',
vScheme,
vTable,
vScheme,
vTable,
vScheme,
vTable
));
END$$
DELIMITER ;
*/

View File

@ -1,24 +0,0 @@
DROP procedure IF EXISTS `vn`.`routeGuessPriority`;
DELIMITER $$
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`routeGuessPriority`(IN vRuta INT)
BEGIN
/* Usa los valores del ultimo año para adivinar el orden de los tickets en la ruta
* vRuta id ruta
*/
UPDATE ticket mt
JOIN (
SELECT tt.addressFk, ROUND(IFNULL(AVG(t.priority),0),0) AS priority
FROM ticket t
JOIN ticket tt ON tt.addressFk = t.addressFk
WHERE t.shipped > TIMESTAMPADD(YEAR,-1,CURDATE())
AND tt.routeFk = vRuta
GROUP BY addressFk
) sub ON sub.addressFk = mt.addressFk
SET mt.priority = sub.priority
WHERE mt.routeFk = vRuta;
END$$
DELIMITER ;

View File

@ -1,72 +0,0 @@
USE `vn`;
DROP procedure IF EXISTS `ticketCalculateSale`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`%` PROCEDURE `ticketCalculateSale`(IN vSale BIGINT)
proc: BEGIN
/*
Este procedimiento bioniza una linea de movimiento
*/
DECLARE vShipped DATE;
DECLARE vWarehouse SMALLINT;
DECLARE vAgencyMode INT;
DECLARE vAddress INT;
DECLARE vTicket BIGINT;
DECLARE vItem BIGINT;
DECLARE vLanded DATE;
DECLARE vTicketFree BOOLEAN DEFAULT TRUE;
SELECT FALSE
INTO vTicketFree
FROM vn.ticket t
JOIN vn.sale s ON s.ticketFk = t.id
LEFT JOIN vn.ticketState ts ON ts.ticketFk = t.id
WHERE s.id = vSale
AND (t.refFk != "" OR (ts.alertLevel > 0 AND s.price != 0))
LIMIT 1;
SELECT ticketFk, itemFk
INTO vTicket, vItem
FROM sale
WHERE id = vSale;
SELECT t.warehouseFk, DATE(t.shipped), t.addressFk, t.agencyModeFk, t.landed
INTO vWarehouse, vShipped, vAddress, vAgencyMode, vLanded
FROM agencyMode a
JOIN ticket t ON t.agencyModeFk = a.id
WHERE t.id = vTicket;
DROP TEMPORARY TABLE IF EXISTS tmp.agencyHourGetShipped;
CREATE TEMPORARY TABLE tmp.agencyHourGetShipped ENGINE = MEMORY
SELECT vWarehouse warehouseFk, vShipped shipped, vLanded landed;
CALL buyUltimate (vWarehouse, vShipped); -- rellena la tabla tmp.buyUltimate con la ultima compra
DELETE FROM tmp.buyUltimate WHERE itemFk != vItem;
DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot;
CREATE TEMPORARY TABLE tmp.ticketLot
SELECT vWarehouse warehouseFk, NULL available, vItem itemFk, buyFk
FROM tmp.buyUltimate
WHERE itemFk = vItem;
CALL ticketComponentCalculate(vAddress, vAgencyMode);
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
CREATE TEMPORARY TABLE tmp.sale
(PRIMARY KEY (saleFk)) ENGINE = MEMORY
SELECT vSale saleFk,vWarehouse warehouseFk;
CALL ticketComponentUpdateSale(IF(vTicketFree,1,6)); -- si el ticket esta facturado, respeta los precios
-- Log
INSERT INTO vn.ticketLog (originFk, userFk, `action`, description)
VALUES (vTicket, account.userGetId(), 'update', CONCAT('Bionizo linea id ', vSale));
-- Limpieza
DROP TEMPORARY TABLE tmp.buyUltimate;
END$$
DELIMITER ;

View File

@ -1,42 +0,0 @@
USE `vn`;
DROP procedure IF EXISTS `ticketComponentMakeUpdate`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketComponentMakeUpdate`(
vTicketFk INT,
vClientFk INT,
vAgencyModeFk INT,
vAddressFk INT,
vWarehouseFk TINYINT,
vCompanyFk SMALLINT,
vShipped DATETIME,
vLanded DATE,
vIsDeleted BOOLEAN,
vHasToBeUnrouted BOOLEAN,
vOption INT)
BEGIN
CALL vn.ticketComponentPreview (vTicketFk, vLanded, vAddressFk, vAgencyModeFk, vWarehouseFk);
CALL vn.ticketComponentUpdate (
vTicketFk,
vClientFk,
vAgencyModeFk,
vAddressFk,
vWarehouseFk,
vCompanyFk,
vShipped,
vLanded,
vIsDeleted,
vHasToBeUnrouted,
vOption
);
DROP TEMPORARY TABLE
tmp.ticketComponent,
tmp.ticketComponentPrice;
END$$
DELIMITER ;

View File

@ -1,134 +0,0 @@
USE `vn`;
DROP procedure IF EXISTS `ticketComponentPreview`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentPreview`(
vTicketFk INT,
vLanded DATE,
vAddressFk INT,
vAgencyModeFk INT,
vWarehouseFk SMALLINT)
BEGIN
/**
* Devuelve un listado previo de
* componentes para un ticket
*
* @param vTicketFk Id del ticket
* @param vLanded Fecha de recepcion
* @param vAddressFk Id del consignatario
* @param vAgencyModeFk Id del modo de agencia
* @param vWarehouseFk Id del almacén
*/
DECLARE vAgencyFk INT;
DECLARE vShipped DATE;
DECLARE vBuyOrderItem INT DEFAULT 100;
DECLARE vHasDataChanged BOOL DEFAULT FALSE;
DECLARE vHasAddressChanged BOOL;
DECLARE vHasAgencyModeChanged BOOL DEFAULT FALSE;
DECLARE vHasWarehouseChanged BOOL DEFAULT FALSE;
DECLARE vAddressTypeRateFk INT DEFAULT NULL;
DECLARE vAgencyModeTypeRateFk INT DEFAULT NULL;
DECLARE vHasChangeAll BOOL DEFAULT FALSE;
SELECT DATE(landed) <> vLanded,
addressFk <> vAddressFk,
agencyModeFk <> vAgencyModeFk,
warehouseFk <> vWarehouseFk
INTO
vHasDataChanged,
vHasAddressChanged,
vHasAgencyModeChanged,
vHasWarehouseChanged
FROM vn.ticket t
WHERE t.id = vTicketFk;
/*SELECT vHasDataChanged,
vHasAddressChanged,
vHasAgencyModeChanged,
vHasWarehouseChanged;
*/
IF vHasDataChanged OR vHasWarehouseChanged THEN
SET vHasChangeAll = TRUE;
END IF;
IF vHasAddressChanged THEN
SET vAddressTypeRateFk = 5;
END IF;
IF vHasAgencyModeChanged THEN
SET vAgencyModeTypeRateFk = 6;
END IF;
SELECT agencyFk INTO vAgencyFk
FROM agencyMode
WHERE id = vAgencyModeFk;
CALL agencyHourGetShipped(vLanded, vAddressFk, vAgencyFk);
SELECT shipped INTO vShipped
FROM tmp.agencyHourGetShipped
WHERE warehouseFk = vWarehouseFk;
CALL buyUltimate(vWarehouseFk, vShipped);
DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot;
CREATE TEMPORARY TABLE tmp.ticketLot ENGINE = MEMORY (
SELECT
vWarehouseFk AS warehouseFk,
NULL AS available,
s.itemFk,
bu.buyFk
FROM sale s
LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
WHERE s.ticketFk = vTicketFk
AND s.itemFk != vBuyOrderItem
GROUP BY bu.warehouseFk, bu.itemFk);
CALL ticketComponentCalculate(vAddressFk, vAgencyModeFk);
/*SELECT *,vHasChangeAll,cr.isRenewable = FALSE,vHasChangeAll,
NOT (cr.componentTypeRate <=> vAddressTypeRateFk),NOT (cr.componentTypeRate <=> vAgencyModeTypeRateFk),
NOT (cr.componentTypeRate <=> vAddressTypeRateFk) OR NOT (cr.componentTypeRate <=> vAgencyModeTypeRateFk)
FROM saleComponent sc
JOIN sale s ON s.id = sc.saleFk
JOIN ticket t ON t.id = s.ticketFk
JOIN componentRate cr ON cr.id = sc.componentFk
WHERE s.ticketFk = vTicketFk
AND (cr.isRenewable = FALSE
OR
(NOT vHasChangeAll
AND (NOT (cr.componentTypeRate <=> vAddressTypeRateFk
OR cr.componentTypeRate <=> vAgencyModeTypeRateFk))));*/
/*SELECT * FROM tmp.ticketComponent;*/
-- Inserta los componentes que NO seran modificados
REPLACE INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost)
SELECT t.warehouseFk, s.itemFk, sc.componentFk, sc.value
FROM saleComponent sc
JOIN sale s ON s.id = sc.saleFk
JOIN ticket t ON t.id = s.ticketFk
JOIN componentRate cr ON cr.id = sc.componentFk
WHERE s.ticketFk = vTicketFk
AND (cr.isRenewable = FALSE
OR
(NOT vHasChangeAll
AND (NOT (cr.componentTypeRate <=> vAddressTypeRateFk
OR cr.componentTypeRate <=> vAgencyModeTypeRateFk))));
/*SELECT * FROM tmp.ticketComponent;*/
SET @shipped = vShipped;
DROP TEMPORARY TABLE
tmp.agencyHourGetShipped,
tmp.buyUltimate,
tmp.ticketLot;
IF IFNULL(vShipped, CURDATE() - 1) < CURDATE() THEN
CALL util.throw('NO_AGENCY_AVAILABLE');
END IF;
END$$
DELIMITER ;

View File

@ -1,62 +0,0 @@
USE `vn`;
DROP procedure IF EXISTS `ticketComponentUpdate`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentUpdate`(
vTicketFk INT,
vClientFk INT,
vAgencyModeFk INT,
vAddressFk INT,
vWarehouseFk TINYINT,
vCompanyFk SMALLINT,
vShipped DATETIME,
vLanded DATE,
vIsDeleted BOOLEAN,
vHasToBeUnrouted BOOLEAN,
vOption INT)
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
RESIGNAL;
END;
START TRANSACTION;
UPDATE ticket t
SET
t.clientFk = vClientFk,
t.agencyModeFk = vAgencyModeFk,
t.addressFk = vAddressFk,
t.warehouseFk = vWarehouseFk,
t.companyFk = vCompanyFk,
t.landed = vLanded,
t.shipped = vShipped,
t.isDeleted = vIsDeleted
WHERE
t.id = vTicketFk;
IF vHasToBeUnrouted THEN
UPDATE ticket t SET t.routeFk = NULL
WHERE t.id = vTicketFk;
END IF;
IF vOption <> 8 THEN
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
CREATE TEMPORARY TABLE tmp.sale
(PRIMARY KEY (saleFk))
ENGINE = MEMORY
SELECT id AS saleFk, vWarehouseFk warehouseFk
FROM sale s WHERE s.ticketFk = vTicketFk;
CALL ticketComponentUpdateSale (vOption);
DROP TEMPORARY TABLE tmp.sale;
END IF;
COMMIT;
END$$
DELIMITER ;

View File

@ -1,165 +0,0 @@
USE `vn`;
DROP procedure IF EXISTS `ticketGetProblems`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`%` PROCEDURE `ticketGetProblems`()
BEGIN
/**
* Obtiene los problemas de uno o varios tickets
*
* @table tmp.ticketGetProblems(ticketFk, clientFk, warehouseFk, shipped)
* @return tmp.ticketProblems
*/
DECLARE vWarehouse INT;
DECLARE vDate DATE;
DECLARE vAvailableCache INT;
DECLARE vVisibleCache INT;
DECLARE vDone INT DEFAULT 0;
DECLARE vCursor CURSOR FOR
SELECT DISTINCT tt.warehouseFk, date(tt.shipped)
FROM tmp.ticketGetProblems tt
WHERE DATE(tt.shipped) BETWEEN CURDATE()
AND TIMESTAMPADD(DAY, 1.9, CURDATE());
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = 1;
DROP TEMPORARY TABLE IF EXISTS tmp.ticketProblems;
CREATE TEMPORARY TABLE tmp.ticketProblems (
ticketFk INT(11) PRIMARY KEY,
isFreezed INTEGER(1) DEFAULT 0,
risk DECIMAL(10,2) DEFAULT 0,
hasTicketRequest INTEGER(1) DEFAULT 0,
isAvailable INTEGER(1) DEFAULT 1
) ENGINE = MEMORY;
DROP TEMPORARY TABLE IF EXISTS tmp.ticketList;
CREATE TEMPORARY TABLE tmp.ticketList
(PRIMARY KEY (ticketFk))
ENGINE = MEMORY
SELECT tp.ticketFk, c.id clientFk
FROM tmp.ticketGetProblems tp
JOIN vn.client c ON c.id = tp.clientFk;
-- Inserta tickets de clientes congelados
INSERT INTO tmp.ticketProblems(ticketFk, isFreezed)
SELECT DISTINCT tl.ticketFk, 1
FROM tmp.ticketList tl
JOIN vn.client c ON c.id = tl.clientFk
WHERE c.isFreezed;
DELETE tl FROM tmp.ticketList tl
JOIN tmp.ticketProblems tp ON tl.ticketFk = tp.ticketFk;
DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt;
CREATE TEMPORARY TABLE tmp.clientGetDebt
(PRIMARY KEY (clientFk))
ENGINE = MEMORY
SELECT DISTINCT clientFk
FROM tmp.ticketList;
CALL clientGetDebt(CURDATE());
-- Inserta tickets de clientes con riesgo
INSERT INTO tmp.ticketProblems(ticketFk, risk)
SELECT DISTINCT tl.ticketFk, r.risk
FROM tmp.ticketList tl
JOIN vn.ticket t ON t.id = tl.ticketFk
JOIN vn.agencyMode a ON t.agencyModeFk = a.id
JOIN tmp.risk r ON r.clientFk = t.clientFk
JOIN vn.client c ON c.id = t.clientFk
WHERE r.risk > c.credit + 10
AND a.deliveryMethodFk != 3
ON DUPLICATE KEY UPDATE
risk = r.risk;
DELETE tl FROM tmp.ticketList tl
JOIN tmp.ticketProblems tp ON tl.ticketFk = tp.ticketFk;
-- Inserta tickets que tengan codigos 100
INSERT INTO tmp.ticketProblems(ticketFk, hasTicketRequest)
SELECT DISTINCT tl.ticketFk, 1
FROM tmp.ticketList tl
JOIN vn.ticketRequest tr ON tr.ticketFk = tl.ticketFk
WHERE tr.isOK IS NULL
ON DUPLICATE KEY UPDATE
hasTicketRequest = 1;
DELETE tl FROM tmp.ticketList tl
JOIN tmp.ticketProblems tp ON tl.ticketFk = tp.ticketFk;
OPEN vCursor;
WHILE NOT vDone
DO
FETCH vCursor INTO vWarehouse, vDate;
CALL cache.visible_refresh(vVisibleCache, FALSE, vWarehouse);
CALL cache.available_refresh(vAvailableCache, FALSE, vWarehouse, vDate);
-- Inserta tickets con articulos que no tegan disponible
INSERT INTO tmp.ticketProblems(ticketFk, isAvailable)
SELECT tl.ticketFk, 0
FROM tmp.ticketList tl
JOIN vn.ticket t ON t.id = tl.ticketFk
LEFT JOIN vn.sale s ON s.ticketFk = t.id
JOIN vn.item i ON i.id = s.itemFk
JOIN vn.itemType it on it.id = i.typeFk
LEFT JOIN cache.visible v ON i.id = v.item_id
AND v.calc_id = vVisibleCache
LEFT JOIN cache.available av ON av.item_id = i.id
AND av.calc_id = vAvailableCache
WHERE date(t.shipped) = vDate
AND categoryFk != 6
AND s.quantity > IFNULL(v.visible, 0)
AND IFNULL(av.available, 0) < 0
AND s.isPicked = FALSE
AND NOT i.generic
AND vWarehouse = t.warehouseFk
GROUP BY tl.ticketFk
ON DUPLICATE KEY UPDATE
isAvailable = 0;
DELETE tl FROM tmp.ticketList tl
JOIN tmp.ticketProblems tp ON tl.ticketFk = tp.ticketFk;
INSERT INTO tmp.ticketProblems(ticketFk, isAvailable)
SELECT tl.ticketFk, 0
FROM tmp.ticketList tl
JOIN vn.ticket t ON t.id = tl.ticketFk
LEFT JOIN vn.sale s ON s.ticketFk = t.id
JOIN vn.item i ON i.id = s.itemFk
JOIN vn.itemType it on it.id = i.typeFk
LEFT JOIN cache.visible v ON i.id = v.item_id AND v.calc_id = vVisibleCache
LEFT JOIN cache.available av ON av.item_id = i.id AND av.calc_id = vAvailableCache
WHERE IFNULL(av.available, 0) >= 0
AND s.quantity > IFNULL(v.visible, 0)
AND s.isPicked = FALSE
AND s.reserved = FALSE
AND it.categoryFk != 6
AND date(t.shipped) = vDate
AND NOT i.generic
AND CURDATE() = vDate
AND t.warehouseFk = vWarehouse
GROUP BY tl.ticketFk
ON DUPLICATE KEY UPDATE
isAvailable = 0;
DELETE tl FROM tmp.ticketList tl
JOIN tmp.ticketProblems tp ON tl.ticketFk = tp.ticketFk;
END WHILE;
CLOSE vCursor;
SELECT * FROM tmp.ticketProblems;
DROP TEMPORARY TABLE
tmp.clientGetDebt,
tmp.ticketList;
END$$
DELIMITER ;

View File

@ -1,39 +0,0 @@
USE `vn`;
DROP procedure IF EXISTS `ticketGetVisibleAvailable`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`%` PROCEDURE `ticketGetVisibleAvailable`(
vTicket INT)
BEGIN
DECLARE vVisibleCalc INT;
DECLARE vAvailableCalc INT;
DECLARE vShipped DATE;
DECLARE vWarehouse TINYINT;
DECLARE vAlertLevel INT;
SELECT t.warehouseFk, t.shipped, ts.alertLevel INTO vWarehouse, vShipped, vAlertLevel
FROM ticket t
LEFT JOIN ticketState ts ON ts.ticketFk = vTicket
WHERE t.id = vTicket;
IF vAlertLevel IS NULL OR vAlertLevel = 0 THEN
IF vShipped >= CURDATE() THEN
CALL cache.available_refresh(vAvailableCalc, FALSE, vWarehouse, vShipped);
END IF;
IF vShipped = CURDATE() THEN
CALL cache.visible_refresh(vVisibleCalc, FALSE, vWarehouse);
END IF;
END IF;
SELECT s.id, s.itemFk, s.quantity, s.concept, s.price, s.reserved, s.discount, v.visible, av.available, it.image, it.subName
FROM sale s
LEFT JOIN cache.visible v ON v.item_id = s.itemFk AND v.calc_id = vVisibleCalc
LEFT JOIN cache.available av ON av.item_id = s.itemFk AND av.calc_id = vAvailableCalc
LEFT JOIN item it ON it.id = s.itemFk
WHERE s.ticketFk = vTicket
ORDER BY s.concept;
END$$
DELIMITER ;

View File

@ -1 +0,0 @@
ALTER TABLE vn.itemLog MODIFY COLUMN userFk int(10) unsigned NULL;

View File

@ -1,11 +0,0 @@
DROP VIEW IF EXISTS `vn`.`workCenterHoliday`;
CREATE
ALGORITHM = UNDEFINED
DEFINER = `root`@`%`
SQL SECURITY DEFINER
VIEW `vn`.`workCenterHoliday` AS
SELECT
`wh`.`workcenter_id` AS `workCenterFk`,
`wh`.`day` AS `days`,
`wh`.`year` AS `year`
FROM `vn2008`.`workcenter_holiday` `wh`

View File

@ -1,16 +0,0 @@
DROP VIEW IF EXISTS `vn`.`workerCalendar`;
CREATE
ALGORITHM = UNDEFINED
DEFINER = `root`@`%`
SQL SECURITY DEFINER
VIEW `vn`.`workerCalendar` AS
SELECT
`ce`.`business_id` AS `businessFk`,
`p`.`id_trabajador` AS `workerFk`,
`ce`.`calendar_state_id` AS `absenceTypeFk`,
`ce`.`date` AS `dated`
FROM
(((`postgresql`.`person` `p`
JOIN `postgresql`.`profile` `pr` ON ((`pr`.`person_id` = `p`.`person_id`)))
JOIN `postgresql`.`business` `b` ON ((`b`.`client_id` = `pr`.`profile_id`)))
JOIN `postgresql`.`calendar_employee` `ce` ON ((`ce`.`business_id` = `b`.`business_id`)))

View File

@ -1,18 +0,0 @@
DROP VIEW IF EXISTS `vn`.`workerLabour`;
CREATE
ALGORITHM = UNDEFINED
DEFINER = `root`@`%`
SQL SECURITY DEFINER
VIEW `vn`.`workerLabour` AS
SELECT
`b`.`business_id` AS `businessFk`,
`p`.`id_trabajador` AS `workerFk`,
`bl`.`workcenter_id` AS `workCenterFk`,
`b`.`date_start` AS `started`,
`b`.`date_end` AS `ended`,
`d`.`id` AS `departmentFk`
FROM `postgresql`.`person` `p`
JOIN `postgresql`.`profile` `pr` ON `pr`.`person_id` = `p`.`person_id`
JOIN `postgresql`.`business` `b` ON `b`.`client_id` = `pr`.`profile_id`
JOIN `postgresql`.`business_labour` `bl` ON `b`.`business_id` = `bl`.`business_id`
JOIN `vn`.`department` `d` ON `d`.`id` = `bl`.`department_id`

File diff suppressed because one or more lines are too long

View File

@ -1223,14 +1223,6 @@ INSERT INTO `vn`.`zone` (`id`, `name`, `hour`, `warehouseFk`, `agencyModeFk`, `t
(5, 'Zone 3 A', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), '1', '1', '1', '2', '2'),
(6, 'Zone 3 B', CONCAT(CURRENT_DATE(), ' ', TIME('22:00')), '1', '1', '1', '2', '2');
INSERT INTO `vn`.`zoneGeo` (`id`, `name`, `lft`, `rgt`, `depth`, `sons`)
VALUES
('1', 'World', '1', '11', '0', '4'),
('2', 'United States of America', '2', '8', '1', '2'),
('3', 'New york', '4', '5', '2', '0'),
('4', 'Gotham', '6', '7', '2', '0'),
('5', 'Spain', '9', '10', '1', '0');
INSERT INTO `vn`.`zoneIncluded` (`zoneFk`, `geoFk`, `isIncluded`)
VALUES
(1, 3, 0),

File diff suppressed because it is too large Load Diff

View File

@ -41,6 +41,7 @@ TABLES=(
cplusTaxBreak
pgc
tag
zoneGeo
)
dump_tables ${TABLES[@]}

View File

@ -107,6 +107,7 @@ describe('Client risk path', () => {
let result = await nightmare
.clearInput(selectors.clientRisk.newPaymentAmountInput)
.write(selectors.clientRisk.newPaymentAmountInput, '-150')
.wait(1999)
.waitToClick(selectors.clientRisk.saveButton)
.waitForLastSnackbar();