From 78f3376c20f9f15a7ae07bb5511b2ac95291b09b Mon Sep 17 00:00:00 2001 From: Bernat Date: Tue, 24 Jul 2018 07:34:14 +0200 Subject: [PATCH] export production structure DB to local --- services/db/install/changes/1.0.8/01-ACL.sql | 5 - .../install/changes/1.0.8/02-alertLevel.sql | 18 - .../db/install/changes/1.0.8/03-itemDiary.sql | 105 - .../1.0.8/04-ticketComponentCalculate.sql | 294 -- .../05-ticketComponentPriceDifference.sql | 55 - .../1.0.8/06-ticketComponentUpdateSale.sql | 154 - .../1.0.8/08-ticketGetVisibleAvailable.sql | 38 - .../changes/1.0.8/09-manaSpellersRequery.sql | 61 - .../changes/1.0.8/10-triggerTicket.sql | 58 - .../changes/1.0.8/11-orderTotalVolume.sql | 20 - .../1.0.8/12-orderTotalVolumeBoxes.sql | 27 - .../changes/1.0.8/13-orderListVolume.sql | 0 services/db/install/dump/01-structure.sql | 2708 ++++++++++++----- services/db/install/dump/fixtures.sql | 10 +- services/loopback/common/models/item.json | 102 +- 15 files changed, 2017 insertions(+), 1638 deletions(-) delete mode 100644 services/db/install/changes/1.0.8/01-ACL.sql delete mode 100644 services/db/install/changes/1.0.8/02-alertLevel.sql delete mode 100644 services/db/install/changes/1.0.8/03-itemDiary.sql delete mode 100644 services/db/install/changes/1.0.8/04-ticketComponentCalculate.sql delete mode 100644 services/db/install/changes/1.0.8/05-ticketComponentPriceDifference.sql delete mode 100644 services/db/install/changes/1.0.8/06-ticketComponentUpdateSale.sql delete mode 100644 services/db/install/changes/1.0.8/08-ticketGetVisibleAvailable.sql delete mode 100644 services/db/install/changes/1.0.8/09-manaSpellersRequery.sql delete mode 100644 services/db/install/changes/1.0.8/10-triggerTicket.sql delete mode 100644 services/db/install/changes/1.0.8/11-orderTotalVolume.sql delete mode 100644 services/db/install/changes/1.0.8/12-orderTotalVolumeBoxes.sql delete mode 100644 services/db/install/changes/1.0.8/13-orderListVolume.sql diff --git a/services/db/install/changes/1.0.8/01-ACL.sql b/services/db/install/changes/1.0.8/01-ACL.sql deleted file mode 100644 index af52bf4fe..000000000 --- a/services/db/install/changes/1.0.8/01-ACL.sql +++ /dev/null @@ -1,5 +0,0 @@ -UPDATE `salix`.`ACL` SET `accessType`='*' WHERE `id`='58'; -UPDATE `salix`.`ACL` SET `accessType`='*' WHERE `id`='60'; -INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)VALUES (92, 'Sale', 'moveToNewTicket', '*', 'ALLOW', 'ROLE', 'employee'); -INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (93, 'Sale', 'reserve', '*', 'ALLOW', 'ROLE', 'employee'); -INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (94, 'Agency', 'landsThatDay', '*', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/services/db/install/changes/1.0.8/02-alertLevel.sql b/services/db/install/changes/1.0.8/02-alertLevel.sql deleted file mode 100644 index c338d681b..000000000 --- a/services/db/install/changes/1.0.8/02-alertLevel.sql +++ /dev/null @@ -1,18 +0,0 @@ -USE `vn`; - -CREATE TABLE `vn`.`alertLevel` ( - `code` VARCHAR(45) CHARACTER SET 'utf8' NOT NULL, - `alertLevel` INT(11) NOT NULL, - PRIMARY KEY (`code`)); - -ALTER TABLE `vn`.`alertLevel` -ADD CONSTRAINT `fk_code_1` - FOREIGN KEY (`code`) - REFERENCES `vn2008`.`state` (`code`) - ON DELETE CASCADE - ON UPDATE CASCADE; - -INSERT INTO `vn`.`alertLevel` (`code`, `alertLevel`) VALUES ('FREE', '0'); -INSERT INTO `vn`.`alertLevel` (`code`, `alertLevel`) VALUES ('ON_PREPARATION', '1'); -INSERT INTO `vn`.`alertLevel` (`code`, `alertLevel`) VALUES ('PACKED', '2'); -INSERT INTO `vn`.`alertLevel` (`code`, `alertLevel`) VALUES ('DELIVERED', '3'); diff --git a/services/db/install/changes/1.0.8/03-itemDiary.sql b/services/db/install/changes/1.0.8/03-itemDiary.sql deleted file mode 100644 index ca853c5af..000000000 --- a/services/db/install/changes/1.0.8/03-itemDiary.sql +++ /dev/null @@ -1,105 +0,0 @@ -USE `vn`; -DROP procedure IF EXISTS `itemDiary`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `itemDiary`(IN vItemId INT, IN vWarehouse INT) -BEGIN - DECLARE vDateInventory DATETIME; - DECLARE vCurdate DATE DEFAULT CURDATE(); - -- traduccion: date, alertLevel, origin, reference, name, In, Out, Balance - SELECT Fechainventario INTO vDateInventory FROM vn2008.tblContadores; - SET @a = 0; - SELECT DATE(date) AS date, - alertLevel, - stateName, - origin, - reference, - name, - `in`, - `out`, - @a := @a + IFNULL(`in`,0) - IFNULL(`out`,0) as balance - FROM - ( SELECT tr.landed as date, - b.quantity as `in`, - NULL as `out`, - IF(tr.isReceived != FALSE,3, IF(tr.isDelivered,1,0)) as alertLevel, - st.name AS stateName, - s.name as name, - e.ref as reference, - e.id as origin - FROM vn.buy b - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.travel tr ON tr.id = e.travelFk - JOIN vn.supplier s ON s.id = e.supplierFk - JOIN vn.alertLevel al ON al.alertLevel = - CASE - WHEN tr.isReceived != FALSE THEN 3 - WHEN tr.isDelivered THEN 1 - ELSE 0 - END - JOIN vn.state st ON st.code = al.code - WHERE tr.landed >= vDateInventory - AND vWarehouse = tr.warehouseInFk - AND b.itemFk = vItemId - AND e.isInventory = 0 - - UNION ALL - - SELECT tr.shipped as date, - NULL as `in`, - b.quantity as `out`, - IF(tr.isReceived != FALSE,3, IF(tr.isDelivered,1,0)) as alertLevel, - st.name AS stateName, - s.name as name, - e.ref as reference, - e.id as origin - FROM vn.buy b - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.travel tr ON tr.id = e.travelFk - JOIN vn.warehouse w ON w.id = tr.warehouseOutFk - JOIN vn.supplier s ON s.id = e.supplierFk - JOIN vn.alertLevel al ON al.alertLevel = - CASE - WHEN tr.isReceived != FALSE THEN 3 - WHEN tr.isDelivered THEN 1 - ELSE 0 - END - JOIN vn.state st ON st.code = al.code - WHERE tr.shipped >= vDateInventory - AND vWarehouse =tr.warehouseOutFk - AND s.id <> 4 - AND b.itemFk = vItemId - AND e.isInventory = 0 - AND w.isFeedStock = 0 - - UNION ALL - - SELECT t.shipped as date, - NULL as `in`, - s.quantity as `out`, - IF(t.shipped < vCurdate,3,IF(t.shipped > vCurdate, 0, IFNULL(ts.alertLevel,0))) as alertLevel, - st.name AS stateName, - t.nickname as name, - t.refFk as reference, - t.id as origin - FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk - LEFT JOIN vn.ticketState ts ON ts.ticket = t.id - JOIN vn.client c ON c.id = t.clientFk - JOIN vn.alertLevel al ON al.alertLevel = - CASE - WHEN t.shipped < vCurdate THEN 3 - WHEN t.shipped > vCurdate THEN 0 - ELSE IFNULL(ts.alertLevel, 0) - END - JOIN vn.state st ON st.code = al.code - WHERE t.shipped >= vDateInventory - AND s.itemFk = vItemId - AND vWarehouse =t.warehouseFk - ) AS itemDiary - ORDER BY date, alertLevel, `in` DESC; -END$$ - -DELIMITER ; - diff --git a/services/db/install/changes/1.0.8/04-ticketComponentCalculate.sql b/services/db/install/changes/1.0.8/04-ticketComponentCalculate.sql deleted file mode 100644 index f7fe61d75..000000000 --- a/services/db/install/changes/1.0.8/04-ticketComponentCalculate.sql +++ /dev/null @@ -1,294 +0,0 @@ -USE `vn`; -DROP procedure IF EXISTS `ticketComponentCalculate`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentCalculate`( - vAddressFk INT, - vAgencyModeFk INT) -proc: BEGIN -/** - * Calcula los componentes de un ticket - * - * @param vAddressFk Id del consignatario - * @param vAgencyModeFk Id del modo de agencia - * @return tmp.ticketComponent, tmp.ticketComponentPrice - */ - DECLARE vClientFk INT; - DECLARE vGeneralInflationCoefficient INT DEFAULT 1.3; - DECLARE vMinimumDensityWeight INT DEFAULT 167; - DECLARE vBoxFreightItem INT DEFAULT 71; - DECLARE vBoxVolume BIGINT DEFAULT 138000; - DECLARE vSpecialPriceComponent INT DEFAULT 10; - DECLARE vExtraFreightComponent INT DEFAULT 14; - DECLARE vDeliveryComponent INT DEFAULT 15; - DECLARE vRecoveryComponent INT DEFAULT 17; - DECLARE vSellByPacketComponent INT DEFAULT 22; - DECLARE vBuyValueComponent INT DEFAULT 28; - DECLARE vMarginComponent INT DEFAULT 29; - DECLARE vDiscountLastItemComponent INT DEFAULT 32; - DECLARE vExtraBaggedComponent INT DEFAULT 38; - DECLARE vManaAutoComponent INT DEFAULT 39; - DECLARE vFreightBonusComponent INT DEFAULT 41; - - SELECT clientFk INTO vClientFK - FROM address - WHERE id = vAddressFk; - - SET @rate2 := 0; - SET @rate3 := 0; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentCalculate; - CREATE TEMPORARY TABLE tmp.ticketComponentCalculate - (PRIMARY KEY (itemFk, warehouseFk)) - ENGINE = MEMORY - SELECT - tl.itemFk, tl.warehouseFk, tl.available, - IF((@rate2 := IFNULL(pf.rate2, b.price2)) < i.minPrice AND i.hasMinPrice, i.minPrice, @rate2) * 1.0 rate2, - IF((@rate3 := IFNULL(pf.rate3, b.price3)) < i.minPrice AND i.hasMinPrice, i.minPrice, @rate3) * 1.0 rate3, - IFNULL(pf.rate3, 0) AS minPrice, - IFNULL(pf.packing, b.packing) packing, - IFNULL(pf.grouping, b.grouping) grouping, - ABS(IFNULL(pf.box, b.groupingMode)) groupingMode, - tl.buyFk, i.typeFk - FROM tmp.ticketLot tl - JOIN buy b ON b.id = tl.buyFk - JOIN item i ON i.id = tl.itemFk - JOIN itemType it ON it.id = i.typeFk - LEFT JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN specialPrice sp ON sp.itemFk = i.id AND sp.clientFk = vClientFk - LEFT JOIN ( - SELECT * FROM ( - SELECT pf.itemFk, pf.grouping, pf.packing, pf.box, pf.rate2, pf.rate3, aho.warehouseFk - FROM priceFixed pf - JOIN tmp.agencyHourGetShipped aho ON pf.warehouseFk = aho.warehouseFk OR pf.warehouseFk = 0 - WHERE aho.shipped BETWEEN pf.started AND pf.ended ORDER BY pf.itemFk, pf.warehouseFk DESC - ) tpf - GROUP BY tpf.itemFk, tpf.warehouseFk - ) pf ON pf.itemFk = tl.itemFk AND pf.warehouseFk = tl.warehouseFk - WHERE b.buyingValue + b.freightValue + b.packageValue + b.comissionValue > 0.01 AND ic.display <> 0; - - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; - CREATE TEMPORARY TABLE tmp.ticketComponent ( - `warehouseFk` INT UNSIGNED NOT NULL, - `itemFk` INT NOT NULL, - `componentFk` INT UNSIGNED NOT NULL, - `cost` DECIMAL(10,4) NOT NULL, - INDEX `itemWarehouse` USING BTREE (`itemFk` ASC, `warehouseFk` ASC), - UNIQUE INDEX `itemWarehouseComponent` (`itemFk` ASC, `warehouseFk` ASC, `componentFk` ASC)); - - - - INSERT INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost) - SELECT - tcc.warehouseFk, - tcc.itemFk, - vBuyValueComponent, - b.buyingValue + b.freightValue + b.packageValue + b.comissionValue - FROM tmp.ticketComponentCalculate tcc - JOIN buy b ON b.id = tcc.buyFk; - - INSERT INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost) - SELECT - tcc.warehouseFk, - tcc.itemFk, - vMarginComponent, - tcc.rate3 - b.buyingValue - b.freightValue - b.packageValue - b.comissionValue - FROM tmp.ticketComponentCalculate tcc - JOIN buy b ON b.id = tcc.buyFk; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentBase; - CREATE TEMPORARY TABLE tmp.ticketComponentBase ENGINE = MEMORY - SELECT tc.itemFk, ROUND(SUM(tc.cost), 4) AS base, tc.warehouseFk - FROM tmp.ticketComponent tc - GROUP BY tc.itemFk, warehouseFk; - - INSERT INTO tmp.ticketComponent - SELECT tcb.warehouseFk, tcb.itemFk, vRecoveryComponent, ROUND(tcb.base * LEAST(cr.recobro, 0.25), 3) - FROM tmp.ticketComponentBase tcb - JOIN bi.claims_ratio cr ON cr.Id_Cliente = vClientFk - WHERE cr.recobro > 0.009; - - INSERT INTO tmp.ticketComponent - SELECT tcb.warehouseFk, tcb.itemFk, vManaAutoComponent, ROUND(base * (0.01 + prices_modifier_rate), 3) as manaAuto - FROM tmp.ticketComponentBase tcb - JOIN `client` c on c.id = vClientFk - JOIN bs.mana_spellers ms ON c.salesPersonFk = ms.Id_Trabajador - WHERE ms.prices_modifier_activated - HAVING manaAuto <> 0; - - INSERT INTO tmp.ticketComponent - SELECT - tcb.warehouseFk, - tcb.itemFk, - cr.id, - GREATEST(IFNULL(ROUND(tcb.base * cr.tax, 4), 0), tcc.minPrice - tcc.rate3) - FROM tmp.ticketComponentBase tcb - JOIN componentRate cr - JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tcb.itemFk AND tcc.warehouseFk = tcb.warehouseFk - LEFT JOIN specialPrice sp ON sp.clientFk = vClientFk AND sp.itemFk = tcc.itemFk - WHERE cr.id = vDiscountLastItemComponent AND cr.tax <> 0 AND tcc.minPrice < tcc.rate3 AND sp.value IS NULL; - - INSERT INTO tmp.ticketComponent - SELECT tcc.warehouseFk, tcc.itemFk, vSellByPacketComponent, tcc.rate2 - tcc.rate3 - FROM tmp.ticketComponentCalculate tcc - JOIN buy b ON b.id = tcc.buyFk - LEFT JOIN specialPrice sp ON sp.clientFk = vClientFk AND sp.itemFk = tcc.itemFk - WHERE sp.value IS NULL; - - INSERT INTO tmp.ticketComponent - SELECT - tcc.warehouseFK, - tcc.itemFk, - vDeliveryComponent, - vGeneralInflationCoefficient - * ROUND( - r.cm3 - * IF(am.deliveryMethodFk = 1, (GREATEST(i.density, vMinimumDensityWeight) / vMinimumDensityWeight), 1) - * IFNULL(amz.price - * amz.inflation, 50) / vBoxVolume, 4 - ) cost - FROM tmp.ticketComponentCalculate tcc - JOIN item i ON i.id = tcc.itemFk - JOIN agencyMode am ON am.id = vAgencyModeFk - JOIN `address` a ON a.id = vAddressFk - JOIN agencyProvince ap ON ap.agencyFk = am.agencyFk - AND ap.warehouseFk = tcc.warehouseFk AND ap.provinceFk = a.provinceFk - JOIN agencyModeZone amz ON amz.agencyModeFk = vAgencyModeFk - AND amz.zone = ap.zone AND amz.itemFk = 71 AND amz.warehouseFk = tcc.warehouseFk - LEFT JOIN bi.rotacion r ON r.warehouse_id = tcc.warehouseFk - AND r.Id_Article = tcc.itemFk - HAVING cost <> 0; - - INSERT INTO tmp.ticketComponent - SELECT - tcc.warehouseFk, - tcc.itemFk, - vFreightBonusComponent, - vGeneralInflationCoefficient - * ROUND( - r.cm3 - * IF(am.deliveryMethodFk = 1, (GREATEST(i.density, vMinimumDensityWeight) / vMinimumDensityWeight), 1) - * awb.bonus - * amz.inflation / vBoxVolume, 4 - ) cost - FROM tmp.ticketComponentCalculate tcc - JOIN item i ON i.id = tcc.itemFk - JOIN agencyMode am ON am.id = vAgencyModeFk - JOIN `address` a ON a.id = vAddressFk - JOIN agencyProvince ap ON ap.agencyFk = a.id - AND ap.warehouseFk = tcc.warehouseFk AND ap.provinceFk = a.provinceFk - JOIN agencyModeZone amz ON amz.agencyModeFk = vAgencyModeFk - AND amz.zone = ap.zone AND amz.itemFk = vBoxFreightItem AND amz.warehouseFk = tcc.warehouseFk - JOIN agencyWeekDayBonus awb ON awb.warehouseFk = amz.warehouseFk AND awb.zone = amz.zone AND am.id = awb.agencyFk - LEFT JOIN bi.rotacion r ON r.warehouse_id = tcc.warehouseFk - AND r.Id_Article = tcc.itemFk - JOIN tmp.agencyHourGetShipped aho ON aho.warehouseFk = awb.warehouseFk - AND WEEKDAY(aho.landed) = awb.weekDay - HAVING cost <> 0 - LIMIT 1; - - IF (SELECT COUNT(*) FROM vn.addressForPackaging WHERE addressFk = vAddressFk) THEN - INSERT INTO tmp.ticketComponent - SELECT tcc.warehouseFk, b.itemFk, vExtraBaggedComponent, ap.packagingValue cost - FROM tmp.ticketComponentCalculate tcc - JOIN vn.addressForPackaging ap - WHERE ap.addressFk = vAddressFk; - END IF; - - INSERT INTO tmp.ticketComponent - SELECT tcb.warehouseFk, tcb.itemFk, vExtraFreightComponent, tcb.base * (IFNULL(pe.percentage,pp.percentage)/100) - FROM tmp.ticketComponentBase tcb - JOIN tmp.agencyHourGetShipped aho ON aho.warehouseFk = tcb.warehouseFk - LEFT JOIN preparationPercentage pp ON pp.weekDay = WEEKDAY(aho.shipped) - AND tcb.warehouseFk = IFNULL(pp.warehouseFk, tcb.warehouseFk) - LEFT JOIN preparationException pe ON pe.exceptionDay = aho.shipped - AND tcb.warehouseFk = IFNULL(pe.warehouseFk, tcb.warehouseFk) - WHERE IFNULL(pe.percentage, pp.percentage); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentCopy; - CREATE TEMPORARY TABLE tmp.ticketComponentCopy ENGINE = MEMORY - SELECT * FROM tmp.ticketComponent; - - INSERT INTO tmp.ticketComponent - SELECT - tcc.warehouseFk, - tcc.itemFk, - vSpecialPriceComponent, - sp.value - SUM(tcc.cost) sumCost - FROM tmp.ticketComponentCopy tcc - JOIN componentRate cr ON cr.id = tcc.componentFk - JOIN specialPrice sp ON sp.clientFk = vClientFK AND sp.itemFk = tcc.itemFk - WHERE cr.classRate IS NULL - GROUP BY tcc.itemFk, tcc.warehouseFk - HAVING ABS(sumCost) > 0.001; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentSum; - CREATE TEMPORARY TABLE tmp.ticketComponentSum - (INDEX (itemFk, warehouseFk)) - ENGINE = MEMORY - SELECT SUM(cost) sumCost, tc.itemFk, tc.warehouseFk, cr.classRate - FROM tmp.ticketComponent tc - JOIN componentRate cr ON cr.id = tc.componentFk - GROUP BY tc.itemFk, tc.warehouseFk, cr.classRate; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentRate; - CREATE TEMPORARY TABLE tmp.ticketComponentRate ENGINE = MEMORY - SELECT - tcc.warehouseFk, - tcc.itemFk, - 1 rate, - IF(tcc.groupingMode = 1, tcc.grouping, 1) grouping, - SUM(tcs.sumCost) price - FROM tmp.ticketComponentCalculate tcc - JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk - AND tcs.warehouseFk = tcc.warehouseFk - WHERE IFNULL(tcs.classRate, 1) = 1 - AND tcc.groupingMode < 2 AND (tcc.packing > tcc.grouping or tcc.groupingMode = 0) - GROUP BY tcs.warehouseFk, tcs.itemFk; - - INSERT INTO tmp.ticketComponentRate (warehouseFk, itemFk, rate, grouping, price) - SELECT - tcc.warehouseFk, - tcc.itemFk, - 2 rate, - tcc.packing grouping, - SUM(tcs.sumCost) price - FROM tmp.ticketComponentCalculate tcc - JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk - AND tcs.warehouseFk = tcc.warehouseFk - WHERE tcc.available IS NULL OR (IFNULL(tcs.classRate, 2) = 2 - AND tcc.packing > 0 AND tcc.available >= tcc.packing) - GROUP BY tcs.warehouseFk, tcs.itemFk; - - INSERT INTO tmp.ticketComponentRate (warehouseFk, itemFk, rate, grouping, price) - SELECT - tcc.warehouseFk, - tcc.itemFk, - 3 rate, - tcc.available grouping, - SUM(tcs.sumCost) price - FROM tmp.ticketComponentCalculate tcc - JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk - AND tcs.warehouseFk = tcc.warehouseFk - WHERE IFNULL(tcs.classRate, 3) = 3 - GROUP BY tcs.warehouseFk, tcs.itemFk; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentPrice; - CREATE TEMPORARY TABLE tmp.ticketComponentPrice ENGINE = MEMORY - SELECT * FROM ( - SELECT * FROM tmp.ticketComponentRate ORDER BY price - ) t - GROUP BY itemFk, warehouseFk, grouping; - - DROP TEMPORARY TABLE - tmp.ticketComponentCalculate, - tmp.ticketComponentSum, - tmp.ticketComponentBase, - tmp.ticketComponentRate, - tmp.ticketComponentCopy; -END$$ - -DELIMITER ; - diff --git a/services/db/install/changes/1.0.8/05-ticketComponentPriceDifference.sql b/services/db/install/changes/1.0.8/05-ticketComponentPriceDifference.sql deleted file mode 100644 index 571990103..000000000 --- a/services/db/install/changes/1.0.8/05-ticketComponentPriceDifference.sql +++ /dev/null @@ -1,55 +0,0 @@ -USE `vn`; -DROP procedure IF EXISTS `ticketComponentPriceDifference`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentPriceDifference`( - vTicketFk INT, - vDate DATE, - vAddressFk INT, - vAgencyModeFk INT, - vWarehouseFk INT) -BEGIN -/** - * Devuelve las diferencias de precio - * de los movimientos de un ticket. - * - * @param vTicketFk Id del ticket - * @param vDate Fecha de envío - * @param vAddressFk Id del consignatario - * @param vAgencyModeFk Id del modo de agencia - * @param vWarehouseFk Id del almacén - */ - CALL vn.ticketComponentPreview(vTicketFk, vDate, vAddressFk, vAgencyModeFk, vWarehouseFk); - - SELECT - s.itemFk, - i.name, - i.size, - i.category, - IFNULL(s.quantity, 0) AS quantity, - IFNULL(s.price, 0) AS price, - ROUND(SUM(tc.cost), 2) AS newPrice, - s.quantity * (s.price - ROUND(SUM(cost), 2)) difference, - s.id AS saleFk - FROM sale s - JOIN item i ON i.id = s.itemFk - JOIN ticket t ON t.id = s.ticketFk - LEFT JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk - AND tc.warehouseFk = t.warehouseFk - LEFT JOIN saleComponent sc ON sc.saleFk = s.id - AND sc.componentFk = tc.componentFk - LEFT JOIN componentRate cr ON cr.id = tc.componentFk - WHERE - t.id = vTicketFk - AND IF(sc.componentFk IS NULL - AND cr.classRate IS NOT NULL, FALSE, TRUE) - GROUP BY s.id ORDER BY s.id; - - DROP TEMPORARY TABLE - tmp.ticketComponent, - tmp.ticketComponentPrice; -END$$ - -DELIMITER ; - diff --git a/services/db/install/changes/1.0.8/06-ticketComponentUpdateSale.sql b/services/db/install/changes/1.0.8/06-ticketComponentUpdateSale.sql deleted file mode 100644 index ef02c2746..000000000 --- a/services/db/install/changes/1.0.8/06-ticketComponentUpdateSale.sql +++ /dev/null @@ -1,154 +0,0 @@ -USE `vn`; -DROP procedure IF EXISTS `ticketComponentUpdateSale`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentUpdateSale`(vOption INT) -BEGIN -/** - * A partir de la tabla tmp.sale, crea los Movimientos_componentes - * y modifica el campo Preu de la tabla Movimientos - * - * @param i_option integer tipo de actualizacion - * @param table tmp.sale tabla memory con el campo Id_Movimiento, warehouse_id - **/ - DECLARE vComponentFk INT; - DECLARE vRenewComponents BOOLEAN; - DECLARE vKeepPrices BOOLEAN; - - CASE vOption - WHEN 1 THEN - SET vRenewComponents = TRUE; - SET vKeepPrices = FALSE; - WHEN 2 THEN - SET vComponentFk = 17; - SET vRenewComponents = TRUE; - SET vKeepPrices = TRUE; - WHEN 3 THEN - SET vComponentFk = 37; - SET vRenewComponents = TRUE; - SET vKeepPrices = TRUE; - WHEN 4 THEN - SET vComponentFk = 34; - SET vRenewComponents = TRUE; - SET vKeepPrices = TRUE; - WHEN 5 THEN - SET vComponentFk = 35; - SET vRenewComponents = TRUE; - SET vKeepPrices = TRUE; - WHEN 6 THEN - SET vComponentFk = 36; - SET vRenewComponents = TRUE; - SET vKeepPrices = TRUE; - WHEN 7 THEN - REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.8, 3) - FROM sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id - LEFT JOIN saleComponent sc ON sc.saleFk = s.id - AND sc.componentFk NOT IN (28, 29) - GROUP BY s.id; - - REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, 29, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.2, 3) - FROM sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id - LEFT JOIN saleComponent sc ON sc.saleFk = s.id - AND sc.componentFk NOT IN (28, 29) - GROUP BY s.id; - - SET vRenewComponents = FALSE; - SET vKeepPrices = FALSE; - WHEN 8 THEN - DELETE sc.* - FROM tmp.sale tmps JOIN saleComponent sc ON sc.saleFk = tmps.saleFk; - - REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100)), 3) - FROM sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id; - - SET vRenewComponents = FALSE; - SET vKeepPrices = FALSE; - WHEN 9 THEN - SET vRenewComponents = TRUE; - SET vKeepPrices = TRUE; - END CASE; - - IF vRenewComponents THEN - DELETE sc.* - FROM tmp.sale tmps - JOIN saleComponent sc ON sc.saleFk = tmps.saleFk - JOIN componentRate cr ON cr.id = sc.componentFk - WHERE cr.isRenewable; - - REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, tc.componentFk, tc.cost - FROM sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id - JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk - LEFT JOIN saleComponent sc ON sc.saleFk = s.id - AND sc.componentFk = tc.componentFk - LEFT JOIN componentRate cr ON cr.id = tc.componentFk - WHERE IF(sc.componentFk IS NULL AND NOT cr.isRenewable, FALSE, TRUE); - END IF; - - IF vKeepPrices THEN - REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, vComponentFk, ROUND((s.price * (100 - s.discount) / 100) - SUM(sc.value), 3) dif - FROM sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id - LEFT JOIN saleComponent sc ON sc.saleFk = s.id - WHERE sc.saleFk <> vComponentFk - GROUP BY s.id - HAVING dif <> 0; - ELSE - UPDATE sale s - JOIN item i on i.id = s.itemFk - JOIN itemType it on it.id = i.typeFk - JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk - FROM saleComponent sc - JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk - GROUP BY sc.saleFk) sc ON sc.saleFk = s.id - SET s.price = sumValue - WHERE it.code != 'PRT'; - - REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, 21, s.price * (100 - s.discount) / 100 - sum(value) saleValue - FROM sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id - LEFT JOIN saleComponent sc ON sc.saleFk = s.id - WHERE sc.componentFk != 21 - GROUP BY s.id - HAVING ROUND(saleValue, 4) <> 0; - END IF; - - UPDATE sale s - JOIN ( - SELECT SUM(sc.value) sumValue, sc.saleFk - FROM saleComponent sc - JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk - JOIN componentRate cr ON cr.id = sc.componentFk - JOIN componentTypeRate ctr on ctr.id = cr.componentTypeRate AND ctr.base - GROUP BY sc.saleFk) sc ON sc.saleFk = s.id - SET s.priceFixed = sumValue, s.isPriceFixed = 1; - - DELETE sc.* - FROM saleComponent sc - JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk - JOIN sale s on s.id = sc.saleFk - JOIN item i ON i.id = s.itemFk - JOIN itemType it ON it.id = i.typeFk - WHERE it.code = 'PRT'; - - INSERT INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, 15, s.price - FROM sale s - JOIN tmp.sale tmps ON tmps.saleFk = s.id - JOIN item i ON i.id = s.itemFK - JOIN itemType it ON it.id = i.typeFk - WHERE it.code = 'PRT' AND s.price > 0; -END$$ - -DELIMITER ; - diff --git a/services/db/install/changes/1.0.8/08-ticketGetVisibleAvailable.sql b/services/db/install/changes/1.0.8/08-ticketGetVisibleAvailable.sql deleted file mode 100644 index a6bd524ac..000000000 --- a/services/db/install/changes/1.0.8/08-ticketGetVisibleAvailable.sql +++ /dev/null @@ -1,38 +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 - 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; - -END$$ - -DELIMITER ; \ No newline at end of file diff --git a/services/db/install/changes/1.0.8/09-manaSpellersRequery.sql b/services/db/install/changes/1.0.8/09-manaSpellersRequery.sql deleted file mode 100644 index 862132850..000000000 --- a/services/db/install/changes/1.0.8/09-manaSpellersRequery.sql +++ /dev/null @@ -1,61 +0,0 @@ -USE `vn`; -DROP procedure IF EXISTS `manaSpellersRequery`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `manaSpellersRequery`(worker INTEGER) -BEGIN - - DECLARE vWorkerIsExcluded BOOLEAN; - DECLARE vFromDated DATE; - DECLARE vToDated DATE DEFAULT TIMESTAMPADD(DAY,1,CURDATE()); - - SELECT COUNT(*) INTO vWorkerIsExcluded - FROM bs.manaSpellersExcluded - WHERE workerFk = worker; - - IF NOT vWorkerIsExcluded THEN - - SELECT max(dated) INTO vFromDated - FROM clientManaCache; - - REPLACE bs.workerMana (workerFk, amount) - SELECT worker, sum(mana) FROM - ( - SELECT s.quantity * sc.value as mana - FROM ticket t - JOIN address a ON a.id = t.addressFk - JOIN client c ON c.id = a.clientFk - JOIN sale s ON s.ticketFk = t.id - JOIN saleComponent sc ON sc.saleFk = s.id - WHERE c.salesPersonFk = worker AND componentFk IN (39, 37) -- maná auto y maná - AND t.shipped > vFromDated AND t.shipped < vToDated - - UNION ALL - - SELECT - r.amountPaid - FROM receipt r - JOIN client c ON c.id = r.clientFk - WHERE c.salesPersonFk = worker AND bankFk = 66 - AND payed > vFromDated - - UNION ALL - - SELECT g.amount - FROM greuge g - JOIN client c ON c.id = g.clientFk - WHERE c.salesPersonFk = worker AND g.greugeTypeFk = 3 -- Maná - AND g.shipped > vFromDated and g.shipped < CURDATE() - - UNION ALL - - SELECT mana - FROM clientManaCache cc - JOIN client c ON c.id = cc.clientFk - WHERE c.salesPersonFk = worker AND cc.dated = vFromDated - ) sub; - END IF; -END$$ - -DELIMITER ; - diff --git a/services/db/install/changes/1.0.8/10-triggerTicket.sql b/services/db/install/changes/1.0.8/10-triggerTicket.sql deleted file mode 100644 index 70cbdb205..000000000 --- a/services/db/install/changes/1.0.8/10-triggerTicket.sql +++ /dev/null @@ -1,58 +0,0 @@ -DROP TRIGGER IF EXISTS `vn2008`.`TicketsBeforeUpdate`; - -DELIMITER $$ -USE `vn2008`$$ -CREATE DEFINER=`root`@`%` TRIGGER `TicketsBeforeUpdate` - BEFORE UPDATE ON `Tickets` FOR EACH ROW -BEGIN - DECLARE vAgency INT; - DECLARE vEmployee INT; - DECLARE vIsCee TINYINT; - DECLARE vHasVies TINYINT; - - SELECT Id_Trabajador INTO vEmployee - FROM Trabajadores WHERE user_id = account.userGetId(); - - IF vEmployee IS NULL THEN - SET vEmployee = 20; - END IF; - - -- Comprobación de VIES - - IF NEW.empresa_id <> OLD.empresa_id THEN - - SELECT CEE INTO vIsCee - FROM Proveedores AS pr - INNER JOIN Paises p ON p.Id = pr.pais_id - WHERE Id_Proveedor = NEW.empresa_id; - - SELECT isVies INTO vHasVies - FROM vn.`client` - WHERE id = OLD.Id_Cliente; - - IF vIsCee = 1 AND NOT vHasVies Then - CALL util.throw("NO_VALID_VIES"); - END IF; - - END IF; - - - IF NEW.Fecha < '2001-01-01' - THEN - SET NEW.Id_Ruta = NULL; - - IF NEW.Fecha < '2000-01-01' then - SET NEW.Fecha = OLD.Fecha; - END IF; - - INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) - VALUES(17, NEW.Id_Ticket, vEmployee); - END IF; - - IF NEW.isDeleted = 1 THEN - SET NEW.Fecha = DATE_FORMAT(NEW.Fecha, '2000-%m-%d %T'); - SET NEW.landing = DATE_FORMAT(NEW.landing, '2000-%m-%d %T'); - END IF; - -END$$ -DELIMITER ; diff --git a/services/db/install/changes/1.0.8/11-orderTotalVolume.sql b/services/db/install/changes/1.0.8/11-orderTotalVolume.sql deleted file mode 100644 index 185e8ecc1..000000000 --- a/services/db/install/changes/1.0.8/11-orderTotalVolume.sql +++ /dev/null @@ -1,20 +0,0 @@ -USE `vn`; -DROP function IF EXISTS `orderTotalVolume`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` FUNCTION `orderTotalVolume`(vOrderId INT) RETURNS decimal(10,3) -BEGIN - -- Devuelte el volumen total de la orden sumada - DECLARE vWarehouseId INTEGER; - DECLARE vVolume DECIMAL(10,3); - - SELECT IFNULL(SUM(o.amount * r.cm3)/1000000,0) INTO vVolume - FROM hedera.orderRow o - JOIN bi.rotacion r on r.Id_Article = o.itemFk AND r.warehouse_id = o.warehouseFk - WHERE o.orderFk = vOrderId; - - RETURN vVolume; -END$$ - -DELIMITER ; diff --git a/services/db/install/changes/1.0.8/12-orderTotalVolumeBoxes.sql b/services/db/install/changes/1.0.8/12-orderTotalVolumeBoxes.sql deleted file mode 100644 index 69d6697c8..000000000 --- a/services/db/install/changes/1.0.8/12-orderTotalVolumeBoxes.sql +++ /dev/null @@ -1,27 +0,0 @@ -USE `vn`; -DROP function IF EXISTS `orderTotalVolumeBoxes`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` FUNCTION `orderTotalVolumeBoxes`(vOrderId INT) RETURNS decimal(10,3) -BEGIN - -/* - * Devuelve el volumen estimado del ticket sumado, en cajas - * - * idT Numero de ticket - * - */ - DECLARE vVolumeBoxM3 DOUBLE; - DECLARE vOrderTotalVolumeBoxes DECIMAL(10,1); - DECLARE vVnBoxId VARCHAR(10) DEFAULT '94'; - - SELECT volume / 1000000 INTO vVolumeBoxM3 FROM packaging WHERE id = vVnBoxId; - - SET vOrderTotalVolumeBoxes = orderTotalVolume(vOrderId) / vVolumeBoxM3; - - RETURN vOrderTotalVolumeBoxes; - -END$$ - -DELIMITER ; \ No newline at end of file diff --git a/services/db/install/changes/1.0.8/13-orderListVolume.sql b/services/db/install/changes/1.0.8/13-orderListVolume.sql deleted file mode 100644 index e69de29bb..000000000 diff --git a/services/db/install/dump/01-structure.sql b/services/db/install/dump/01-structure.sql index b7e39e015..1227d3b0c 100644 --- a/services/db/install/dump/01-structure.sql +++ b/services/db/install/dump/01-structure.sql @@ -363,7 +363,7 @@ CREATE TABLE `user` ( KEY `nickname` (`nickname`), KEY `lang` (`lang`), CONSTRAINT `user_ibfk_2` FOREIGN KEY (`role`) REFERENCES `role` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=14382 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global users'; +) ENGINE=InnoDB AUTO_INCREMENT=14445 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global users'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -2414,7 +2414,7 @@ CREATE TABLE `Agencias` ( PRIMARY KEY (`Id_Agencia`), KEY `Agencias` (`Agencia`), KEY `Vista` (`Vista`) -) ENGINE=InnoDB AUTO_INCREMENT=1207 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1209 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -2433,7 +2433,7 @@ CREATE TABLE `Agencias_dits` ( `value_old` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `value_new` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`idAgencia_dits`) -) ENGINE=InnoDB AUTO_INCREMENT=21044 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=21339 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -2519,6 +2519,16 @@ CREATE TABLE `Articles` ( `relevancy` tinyint(1) NOT NULL DEFAULT '0', `expenceFk` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT '7001000000', `isActive` tinyint(1) NOT NULL DEFAULT '1', + `longName` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, + `subName` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, + `tag5` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, + `value5` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, + `tag6` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, + `value6` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, + `tag7` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, + `value7` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, + `tag8` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, + `value8` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`Id_Article`), KEY `Article` (`Article`), KEY `Color` (`Color`), @@ -2534,7 +2544,7 @@ CREATE TABLE `Articles` ( CONSTRAINT `Articles_ibfk_5` FOREIGN KEY (`tipo_id`) REFERENCES `Tipos` (`tipo_id`) ON UPDATE CASCADE, CONSTRAINT `expenceFk` FOREIGN KEY (`expenceFk`) REFERENCES `Gastos` (`Id_Gasto`) ON UPDATE CASCADE, CONSTRAINT `producer_id` FOREIGN KEY (`producer_id`) REFERENCES `producer` (`producer_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=316296 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=317390 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -2548,8 +2558,11 @@ DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`ArticlesBeforeInsert` BEFORE INSERT ON `Articles` FOR EACH ROW BEGIN + DECLARE vDensity DOUBLE; DECLARE vInsertId INT; + DECLARE vProducerFk VARCHAR(50); + DECLARE vInkName VARCHAR(50); IF NEW.density IS NULL THEN @@ -2568,6 +2581,36 @@ BEGIN SET NEW.Foto = vInsertId; END IF; + + SET NEW.longName = NEW.Article; + + -- MIGRACION + IF NEW.producer_id is not null THEN + SELECT name INTO vProducerFk FROM producer WHERE producer_id = NEW.producer_id; + SET NEW.subname = vProducerFk; + END IF; + + IF NEW.Medida IS NOT NULL AND NEW.value5 IS NULL THEN + SET NEW.tag5 ='Medida'; + SET NEW.value5 = NEW.medida; + END IF; + + IF NEW.Color IS NOT NULL AND NEW.value6 IS NULL THEN + SET NEW.tag6 ='Color'; + SELECT name INTO vInkName FROM vn.ink i where i.id = NEW.Color; + SET NEW.value6 = vInkName; + END IF; + + IF NEW.Categoria IS NOT NULL AND NEW.value7 IS NULL THEN + SET NEW.tag7 ='Categoria'; + SET NEW.value7 = NEW.Categoria; + END IF; + + IF NEW.Tallos IS NOT NULL AND NEW.value8 IS NULL THEN + SET NEW.tag8 ='Tallos'; + SET NEW.value8 = NEW.Tallos; + END IF; + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -2596,13 +2639,64 @@ BEGIN INSERT INTO vn.itemTaxCountry(itemFk, countryFk, taxClassFk) SELECT NEW.Id_Article, 30, NEW.iva_group_id; - + /* IF NEW.tipo_id IS NOT NULL THEN INSERT INTO vn.itemTag (itemFk, tagFk, priority) SELECT NEW.Id_Article, tagFk, priority FROM vn.itemTypeTag WHERE itemTypeFk = NEW.tipo_id; END IF; +*/ +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`Articles_BEFORE_UPDATE` BEFORE UPDATE ON `Articles` FOR EACH ROW +BEGIN + DECLARE vProducerFk VARCHAR(50); + DECLARE vInkName VARCHAR(50); + + IF OLD.Article <> NEW.Article THEN + SET NEW.longName = NEW.Article; + END IF; + + -- MIGRACION + IF NEW.producer_id is not null AND NOT (NEW.producer_id <=> OLD.producer_id) THEN + SELECT name INTO vProducerFk FROM producer WHERE producer_id = NEW.producer_id; + SET NEW.subname = vProducerFk; + END IF; + + IF NEW.Medida IS NOT NULL AND NEW.value5 IS NULL THEN + SET NEW.tag5 ='Medida'; + SET NEW.value5 = NEW.medida; + END IF; + + IF NEW.Color IS NOT NULL AND NEW.value6 IS NULL THEN + SET NEW.tag6 ='Color'; + SELECT name INTO vInkName FROM vn.ink i where i.id = NEW.Color; + SET NEW.value6 = vInkName; + END IF; + + IF NEW.Categoria IS NOT NULL AND NEW.value7 IS NULL THEN + SET NEW.tag7 ='Categoria'; + SET NEW.value7 = NEW.Categoria; + END IF; + + IF NEW.Tallos IS NOT NULL AND NEW.value8 IS NULL THEN + SET NEW.tag8 ='Tallos'; + SET NEW.value8 = NEW.Tallos; + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -2621,7 +2715,7 @@ DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`Articles_AFTER_UPDATE` AFTER UPDATE ON `Articles` FOR EACH ROW BEGIN - CALL itemTagArrangedUpdate(NEW.Id_Article); + CALL itemTagArrangedUpdate(NEW.Id_Article); END */;; DELIMITER ; @@ -2724,7 +2818,7 @@ CREATE TABLE `Articles_dits` ( KEY `fgkey1_idx` (`idaccion_dits`), KEY `fgkey2_idx` (`Id_Ticket`), KEY `fgkey3_idx` (`Id_Trabajador`) -) ENGINE=InnoDB AUTO_INCREMENT=20282 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=20466 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -2746,7 +2840,7 @@ CREATE TABLE `Articles_nicho` ( KEY `Articles_nicho_wh_fk` (`warehouse_id`), CONSTRAINT `Articles_nicho_wh_fk` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Articles_nichos_fk` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=492701 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=508972 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -2910,7 +3004,7 @@ CREATE TABLE `Cajas` ( KEY `warehouse_id` (`warehouse_id`), KEY `fk_Cajas_Proveedores_account1_idx` (`Proveedores_account_Id`), CONSTRAINT `Cajas_ibfk_2` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=596625 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=601535 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -3058,7 +3152,7 @@ CREATE TABLE `Clientes` ( CONSTRAINT `Clientes_ibfk_5` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON UPDATE CASCADE, CONSTRAINT `canal_nuevo_cliente` FOREIGN KEY (`chanel_id`) REFERENCES `chanel` (`chanel_id`) ON UPDATE CASCADE, CONSTRAINT `tipos_de_cliente` FOREIGN KEY (`clientes_tipo_id`) REFERENCES `clientes_tipo` (`clientes_tipo_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=14382 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=14445 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -3341,7 +3435,7 @@ CREATE TABLE `Colas` ( CONSTRAINT `Colas_ibfk_3` FOREIGN KEY (`Id_Prioridad`) REFERENCES `Prioridades` (`Id_Prioridad`) ON UPDATE CASCADE, CONSTRAINT `Colas_ibfk_4` FOREIGN KEY (`Id_Impresora`) REFERENCES `Impresoras` (`Id_Impresora`) ON UPDATE CASCADE, CONSTRAINT `Colas_ibfk_5` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=284201 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=312061 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3423,7 +3517,7 @@ CREATE TABLE `Compres` ( CONSTRAINT `Compres_ibfk_2` FOREIGN KEY (`Id_Cubo`) REFERENCES `Cubos` (`Id_Cubo`) ON UPDATE CASCADE, CONSTRAINT `Compres_ibfk_3` FOREIGN KEY (`container_id`) REFERENCES `container` (`container_id`) ON UPDATE CASCADE, CONSTRAINT `buy_id` FOREIGN KEY (`Id_Entrada`) REFERENCES `Entradas` (`Id_Entrada`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=260214635 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC; +) ENGINE=InnoDB AUTO_INCREMENT=263702614 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -3675,7 +3769,7 @@ CREATE TABLE `Compres_ok` ( KEY `Id_Movimiento` (`Id_Compra`), KEY `Id_Accion` (`Id_Accion`), CONSTRAINT `Compres_ok_ibfk_1` FOREIGN KEY (`Id_Compra`) REFERENCES `Compres` (`Id_Compra`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=20389 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=21030 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3719,7 +3813,7 @@ CREATE TABLE `Consignatarios` ( CONSTRAINT `Consignatarios_ibfk_3` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON UPDATE CASCADE, CONSTRAINT `Consignatarios_ibfk_4` FOREIGN KEY (`Id_Agencia`) REFERENCES `Agencias` (`Id_Agencia`) ON UPDATE CASCADE, CONSTRAINT `address_customer_id` FOREIGN KEY (`Id_cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=25379 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=25490 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -3903,7 +3997,7 @@ CREATE TABLE `Contactos` ( PRIMARY KEY (`Id_Contacto`), KEY `Telefono` (`Telefono`), KEY `Movil` (`Movil`) -) ENGINE=InnoDB AUTO_INCREMENT=2638 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2644 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -4100,7 +4194,7 @@ CREATE TABLE `Entradas` ( CONSTRAINT `Entradas_ibfk_1` FOREIGN KEY (`Id_Proveedor`) REFERENCES `Proveedores` (`Id_Proveedor`) ON UPDATE CASCADE, CONSTRAINT `Entradas_ibfk_6` FOREIGN KEY (`travel_id`) REFERENCES `travel` (`id`) ON UPDATE CASCADE, CONSTRAINT `Entradas_ibfk_7` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=145185 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='InnoDB free: 88064 kB; (`Id_Proveedor`) REFER `vn2008/Provee'; +) ENGINE=InnoDB AUTO_INCREMENT=146517 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='InnoDB free: 88064 kB; (`Id_Proveedor`) REFER `vn2008/Provee'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -4264,7 +4358,7 @@ CREATE TABLE `Entradas_dits` ( CONSTRAINT `Entradas_dits_ibfk_1` FOREIGN KEY (`Id_Ticket`) REFERENCES `Entradas` (`Id_Entrada`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fgkey_entradas_1` FOREIGN KEY (`idaccion_dits`) REFERENCES `accion_dits` (`idaccion_dits`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `fgkey_entradas_3` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2877088 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2913868 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -4282,7 +4376,7 @@ CREATE TABLE `Entradas_kop` ( PRIMARY KEY (`Id_Entradas_kop`), KEY `entradas_entradas_kop_idx` (`Id_Entrada`), CONSTRAINT `entradas_entradas_kop` FOREIGN KEY (`Id_Entrada`) REFERENCES `Entradas` (`Id_Entrada`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=632 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relaciona las entradas con los origenes de compra'; +) ENGINE=InnoDB AUTO_INCREMENT=774 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relaciona las entradas con los origenes de compra'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -4370,7 +4464,7 @@ CREATE TABLE `Equipos` ( PRIMARY KEY (`id`), KEY `trabajador_id` (`trabajador_id`), CONSTRAINT `Equipos_ibfk_1` FOREIGN KEY (`trabajador_id`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=157 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=159 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -4525,7 +4619,7 @@ CREATE TABLE `Facturas` ( CONSTRAINT `Facturas_ibfk_4` FOREIGN KEY (`cplusTaxBreakFk`) REFERENCES `vn`.`cplusTaxBreak` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoice_bank_id` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE, CONSTRAINT `invoice_customer_id` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=460773 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=461076 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -4743,7 +4837,7 @@ CREATE TABLE `Greuges` ( KEY `Id_Ticket_Greuge_Ticket_idx` (`Id_Ticket`), CONSTRAINT `Id_Ticket_Greuge_Ticket` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `greuges_type_fk` FOREIGN KEY (`Greuges_type_id`) REFERENCES `Greuges_type` (`Greuges_type_id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2297969 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=FIXED; +) ENGINE=InnoDB AUTO_INCREMENT=2327063 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=FIXED; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -4944,7 +5038,7 @@ CREATE TABLE `Movimientos` ( KEY `itemFk_ticketFk` (`Id_Article`,`Id_Ticket`), CONSTRAINT `Movimientos_ibfk_1` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON UPDATE CASCADE, CONSTRAINT `movement_ticket_id` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=21351994 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=21497719 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -5091,10 +5185,37 @@ CREATE TABLE `Movimientos_mark` ( `Id_Trabajador` int(11) NOT NULL, `Id_Accion` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `Id_Movimiento_mark` int(11) NOT NULL AUTO_INCREMENT, + `stateFk` tinyint(3) unsigned NOT NULL, PRIMARY KEY (`Id_Movimiento_mark`), - KEY `Id_Movimiento` (`Id_Movimiento`) -) ENGINE=InnoDB AUTO_INCREMENT=11148908 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + KEY `Id_Movimiento` (`Id_Movimiento`), + KEY `fgnStateFk_idx` (`stateFk`), + CONSTRAINT `fgnStateFk` FOREIGN KEY (`stateFk`) REFERENCES `state` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=11348616 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`Movimientos_mark_BEFORE_INSERT` BEFORE INSERT ON `Movimientos_mark` FOR EACH ROW +BEGIN + IF(NEW.stateFk = 14) THEN + SET NEW.Id_Accion = 3; + END IF; + + IF(NEW.stateFk = 8) THEN + SET NEW.Id_Accion = 4; + END IF; +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `Movimientos_revisar` @@ -5163,7 +5284,7 @@ CREATE TABLE `Ordenes` ( KEY `Id_Comprador` (`CodCOMPRADOR`), KEY `Id_Movimiento` (`Id_Movimiento`), KEY `Id_Vendedor` (`CodVENDEDOR`) -) ENGINE=InnoDB AUTO_INCREMENT=32222 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=32790 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5209,7 +5330,7 @@ CREATE TABLE `Pagares` ( KEY `empresa_id` (`kk_empresa_id`), KEY `pago_id` (`pago_id`), CONSTRAINT `Pagares_ibfk_2` FOREIGN KEY (`pago_id`) REFERENCES `pago` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2841 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2843 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5335,7 +5456,7 @@ CREATE TABLE `Proveedores` ( CONSTRAINT `pay_dem_id` FOREIGN KEY (`pay_dem_id`) REFERENCES `pay_dem` (`id`) ON UPDATE CASCADE, CONSTRAINT `pay_met_id` FOREIGN KEY (`pay_met_id`) REFERENCES `pay_met` (`id`) ON UPDATE CASCADE, CONSTRAINT `province_id` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2535 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2542 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5361,7 +5482,7 @@ CREATE TABLE `Proveedores_account` ( KEY `fk_Proveedores_account_entity1_idx` (`entity_id`), KEY `fk_banco_prov_account_idx` (`Id_Banco`), CONSTRAINT `fk_banco_prov_account` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=653 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=660 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5452,7 +5573,7 @@ CREATE TABLE `Recibos` ( CONSTRAINT `Recibos_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE, CONSTRAINT `Recibos_ibfk_2` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE, CONSTRAINT `recibo_customer_id` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=472398 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=475796 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -5543,7 +5664,7 @@ CREATE TABLE `Relaciones` ( KEY `Id_Contacto` (`Id_Contacto`), KEY `Id_Proveedor` (`Id_Proveedor`), KEY `Id_Cliente` (`Id_Cliente`) -) ENGINE=InnoDB AUTO_INCREMENT=2639 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2644 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5563,7 +5684,7 @@ CREATE TABLE `Remesas` ( KEY `empresa_id` (`empresa_id`), CONSTRAINT `Remesas_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE, CONSTRAINT `Remesas_ibfk_2` FOREIGN KEY (`Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1099 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1111 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5588,7 +5709,7 @@ CREATE TABLE `Reservas` ( PRIMARY KEY (`Id_Reserva`), KEY `Id_1` (`Id_Ticket`), KEY `Id_Article` (`Id_Article`) -) ENGINE=InnoDB AUTO_INCREMENT=2178 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2674 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5619,7 +5740,7 @@ CREATE TABLE `Rutas` ( KEY `Fecha` (`Fecha`), KEY `gestdoc_id` (`gestdoc_id`), CONSTRAINT `Rutas_ibfk_1` FOREIGN KEY (`gestdoc_id`) REFERENCES `gestdoc` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=40088 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=40670 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -5807,7 +5928,7 @@ CREATE TABLE `Split_lines` ( KEY `Id_Compra` (`Id_Compra`), CONSTRAINT `Id_Compra` FOREIGN KEY (`Id_Compra`) REFERENCES `Compres` (`Id_Compra`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Split_lines_ibfk_1` FOREIGN KEY (`Id_Split`) REFERENCES `Splits` (`Id_Split`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=325141 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=328297 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5825,7 +5946,7 @@ CREATE TABLE `Splits` ( `Notas` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`Id_Split`), KEY `Id_Entrada` (`Id_Entrada`) -) ENGINE=InnoDB AUTO_INCREMENT=36281 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=36309 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5853,7 +5974,7 @@ CREATE TABLE `Stockcontrol` ( CONSTRAINT `Stockcontrol_ibfk_1` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Stockcontrol_ibfk_2` FOREIGN KEY (`Id_Remitente`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Stockcontrol_ibfk_3` FOREIGN KEY (`Id_Solver`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=23581 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=23609 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5911,7 +6032,7 @@ CREATE TABLE `Tickets` ( CONSTRAINT `Tickets_ibfk_9` FOREIGN KEY (`Id_Ruta`) REFERENCES `Rutas` (`Id_Ruta`) ON UPDATE CASCADE, CONSTRAINT `ticket_customer_id` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE, CONSTRAINT `tickets_fk10` FOREIGN KEY (`Factura`) REFERENCES `Facturas` (`Id_Factura`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1913059 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1931370 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -6041,6 +6162,11 @@ BEGIN INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) VALUES(17, NEW.Id_Ticket, vEmployee); END IF; + + IF NEW.isDeleted = 1 THEN + SET NEW.Fecha = DATE_FORMAT(NEW.Fecha, '2000-%m-%d %T'); + SET NEW.landing = DATE_FORMAT(NEW.landing, '2000-%m-%d %T'); + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -6120,7 +6246,7 @@ CREATE TABLE `Tickets_dits` ( CONSTRAINT `Tickets_dits_ibfk_1` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fgkey1` FOREIGN KEY (`idaccion_dits`) REFERENCES `accion_dits` (`idaccion_dits`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `fgkey3` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=59579031 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=59847665 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -6169,7 +6295,7 @@ CREATE TABLE `Tickets_turno` ( `weekDay` tinyint(1) DEFAULT NULL COMMENT 'funcion de mysql Lunes = 0, Domingo = 6', PRIMARY KEY (`Id_Ticket`), CONSTRAINT `Id_Ticket_fk` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1911195 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1922539 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -6326,7 +6452,7 @@ CREATE TABLE `Trabajadores` ( KEY `sub` (`sub`), CONSTRAINT `Clientes` FOREIGN KEY (`Id_Cliente_Interno`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE, CONSTRAINT `Trabajadores_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1152 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1160 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -6453,7 +6579,7 @@ CREATE TABLE `Vehiculos` ( KEY `provinceFk_idx` (`warehouseFk`), CONSTRAINT `Vehiculos_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE, CONSTRAINT `provinceFk` FOREIGN KEY (`warehouseFk`) REFERENCES `province` (`province_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=380 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=381 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -6479,7 +6605,7 @@ CREATE TABLE `Vehiculos_consumo` ( PRIMARY KEY (`Vehiculos_consumo_id`,`Id_Vehiculo`), KEY `fk_Vehiculos_consumo_Vehiculos_idx` (`Id_Vehiculo`), CONSTRAINT `fk_Vehiculos_consumo_Vehiculos` FOREIGN KEY (`Id_Vehiculo`) REFERENCES `Vehiculos` (`Id_Vehiculo`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=8492 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='En esta tabla apuntan el importe de los tickets de la gasolinera solred, con quien tenemos un contrato y nos facturan mensualmente'; +) ENGINE=InnoDB AUTO_INCREMENT=8671 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='En esta tabla apuntan el importe de los tickets de la gasolinera solred, con quien tenemos un contrato y nos facturan mensualmente'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -6593,7 +6719,7 @@ CREATE TABLE `XDiario` ( PRIMARY KEY (`id`), KEY `empresa_id` (`empresa_id`), CONSTRAINT `XDiario_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=3387978 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3398144 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -6701,7 +6827,7 @@ CREATE TABLE `account_conciliacion` ( KEY `fg_accconciliacion_key1_idx` (`Id_Proveedores_account`), KEY `index_id_calculated` (`id_calculated`), CONSTRAINT `fg_key1_accountconc` FOREIGN KEY (`Id_Proveedores_account`) REFERENCES `Proveedores_account` (`Id_Proveedores_account`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=4408 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=5378 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -6822,7 +6948,7 @@ CREATE TABLE `agency` ( KEY `agencias_alias_idx` (`warehouse_alias_id`), CONSTRAINT `agency_ibfk_1` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `agency_ibfk_2` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=230 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=231 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -6868,7 +6994,7 @@ CREATE TABLE `agency_hour` ( CONSTRAINT `agency_hour_ibfk_1` FOREIGN KEY (`agency_id`) REFERENCES `agency` (`agency_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `agency_hour_ibfk_2` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `agency_hour_ibfk_3` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=4640 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=4671 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -7034,7 +7160,7 @@ CREATE TABLE `albaran` ( CONSTRAINT `fk_albaran_empresa1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE, CONSTRAINT `fk_albaran_recibida` FOREIGN KEY (`recibida_id`) REFERENCES `recibida` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `fk_albaran_warehouse1` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2387 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2528 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7111,7 +7237,7 @@ CREATE TABLE `awb` ( CONSTRAINT `awbInvoiceIn` FOREIGN KEY (`invoiceInFk`) REFERENCES `recibida` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `awbTransitoryFk` FOREIGN KEY (`transitario_id`) REFERENCES `Proveedores` (`Id_Proveedor`) ON UPDATE CASCADE, CONSTRAINT `awb_ibfk_1` FOREIGN KEY (`iva_id`) REFERENCES `iva_codigo` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2600 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2629 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -7288,7 +7414,7 @@ CREATE TABLE `awb_component_template` ( CONSTRAINT `Id_Moneda` FOREIGN KEY (`Id_Moneda`) REFERENCES `Monedas` (`Id_Moneda`) ON UPDATE CASCADE, CONSTRAINT `awb_unit_fk1` FOREIGN KEY (`awb_unit_id`) REFERENCES `awb_unit` (`awb_unit_id`) ON UPDATE CASCADE, CONSTRAINT `role_fk` FOREIGN KEY (`awb_role_id`) REFERENCES `awb_role` (`awb_role_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=557 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=591 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7369,7 +7495,7 @@ CREATE TABLE `awb_gestdoc` ( KEY `awb_gestdoc_gestdoc_fk` (`gestdoc_id`), CONSTRAINT `awb_gestdoc_awb_fk` FOREIGN KEY (`awb_id`) REFERENCES `awb` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `awb_gestdoc_gestdoc_fk` FOREIGN KEY (`gestdoc_id`) REFERENCES `gestdoc` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2262 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2291 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7468,7 +7594,7 @@ CREATE TABLE `balance_nest_tree` ( `id` int(11) NOT NULL AUTO_INCREMENT, `Id_Gasto` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=386 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=388 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7487,7 +7613,7 @@ CREATE TABLE `barcodes` ( UNIQUE KEY `Id_Article_2` (`Id_Article`,`code`), KEY `Id_Article` (`Id_Article`), CONSTRAINT `barcodes_ibfk_1` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=36189 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=36324 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7628,7 +7754,7 @@ CREATE TABLE `buy_edi` ( KEY `kop` (`kop`), KEY `barcode` (`barcode`), KEY `fec` (`fec`) -) ENGINE=InnoDB AUTO_INCREMENT=719182 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=729001 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7882,7 +8008,7 @@ CREATE TABLE `cl_act` ( CONSTRAINT `cl_act_ibfk_1` FOREIGN KEY (`Id_Movimiento`) REFERENCES `Movimientos` (`Id_Movimiento`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `cl_act_ibfk_3` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE, CONSTRAINT `cl_act_ibfk_4` FOREIGN KEY (`cl_main_id`) REFERENCES `cl_main` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=86208 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Acciones en respuesta a las reclamaciones'; +) ENGINE=InnoDB AUTO_INCREMENT=87589 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Acciones en respuesta a las reclamaciones'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7916,7 +8042,7 @@ CREATE TABLE `cl_cau` ( CONSTRAINT `cl_cau_ibfk_7` FOREIGN KEY (`cl_mot_id`) REFERENCES `cl_mot` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_cau_ibfk_8` FOREIGN KEY (`cl_con_id`) REFERENCES `cl_con` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_cau_ibfk_9` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=46256 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Causas de las reclamaciones'; +) ENGINE=InnoDB AUTO_INCREMENT=46753 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Causas de las reclamaciones'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7970,7 +8096,7 @@ CREATE TABLE `cl_det` ( CONSTRAINT `cl_det_ibfk_6` FOREIGN KEY (`cl_pet_id`) REFERENCES `cl_pet` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_det_ibfk_7` FOREIGN KEY (`Id_Movimiento`) REFERENCES `Movimientos` (`Id_Movimiento`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `cl_det_ibfk_8` FOREIGN KEY (`cl_main_id`) REFERENCES `cl_main` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=118534 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalle de las reclamaciones'; +) ENGINE=InnoDB AUTO_INCREMENT=120079 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalle de las reclamaciones'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8027,7 +8153,7 @@ CREATE TABLE `cl_main` ( CONSTRAINT `cl_main_ibfk_3` FOREIGN KEY (`cl_est_id`) REFERENCES `cl_est` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_main_ibfk_4` FOREIGN KEY (`cl_dep_id`) REFERENCES `cl_dep` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_main_ibfk_5` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=51317 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Reclamaciones, tabla principal'; +) ENGINE=InnoDB AUTO_INCREMENT=51989 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Reclamaciones, tabla principal'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8140,7 +8266,7 @@ CREATE TABLE `client_observation` ( KEY `Id_Cliente` (`Id_Cliente`), CONSTRAINT `client_observation_ibfk_1` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `client_observation_ibfk_2` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=64829 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; +) ENGINE=InnoDB AUTO_INCREMENT=65649 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8306,7 +8432,7 @@ CREATE TABLE `consignatarios_observation` ( `text` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`consignatarios_observation_id`), UNIQUE KEY `Id_Consigna` (`Id_Consigna`,`observation_type_id`) -) ENGINE=InnoDB AUTO_INCREMENT=3258 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Observaciones de los consignatarios'; +) ENGINE=InnoDB AUTO_INCREMENT=3298 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Observaciones de los consignatarios'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8388,7 +8514,7 @@ CREATE TABLE `credit` ( KEY `credit_ClienteFk` (`Id_Cliente`), CONSTRAINT `credit_ClienteFk` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `workers_fk` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=64308 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=64862 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8513,7 +8639,7 @@ CREATE TABLE `device` ( PRIMARY KEY (`device_id`), UNIQUE KEY `device_id_UNIQUE` (`device_id`), UNIQUE KEY `sn_UNIQUE` (`sn`) -) ENGINE=InnoDB AUTO_INCREMENT=225 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=227 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8863,7 +8989,7 @@ CREATE TABLE `entity` ( UNIQUE KEY `bic_UNIQUE` (`bic`), KEY `fg_entity1_idx` (`pais_id`), CONSTRAINT `fg_entity1` FOREIGN KEY (`pais_id`) REFERENCES `Paises` (`Id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=30008 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Entidades bancarias '; +) ENGINE=InnoDB AUTO_INCREMENT=30009 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Entidades bancarias '; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8902,7 +9028,7 @@ CREATE TABLE `escritos_det` ( PRIMARY KEY (`id`), KEY `empresa_id` (`empresa_id`), CONSTRAINT `escritos_det_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=15657 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=15761 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8931,7 +9057,7 @@ CREATE TABLE `expeditions` ( KEY `index4` (`ticket_id`), CONSTRAINT `Id_Agencia` FOREIGN KEY (`agency_id`) REFERENCES `Agencias` (`Id_Agencia`) ON UPDATE CASCADE, CONSTRAINT `ticket_id` FOREIGN KEY (`ticket_id`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2477079 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2506556 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -9191,7 +9317,7 @@ CREATE TABLE `gestdoc` ( UNIQUE KEY `emp_id` (`emp_id`,`orden`,`warehouse_id`), KEY `trabajador_id` (`trabajador_id`), KEY `warehouse_id` (`warehouse_id`) -) ENGINE=InnoDB AUTO_INCREMENT=1026134 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='document managment system'; +) ENGINE=InnoDB AUTO_INCREMENT=1038334 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='document managment system'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -9390,7 +9516,7 @@ CREATE TABLE `intrastat_data` ( KEY `recibida` (`recibida_id`), CONSTRAINT `intrastat_data_ibfk_1` FOREIGN KEY (`intrastat_id`) REFERENCES `Intrastat` (`Codintrastat`) ON UPDATE CASCADE, CONSTRAINT `intrastat_data_ibfk_2` FOREIGN KEY (`recibida_id`) REFERENCES `recibida` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=67013 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=67333 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9728,7 +9854,7 @@ CREATE TABLE `mail` ( `recipientFk` int(11) DEFAULT NULL, `plainTextBody` text COLLATE utf8_unicode_ci, PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=1381925 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=MyISAM AUTO_INCREMENT=1397408 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9786,7 +9912,7 @@ CREATE TABLE `mandato` ( CONSTRAINT `mandato_fgkey1` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `mandato_fgkey2` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `mandato_fgkey3` FOREIGN KEY (`idmandato_tipo`) REFERENCES `mandato_tipo` (`idmandato_tipo`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=15310 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=15390 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -9995,7 +10121,7 @@ CREATE TABLE `pago` ( CONSTRAINT `pago_moneda` FOREIGN KEY (`id_moneda`) REFERENCES `Monedas` (`Id_Moneda`) ON UPDATE CASCADE, CONSTRAINT `pago_pay_met` FOREIGN KEY (`pay_met_id`) REFERENCES `pay_met` (`id`) ON UPDATE CASCADE, CONSTRAINT `proveedor_pago` FOREIGN KEY (`id_proveedor`) REFERENCES `Proveedores` (`Id_Proveedor`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=42351 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=42715 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -10490,7 +10616,7 @@ CREATE TABLE `price_fixed` ( KEY `date_end` (`date_end`), KEY `warehouse_id` (`warehouse_id`), CONSTRAINT `price_fixed_ibfk_1` FOREIGN KEY (`item_id`) REFERENCES `Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=54167 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=54747 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -10552,7 +10678,7 @@ CREATE TABLE `producer` ( `visible` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`producer_id`), UNIQUE KEY `name_UNIQUE` (`name`) -) ENGINE=InnoDB AUTO_INCREMENT=4779 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=4897 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -10721,7 +10847,7 @@ CREATE TABLE `recibida` ( CONSTRAINT `recibida_ibfk_5` FOREIGN KEY (`cplusInvoiceType472Fk`) REFERENCES `vn`.`cplusInvoiceType472` (`id`) ON UPDATE CASCADE, CONSTRAINT `recibida_ibfk_6` FOREIGN KEY (`cplusRectificationTypeFk`) REFERENCES `vn`.`cplusRectificationType` (`id`) ON UPDATE CASCADE, CONSTRAINT `recibida_ibfk_7` FOREIGN KEY (`cplusTrascendency472Fk`) REFERENCES `vn`.`cplusTrascendency472` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=69434 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=70038 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -11310,7 +11436,7 @@ CREATE TABLE `recibida_iva` ( CONSTRAINT `recibida_iva_ibfk_2` FOREIGN KEY (`iva_id`) REFERENCES `iva_codigo` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `recibida_iva_ibfk_5` FOREIGN KEY (`recibida_id`) REFERENCES `recibida` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `recibida_iva_ibfk_6` FOREIGN KEY (`gastos_id`) REFERENCES `Gastos` (`Id_Gasto`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=94330 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=95620 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11333,7 +11459,7 @@ CREATE TABLE `recibida_vencimiento` ( KEY `banco_id` (`banco_id`), CONSTRAINT `recibida_vencimiento_ibfk_6` FOREIGN KEY (`banco_id`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE, CONSTRAINT `recibida_vencimiento_ibfk_7` FOREIGN KEY (`recibida_id`) REFERENCES `recibida` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=91558 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=92992 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -11570,7 +11696,7 @@ CREATE TABLE `scan` ( `name` varchar(45) CHARACTER SET utf8 DEFAULT NULL, `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=60975 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Se borra automaticamente 8 dias en el pasado desde vn2008.clean'; +) ENGINE=InnoDB AUTO_INCREMENT=62461 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Se borra automaticamente 8 dias en el pasado desde vn2008.clean'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11610,7 +11736,7 @@ CREATE TABLE `scan_line` ( PRIMARY KEY (`scan_line_id`), KEY `id_scan_id_idx` (`scan_id`), CONSTRAINT `id_scan_id` FOREIGN KEY (`scan_id`) REFERENCES `scan` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=770397 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=785415 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11632,7 +11758,7 @@ CREATE TABLE `sharingcart` ( KEY `Suplent` (`Id_Suplente`), CONSTRAINT `Suplent_key` FOREIGN KEY (`Id_Suplente`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE, CONSTRAINT `Trabajador_key` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1817 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1838 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -11805,7 +11931,7 @@ CREATE TABLE `state` ( `code` varchar(45) CHARACTER SET utf8 NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `code_UNIQUE` (`code`) -) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -12087,7 +12213,7 @@ CREATE TABLE `ticket_observation` ( KEY `observation_type_id` (`observation_type_id`), CONSTRAINT `ticket_observation_ibfk_1` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticket_observation_ibfk_2` FOREIGN KEY (`observation_type_id`) REFERENCES `observation_type` (`observation_type_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1099271 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; +) ENGINE=InnoDB AUTO_INCREMENT=1113187 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -12210,7 +12336,7 @@ CREATE TABLE `travel` ( CONSTRAINT `travel_ibfk_2` FOREIGN KEY (`warehouse_id_out`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `travel_ibfk_3` FOREIGN KEY (`agency_id`) REFERENCES `Agencias` (`Id_Agencia`) ON UPDATE CASCADE, CONSTRAINT `travel_ibfk_4` FOREIGN KEY (`cargoSupplierFk`) REFERENCES `Proveedores` (`Id_Proveedor`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=108897 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC; +) ENGINE=InnoDB AUTO_INCREMENT=110172 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -12347,7 +12473,7 @@ CREATE TABLE `travel_dits` ( KEY `fgkey2_idx` (`Id_Ticket`), KEY `fgkey3_idx` (`Id_Trabajador`), CONSTRAINT `travel_dits_ibfk_1` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=172557 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=175463 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -12374,7 +12500,7 @@ CREATE TABLE `travel_pattern` ( CONSTRAINT `travel_pattern_ibfk_3` FOREIGN KEY (`warehouse_out`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `travel_pattern_ibfk_4` FOREIGN KEY (`agency_id`) REFERENCES `Agencias` (`Id_Agencia`) ON UPDATE CASCADE, CONSTRAINT `travel_pattern_ibfk_5` FOREIGN KEY (`warehouse_in`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=325 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=327 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -13721,7 +13847,7 @@ CREATE TABLE `workerTeam` ( PRIMARY KEY (`id`), KEY `user_team_idx` (`user`), CONSTRAINT `user_team` FOREIGN KEY (`user`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=159 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=165 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -15577,7 +15703,7 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP FUNCTION IF EXISTS `ticket_total` */; +/*!50003 DROP FUNCTION IF EXISTS `ticket_totalkk` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -15587,7 +15713,7 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` FUNCTION `ticket_total`(ticket_id INT) RETURNS double +CREATE DEFINER=`root`@`%` FUNCTION `ticket_totalkk`(ticket_id INT) RETURNS double BEGIN /** * Calcula el total con IVA de un ticket. @@ -22338,27 +22464,28 @@ CREATE DEFINER=`root`@`%` PROCEDURE `CalculoRemesas`(IN vFechaRemesa DATE) BEGIN DROP TEMPORARY TABLE IF EXISTS TMP_REMESAS; - CREATE TEMPORARY TABLE TMP_REMESAS SELECT - CONCAT(p.NIF,REPEAT('0', 12-LENGTH(p.NIF))) as CIF1, - cli.Id_Cliente, - cli.Cliente, - cli.`IF` as NIF, - c.PaymentDate as Vencimiento, - 0 ImporteFac, - cast(c.Recibo as decimal(10,2)) as ImporteRec, - 0 as ImporteActual, - c.company_id empresa_id, - cli.RazonSocial, - cast(c.Recibo as decimal(10,2)) as ImporteTotal, - cast(c.Recibo as decimal(10,2)) as Saldo, - p.Proveedor as Empresa, - e.abbreviation as EMP, - cli.cuenta, - iban AS Iban, - CONVERT(SUBSTRING(iban,5,4),UNSIGNED INT) AS nrbe , - sepavnl as SEPA, - corevnl as RecibidoCORE - + CREATE TEMPORARY TABLE TMP_REMESAS + SELECT + CONCAT(p.NIF,REPEAT('0', 12-LENGTH(p.NIF))) as CIF1, + cli.Id_Cliente, + cli.Cliente, + cli.`IF` as NIF, + c.PaymentDate as Vencimiento, + 0 ImporteFac, + cast(c.Recibo as decimal(10,2)) as ImporteRec, + 0 as ImporteActual, + c.company_id empresa_id, + cli.RazonSocial, + cast(c.Recibo as decimal(10,2)) as ImporteTotal, + cast(c.Recibo as decimal(10,2)) as Saldo, + p.Proveedor as Empresa, + e.abbreviation as EMP, + cli.cuenta, + iban AS Iban, + CONVERT(SUBSTRING(iban,5,4),UNSIGNED INT) AS nrbe , + sepavnl as SEPA, + corevnl as RecibidoCORE, + hasLcr FROM Clientes cli JOIN (SELECT risk.company_id, @@ -24104,248 +24231,6 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `comparativeTestkk` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `comparativeTestkk`( - v_date DATETIME - ,days TINYINT - ,i_wh TINYINT - ,i_tipo INT - ,i_filtro INT -) -BEGIN - DECLARE wstart INT; - DECLARE wend INT; - DECLARE cyear INT; - DECLARE date_cyear_ini DATETIME; - DECLARE date_cyear_end DATETIME; - DECLARE week_count TINYINT DEFAULT 7; - DECLARE date_lyear_ini DATETIME; - DECLARE date_lyear_end DATETIME; - DECLARE corrector INT; - DECLARE w1, w2, w3, w4, w5, w6, w7 INT; - DECLARE y1, y2, y3, y4, y5, y6, y7 INT; - DECLARE wperiod INT;-- DECLARE ws, ys INT; -- PAK 11/01/2016 - DECLARE i INT DEFAULT 0; - DECLARE lastCOMP BIGINT; -- Almacena el ultimo valor del Periodo - DECLARE strFILTRO VARCHAR(255) DEFAULT 'TRUE'; - - IF i_filtro THEN - SELECT `sql` INTO strFILTRO FROM filtros WHERE id = i_filtro; - END IF; - - SET corrector = 1; - - IF days < 0 OR days > 30 THEN - SET days = 15; - END IF; - - IF i_wh = NULL THEN - SET i_wh = 0; - END IF; - -- JGF 2015-04-16 cambio -21 por -22 para que la semana cuente de domingo a sabado - SET date_cyear_ini = TIMESTAMP(DATE(TIMESTAMPADD(DAY, -22 - WEEKDAY(v_date), v_date)), '00:00:00'); - SET date_cyear_end = TIMESTAMP(DATE(TIMESTAMPADD(DAY, (7 * week_count) -1, date_cyear_ini)), '23:59:59'); - -- Eliminamos el calculo del inventario para fechas en el pasado - - CALL article (); - - INSERT INTO article_inventory (article_id) - SELECT Id_Article FROM Articles a - JOIN Tipos t ON a.tipo_id = t.tipo_id - LEFT JOIN vn2008.reinos r ON r.id = t.reino_id - WHERE (i_tipo = 0 OR a.tipo_id = i_tipo) - AND r.display <> 0; - - IF v_date < CURDATE() - THEN - ALTER TABLE `article_inventory` - ADD `buy_id` INT NOT NULL DEFAULT 0, - ADD `buy_date` DATE DEFAULT '2000-01-01', - ADD `life` INT DEFAULT 0, - ADD `sd` INT DEFAULT 0, - ADD `avalaible` INT DEFAULT 0, - ADD `visible` INT DEFAULT 0; - - ELSE - - CALL inventario_multiple_2 (v_date, i_wh, days); - - CALL article_multiple_buy (v_date, i_wh); - - CALL article_multiple_buy_date (v_date, i_wh); - - - END IF; - - - DROP TEMPORARY TABLE IF EXISTS wtable; - - CREATE TEMPORARY TABLE wtable ( - cy INT(6), - ly INT(6) - ); - - REPEAT - SET i = i + 1; - SET wperiod = vnperiod(TIMESTAMPADD(DAY, 7*(i - 1), date_cyear_ini)); -- PAK 11/01/2016 - INSERT INTO wtable(cy, ly) VALUES(wperiod, wperiod - 100); -- VALUES( ys * 100 + ws, (ys -1) * 100 + ws); -- PAK 11/01/2016 - - UNTIL i = 7 END REPEAT; - - - SELECT cy, ly INTO w1, y1 FROM wtable limit 1; - SELECT cy, ly INTO w2, y2 FROM wtable WHERE cy > w1 limit 1; - SELECT cy, ly INTO w3, y3 FROM wtable WHERE cy > w2 limit 1; - SELECT cy, ly INTO w4, y4 FROM wtable WHERE cy > w3 limit 1; - - SELECT cy, ly INTO w5, y5 FROM wtable WHERE cy > w4 limit 1; - SELECT cy, ly INTO w6, y6 FROM wtable WHERE cy > w5 limit 1; - SELECT cy, ly INTO w7, y7 FROM wtable WHERE cy > w6 limit 1; - DROP TEMPORARY TABLE wtable; - - SET cyear = YEAR(date_cyear_ini); - - -- Genera una tabla con los datos del año pasado. - - DROP TEMPORARY TABLE IF EXISTS last_year; - CREATE TEMPORARY TABLE last_year - (KEY (Id_Article)) - ENGINE = MEMORY - SELECT Id_Article - - ,CAST(SUM(IF(Periodo = y1, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek1 - ,CAST(SUM(IF(Periodo = y2, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek2 - ,CAST(SUM(IF(Periodo = y3, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek3 - ,CAST(SUM(IF(Periodo = y4, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek4 - ,CAST(SUM(IF(Periodo = y5, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek5 - ,CAST(SUM(IF(Periodo = y6, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek6 - ,CAST(SUM(IF(Periodo = y7, Cantidad, 0)) AS DECIMAL(10,0)) AS lweek7 - - ,CAST(SUM(IF(Periodo = y1, price, 0)) AS DECIMAL(10,0)) AS lprice1 - ,CAST(SUM(IF(Periodo = y2, price, 0)) AS DECIMAL(10,0)) AS lprice2 - ,CAST(SUM(IF(Periodo = y3, price, 0)) AS DECIMAL(10,0)) AS lprice3 - ,CAST(SUM(IF(Periodo = y4, price, 0)) AS DECIMAL(10,0)) AS lprice4 - ,CAST(SUM(IF(Periodo = y5, price, 0)) AS DECIMAL(10,0)) AS lprice5 - ,CAST(SUM(IF(Periodo = y6, price, 0)) AS DECIMAL(10,0)) AS lprice6 - ,CAST(SUM(IF(Periodo = y7, price, 0)) AS DECIMAL(10,0)) AS lprice7 - - FROM Comparativa - JOIN warehouse W on W.id = warehouse_id - WHERE (Periodo BETWEEN y1 and y7) - AND IF(i_wh = 0, W.is_comparative, i_wh = warehouse_id) - GROUP BY Id_Article; - - -- Genera una tabla con los datos de este año. - - DROP TEMPORARY TABLE IF EXISTS cur_year; - CREATE TEMPORARY TABLE cur_year - (KEY (Id_Article)) - ENGINE = MEMORY - SELECT Id_Article - - ,CAST(SUM(IF(week = w1, Total, 0)) AS DECIMAL(10,0)) AS cweek1 - ,CAST(SUM(IF(week = w2, Total, 0)) AS DECIMAL(10,0)) AS cweek2 - ,CAST(SUM(IF(week = w3, Total, 0)) AS DECIMAL(10,0)) AS cweek3 - ,CAST(SUM(IF(week = w4, Total, 0)) AS DECIMAL(10,0)) AS cweek4 - ,CAST(SUM(IF(week = w5, Total, 0)) AS DECIMAL(10,0)) AS cweek5 - ,CAST(SUM(IF(week = w6, Total, 0)) AS DECIMAL(10,0)) AS cweek6 - ,CAST(SUM(IF(week = w7, Total, 0)) AS DECIMAL(10,0)) AS cweek7 - - ,CAST(SUM(IF(week = w1, price, 0)) AS DECIMAL(10,0)) AS cprice1 - ,CAST(SUM(IF(week = w2, price, 0)) AS DECIMAL(10,0)) AS cprice2 - ,CAST(SUM(IF(week = w3, price, 0)) AS DECIMAL(10,0)) AS cprice3 - ,CAST(SUM(IF(week = w4, price, 0)) AS DECIMAL(10,0)) AS cprice4 - ,CAST(SUM(IF(week = w5, price, 0)) AS DECIMAL(10,0)) AS cprice5 - ,CAST(SUM(IF(week = w6, price, 0)) AS DECIMAL(10,0)) AS cprice6 - ,CAST(SUM(IF(week = w7, price, 0)) AS DECIMAL(10,0)) AS cprice7 - - FROM ( - SELECT A.Id_Article - ,CTS.period week - ,SUM(Cantidad) AS Total - ,TRUNCATE(SUM(Cantidad * IF(T.Fecha >= '2015-10-01',M.CostFixat,Preu * (100 - Descuento) / 100)),0) AS price - FROM Movimientos M - LEFT JOIN Tickets T ON T.Id_Ticket = M.Id_Ticket - INNER JOIN `time` CTS ON CTS.`date` = DATE(T.Fecha) - INNER JOIN Articles A USING (Id_Article) - INNER JOIN Tipos tp ON tp.tipo_id = A.tipo_id - LEFT JOIN reinos r ON r.id = tp.reino_id - JOIN warehouse W ON W.id = T.warehouse_id - WHERE Fecha BETWEEN date_cyear_ini AND date_cyear_end - AND T.Id_Cliente NOT IN(400,200) - AND IF(i_wh = 0, W.is_comparative, i_wh = T.warehouse_id) - AND r.display <> 0 - - GROUP BY A.Id_Article, week - ) t - GROUP BY Id_Article; - -- Genera la tabla con la comparativa. - - DROP TEMPORARY TABLE IF EXISTS remcom; - - SET strFILTRO = REPLACE(strFILTRO, 'Id_Article','A.Id_Article'); - SET strFILTRO = REPLACE(strFILTRO, 'tipo_id','tp.tipo_id'); - -- select * from article_inventory; - CALL util.exec (sql_printf - ( - 'SELECT - an.nicho, p.name Productor, C.Packing, C.Costefijo - ,A.Color, Id_Tipo as Tipo,A.tipo_id, o.Abreviatura as Origen, A.Categoria - ,A.Tallos, A.Medida, A.Article, TR.CodigoTrabajador - - ,cweek1, cweek2, cweek3, cweek4, cweek5, cweek6, cweek7 - ,lweek1, lweek2, lweek3, lweek4, lweek5, lweek6, lweek7 - - ,cprice1, cprice2, cprice3, cprice4, cprice5, cprice6, cprice7 - ,lprice1, lprice2, lprice3, lprice4, lprice5, lprice6, lprice7 - - ,A.Id_Article, i.buy_id , tp.life , CAST(IFNULL(i.sd,0) AS SIGNED) as sd - ,CAST(i.avalaible AS SIGNED) avalaible, CAST(i.visible AS SIGNED) visible, i.buy_date - ,E.Id_Proveedor AS provider_id, t.Orden, t.Tinta - ,A.offer, A.bargain, A.comments, A.relevancy, A.description itemDescription - ,IF(cy.Id_Article IS NULL AND i.visible = 0 AND i.avalaible = 0 AND IFNULL(i.sd, 0) = 0, FALSE, TRUE) AS filtret - ,(IFNULL(it.itemFk,0) != 0) isTagged - FROM vn2008.article_inventory i - JOIN vn2008.Articles A ON A.Id_Article = i.article_id - LEFT JOIN vn.itemTagged it ON it.itemFk = i.article_id - LEFT JOIN vn2008.Articles_nicho an ON A.Id_Article = an.Id_Article AND an.warehouse_id = %s - LEFT JOIN vn2008.producer p ON p.producer_id = A.producer_id - LEFT JOIN vn2008.Tipos tp ON A.tipo_id = tp.tipo_id - LEFT JOIN vn2008.reinos r ON r.id = tp.reino_id - LEFT JOIN vn2008.Trabajadores TR ON TR.Id_Trabajador = tp.Id_Trabajador - LEFT JOIN vn2008.Tintas t ON t.Id_Tinta = A.color - LEFT JOIN vn2008.Compres C ON i.buy_id = C.Id_Compra - LEFT JOIN vn2008.Entradas E USING(Id_Entrada) - LEFT JOIN vn2008.Origen o ON o.id = A.id_origen - LEFT JOIN vn2008.last_year ly ON ly.Id_Article = A.Id_Article - LEFT JOIN vn2008.cur_year cy ON cy.Id_Article = A.Id_Article AND (i.avalaible <> 0 OR i.visible <> 0 OR cweek1 OR cweek2 OR cweek3 OR cweek4 - OR cweek5 OR cweek6 OR cweek7 OR lweek1 OR lweek2 OR lweek3 OR lweek4 OR lweek5 - OR lweek6 OR lweek7) - WHERE r.display <> 0 AND %s ' - - ,i_wh,strFILTRO - )); - - -- Destruye las tablas temporales creadas. - - DROP TEMPORARY TABLE last_year; - DROP TEMPORARY TABLE cur_year; - DROP TEMPORARY TABLE article_inventory; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `compresFromTicket` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -38601,7 +38486,7 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticket_iva` */; +/*!50003 DROP PROCEDURE IF EXISTS `ticket_ivakk` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -38611,7 +38496,7 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `ticket_iva`(vBillingDate DATE) +CREATE DEFINER=`root`@`%` PROCEDURE `ticket_ivakk`(vBillingDate DATE) READS SQL DATA BEGIN /** @@ -38630,7 +38515,7 @@ BEGIN ENGINE = MEMORY SELECT ticket_id ticketFk FROM ticket_tmp; - CALL vn.ticketGetTax (vBillingDate); + CALL vn.ticketGetTax (); CREATE TEMPORARY TABLE ticket_iva (INDEX (ticket_id)) @@ -38842,7 +38727,7 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticket_total` */; +/*!50003 DROP PROCEDURE IF EXISTS `ticket_totalkk` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -38852,7 +38737,7 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `ticket_total`() +CREATE DEFINER=`root`@`%` PROCEDURE `ticket_totalkk`() BEGIN /** * Calcula el total con IVA de un conjunto de tickets. @@ -40308,79 +40193,80 @@ DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `travelDetail`() BEGIN -DECLARE vGap VARCHAR(10) DEFAULT ' '; -DECLARE vDateFrom DATE DEFAULT TIMESTAMPADD(WEEK,-1,CURDATE()); + DECLARE vDateFrom DATE DEFAULT TIMESTAMPADD(WEEK,-1,CURDATE()); -SELECT * FROM -( -SELECT - 1 as IsTravel, - tr.id as travel, - NULL as Entrada, - ag.Agencia, - tr.ref, - tr.shipment, - wo.name as OrigenCajas, - tr.landing, - w.name as Destino, - sum(c.Etiquetas) as Etiquetas, - NULL as Notas_Eva, - kg, - cast(sum(a.density * c.Etiquetas * IF(cb.Volumen, cb.Volumen, cb.X * cb.Y * cb.Z) / 1000000 ) as DECIMAL(10,0)) as loadedKg, - NULL as loadPriority, - NULL as Notas, - pc.Alias as Carguera - FROM travel tr - LEFT JOIN Proveedores pc ON pc.Id_Proveedor = tr.cargoSupplierFk - LEFT JOIN Entradas e ON e.travel_id = tr.id - LEFT JOIN Compres c ON c.Id_Entrada = e.Id_Entrada - LEFT JOIN Cubos cb ON cb.Id_Cubo = c.Id_Cubo - LEFT JOIN Articles a ON a.Id_Article = c.Id_Article - LEFT JOIN Tipos tp ON tp.tipo_id = a.tipo_id - JOIN warehouse w ON w.id = tr.warehouse_id - JOIN warehouse wo ON wo.id = tr.warehouse_id_out - JOIN Agencias ag ON ag.Id_Agencia = tr.agency_id - WHERE tr.landing >= vDateFrom - GROUP BY tr.id + SELECT * FROM + ( + SELECT + 1 as IsTravel, + tr.id as travel, + NULL as Entrada, + ag.Agencia, + tr.ref, + tr.shipment, + wo.name as OrigenCajas, + tr.landing, + w.name as Destino, + sum(c.Etiquetas) as Etiquetas, + NULL as Notas_Eva, + kg, + cast(sum(a.density * c.Etiquetas * IF(cb.Volumen, cb.Volumen, cb.X * cb.Y * cb.Z) / 1000000 ) as DECIMAL(10,0)) as loadedKg, + cast(sum(167.5 * c.Etiquetas * IF(cb.Volumen, cb.Volumen, cb.X * cb.Y * cb.Z) / 1000000 ) as DECIMAL(10,0)) as volumeKg, + NULL as loadPriority, + NULL as Notas, + pc.Alias as Carguera + FROM travel tr + LEFT JOIN Proveedores pc ON pc.Id_Proveedor = tr.cargoSupplierFk + LEFT JOIN Entradas e ON e.travel_id = tr.id + LEFT JOIN Compres c ON c.Id_Entrada = e.Id_Entrada + LEFT JOIN Cubos cb ON cb.Id_Cubo = c.Id_Cubo + LEFT JOIN Articles a ON a.Id_Article = c.Id_Article + LEFT JOIN Tipos tp ON tp.tipo_id = a.tipo_id + JOIN warehouse w ON w.id = tr.warehouse_id + JOIN warehouse wo ON wo.id = tr.warehouse_id_out + JOIN Agencias ag ON ag.Id_Agencia = tr.agency_id + WHERE tr.landing >= vDateFrom + GROUP BY tr.id -UNION ALL + UNION ALL -SELECT - 0 as IsTravel, - e.travel_id as travel, - e.Id_Entrada, - CONCAT(vGap,p.Proveedor), - e.Referencia, - tr.shipment, - wo.name as OrigenCajas, - tr.landing, - w.name as Destino, - sum(Etiquetas) as Etiquetas, - e.Notas_Eva, - NULL as kg, - cast(sum(a.density * c.Etiquetas * IF(cb.Volumen, cb.Volumen, cb.X * cb.Y * cb.Z) / 1000000 ) as DECIMAL(10,0)) as loadedkg, - loadPriority, - -- CAST(awb.codigo AS DECIMAL(11,0)) as awb, - e.Notas, - pc.Alias as carguera - - FROM Entradas e - /* LEFT JOIN recibida_entrada re ON re.Id_Entrada = e.Id_Entrada - LEFT JOIN awb_recibida ar ON ar.recibida_id = re.awb_recibida - LEFT JOIN awb ON awb.id = ar.awb_id - */ JOIN Compres c ON c.Id_Entrada = e.Id_Entrada - JOIN Cubos cb ON cb.Id_Cubo = c.Id_Cubo - JOIN Articles a ON a.Id_Article = c.Id_Article - JOIN Tipos tp ON tp.tipo_id = a.tipo_id - JOIN Proveedores p ON p.Id_Proveedor = e.Id_Proveedor - JOIN travel tr ON tr.id = e.travel_id - LEFT JOIN Proveedores pc ON pc.Id_Proveedor = tr.cargoSupplierFk - JOIN warehouse w ON w.id = tr.warehouse_id - JOIN warehouse wo ON wo.id = tr.warehouse_id_out - WHERE tr.landing >= vDateFrom - GROUP BY e.Id_Entrada -) sub -ORDER BY landing,shipment, travel, IsTravel DESC, (loadPriority > 0) DESC,loadPriority, Agencia, Notas_Eva ; + SELECT + 0 as IsTravel, + e.travel_id as travel, + e.Id_Entrada, + p.Proveedor, + e.Referencia, + tr.shipment, + wo.name as OrigenCajas, + tr.landing, + w.name as Destino, + sum(Etiquetas) as Etiquetas, + e.Notas_Eva, + NULL as kg, + cast(sum(a.density * c.Etiquetas * IF(cb.Volumen, cb.Volumen, cb.X * cb.Y * cb.Z) / 1000000 ) as DECIMAL(10,0)) as loadedkg, + cast(sum(167.5 * c.Etiquetas * IF(cb.Volumen, cb.Volumen, cb.X * cb.Y * cb.Z) / 1000000 ) as DECIMAL(10,0)) as volumeKg, + loadPriority, + -- CAST(awb.codigo AS DECIMAL(11,0)) as awb, + e.Notas, + pc.Alias as carguera + + FROM Entradas e + /* LEFT JOIN recibida_entrada re ON re.Id_Entrada = e.Id_Entrada + LEFT JOIN awb_recibida ar ON ar.recibida_id = re.awb_recibida + LEFT JOIN awb ON awb.id = ar.awb_id + */ JOIN Compres c ON c.Id_Entrada = e.Id_Entrada + JOIN Cubos cb ON cb.Id_Cubo = c.Id_Cubo + JOIN Articles a ON a.Id_Article = c.Id_Article + JOIN Tipos tp ON tp.tipo_id = a.tipo_id + JOIN Proveedores p ON p.Id_Proveedor = e.Id_Proveedor + JOIN travel tr ON tr.id = e.travel_id + LEFT JOIN Proveedores pc ON pc.Id_Proveedor = tr.cargoSupplierFk + JOIN warehouse w ON w.id = tr.warehouse_id + JOIN warehouse wo ON wo.id = tr.warehouse_id_out + WHERE tr.landing >= vDateFrom + GROUP BY e.Id_Entrada + ) sub + ORDER BY landing,shipment, travel, IsTravel DESC, (loadPriority > 0) DESC,loadPriority, Agencia, Notas_Eva ; END ;; DELIMITER ; @@ -40584,6 +40470,7 @@ BEGIN ORDER BY ( (ah.week_day IS NOT NULL) + (ah.agency_id IS NOT NULL) + + (- ah.subtract_day) + ((ah.province_id IS NOT NULL)*3) ) DESC ) t @@ -42833,6 +42720,21 @@ SET character_set_client = utf8; 1 AS `bonus`*/; SET character_set_client = @saved_cs_client; +-- +-- Table structure for table `alertLevel` +-- + +DROP TABLE IF EXISTS `alertLevel`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `alertLevel` ( + `code` varchar(45) CHARACTER SET utf8 NOT NULL, + `alertLevel` int(11) NOT NULL, + PRIMARY KEY (`code`), + CONSTRAINT `fk_code_1` FOREIGN KEY (`code`) REFERENCES `vn2008`.`state` (`code`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Temporary table structure for view `annualAverageInvoiced` -- @@ -43307,7 +43209,7 @@ CREATE TABLE `clientLog` ( KEY `userFk` (`userFk`), CONSTRAINT `clientLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `clientLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=166687 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=168406 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43726,7 +43628,7 @@ CREATE TABLE `creditClassification` ( KEY `creditClassifClientFk_idx` (`client`), KEY `creditClassifdateEnd_idx` (`dateEnd`), CONSTRAINT `creditClassifClientFk` FOREIGN KEY (`client`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2768 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2802 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; @@ -43771,7 +43673,7 @@ CREATE TABLE `creditInsurance` ( PRIMARY KEY (`id`), KEY `CreditInsurance_Fk1_idx` (`creditClassification`), CONSTRAINT `CreditInsurance_Fk1` FOREIGN KEY (`creditClassification`) REFERENCES `creditClassification` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1935 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalla los clientes que tienen seguro de credito'; +) ENGINE=InnoDB AUTO_INCREMENT=1996 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalla los clientes que tienen seguro de credito'; /*!40101 SET character_set_client = @saved_cs_client */; ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; @@ -43926,7 +43828,7 @@ CREATE TABLE `dua` ( CONSTRAINT `dua_fk1` FOREIGN KEY (`gestdocFk`) REFERENCES `vn2008`.`gestdoc` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `dua_fk2` FOREIGN KEY (`awbFk`) REFERENCES `vn2008`.`awb` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `dua_fk4` FOREIGN KEY (`companyFk`) REFERENCES `vn2008`.`empresa` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=3219 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3248 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43967,7 +43869,7 @@ CREATE TABLE `duaIntrastat` ( KEY `duaIntrastat_fk2_idx` (`duaFk`), CONSTRAINT `duaIntrastat_fk1` FOREIGN KEY (`intrastatFk`) REFERENCES `vn2008`.`Intrastat` (`Codintrastat`) ON UPDATE CASCADE, CONSTRAINT `duaIntrastat_fk2` FOREIGN KEY (`duaFk`) REFERENCES `dua` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=4482 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=4542 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43987,7 +43889,7 @@ CREATE TABLE `duaInvoiceIn` ( KEY `duaInvoiceIn_fk2_idx` (`invoiceInFk`), CONSTRAINT `duaInvoiceIn_fk1` FOREIGN KEY (`duaFk`) REFERENCES `dua` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `duaInvoiceIn_fk2` FOREIGN KEY (`invoiceInFk`) REFERENCES `vn2008`.`recibida` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=4173 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Facturas asociadas a la declaración aduanera, básicamente la del agente transitario'; +) ENGINE=InnoDB AUTO_INCREMENT=4191 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Facturas asociadas a la declaración aduanera, básicamente la del agente transitario'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44012,7 +43914,7 @@ CREATE TABLE `duaTax` ( CONSTRAINT `duaTax_fk1` FOREIGN KEY (`duaFk`) REFERENCES `dua` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `duaTax_fk2` FOREIGN KEY (`supplierFk`) REFERENCES `vn2008`.`Proveedores` (`Id_Proveedor`) ON UPDATE CASCADE, CONSTRAINT `duaTax_fk3` FOREIGN KEY (`taxClassFk`) REFERENCES `vn2008`.`iva_group` (`iva_group_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1277 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1496 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44108,7 +44010,7 @@ CREATE TABLE `entryLog` ( KEY `entryLog_ibfk_2` (`userFk`), CONSTRAINT `entryLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Entradas` (`Id_Entrada`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `entryLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=53296 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=57239 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44692,7 +44594,7 @@ CREATE TABLE `invoiceOutExpence` ( KEY `invoiceOutExpence_FK_2_idx` (`expenceFk`), CONSTRAINT `invoiceOutExpence_FK_1` FOREIGN KEY (`invoiceOutFk`) REFERENCES `vn2008`.`Facturas` (`factura_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `invoiceOutExpence_FK_2` FOREIGN KEY (`expenceFk`) REFERENCES `vn2008`.`Gastos` (`Id_Gasto`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=70220 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Desglosa la base imponible de una factura en funcion del tipo de gasto/venta'; +) ENGINE=InnoDB AUTO_INCREMENT=70587 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Desglosa la base imponible de una factura en funcion del tipo de gasto/venta'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44735,7 +44637,7 @@ CREATE TABLE `invoiceOutTax` ( KEY `pgcFk` (`pgcFk`), CONSTRAINT `invoiceOutFk` FOREIGN KEY (`invoiceOutFk`) REFERENCES `vn2008`.`Facturas` (`factura_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `invoiceOutTax_ibfk_1` FOREIGN KEY (`pgcFk`) REFERENCES `pgc` (`code`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=940415 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=940830 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44769,7 +44671,17 @@ SET character_set_client = utf8; 1 AS `taxClassFk`, 1 AS `minPrice`, 1 AS `hasMinPrice`, - 1 AS `isActive`*/; + 1 AS `isActive`, + 1 AS `longName`, + 1 AS `subName`, + 1 AS `tag5`, + 1 AS `value5`, + 1 AS `tag6`, + 1 AS `value6`, + 1 AS `tag7`, + 1 AS `value7`, + 1 AS `tag8`, + 1 AS `value8`*/; SET character_set_client = @saved_cs_client; -- @@ -44930,6 +44842,64 @@ CREATE TABLE `itemPlacement2` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `itemShelving` +-- + +DROP TABLE IF EXISTS `itemShelving`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `itemShelving` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `itemFk` int(11) NOT NULL, + `shelvingFk` varchar(5) COLLATE utf8_unicode_ci NOT NULL, + `shelve` varchar(2) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'A', + `deep` int(11) unsigned NOT NULL DEFAULT '1', + `quantity` int(11) unsigned NOT NULL DEFAULT '0', + `visible` int(11) unsigned NOT NULL DEFAULT '0', + `available` int(11) unsigned NOT NULL DEFAULT '0', + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `priority` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'El 0 es la mínima prioridad', + `grouping` smallint(5) unsigned DEFAULT NULL, + `packing` int(11) unsigned DEFAULT NULL, + `packagingFk` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `itemShelving_UNIQUE` (`shelvingFk`,`shelve`,`deep`), + KEY `itemShelving_fk1_idx` (`itemFk`), + KEY `itemShelving_fk2_idx` (`shelvingFk`), + KEY `itemShelving_fk3_idx` (`packagingFk`), + CONSTRAINT `itemShelving_fk1` FOREIGN KEY (`itemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `itemShelving_fk2` FOREIGN KEY (`shelvingFk`) REFERENCES `shelving` (`code`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `itemShelving_fk3` FOREIGN KEY (`packagingFk`) REFERENCES `vn2008`.`Cubos` (`Id_Cubo`) ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Temporary table structure for view `itemShelvingAvailable` +-- + +DROP TABLE IF EXISTS `itemShelvingAvailable`; +/*!50001 DROP VIEW IF EXISTS `itemShelvingAvailable`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `itemShelvingAvailable` AS SELECT + 1 AS `saleFk`, + 1 AS `Modificado`, + 1 AS `ticketFk`, + 1 AS `isPicked`, + 1 AS `itemFk`, + 1 AS `quantity`, + 1 AS `concept`, + 1 AS `size`, + 1 AS `Estado`, + 1 AS `orden`, + 1 AS `available`, + 1 AS `sectorFk`, + 1 AS `matricula`, + 1 AS `parking`, + 1 AS `itemShelving`*/; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `itemTag` -- @@ -44948,8 +44918,100 @@ CREATE TABLE `itemTag` ( KEY `priorityItem` (`itemFk`,`priority`), KEY `tagFk` (`tagFk`,`value`), CONSTRAINT `itemFK` FOREIGN KEY (`itemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=327619 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=379836 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn`.`itemTag_BEFORE_INSERT` BEFORE INSERT ON `itemTag` FOR EACH ROW +BEGIN + + IF NEW.priority = 1 AND NEW.value IS NOT NULL THEN + UPDATE item i + JOIN tag t ON t.id = NEW.tagFk + SET tag5 = t.name, value5 = NEW.value + WHERE i.id = NEW.itemFk; + END IF; + + IF NEW.priority = 2 AND NEW.value IS NOT NULL THEN + UPDATE item i + JOIN tag t ON t.id = NEW.tagFk + SET tag6 = t.name, value6 = NEW.value + WHERE i.id = NEW.itemFk; + END IF; + + IF NEW.priority = 3 AND NEW.value IS NOT NULL THEN + UPDATE item i + JOIN tag t ON t.id = NEW.tagFk + SET tag7 = t.name, value7 = NEW.value + WHERE i.id = NEW.itemFk; + END IF; + + IF NEW.priority = 4 AND NEW.value IS NOT NULL then + UPDATE item i + JOIN tag t ON t.id = NEW.tagFk + SET tag8 = t.name, value8 = NEW.value + WHERE i.id = NEW.itemFk; + END IF; + +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn`.`itemTag_BEFORE_UPDATE` BEFORE UPDATE ON `itemTag` FOR EACH ROW +BEGIN + + IF NEW.priority = 1 AND NEW.value IS NOT NULL THEN + UPDATE item i + JOIN tag t ON t.id = NEW.tagFk + SET tag5 = t.name, value5 = NEW.value + WHERE i.id = NEW.itemFk; + END IF; + + IF NEW.priority = 2 AND NEW.value IS NOT NULL THEN + UPDATE item i + JOIN tag t ON t.id = NEW.tagFk + SET tag6 = t.name, value6 = NEW.value + WHERE i.id = NEW.itemFk; + END IF; + + IF NEW.priority = 3 AND NEW.value IS NOT NULL THEN + UPDATE item i + JOIN tag t ON t.id = NEW.tagFk + SET tag7 = t.name, value7 = NEW.value + WHERE i.id = NEW.itemFk; + END IF; + + IF NEW.priority = 4 AND NEW.value IS NOT NULL then + UPDATE item i + JOIN tag t ON t.id = NEW.tagFk + SET tag8 = t.name, value8 = NEW.value + WHERE i.id = NEW.itemFk; + END IF; + +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `itemTagArranged` @@ -45010,7 +45072,7 @@ CREATE TABLE `itemTaxCountry` ( CONSTRAINT `countryFK_paises` FOREIGN KEY (`countryFk`) REFERENCES `vn2008`.`Paises` (`Id`) ON UPDATE CASCADE, CONSTRAINT `itemFK_Article` FOREIGN KEY (`itemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `taxClassFK_Iva_Group` FOREIGN KEY (`taxClassFk`) REFERENCES `vn2008`.`iva_group` (`iva_group_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=502664 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Define la clase de iva por artículo y pais'; +) ENGINE=InnoDB AUTO_INCREMENT=507938 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Define la clase de iva por artículo y pais'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -45242,7 +45304,7 @@ CREATE TABLE `message` ( KEY `sender` (`sender`), KEY `recipient` (`recipient`), KEY `uuid` (`uuid`(8)) -) ENGINE=InnoDB AUTO_INCREMENT=1519133 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1534736 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -45264,7 +45326,7 @@ CREATE TABLE `messageInbox` ( PRIMARY KEY (`id`), KEY `uuid` (`uuid`(8)), KEY `finalRecipient` (`finalRecipient`) -) ENGINE=InnoDB AUTO_INCREMENT=1666176 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1682549 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -45499,6 +45561,24 @@ SET character_set_client = utf8; 1 AS `isBox`*/; SET character_set_client = @saved_cs_client; +-- +-- Table structure for table `parking` +-- + +DROP TABLE IF EXISTS `parking`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `parking` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `column` varchar(5) COLLATE utf8_unicode_ci NOT NULL, + `row` varchar(5) COLLATE utf8_unicode_ci NOT NULL, + `sectorFk` int(11) NOT NULL DEFAULT '2', + PRIMARY KEY (`id`), + KEY `parking_fk1_idx` (`sectorFk`), + CONSTRAINT `parking_fk1` FOREIGN KEY (`sectorFk`) REFERENCES `sector` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Temporary table structure for view `payDem` -- @@ -45917,7 +45997,8 @@ SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE VIEW `producer` AS SELECT 1 AS `id`, - 1 AS `name`*/; + 1 AS `name`, + 1 AS `isVisible`*/; SET character_set_client = @saved_cs_client; -- @@ -46165,7 +46246,7 @@ CREATE TABLE `routeLog` ( `creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `description` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=515021 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=534339 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46234,6 +46315,24 @@ SET character_set_client = utf8; 1 AS `value`*/; SET character_set_client = @saved_cs_client; +-- +-- Table structure for table `saleItemShelving` +-- + +DROP TABLE IF EXISTS `saleItemShelving`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `saleItemShelving` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `saleFk` int(11) NOT NULL, + `itemShelvingFk` int(11) NOT NULL, + `quantity` int(11) NOT NULL DEFAULT '0', + `isPicked` tinyint(4) NOT NULL DEFAULT '0', + `ubication` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=51 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Temporary table structure for view `saleTracking` -- @@ -46249,9 +46348,43 @@ SET character_set_client = utf8; 1 AS `originalQuantity`, 1 AS `workerFk`, 1 AS `actionFk`, - 1 AS `id`*/; + 1 AS `id`, + 1 AS `stateFk`*/; SET character_set_client = @saved_cs_client; +-- +-- Table structure for table `sector` +-- + +DROP TABLE IF EXISTS `sector`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `sector` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `description` varchar(45) COLLATE utf8_unicode_ci NOT NULL, + `warehouseFk` smallint(6) unsigned NOT NULL DEFAULT '1', + PRIMARY KEY (`id`,`warehouseFk`), + KEY `sector_fk1_idx` (`warehouseFk`), + CONSTRAINT `sector_fk1` FOREIGN KEY (`warehouseFk`) REFERENCES `vn2008`.`warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `shelving` +-- + +DROP TABLE IF EXISTS `shelving`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `shelving` ( + `code` varchar(5) COLLATE utf8_unicode_ci NOT NULL, + `parkingFk` int(11) DEFAULT NULL, + PRIMARY KEY (`code`), + KEY `shelving_fk1_idx` (`parkingFk`), + CONSTRAINT `shelving_fk1` FOREIGN KEY (`parkingFk`) REFERENCES `parking` (`id`) ON DELETE SET NULL ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `sms` -- @@ -46270,7 +46403,7 @@ CREATE TABLE `sms` ( `status` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=98690 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=100073 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46434,7 +46567,22 @@ CREATE TABLE `stockBuyed` ( UNIQUE KEY `date_UNIQUE` (`date`,`user`), KEY `stockBuyed_user_idx` (`user`), CONSTRAINT `stockBuyedUserFk` FOREIGN KEY (`user`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=342251 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=356828 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `stowaway` +-- + +DROP TABLE IF EXISTS `stowaway`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `stowaway` ( + `id` int(11) NOT NULL, + `shipFk` int(11) NOT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tickets polizones y sus naves de embarque'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46496,7 +46644,7 @@ CREATE TABLE `tag` ( `sourceTable` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `unit` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=79 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Categorias para etiquetar los productos'; +) ENGINE=InnoDB AUTO_INCREMENT=80 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Categorias para etiquetar los productos'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46657,7 +46805,7 @@ CREATE TABLE `ticketLog` ( KEY `logTicketuserFk` (`userFk`), CONSTRAINT `ticketLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticketLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1037767 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1096716 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46757,7 +46905,7 @@ CREATE TABLE `ticketPackaging` ( KEY `ticketPackaging_fk2_idx` (`packagingFk`), CONSTRAINT `ticketPackaging_fk1` FOREIGN KEY (`ticketFk`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticketPackaging_fk2` FOREIGN KEY (`packagingFk`) REFERENCES `vn2008`.`Cubos` (`Id_Cubo`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=32971 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=34863 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -47237,7 +47385,7 @@ CREATE TABLE `workerDocument` ( KEY `workerDocument_ibfk_2` (`document`), CONSTRAINT `workerDocument_ibfk_1` FOREIGN KEY (`worker`) REFERENCES `vn2008`.`Trabajadores` (`user_id`) ON UPDATE CASCADE, CONSTRAINT `workerDocument_ibfk_2` FOREIGN KEY (`document`) REFERENCES `vn2008`.`gestdoc` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=6173 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=6318 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -47281,11 +47429,13 @@ CREATE TABLE `workerJourney` ( `priceExtraHollyday` decimal(5,2) NOT NULL DEFAULT '0.00', `businessFk` int(11) DEFAULT NULL, `isPaid` tinyint(1) NOT NULL DEFAULT '0', + `isUpdated` tinyint(1) NOT NULL DEFAULT '0', + `permission` decimal(5,2) NOT NULL DEFAULT '0.00', PRIMARY KEY (`id`), UNIQUE KEY `userFk_UNIQUE` (`userFk`,`dated`), KEY `fk_workerJourney_user_idx` (`userFk`), CONSTRAINT `fk_workerJourney_user` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=736885 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=4005101 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -47307,7 +47457,7 @@ CREATE TABLE `workerLog` ( KEY `userFk_idx` (`userFk`), CONSTRAINT `userFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `workerFk` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=4578 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=4964 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -47333,15 +47483,50 @@ DROP TABLE IF EXISTS `workerTimeControl`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `workerTimeControl` ( - `id` int(11) NOT NULL, + `id` int(11) NOT NULL AUTO_INCREMENT, `userFk` int(10) unsigned NOT NULL, `timed` datetime NOT NULL, `manual` tinyint(4) NOT NULL DEFAULT '0', `order` int(11) DEFAULT NULL, + `warehouseFk` smallint(6) unsigned DEFAULT NULL, PRIMARY KEY (`id`), - KEY `workerTimeControl_fk1_idx` (`userFk`), + UNIQUE KEY `userFk_Timed_uniq` (`userFk`,`timed`), + KEY `warehouseFkfk1_idx` (`warehouseFk`), + CONSTRAINT `warehouseFk_1` FOREIGN KEY (`warehouseFk`) REFERENCES `vn2008`.`warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `workerTimeControl_fk1` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Fichadas'; +) ENGINE=InnoDB AUTO_INCREMENT=1350792 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Fichadas'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `workerTimeControlConfig` +-- + +DROP TABLE IF EXISTS `workerTimeControlConfig`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `workerTimeControlConfig` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `warehouseFk` smallint(6) unsigned NOT NULL, + `host` varchar(45) COLLATE utf8_unicode_ci NOT NULL, + PRIMARY KEY (`id`), + KEY `warehouseFk_1_idx` (`warehouseFk`), + CONSTRAINT `warehouseFk_2` FOREIGN KEY (`warehouseFk`) REFERENCES `vn2008`.`warehouse` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `workerTimeControlSchedule` +-- + +DROP TABLE IF EXISTS `workerTimeControlSchedule`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `workerTimeControlSchedule` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `time` time DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `punique_trhf` (`time`) +) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -47361,6 +47546,23 @@ SET character_set_client = utf8; 1 AS `firstname`*/; SET character_set_client = @saved_cs_client; +-- +-- Temporary table structure for view `workerTimeJourneyNG` +-- + +DROP TABLE IF EXISTS `workerTimeJourneyNG`; +/*!50001 DROP VIEW IF EXISTS `workerTimeJourneyNG`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `workerTimeJourneyNG` AS SELECT + 1 AS `userFk`, + 1 AS `dated`, + 1 AS `Journey`, + 1 AS `dayName`, + 1 AS `name`, + 1 AS `firstname`*/; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `workingHours` -- @@ -48750,52 +48952,6 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP FUNCTION IF EXISTS `isWorkerBosskk` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` FUNCTION `isWorkerBosskk`(vUserId INT(11)) RETURNS tinyint(1) - DETERMINISTIC -BEGIN -/*DEPRECATED usar workerIsBoss 2018-05-15 jgf*/ - DECLARE subjectId INT(11) DEFAULT vUserId; - DECLARE tmpSubjectId INT(11); - DECLARE tmpBossId INT(11); - - LOOP - SELECT - bossWorker.user_id AS tmpBossId, - subjectWorker.user_id AS tmpSubjectId - INTO tmpBossId, tmpSubjectId - FROM - vn2008.Trabajadores AS subjectWorker - JOIN - vn2008.Trabajadores AS bossWorker ON bossWorker.Id_Trabajador = subjectWorker.boss - WHERE - subjectWorker.user_id = subjectId; - - IF tmpBossId = tmpSubjectId THEN - RETURN FALSE; - ELSEIF tmpBossId = account.userGetId() THEN - RETURN TRUE; - ELSE - SET subjectId = tmpBossId; - END IF; - END LOOP; - -RETURN FALSE; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `itemPlacementGet` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48934,6 +49090,70 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +/*!50003 DROP FUNCTION IF EXISTS `orderTotalVolume` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` FUNCTION `orderTotalVolume`(vOrderId INT) RETURNS decimal(10,3) +BEGIN + -- Devuelte el volumen total de la orden sumada + DECLARE vWarehouseId INTEGER; + DECLARE vVolume DECIMAL(10,3); + + SELECT IFNULL(SUM(o.amount * r.cm3)/1000000,0) INTO vVolume + FROM hedera.orderRow o + JOIN bi.rotacion r on r.Id_Article = o.itemFk AND r.warehouse_id = o.warehouseFk + WHERE o.orderFk = vOrderId; + + RETURN vVolume; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP FUNCTION IF EXISTS `orderTotalVolumeBoxes` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` FUNCTION `orderTotalVolumeBoxes`(vOrderId INT) RETURNS decimal(10,3) +BEGIN + +/* + * Devuelve el volumen estimado del ticket sumado, en cajas + * + * idT Numero de ticket + * + */ + DECLARE vVolumeBoxM3 DOUBLE; + DECLARE vOrderTotalVolumeBoxes DECIMAL(10,1); + DECLARE vVnBoxId VARCHAR(10) DEFAULT '94'; + + SELECT volume / 1000000 INTO vVolumeBoxM3 FROM packaging WHERE id = vVnBoxId; + + SET vOrderTotalVolumeBoxes = orderTotalVolume(vOrderId) / vVolumeBoxM3; + + RETURN vOrderTotalVolumeBoxes; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `phytoPassport` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -49764,9 +49984,11 @@ BEGIN DECLARE vDateShort DATETIME; DECLARE oneYearAgo DATE; + DECLARE twoYearsAgo DATE; SET vDateShort = TIMESTAMPADD(MONTH, -2, CURDATE()); SET oneYearAgo = TIMESTAMPADD(YEAR,-1,CURDATE()); + SET twoYearsAgo = TIMESTAMPADD(YEAR,-2,CURDATE()); DELETE FROM vn.dailyTaskLog WHERE created < vDateShort; @@ -49775,7 +49997,7 @@ BEGIN DELETE FROM vn.message WHERE sendDate < vDateShort; DELETE FROM vn.messageInbox WHERE sendDate < vDateShort; DELETE FROM vn.messageInbox WHERE sendDate < vDateShort; - DELETE FROM vn.workerTimeControl WHERE timed < oneYearAgo; + DELETE FROM vn.workerTimeControl WHERE timed < twoYearsAgo; INSERT INTO vn.dailyTaskLog(state) VALUES('clean END'); END ;; @@ -50398,7 +50620,81 @@ BEGIN WHERE di.duaFk = vDuaFk; -- Apuntes por tipo de IVA y proveedor + + INSERT INTO vn2008.XDiario( + ASIEN, + FECHA, + SUBCTA, + CONTRA, + EURODEBE, + BASEEURO, + CONCEPTO, + FACTURA, + IVA, + AUXILIAR, + SERIE, + FECHA_EX, + FECHA_OP, + FACTURAEX, + NFACTICK, + L340, + LDIFADUAN, + TIPOCLAVE, + TIPOEXENCI, + TIPONOSUJE, + TIPOFACT, + TIPORECTIF, + TERIDNIF, + TERNIF, + TERNOM, + empresa_id, + FECREGCON + ) + SELECT + vBookNumber ASIEN, + vBookDated FECHA, + tr.account SUBCTA, + '4330002067' CONTRA, + sum(dt.tax) EURODEBE, + sum(dt.base) BASEEURO, + CONCAT('DUA nº',d.code) CONCEPTO, + d.id FACTURA, + dt.rate IVA, + '*' AUXILIAR, + 'D' SERIE, + d.issued FECHA_EX, + d.operated FECHA_OP, + d.code FACTURAEX, + 1 NFACTICK, + 1 L340, + TRUE LDIFADUAN, + 1 TIPOCLAVE, + 1 TIPOEXENCI, + 1 TIPONOSUJE, + 5 TIPOFACT, + 1 TIPORECTIF, + IF(s.countryFk IN (30, 1), 1, 4) TERIDNIF, + s.nif TERNIF, + s.name TERNOM, + d.companyFk, + IFNULL(d.bookEntried, d.booked) FECREGCON + FROM duaTax dt + JOIN dua d ON dt.duaFk = d.id + JOIN (SELECT account, rate + FROM + (SELECT rate, account + FROM invoiceInTaxBookingAccount ta + WHERE ta.effectived <= vBookDated + AND taxAreaFk = 'WORLD' + ORDER BY ta.effectived DESC + ) tba + GROUP BY rate + ) tr ON tr.rate = dt.rate + JOIN supplier s ON s.id = d.companyFk + WHERE d.id = vDuaFk + GROUP BY dt.rate; +/* INSERT INTO vn2008.XDiario( ASIEN, FECHA, @@ -50478,7 +50774,7 @@ BEGIN GROUP BY s.id ) inv ON inv.id = dt.supplierFk WHERE d.id = vDuaFk; - +*/ SELECT SUM(EURODEBE) -SUM(EUROHABER), MAX(id) INTO vDiff, vApunte FROM vn2008.XDiario WHERE ASIEN = vBookNumber; @@ -51870,7 +52166,7 @@ BEGIN JOIN taxCode tcLink ON tcLink.link = tc.link AND tc.id != tcLink.id AND tc.link JOIN expence e ON e.id = it.expenceFk AND e.taxTypeFk = tc.taxTypeFk WHERE tc.isActive - AND tc.type = 'S' + AND (tc.type = 'S' OR MID(s.supplierAccount,4,1) = '1') GROUP BY tcLink.rate, e.id; @@ -52892,6 +53188,7 @@ BEGIN SET @a = 0; SELECT DATE(date) AS date, alertLevel, + stateName, origin, reference, name, @@ -52903,6 +53200,7 @@ BEGIN b.quantity as `in`, NULL as `out`, IF(tr.isReceived != FALSE,3, IF(tr.isDelivered,1,0)) as alertLevel, + st.name AS stateName, s.name as name, e.ref as reference, e.id as origin @@ -52910,6 +53208,13 @@ BEGIN JOIN vn.entry e ON e.id = b.entryFk JOIN vn.travel tr ON tr.id = e.travelFk JOIN vn.supplier s ON s.id = e.supplierFk + JOIN vn.alertLevel al ON al.alertLevel = + CASE + WHEN tr.isReceived != FALSE THEN 3 + WHEN tr.isDelivered THEN 1 + ELSE 0 + END + JOIN vn.state st ON st.code = al.code WHERE tr.landed >= vDateInventory AND vWarehouse = tr.warehouseInFk AND b.itemFk = vItemId @@ -52921,6 +53226,7 @@ BEGIN NULL as `in`, b.quantity as `out`, IF(tr.isReceived != FALSE,3, IF(tr.isDelivered,1,0)) as alertLevel, + st.name AS stateName, s.name as name, e.ref as reference, e.id as origin @@ -52929,6 +53235,13 @@ BEGIN JOIN vn.travel tr ON tr.id = e.travelFk JOIN vn.warehouse w ON w.id = tr.warehouseOutFk JOIN vn.supplier s ON s.id = e.supplierFk + JOIN vn.alertLevel al ON al.alertLevel = + CASE + WHEN tr.isReceived != FALSE THEN 3 + WHEN tr.isDelivered THEN 1 + ELSE 0 + END + JOIN vn.state st ON st.code = al.code WHERE tr.shipped >= vDateInventory AND vWarehouse =tr.warehouseOutFk AND s.id <> 4 @@ -52942,6 +53255,7 @@ BEGIN NULL as `in`, s.quantity as `out`, IF(t.shipped < vCurdate,3,IF(t.shipped > vCurdate, 0, IFNULL(ts.alertLevel,0))) as alertLevel, + st.name AS stateName, t.nickname as name, t.refFk as reference, t.id as origin @@ -52949,12 +53263,18 @@ BEGIN JOIN vn.ticket t ON t.id = s.ticketFk LEFT JOIN vn.ticketState ts ON ts.ticket = t.id JOIN vn.client c ON c.id = t.clientFk + JOIN vn.alertLevel al ON al.alertLevel = + CASE + WHEN t.shipped < vCurdate THEN 3 + WHEN t.shipped > vCurdate THEN 0 + ELSE IFNULL(ts.alertLevel, 0) + END + JOIN vn.state st ON st.code = al.code WHERE t.shipped >= vDateInventory AND s.itemFk = vItemId AND vWarehouse =t.warehouseFk ) AS itemDiary ORDER BY date, alertLevel, `in` DESC; - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -53038,6 +53358,127 @@ BEGIN ON DUPLICATE KEY UPDATE code = vPlacement; END IF; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `itemRefreshTags` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `itemRefreshTags`(IN vItem INT) +BEGIN +/** + * Actualiza la tabla item, los campos "cache" de tags + * + * @param vItem El id del articulo. Si es NULL, equivale a todos. + **/ + + UPDATE item i + JOIN itemTag it ON it.itemFk = i.id + SET i.name = GROUP_CONCAT(it.value, ' ') + WHERE it.priority IN (1, 2, 3) + AND (vItem IS NULL OR vItem = i.id); + + UPDATE item i + JOIN itemTag it ON it.itemFk = i.id + SET i.subName = it.value + WHERE it.priority = 4 + AND (vItem IS NULL OR vItem = i.id); + + UPDATE item i + JOIN itemTag it ON it.itemFk = i.id + JOIN tag t ON t.id = it.tagFk + SET tag5 = t.name, value5 = t.name + WHERE it.priority = 5 + AND (vItem IS NULL OR vItem = it.itemFk); + + UPDATE item i + JOIN itemTag it ON it.itemFk = i.id + JOIN tag t ON t.id = it.tagFk + SET tag6 = t.name, value6 = t.name + WHERE it.priority = 6 + AND (vItem IS NULL OR vItem = it.itemFk); + + UPDATE item i + JOIN itemTag it ON it.itemFk = i.id + JOIN tag t ON t.id = it.tagFk + SET tag7 = t.name, value7 = t.name + WHERE it.priority = 7 + AND (vItem IS NULL OR vItem = it.itemFk); + + UPDATE item i + JOIN itemTag it ON it.itemFk = i.id + JOIN tag t ON t.id = it.tagFk + SET tag8 = t.name, value8 = t.name + WHERE it.priority = 8 + AND (vItem IS NULL OR vItem = it.itemFk); +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `itemShelvingMake` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `itemShelvingMake`(vShelvingFk VARCHAR(5), + vItemFk INT, + vShelve VARCHAR(2), + vDeep INT, + vQuantity INT, + vPackagingFk VARCHAR(10), + vGrouping INT, + vPacking INT, + vWarehouseFk INT) +BEGIN + + + INSERT INTO itemShelving( itemFk, + shelvingFk, + shelve, + deep, + quantity, + visible, + available, + grouping, + packing, + packagingFk) + SELECT + vItemFk, + vShelvingFk, + vShelve, + vDeep, + vQuantity, + vQuantity, + vQuantity, + IF(vGrouping = 0, b.grouping, vGrouping) as grouping, + IF(vPacking = 0, b.packing, vPacking) as packing, + IF(vPackagingFk = '', b.packageFk, vPackagingFk) as packaging + FROM bi.Last_buy_id lb + JOIN vn.buy b ON b.id = lb.Id_Compra + WHERE lb.warehouse_id = vWarehouseFk + AND lb.Id_Article = vItemFk; + + + + + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -53164,9 +53605,34 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `itemTagMake`(vItemFk INT) +CREATE DEFINER=`root`@`%` PROCEDURE `itemTagMake`(vWorker INT) BEGIN + INSERT IGNORE INTO itemTag(itemFk, tagFk, value, priority) + SELECT i.id, 4, i.size, 1 + FROM item i + JOIN itemType it ON it.id = i.typeFk + LEFT JOIN itemTag itg ON itg.itemFk = i.id AND itg.priority = 1 AND itg.tagFk = 4 + WHERE it.workerFk = vWorker AND itg.itemFk IS NULL; + + INSERT IGNORE INTO itemTag(itemFk, tagFk, value, priority) + SELECT i.id, 1, ik.name, 2 + FROM item i + JOIN ink ik ON ik.id = i.inkFk + JOIN itemType it ON it.id = i.typeFk + LEFT JOIN itemTag itg ON itg.itemFk = i.id AND itg.priority = 2 AND itg.tagFk = 1 + WHERE it.workerFk = vWorker AND itg.itemFk IS NULL; + + INSERT IGNORE INTO itemTag(itemFk, tagFk, value, priority) + SELECT i.id, 67, i.Category, 3 + FROM item i + JOIN ink ik ON ik.id = i.inkFk + JOIN itemType it ON it.id = i.typeFk + LEFT JOIN itemTag itg ON itg.itemFk = i.id AND itg.priority = 3 AND itg.tagFk = 67 + WHERE it.workerFk = vWorker AND itg.itemFk IS NULL; + +/* +ANTIGUO DELETE FROM itemTag WHERE itemFk = vItemFk; INSERT INTO itemTag(itemFk, tagFk, value, priority) @@ -53206,7 +53672,7 @@ BEGIN WHERE ita.itemFk = vItemFk; CALL itemTagArrangedUpdate(vItemFk); - +*/ END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -53242,7 +53708,6 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemTagUpdatePriority` */; -ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -53254,12 +53719,16 @@ ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `itemTagUpdatePriority`(IN vItem INT) BEGIN + +-- OBSOLETO, CON EL NUEVO SISTEMA NO SE PUEDE ORDENAR +-- JGF 12/07/18 /* * Recalcula las prioridades de articleTag * * @param vItem Id_Article. Si es 0, lo recalcula todo */ - + + /* SET vItem = IFNULL(vItem,0); SET @p := 0; @@ -53277,14 +53746,13 @@ BEGIN ORDER BY itemFk, priority ) sub ON sub.id = a.id SET a.priority = NewPriority; - +*/ END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; /*!50003 DROP PROCEDURE IF EXISTS `itemTagUpdatePriority_launcher` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -53300,6 +53768,60 @@ BEGIN CALL vn.itemTagUpdatePriority(0); +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `itemUpdateTag` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `itemUpdateTag`(IN vItem BIGINT) +BEGIN + + +UPDATE item i +JOIN producer p ON p.id = i.producerFk +SET i.subName = p.name +WHERE p.isVisible +AND (vItem IS NULL OR vItem = i.id); + +UPDATE item i +JOIN itemTag it ON it.itemFk = i.id +JOIN tag t ON t.id = it.tagFk +SET tag5 = t.name, value5 = it.value +WHERE it.priority = 1 +AND (vItem IS NULL OR vItem = i.id); + +UPDATE item i +JOIN itemTag it ON it.itemFk = i.id +JOIN tag t ON t.id = it.tagFk +SET tag6 = t.name, value6 = it.value +WHERE it.priority = 2 +AND (vItem IS NULL OR vItem = it.itemFk); + +UPDATE item i +JOIN itemTag it ON it.itemFk = i.id +JOIN tag t ON t.id = it.tagFk +SET tag7 = t.name, value7 = it.value +WHERE it.priority = 3 +AND (vItem IS NULL OR vItem = it.itemFk); + +UPDATE item i +JOIN itemTag it ON it.itemFk = i.id +JOIN tag t ON t.id = it.tagFk +SET tag8 = t.name, value8 = it.value +WHERE it.priority = 4 +AND (vItem IS NULL OR vItem = it.itemFk); + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -53423,6 +53945,7 @@ BEGIN DECLARE vWorkerIsExcluded BOOLEAN; DECLARE vFromDated DATE; + DECLARE vToDated DATE DEFAULT TIMESTAMPADD(DAY,1,CURDATE()); SELECT COUNT(*) INTO vWorkerIsExcluded FROM bs.manaSpellersExcluded @@ -53432,8 +53955,8 @@ BEGIN SELECT max(dated) INTO vFromDated FROM clientManaCache; - - REPLACE bs.workerMana (workerFk, amount) + + REPLACE bs.workerMana (workerFk, amount) SELECT worker, sum(mana) FROM ( SELECT s.quantity * sc.value as mana @@ -53443,7 +53966,7 @@ BEGIN JOIN sale s ON s.ticketFk = t.id JOIN saleComponent sc ON sc.saleFk = s.id WHERE c.salesPersonFk = worker AND componentFk IN (39, 37) -- maná auto y maná - AND t.shipped > vFromDated and t.shipped <= CURDATE() + AND t.shipped > vFromDated AND t.shipped < vToDated UNION ALL @@ -53877,6 +54400,27 @@ BEGIN SET vOrderId = LAST_INSERT_ID(); +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `orderDelete` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `orderDelete`(IN vId INT) +BEGIN + + DELETE FROM hedera.`order` where id = vId; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -53910,6 +54454,35 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `orderListVolume` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `orderListVolume`(IN vOrderId INT) +BEGIN + + SELECT + o.id, + o.itemFk, + i.description, + o.amount, + round(r.cm3 * o.amount / 1000000,3) as volume + FROM hedera.orderRow o + JOIN vn.item i ON i.id = o.itemFk + JOIN bi.rotacion r ON r.Id_Article = o.itemFk AND r.warehouse_id = o.warehouseFk + WHERE o.orderFk = vOrderId; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `packageInvoicing` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -54028,6 +54601,80 @@ BEGIN END IF; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `payRoll` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `payRoll`(IN vFromDated DATE, IN vToDated DATE, IN vFromPaid DATE, IN vToPaid DATE) +BEGIN + + SET @userFk := 0; + + SELECT CONCAT(w.name,', ',w.firstname) AS Trabajador, + CAST(Sum((wj.total + wj.permission + wj.lunch)* wj.priceOrdinaryHour + wj.hollyday * wj.priceHollydayHour + + wj.nocturn * wj.priceNocturnHour + + wj.extra * wj.priceExtraHour) AS DECIMAL(10,2)) AS salario, + CAST(Sum(wj.permission) AS DECIMAL(10,2)) AS permission, + CAST(Sum(wj.total) AS DECIMAL(10,2)) AS total, + CAST(Sum(wj.nocturn) AS DECIMAL(10,2)) AS nocturn, + CAST(Sum(wj.hollyday) AS DECIMAL(10,2)) AS hollyday, + CAST(Sum(wj.lunch) AS DECIMAL(10,2)) AS lunch, + CAST(Sum(wj.extra) AS DECIMAL(10,2)) AS extra, + CAST(Sum(wj.contractJourney) AS DECIMAL(10,2)) AS contractJourney, + d.name AS departamento, + CAST(Sum((wj.contractJourney + wj.permission) * wj.priceOrdinaryHour) AS DECIMAL(10,2)) AS teorico, + CAST(Sum((wj.lunch + wj.permission + wj.total) * wj.priceordinaryhour) AS DECIMAL(10,2)) AS practico, + CAST(Sum(wj.nocturn * wj.pricenocturnhour) AS DECIMAL(10,2)) AS nocturno, + CAST(Sum(wj.hollyday * wj.priceHollydayHour) AS DECIMAL(10,2)) AS festivos, + CAST(Sum(wj.extra * wj.priceextrahour) AS DECIMAL(10,2)) AS extras, + MAX(wj.businessFk) as businessFk, + Min(b.date_start) AS fromDated, + Max(b.date_end) AS toDated, + blp.importepactado, + bl.porhoras, + IF(wj.userFk != @userFk, CAST(a.Anticipos AS DECIMAL(10,2)), 0) AS Anticipos, + IF(wj.userFk != @userFk, CAST(se.SaldoEuros AS DECIMAL(10,2)), 0) AS SaldoEuros, + @userFk := wj.userFk as userFk + + FROM vn.worker w + JOIN vn.workerJourney wj ON w.userFk = wj.userFk + JOIN postgresql.business_labour bl ON bl.business_id = wj.businessFk + JOIN postgresql.department d ON bl.department_id = d.department_id + JOIN postgresql.business_labour_payroll blp ON bl.business_id = blp.business_id + JOIN postgresql.business b ON b.business_id = wj.businessFk + JOIN + (SELECT userFk, sum(debe) as Anticipos + FROM postgresql.income_employee ie + JOIN postgresql.person pe ON ie.person_id = pe.person_id + JOIN vn.worker w ON w.id = pe.id_trabajador + WHERE odbc_date BETWEEN vFromPaid AND vToPaid + AND id_incomeType = 14 -- Salario + GROUP BY userFk + ) a ON a.userFk = wj.userFk + JOIN + (SELECT userFk, sum(debe - haber) as SaldoEuros + FROM postgresql.income_employee ie + JOIN postgresql.person pe ON ie.person_id = pe.person_id + JOIN vn.worker w ON w.id = pe.id_trabajador + GROUP BY userFk + ) se ON se.userFk = wj.userFk + WHERE wj.dated BETWEEN vFromDated AND vToDated + GROUP BY wj.userFk + ORDER BY w.name, w.firstname; + + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -54194,6 +54841,77 @@ BEGIN rg.ready = IF(rg.freeTickets, FALSE, rg.ready); +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `saleItemShelvingMake` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `saleItemShelvingMake`(vTicketFk INT, vSectorFk INT) +BEGIN + + DECLARE vSaleFk INT; + + SET @rest:= CAST(0 AS DECIMAL(10,0)); + SET @saleFk := CAST(0 AS DECIMAL(10,0)); + SET @reserved := CAST(0 AS DECIMAL(10,0)); + + DELETE sis.* + FROM saleItemShelving sis + JOIN sale s ON s.id = sis.saleFk + WHERE s.ticketFk = vTicketFk; + + INSERT INTO saleItemShelving( saleFk, + itemShelvingFk, + quantity, + ubication) + SELECT saleFk, + itemShelvingFk, + Reserved, + ubication + FROM + (SELECT saleFk, + itemShelvingFk, + ubication, + @rest := IF(@saleFk = saleFk, @rest, quantity) as Falta, + @reserved := LEAST(available, @rest - @rest MOD grouping) as Reserved, + @rest := @rest - @reserved, + @saleFk := saleFk + FROM + ( SELECT s.id as saleFk, + ish.created, + ish.id as itemShelvingFk, + ish.available, + s.quantity, + ish.grouping, + CONCAT(p.`column`, '-',p.row,': ', sh.code ,' ', ish.shelve, ish.deep) as ubication + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.sector sc ON sc.warehouseFk = t.warehouseFk + JOIN vn.parking p ON p.sectorFk = sc.id + JOIN vn.shelving sh ON sh.parkingFk = p.id + JOIN vn.itemShelving ish ON ish.shelvingFk = sh.code AND ish.itemFk = s.itemFk + -- JOIN (SELECT @rest:=0,@reserved:=0,@saleFk:=0) sub + WHERE t.id = vTicketFk + AND sc.id = vSectorFk + ORDER BY s.id, + ish. priority, + ish.grouping DESC, + ish.created + ) sub + ) sub2 + WHERE Reserved > 0; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -54785,6 +55503,52 @@ BEGIN amount = tmp.item.amount + VALUES(amount); CALL vn2008.item_last_buy_(vWarehouse,vDate); +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `stowawayBoarding` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `stowawayBoarding`(IN vShipFk INT, IN vStowawayFk INT) +BEGIN + + + REPLACE stowaway(shipFk, id) + VALUES (vShipFk, vStowawayFk); + + -- Polizón + INSERT INTO ticketObservation(ticketFk, observationTypeFk, description) + SELECT vStowawayFk, id, 'POLIZÓN!' + FROM observationType ot + WHERE ot.description IN ('Sacador','Encajador') + ON DUPLICATE KEY UPDATE description = CONCAT('POLIZÓN! ',ticketObservation.description); + -- Nave + INSERT INTO ticketObservation(ticketFk, observationTypeFk, description) + SELECT vShipFk, id, CONCAT('POLIZÓN: ', vStowawayFk) + FROM observationType + WHERE description IN ('Sacador','Repartidor') + ON DUPLICATE KEY UPDATE description = CONCAT('POLIZÓN! ',ticketObservation.description); + + INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador, Id_Supervisor) + SELECT id, vShipFk, getWorker(),20 + FROM state + WHERE code = 'BOARDING'; + + INSERT INTO sale(ticketFk, itemFk, quantity, concept) + VALUES(vShipFk, 98,1, CONCAT('POLIZÓN! ',vStowawayFk)); + + + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -54993,7 +55757,13 @@ BEGIN INSERT INTO dailyTaskLog(state) VALUES('ticketClosure: START'); - OPEN cur; + DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure2; + CREATE TEMPORARY TABLE tmp.ticketClosure2 + SELECT ticketFk FROM tmp.ticketClosure; + INSERT INTO tmp.ticketClosure + SELECT id FROM stowaway s + JOIN tmp.ticketClosure2 tc ON s.shipFk = tc.ticketFk; + OPEN cur; proc: LOOP SET vDone = FALSE; @@ -55076,6 +55846,8 @@ BEGIN CLOSE cur; + DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure2; + INSERT INTO dailyTaskLog(state) VALUES('ticketClosure: END'); END ;; DELIMITER ; @@ -55427,7 +56199,7 @@ proc: BEGIN tcc.warehouseFk, tcc.itemFk, vBuyValueComponent, - tcc.rate3 - b.buyingValue - b.freightValue - b.packageValue - b.comissionValue + b.buyingValue + b.freightValue + b.packageValue + b.comissionValue FROM tmp.ticketComponentCalculate tcc JOIN buy b ON b.id = tcc.buyFk; @@ -55495,7 +56267,7 @@ proc: BEGIN JOIN item i ON i.id = tcc.itemFk JOIN agencyMode am ON am.id = vAgencyModeFk JOIN `address` a ON a.id = vAddressFk - JOIN agencyProvince ap ON ap.agencyFk = a.id + JOIN agencyProvince ap ON ap.agencyFk = am.agencyFk AND ap.warehouseFk = tcc.warehouseFk AND ap.provinceFk = a.provinceFk JOIN agencyModeZone amz ON amz.agencyModeFk = vAgencyModeFk AND amz.zone = ap.zone AND amz.itemFk = 71 AND amz.warehouseFk = tcc.warehouseFk @@ -55815,8 +56587,8 @@ BEGIN i.category, IFNULL(s.quantity, 0) AS quantity, IFNULL(s.price, 0) AS price, - ROUND(SUM(tc.cost), 4) AS newPrice, - s.quantity * (s.price - ROUND(SUM(cost), 4)) difference, + ROUND(SUM(tc.cost), 2) AS newPrice, + s.quantity * (s.price - ROUND(SUM(cost), 2)) difference, s.id AS saleFk FROM sale s JOIN item i ON i.id = s.itemFk @@ -56033,7 +56805,7 @@ BEGIN HAVING dif <> 0; ELSE UPDATE sale s - JOIN item i on i.id = s.id + JOIN item i on i.id = s.itemFk JOIN itemType it on it.id = i.typeFk JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk FROM saleComponent sc @@ -56043,11 +56815,11 @@ BEGIN WHERE it.code != 'PRT'; REPLACE INTO saleComponent(saleFk, componentFk, value) - SELECT s.id, 21, s.price * (100 - s.discount) / 100 - sum(sc.value) saleValue + SELECT s.id, 21, s.price * (100 - s.discount) / 100 - sum(value) saleValue FROM sale s JOIN tmp.sale tmps ON tmps.saleFk = s.id LEFT JOIN saleComponent sc ON sc.saleFk = s.id - WHERE sc.saleFk != 21 + WHERE sc.componentFk != 21 GROUP BY s.id HAVING ROUND(saleValue, 4) <> 0; END IF; @@ -56109,69 +56881,60 @@ BEGIN DECLARE vProvinceName VARCHAR(255); SELECT p.name INTO vProvinceName - FROM vn.client c + FROM vn.client c JOIN province p ON p.id = c.provinceFk - WHERE c.id = vClientId; + WHERE c.id = vClientId; - IF vProvinceName IN ('SANTA CRUZ DE TENERIFE', 'LAS PALMAS DE -GRAN CANARIA') - AND vClientId <> vClientOrnamentales - THEN - SET vCompanyFk = vCompanyOrn; + IF vProvinceName IN ('SANTA CRUZ DE TENERIFE', 'LAS PALMAS DE GRAN CANARIA') AND vClientId <> vClientOrnamentales THEN + SET vCompanyFk = vCompanyOrn; END IF; IF NOT vAddressFk THEN - SELECT id INTO vAddressFk FROM address + SELECT id INTO vAddressFk + FROM address WHERE clientFk = vClientId AND isDefaultAddress; END IF; INSERT INTO vn2008.Tickets ( - Id_Cliente, - Fecha, - Id_Consigna, - Id_Agencia, - Alias, - warehouse_id, - Id_Ruta, - empresa_id, - landing - ) + Id_Cliente, + Fecha, + Id_Consigna, + Id_Agencia, + Alias, + warehouse_id, + Id_Ruta, + empresa_id, + landing + ) SELECT - vClientId, - vShipped, - a.id, - IF(vAgencyType, vAgencyType, -a.agencyModeFk), - a.nickname, - vWarehouseId, - IF(vRouteFk,vRouteFk,NULL), - vCompanyFk, - vlanded - FROM address a - JOIN agencyMode am ON am.id = -a.agencyModeFk - WHERE a.id = vAddressFk; + vClientId, + vShipped, + a.id, + IF(vAgencyType, vAgencyType, a.agencyModeFk), + a.nickname, + vWarehouseId, + IF(vRouteFk,vRouteFk,NULL), + vCompanyFk, + vlanded + FROM address a + JOIN agencyMode am ON am.id = a.agencyModeFk + WHERE a.id = vAddressFk; SET vNewTicket = LAST_INSERT_ID(); - INSERT INTO ticketObservation(ticketFk, observationTypeFk, -description) - SELECT vNewTicket, ao.observationTypeFk, ao.description - FROM addressObservation ao - JOIN address a ON a.id = ao.addressFk - WHERE a.id = vAddressFk; + INSERT INTO ticketObservation(ticketFk, observationTypeFk, description) + SELECT vNewTicket, ao.observationTypeFk, ao.description + FROM addressObservation ao + JOIN address a ON a.id = ao.addressFk + WHERE a.id = vAddressFk; - CALL logAdd(vNewTicket, 'insert', 'ticket', CONCAT('Ha creado -el ticket', ' ', vNewTicket)); + CALL logAdd(vNewTicket, 'insert', 'ticket', CONCAT('Ha creado el ticket', ' ', vNewTicket)); - IF (SELECT isCreatedAsServed FROM vn.client WHERE id = -vClientId ) <> FALSE - THEN - INSERT INTO vncontrol.inter(state_id, Id_Ticket, -Id_Trabajador) - SELECT id, vNewTicket, getWorker() - FROM state - WHERE `code` = 'DELIVERED'; + IF (SELECT isCreatedAsServed FROM vn.client WHERE id = vClientId ) <> FALSE THEN + INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) + SELECT id, vNewTicket, getWorker() + FROM state + WHERE `code` = 'DELIVERED'; END IF; END ;; DELIMITER ; @@ -56192,7 +56955,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `ticketGetProblems`() BEGIN /* - * Necesita la tabla tmp.ticket_list + * Necesita la tabla tmp.ticket * */ DECLARE vWarehouse INT; @@ -56201,125 +56964,133 @@ BEGIN DECLARE vVisibleCache INT; DECLARE vDone INT DEFAULT 0; - DECLARE vCursor CURSOR FOR - SELECT DISTINCT warehouseFk, date(shipped) - FROM tmp.ticket_list tt - JOIN vn.ticket t ON tt.Id_Ticket = t.id - AND DATE(t.shipped) BETWEEN CURDATE() AND TIMESTAMPADD(DAY,1.9,CURDATE()); + DECLARE vCursor CURSOR FOR + SELECT DISTINCT warehouseFk, date(t.shipped) + FROM tmp.ticket tt + JOIN vn.ticket t ON tt.ticketFk = t.id + AND DATE(t.shipped) BETWEEN CURDATE() + AND TIMESTAMPADD(DAY, 1.9, CURDATE()); - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = 1; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = 1; - DROP TEMPORARY TABLE IF EXISTS tmp.buffer_problems; - CREATE TEMPORARY TABLE tmp.buffer_problems ( - Id_Ticket INT(11), + DROP TEMPORARY TABLE IF EXISTS tmp.ticketProblems; + CREATE TEMPORARY TABLE tmp.ticketProblems ( + ticketFk INT(11), problem VARCHAR(50), - INDEX (Id_Ticket) + INDEX (ticketFk) ) ENGINE = MEMORY; - -- CONGELADO - INSERT INTO tmp.buffer_problems(Id_Ticket, problem) - SELECT DISTINCT tt.Id_Ticket, 'CONGELADO' - FROM tmp.ticket_list tt - JOIN vn.client c ON c.id = tt.Id_Cliente - WHERE c.isFreezed; + INSERT INTO tmp.ticketProblems(ticketFk, problem) + SELECT DISTINCT tt.ticketFk, 'CONGELADO' + FROM tmp.ticket tt + JOIN vn.client c ON c.id = tt.clientFk + WHERE c.isFreezed; -- eliminamos tickets con problemas para no volverlos a mirar DROP TEMPORARY TABLE IF EXISTS tmp.ticketListFiltered; CREATE TEMPORARY TABLE tmp.ticketListFiltered - (PRIMARY KEY (Id_Ticket)) + (PRIMARY KEY (ticketFk)) ENGINE = MEMORY - SELECT tt.Id_Ticket, c.id - FROM tmp.ticket_list tt - JOIN vn.client c ON c.id = tt.Id_Cliente + SELECT tt.ticketFk, c.id + FROM tmp.ticket tt + JOIN vn.client c ON c.id = tt.clientFk WHERE c.isFreezed = 0; + DROP TEMPORARY TABLE IF EXISTS tmp.client_list; + CREATE TEMPORARY TABLE tmp.client_list + (PRIMARY KEY (Id_Cliente)) + ENGINE = MEMORY + SELECT DISTINCT tt.clientFk AS Id_Cliente + FROM tmp.ticket tt; + -- RIESGO CALL vn2008.risk_vs_client_list(CURDATE()); - - INSERT INTO tmp.buffer_problems(Id_Ticket, problem) - SELECT DISTINCT tt.Id_Ticket, 'RIESGO' - FROM tmp.ticketListFiltered tt - JOIN vn.ticket t ON t.id = tt.Id_Ticket - JOIN vn.agencyMode a ON t.agencyModeFk = a.id - JOIN tmp.risk r ON r.Id_Cliente = t.clientFk - JOIN vn.client c ON c.id = t.clientFk - WHERE r.risk > c.credit + 10 - AND a.deliveryMethodFk != 3; -- para que las recogidas se preparen + INSERT INTO tmp.ticketProblems(ticketFk, problem) + SELECT DISTINCT tt.ticketFk, 'RIESGO' + FROM tmp.ticketListFiltered tt + JOIN vn.ticket t ON t.id = tt.ticketFk + JOIN vn.agencyMode a ON t.agencyModeFk = a.id + JOIN tmp.risk r ON r.Id_Cliente = t.clientFk + JOIN vn.client c ON c.id = t.clientFk + WHERE r.risk > c.credit + 10 + AND a.deliveryMethodFk != 3; -- para que las recogidas se preparen -- eliminamos tickets con problemas para no volverlos a mirar DELETE tlf FROM tmp.ticketListFiltered tlf - JOIN tmp.buffer_problems bf ON tlf.Id_Ticket = bf.Id_Ticket; + JOIN tmp.ticketProblems tp ON tlf.ticketFk = tp.ticketFk; -- CODIGO 100 - INSERT INTO tmp.buffer_problems(Id_Ticket, problem) - SELECT DISTINCT tt.Id_Ticket, 'COD 100' - FROM tmp.ticket_list tt - JOIN sale s ON s.ticketFk = tt.Id_Ticket - WHERE s.itemFk = 100; + INSERT INTO tmp.ticketProblems(ticketFk, problem) + SELECT DISTINCT tt.ticketFk, 'COD 100' + FROM tmp.ticket tt + JOIN sale s ON s.ticketFk = tt.ticketFk + WHERE s.itemFk = 100; -- eliminamos tickets con problemas para no volverlos a mirar DELETE tlf FROM tmp.ticketListFiltered tlf - JOIN tmp.buffer_problems bf ON tlf.Id_Ticket = bf.Id_Ticket; + JOIN tmp.ticketProblems tp ON tlf.ticketFk = tp.ticketFk; OPEN vCursor; WHILE NOT vDone DO - FETCH vCursor INTO vWarehouse, vDate ; + FETCH vCursor INTO vWarehouse, vDate; - CALL cache.visible_refresh(vVisibleCache,FALSE,vWarehouse); - CALL cache.available_refresh(vAvailableCache,FALSE,vWarehouse,vDate); + CALL cache.visible_refresh(vVisibleCache, FALSE, vWarehouse); + CALL cache.available_refresh(vAvailableCache, FALSE, vWarehouse, vDate); -- El disponible es menor que 0 - INSERT INTO tmp.buffer_problems(Id_Ticket, problem) - SELECT tt.Id_Ticket, i.name - -- CONCAT(IF( M.Cantidad < IFNULL(v.visible,0) , 'NO HAY ','FALTARÁ ' ), Article) - FROM tmp.ticket_list tt - JOIN vn.ticket t ON t.id = tt.Id_Ticket - 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; + INSERT INTO tmp.ticketProblems(ticketFk, problem) + SELECT tt.ticketFk, i.name + FROM tmp.ticket tt + JOIN vn.ticket t ON t.id = tt.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; -- eliminamos tickets con problemas para no volverlos a mirar DELETE tlf FROM tmp.ticketListFiltered tlf - JOIN tmp.buffer_problems bf ON tlf.Id_Ticket = bf.Id_Ticket; + JOIN tmp.ticketProblems tp ON tlf.ticketFk = tp.ticketFk; -- Amarillo: El disponible es mayor que cero y la cantidad supera el visible, estando aun sin preparar - INSERT INTO tmp.buffer_problems(Id_Ticket, problem) - SELECT tt.Id_Ticket, CONCAT('RETRASO ', i.name) - FROM tmp.ticket_list tt - JOIN vn.ticket t ON t.id = tt.Id_Ticket - 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; + INSERT INTO tmp.ticketProblems(ticketFk, problem) + SELECT tt.ticketFk, CONCAT('RETRASO ', i.name) + FROM tmp.ticket tt + JOIN vn.ticket t ON t.id = tt.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; END WHILE; CLOSE vCursor; + DROP TEMPORARY TABLE tmp.ticketListFiltered; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -56668,37 +57439,35 @@ DELIMITER ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `ticketGetVisibleAvailable`( - vTicket INT) + vTicket INT) BEGIN - DECLARE vVisibleCalc INT; + DECLARE vVisibleCalc INT; DECLARE vAvailableCalc INT; DECLARE vShipped DATE; - DECLARE vWarehouse INT; - 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 + DECLARE vWarehouse TINYINT; + DECLARE vAlertLevel INT; - 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.itemFk, s.quantity, s.price, s.discount, - i.tag1, i.val1, i.tag2, i.val2, i.tag3, i.val3, i.tag4, i.val4, i.tag5, i.val5, i.tag6, i.val6, - v.visible, av.available - FROM vn.sale s - LEFT JOIN vn.itemTagArranged i ON i.itemFk = s.itemFk - 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 - WHERE s.ticketFk = vTicket; + 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 + 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; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -57275,43 +58044,59 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `workerJourneyReplace`(vFromDate DATE, vToDate DATE) +CREATE DEFINER=`root`@`%` PROCEDURE `workerJourneyReplace`(vFromDate DATE, vToDate DATE, vUserFk INT) BEGIN - /* Actualiza la tabla workerJourney para que actue como caché permanente revisable de las jornadas laborales - * - * + /* Actualiza la tabla workerJourney para que actue como caché permanente revisable de las jornadas laborales. + * vUserFk es opcional. El valor 0 indica que se tenga en cuenta a todos los usuarios. * + * PAK Julio '18 */ DELETE FROM workerJourney WHERE dated BETWEEN vFromDate AND vToDate - AND isPaid = FALSE; + AND isPaid = FALSE + AND isUpdated = FALSE + AND vUserFk IN (0,userFk); - CALL workerTimeControlSetOrder; + -- CALL workerTimeControlSetOrder; + /* CAP con parametros de fecha*/ + /* CAP es necesaraio, ya hay un orden en tmp.workerTimeControlSetOrder*/ -- Se inicia la tabla con todas las fechas posibles para cada uno de los trabajadores que han fichado en el rango de fechas. - INSERT IGNORE INTO workerJourney(userFk, dated) - SELECT j.userFk, tm.dated - FROM time tm - JOIN (SELECT DISTINCT userFk FROM workerTimeControl_Journey WHERE dated BETWEEN vFromDate AND vToDate) j - WHERE tm.dated BETWEEN vFromDate AND vToDate; - - -- Se actualiza la cantidad total de horas, así como el tiempo de almuerzo remunerado, si corresponde + INSERT IGNORE INTO workerJourney(userFk, dated, businessFk) + SELECT w.userFk, tm.dated, b.business_id + FROM vn.worker w + JOIN postgresql.person pe ON pe.id_trabajador = w.id + JOIN postgresql.profile p ON p.person_id = pe.person_id + JOIN postgresql.business b ON b.client_id = p.profile_id + JOIN postgresql.business_labour bl ON bl.business_id = b.business_id + JOIN vn.time tm ON tm.dated BETWEEN b.date_start AND IFNULL(b.date_end,CURDATE()) + WHERE b.date_start <= vToDate + AND IFNULL(b.date_end, CURDATE()) >= vFromDate + AND bl.porhoras + AND vUserFk IN (0,w.userFk); + + -- Se actualiza la cantidad total de horas prácticas, así como el tiempo de almuerzo remunerado, si corresponde UPDATE workerJourney wj JOIN workerTimeControl_Journey j ON wj.dated = j.dated AND wj.userFk = j.userFk SET wj.total = j.Journey, wj.lunch = IF(j.Journey < 4,0,0.33) WHERE wj.dated BETWEEN vFromDate AND vToDate - AND wj.isPaid = FALSE; + AND wj.isPaid = FALSE + AND wj.isUpdated = FALSE + AND vUserFk IN (0,wj.userFk); /********** NOCTURNIDAD ************/ DROP TEMPORARY TABLE IF EXISTS tmp.workerTimeControl; CREATE TEMPORARY TABLE tmp.workerTimeControl SELECT w.*, 0 as Non - FROM vn.workerTimeControl w; + FROM vn.workerTimeControl w + WHERE timed BETWEEN vFromDate AND vToDate + AND vUserFk IN (0,userFk) + ORDER BY userFk, timed; -- Regalamos un segundo para evitar que hayan fichadas en las horas claves de inicio y fin de la nocturnidad. UPDATE tmp.workerTimeControl @@ -57322,12 +58107,14 @@ BEGIN INSERT INTO tmp.workerTimeControl(userFk, timed) SELECT userFk, TIMESTAMPADD(HOUR, 6, DATE(timed)) FROM vn.workerTimeControl + WHERE vUserFk IN (0,userFk) GROUP BY userFk, DATE(timed); -- Fichada virtual a las 22:00 h, momento en que empieza la jornada nocturna. INSERT INTO tmp.workerTimeControl(userFk, timed) SELECT userFk, TIMESTAMPADD(HOUR, 22, DATE(timed)) FROM vn.workerTimeControl + WHERE vUserFk IN (0,userFk) GROUP BY userFk, DATE(timed); -- Establece el orden en que se han de leer las fichadas @@ -57358,10 +58145,149 @@ BEGIN HAVING Nocturnidad ) night ON night.userFk = wj.userFk AND night.Dia = wj.dated SET wj.nocturn = night.Nocturnidad - WHERE wj.isPaid = FALSE; + WHERE wj.isPaid = FALSE AND isUpdated = FALSE; - /********** FIN DE LA NOCTURNIDAD ************/ + -- Horas téoricas y precio de la hora ordinaria + UPDATE vn.workerJourney wj + JOIN postgresql.business_labour_payroll blp ON blp.business_id = wj.businessFk + JOIN postgresql.business_labour bl ON bl.business_id = wj.businessFk + JOIN postgresql.calendar_labour_type pclt ON pclt.calendar_labour_type_id = bl.calendar_labour_type_id + SET wj.priceOrdinaryHour = (12 * blp.importepactado) / (52 * pclt.hours_week), + wj.contractJourney = pclt.hours_week/5 + WHERE wj.dated BETWEEN vFromDate AND vToDate + AND vUserFk IN (0,wj.userFk) + AND wj.isPaid = FALSE + AND isUpdated = FALSE; + + -- Precio Extras, Vacaciones y Nocturnas + UPDATE vn.workerJourney wj + JOIN + ( + SELECT dated, hollidayInc, nightInc, extraInc + FROM ( + SELECT tm.dated , hollidayInc, nightInc, extraInc + FROM vn.time tm + JOIN vn.workerHourPrice whp ON tm.dated >= whp.dated + ORDER BY tm.dated, whp.dated DESC + ) sub + GROUP BY dated + ) conv ON conv.dated = wj.dated + SET wj.priceHollydayHour = wj.priceOrdinaryHour * conv.hollidayInc, + wj.priceNocturnHour = wj.priceOrdinaryHour * conv.nightInc, + wj.priceExtraHour = wj.priceOrdinaryHour * conv.extraInc + WHERE wj.dated BETWEEN vFromDate AND vToDate + AND vUserFk IN (0,wj.userFk) + AND wj.isPaid = FALSE + AND wj.isUpdated = FALSE; + + -- Bajas, vacaciones y festivos personales + UPDATE vn.workerJourney wj + JOIN postgresql.calendar_employee pce ON pce.date = wj.dated AND pce.business_id = wj.businessFk + JOIN postgresql.business_labour bl ON bl.business_id = wj.businessFk + SET wj.permission = wj.contractJourney, + wj.contractJourney = IF(pce.calendar_state_id = 6, 0.5, 0) * wj.contractJourney,-- Vacaciones medio dia + wj.hollyday = wj.total - IF(pce.calendar_state_id = 6, 0.5, 0) * wj.contractJourney + WHERE wj.dated BETWEEN vFromDate AND vToDate + AND vUserFk IN (0,wj.userFk) + AND wj.isPaid = FALSE + AND wj.isUpdated = FALSE; + + -- Festivos por centro de trabajo + UPDATE vn.workerJourney wj + JOIN postgresql.calendar_labour pcl ON pcl.day = wj.dated + JOIN postgresql.business_labour pbl ON wj.businessFk = pbl.business_id AND pbl.workcenter_id = pcl.workcenter_id + SET wj.hollyday = wj.total, + wj.contractJourney = 0 + WHERE wj.dated BETWEEN vFromDate AND vToDate + AND vUserFk IN (0,wj.userFk) + AND wj.isPaid = FALSE + AND wj.isUpdated = FALSE; + + -- Domingos + UPDATE vn.workerJourney + SET hollyday = total, + contractJourney = 0 + WHERE weekday(dated) = 6 + AND dated BETWEEN vFromDate AND vToDate + AND vUserFk IN (0,userFk) + AND isPaid = FALSE + AND isUpdated = FALSE; + + -- Sábados + UPDATE vn.workerJourney + SET contractJourney = 0 + WHERE weekday(dated) = 5 + AND dated BETWEEN vFromDate AND vToDate + AND vUserFk IN (0,userFk) + AND isPaid = FALSE + AND isUpdated = FALSE; + + + -- Horas extras + UPDATE workerJourney + SET extra = lunch + total - contractJourney + WHERE dated BETWEEN vFromDate AND vToDate + AND vUserFk IN (0,userFk) + AND isPaid = FALSE + AND isUpdated = FALSE; + + -- Contratos NO por horas + INSERT IGNORE INTO workerJourney( userFk, + dated, + businessFk, + priceOrdinaryHour, + contractJourney, + total) + SELECT w.userFk, + tm.dated, + b.business_id, + (12 * blp.importepactado) / (52 * pclt.hours_week) as priceOrdinaryHour, + IF(weekday(tm.dated) IN (5,6),0, pclt.hours_week/5) as contractJourney, + IF(weekday(tm.dated) IN (5,6),0, pclt.hours_week/5) as total + FROM vn.worker w + JOIN postgresql.person pe ON pe.id_trabajador = w.id + JOIN postgresql.profile p ON p.person_id = pe.person_id + JOIN postgresql.business b ON b.client_id = p.profile_id + JOIN postgresql.business_labour bl ON bl.business_id = b.business_id + JOIN postgresql.calendar_labour_type pclt ON pclt.calendar_labour_type_id = bl.calendar_labour_type_id + JOIN postgresql.business_labour_payroll blp ON blp.business_id = b.business_id + JOIN vn.time tm ON tm.dated BETWEEN b.date_start AND IFNULL(b.date_end,CURDATE()) + WHERE b.date_start <= vToDate + AND IFNULL(b.date_end, CURDATE()) >= vFromDate + AND bl.porhoras = FALSE + AND vUserFk IN (0,w.userFk); + + -- Elimina dias sin fichadas ni contrato + /* DELETE FROM workerJourney + WHERE contractJourney = 0 + AND total = 0 + AND permission = 0 + AND dated BETWEEN vFromDate AND vToDate + AND vUserFk IN (0,userFk) + AND isPaid = FALSE + AND isUpdated = FALSE; +*/ +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `workerTimeControlAdd` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `workerTimeControlAdd`(IN vUserFk INT, IN vWarehouseFk INT, IN vDated DATETIME) +BEGIN + INSERT INTO workerTimeControl(userFk, timed, manual, warehouseFk) + VALUES(vUserFk, vDated, TRUE, vWarehouseFk); END ;; DELIMITER ; @@ -57382,13 +58308,13 @@ DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `workerTimeControlNonDays`() BEGIN - SELECT wtc.userFk, date(wtc.timed) as Fecha , MAX(wtc.`order`) as maxOrder, c.name as worker, wb.workerCode as Boss, CONCAT (au.name, "@verdnatura.es") AS bossMail + SELECT wtc.userFk, date(wtc.timed) as Fecha , COUNT(wtc.`order`) as maxOrder, c.name as worker, wb.workerCode as Boss, CONCAT (au.name, "@verdnatura.es") AS bossMail FROM workerTimeControl wtc JOIN worker w ON w.userFk = wtc.userFk - LEFT JOIN worker wb ON wb.id = w.bossFk + LEFT JOIN worker wb ON wb.id = w.bossFk JOIN client c ON c.id = wtc.userFk LEFT JOIN account.user au ON au.id = wb.userFK - WHERE timed < CURDATE() + WHERE timed BETWEEN TIMESTAMPADD(YEAR,-5,CURDATE()) AND CURDATE() GROUP BY userFk, date(timed) HAVING maxOrder mod 2 = 1 ORDER BY Boss; @@ -57408,7 +58334,7 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `workerTimeControlSetOrder`() +CREATE DEFINER=`root`@`%` PROCEDURE `workerTimeControlSetOrder`(IN vUserFk INT, IN vDated DATE) BEGIN SET @order := 1; @@ -57419,6 +58345,7 @@ BEGIN SET `order` = IF(userFk = @userFk AND day(timed) = @day, @order := @order + 1, @order := 1), userFk = @userFk := userFk, manual = manual + (0 * @day := day(timed)) + WHERE vUserFk IN (0,userFk) AND vDated IN (0,DATE(timed)) ORDER BY userFk, timed; END ;; @@ -57787,7 +58714,7 @@ CREATE TABLE `batch` ( KEY `buy_edi_id` (`buy_edi_id`), CONSTRAINT `batch_ibfk_1` FOREIGN KEY (`message_id`) REFERENCES `message` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `batch_ibfk_2` FOREIGN KEY (`buy_edi_id`) REFERENCES `vn2008`.`buy_edi` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=338525 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=345296 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -58174,7 +59101,7 @@ CREATE TABLE `message` ( UNIQUE KEY `mail_id` (`mail_id`), KEY `sender_id` (`sender_id`), CONSTRAINT `message_ibfk_2` FOREIGN KEY (`sender_id`) REFERENCES `mail` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=360146 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=366962 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -58230,12 +59157,12 @@ CREATE TABLE `putOrder` ( `OrderTradeLineDateTime` datetime DEFAULT NULL, `quantity` int(11) DEFAULT NULL, `EndUserPartyID` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - `EndUserPartyGLN` tinyint(4) DEFAULT '0', + `EndUserPartyGLN` varchar(13) COLLATE utf8_unicode_ci DEFAULT NULL, `OrderStatus` int(11) DEFAULT '0' COMMENT '1 pending\n2 confirmed\n3 canceled', `isOrderProcessed` tinyint(4) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `orderTradelineItemID_UNIQUE` (`orderTradelineItemID`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -58330,6 +59257,7 @@ CREATE TABLE `supplyResponse` ( `PackingPriceQuantity` int(11) DEFAULT NULL, `PackingPriceQuantityType` tinyint(1) DEFAULT NULL COMMENT 'Unit: 1 = piece, 2 = bunch, 3 = box, 4 = layer, 5 = load carrier/trolley', `MarketPlaceID` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `MarketFormCode` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '"002" Standard Sales\n"005" Catalogue (optional)\n"001" Committed (optional)\n"003" Buffer (optional, Clock Pre Sales) ', PRIMARY KEY (`ID`), UNIQUE KEY `ID_UNIQUE` (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=523827 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -58840,6 +59768,24 @@ CREATE TABLE `carteras` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `clientDied` +-- + +DROP TABLE IF EXISTS `clientDied`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `clientDied` ( + `id` int(11) NOT NULL DEFAULT '0', + `clientName` varchar(50) COLLATE utf8_unicode_ci NOT NULL, + `lastInvoiced` date DEFAULT NULL, + `workerCode` varchar(3) COLLATE utf8_unicode_ci NOT NULL, + `Boss` varchar(3) COLLATE utf8_unicode_ci NOT NULL, + `Aviso` varchar(13) CHARACTER SET utf8 DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `compradores` -- @@ -58924,6 +59870,21 @@ CREATE TABLE `fondo_maniobra` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `horasSilla` +-- + +DROP TABLE IF EXISTS `horasSilla`; +/*!50001 DROP VIEW IF EXISTS `horasSilla`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `horasSilla` AS SELECT + 1 AS `Fecha`, + 1 AS `Departamento`, + 1 AS `Horas`, + 1 AS `Salarios`*/; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `indicators` -- @@ -58990,15 +59951,62 @@ CREATE TABLE `m3` ( `fecha` date NOT NULL, `provinceFk` smallint(5) unsigned DEFAULT NULL, `warehouseFk` smallint(6) unsigned NOT NULL DEFAULT '0', - `m3` double DEFAULT NULL, + `m3` decimal(10,2) DEFAULT NULL, `year` int(11) DEFAULT NULL, `month` int(11) DEFAULT NULL, `week` int(11) DEFAULT NULL, `day` int(11) DEFAULT NULL, - `dayName` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL + `dayName` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL, + `euros` decimal(10,2) DEFAULT '0.00' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `m3Silla` +-- + +DROP TABLE IF EXISTS `m3Silla`; +/*!50001 DROP VIEW IF EXISTS `m3Silla`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `m3Silla` AS SELECT + 1 AS `fecha`, + 1 AS `year`, + 1 AS `month`, + 1 AS `week`, + 1 AS `day`, + 1 AS `dayName`, + 1 AS `Volumen`, + 1 AS `Euros`*/; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `m3analisis` +-- + +DROP TABLE IF EXISTS `m3analisis`; +/*!50001 DROP VIEW IF EXISTS `m3analisis`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `m3analisis` AS SELECT + 1 AS `fecha`, + 1 AS `year`, + 1 AS `month`, + 1 AS `week`, + 1 AS `day`, + 1 AS `dayName`, + 1 AS `Volumen`, + 1 AS `Euros`, + 1 AS `Departamento`, + 1 AS `Horas`, + 1 AS `Salarios`, + 1 AS `tiempoM3`, + 1 AS `valorM3`, + 1 AS `costeLaboralM3`, + 1 AS `costeEuros`, + 1 AS `precioHora`*/; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `manaCustomer` -- @@ -59100,7 +60108,7 @@ CREATE TABLE `nightTask` ( `schema` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `procedure` varchar(100) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=43 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=44 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -59365,6 +60373,37 @@ DELIMITER ; -- -- Dumping routines for database 'bs' -- +/*!50003 DROP FUNCTION IF EXISTS `tramo` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` FUNCTION `tramo`(vDateTime DATETIME) RETURNS varchar(20) CHARSET utf8 COLLATE utf8_unicode_ci +BEGIN + + DECLARE vTramo VARCHAR(20); + DECLARE vHour INT; + + SET vHour = HOUR(vDateTime) ; + + SET vTramo = + CASE + WHEN vHour BETWEEN 0 AND 14 THEN 'Mañana' + WHEN vHour BETWEEN 15 AND 24 THEN 'Tarde' + END ; + +RETURN vTramo; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `analisisComponentes` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -59417,7 +60456,6 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bancos_evolution_add` */; -ALTER DATABASE `bs` CHARACTER SET latin1 COLLATE latin1_swedish_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -59440,26 +60478,13 @@ DECLARE vCurrentDate DATE; DECLARE vStartingDate DATE DEFAULT '2015-01-01'; DECLARE vMaxDate DATE DEFAULT TIMESTAMPADD(MONTH, 2, CURDATE()); -SELECT max(Fecha) - INTO vStartingDate - FROM bs.bancos_evolution - WHERE Fecha > '2015-01-01'; - DELETE FROM bs.bancos_evolution WHERE Fecha > vStartingDate; SET vCurrentDate = vStartingDate; - - - WHILE vCurrentDate < vMaxDate DO - - IF day(vCurrentDate) mod 28 = 0 then - SELECT vCurrentDate; - end if; - - + REPLACE bs.bancos_evolution( Fecha ,Id_Banco ,saldo) @@ -59558,7 +60583,6 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -ALTER DATABASE `bs` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; /*!50003 DROP PROCEDURE IF EXISTS `campaignComparative` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -59648,6 +60672,55 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; ALTER DATABASE `bs` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +/*!50003 DROP PROCEDURE IF EXISTS `clientDied` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `clientDied`() +BEGIN + +IF DAY(CURDATE()) = 2 THEN + + SET @primerAviso := TIMESTAMPADD(MONTH,-1,CURDATE()); + SET @segundoAviso := TIMESTAMPADD(MONTH,-2,CURDATE()); + SET @tercerAviso := TIMESTAMPADD(MONTH,-3,CURDATE()); + + TRUNCATE TABLE bs.clientDied; + INSERT INTO bs.clientDied + SELECT c.id, + c.name as clientName, + maxIssued as lastInvoiced, + w.workerCode, + b.workerCode as Boss, + CASE + WHEN IFNULL(maxIssued,'2000-01-01') < @tercerAviso THEN 'Tercer Aviso' + WHEN maxIssued < @segundoAviso THEN 'Segundo Aviso' + WHEN maxIssued < @primerAviso THEN 'Primer Aviso' + END as Aviso + FROM vn.client c + JOIN vn.worker w ON w.id = c.salesPersonFk + JOIN vn2008.jerarquia j ON j.worker_id = w.id + JOIN vn.worker b ON b.id = j.boss_id + JOIN bs.mana_spellers ms ON ms.Id_Trabajador = c.salesPersonFk + LEFT JOIN (SELECT clientFk, max(issued) as maxIssued FROM vn.invoiceOut GROUP BY clientFk) io ON io.clientFk = c.id + WHERE (maxIssued IS NULL OR maxIssued < @primerAviso) + AND c.IsActive + AND c.created < @tercerAviso; + + END IF; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `comercialesCompleto` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -59660,6 +60733,7 @@ ALTER DATABASE `bs` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `comercialesCompleto`(IN vWorker INT) BEGIN + create TEMPORARY TABLE workerAndBelow ENGINE=MEMORY SELECT w.id @@ -59692,11 +60766,11 @@ SELECT cr.recobro FROM vn2008.Clientes c - LEFT JOIN - (SELECT Id_Cliente, Greuge - FROM bi.Greuge_Evolution - WHERE Fecha = (SELECT MAX(Fecha) FROM bi.Greuge_Evolution) - ) g ON g.Id_Cliente = c.Id_Cliente + LEFT JOIN + (SELECT Id_Cliente, CAST( SUM(Importe) as DECIMAL(12,2)) AS Greuge + FROM vn2008.Greuges + GROUP BY Id_Cliente + ) g ON g.Id_Cliente = c.Id_Cliente LEFT JOIN vn2008.province p ON p.province_id = c.province_id JOIN @@ -60165,7 +61239,7 @@ BEGIN DECLARE datSTART DATE; DECLARE datEND DATE; - + SELECT TIMESTAMPADD(WEEK, -1,MAX(fecha)) INTO datSTART FROM bs.m3; @@ -60173,18 +61247,23 @@ BEGIN DELETE FROM bs.m3 WHERE fecha >= datSTART; - + + INSERT INTO bs.m3 - SELECT v.fecha, a.provinceFk, t.warehouseFk, cast(sum(s.quantity * r.cm3) / 1000000 as DECIMAL(10,2)) m3, - year(v.fecha), month(v.fecha), week(v.fecha), day(v.fecha), dayname(v.fecha) + SELECT v.fecha, a.provinceFk, t.warehouseFk, sum(s.quantity * r.cm3) / 1000000 AS m3, + year(v.fecha), month(v.fecha), week(v.fecha), day(v.fecha), dayname(v.fecha), sum(importe) FROM vn.ticket t 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 JOIN bs.ventas v ON v.Id_Movimiento = s.id -- Filtra solo por ventas "buenas" JOIN bi.rotacion r ON r.Id_Article = s.itemFk AND r.warehouse_id = t.warehouseFk JOIN vn.address a ON a.id = t.addressFk WHERE v.fecha BETWEEN datSTART AND datEND + AND it.workerFk != 132 -- Miriam + AND s.quantity > 0 -- evita abonos + AND t.companyFk = 442 -- Verdnatura GROUP BY t.warehouseFk, v.fecha, a.provinceFk; - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -64261,7 +65340,7 @@ CREATE TABLE `cdr` ( KEY `dstchannel` (`dst_channel`), KEY `disposition` (`disposition`), KEY `src` (`src`) -) ENGINE=MyISAM AUTO_INCREMENT=205976 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=MyISAM AUTO_INCREMENT=209546 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -65053,7 +66132,7 @@ CREATE TABLE `cache_calc` ( KEY `cache_id` (`cache_id`), KEY `cacheName` (`cacheName`), KEY `expires` (`expires`) -) ENGINE=InnoDB AUTO_INCREMENT=140616 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=148274 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -66580,7 +67659,7 @@ CREATE TABLE `ACL` ( `principalType` set('ROLE','USER') COLLATE utf8_unicode_ci DEFAULT 'ROLE', `principalId` varchar(512) CHARACTER SET utf8 DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=94 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=95 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -66822,7 +67901,7 @@ CREATE TABLE `inter` ( CONSTRAINT `inter_ibfk_1` FOREIGN KEY (`Id_Ticket`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `inter_state` FOREIGN KEY (`state_id`) REFERENCES `vn2008`.`state` (`id`) ON UPDATE CASCADE, CONSTRAINT `responsable` FOREIGN KEY (`Id_Supervisor`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=11396320 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=11676724 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -67165,7 +68244,7 @@ CREATE TABLE `imageCollectionSize` ( PRIMARY KEY (`id`), KEY `image_schema_id` (`collectionFk`), CONSTRAINT `imageCollectionSize_ibfk_1` FOREIGN KEY (`collectionFk`) REFERENCES `imageCollection` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -67559,7 +68638,7 @@ CREATE TABLE `news` ( KEY `tag` (`tag`), CONSTRAINT `news_ibfk_1` FOREIGN KEY (`userFk`) REFERENCES `account`.`account` (`id`) ON UPDATE CASCADE, CONSTRAINT `news_ibfk_2` FOREIGN KEY (`tag`) REFERENCES `newsTag` (`name`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=13015 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=13017 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -67610,7 +68689,7 @@ CREATE TABLE `order` ( CONSTRAINT `order_ibfk_5` FOREIGN KEY (`address_id`) REFERENCES `vn2008`.`Consignatarios` (`id_consigna`) ON UPDATE CASCADE, CONSTRAINT `order_ibfk_8` FOREIGN KEY (`delivery_method_id`) REFERENCES `vn2008`.`Vistas` (`vista_id`) ON UPDATE CASCADE, CONSTRAINT `order_ibfk_9` FOREIGN KEY (`agency_id`) REFERENCES `vn2008`.`Agencias` (`Id_Agencia`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1453338 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1477609 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -67709,7 +68788,7 @@ CREATE TABLE `orderRow` ( KEY `warehouse_shipment` (`warehouseFk`,`shipment`), CONSTRAINT `orderRow_ibfk_2` FOREIGN KEY (`itemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON UPDATE CASCADE, CONSTRAINT `orderRow_ibfk_3` FOREIGN KEY (`orderFk`) REFERENCES `order` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=8936585 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=9085127 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -68056,7 +69135,7 @@ CREATE TABLE `tpvTransaction` ( CONSTRAINT `receipt_id` FOREIGN KEY (`receiptFk`) REFERENCES `vn2008`.`Recibos` (`Id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `tpvTransaction_ibfk_1` FOREIGN KEY (`clientFk`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `tpvTransaction_ibfk_2` FOREIGN KEY (`merchantFk`) REFERENCES `tpvMerchant` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=227743 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Transactions realized through the virtual TPV'; +) ENGINE=InnoDB AUTO_INCREMENT=232406 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Transactions realized through the virtual TPV'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -68091,7 +69170,7 @@ CREATE TABLE `visit` ( PRIMARY KEY (`id`), KEY `firstAgent` (`firstAgent`), CONSTRAINT `visit_ibfk_1` FOREIGN KEY (`firstAgent`) REFERENCES `visitAgent` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1305030 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1323501 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -68111,7 +69190,7 @@ CREATE TABLE `visitAccess` ( KEY `visit_access_idx_agent` (`agent`), KEY `stamp` (`stamp`), CONSTRAINT `visitAccess_ibfk_1` FOREIGN KEY (`agent`) REFERENCES `visitAgent` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2855411 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2901916 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -68136,7 +69215,7 @@ CREATE TABLE `visitAgent` ( KEY `firstAccess` (`firstAccess`), CONSTRAINT `visitAgent_ibfk_1` FOREIGN KEY (`visit`) REFERENCES `visit` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `visitAgent_ibfk_2` FOREIGN KEY (`firstAccess`) REFERENCES `visitAccess` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1851273 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1871318 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -68156,7 +69235,7 @@ CREATE TABLE `visitUser` ( KEY `date_time` (`stamp`), KEY `user_id` (`user`), CONSTRAINT `visitUser_ibfk_1` FOREIGN KEY (`access`) REFERENCES `visitAccess` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2715474 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2752569 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -69194,28 +70273,22 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `myTicketGetRows`(vTicket INT) -BEGIN -/** - * Returns a current user ticket lines. - * - * @param vTicket The ticket identifier - * @select The ticket lines - */ - SELECT r.itemFk, r.quantity, r.concept, r.price, r.discount, - i.image, i.category, i.size, i.stems, i.inkFk, - t.tag1, t.val1, t.tag2, t.val2, t.tag3, t.val3 - FROM myTicketRow r - JOIN vn.item i ON i.id = r.itemFk - LEFT JOIN vn.itemTagArranged t ON t.itemFk = i.id - WHERE r.ticketFk = vTicket - ORDER BY r.concept; +CREATE DEFINER=`root`@`%` PROCEDURE `myTicketGetRows`(`vTicket` INT) +BEGIN + + SELECT r.itemFk, r.quantity, r.concept, r.price, r.discount, + i.image, i.category, i.size, i.stems, i.inkFk, + i.tag5, i.value5, i.tag6, i.value6, i.tag7, i.value7 + FROM myTicketRow r + JOIN vn.item i ON i.id = r.itemFk + WHERE r.ticketFk = vTicket + ORDER BY r.concept; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -69645,6 +70718,27 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `orderDelete` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `orderDelete`(IN vId INT) +BEGIN + + DELETE FROM hedera.`order` where id = vId; + + END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `orderGetTax` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -71599,7 +72693,7 @@ USE `vn2008`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `item_entry_out` AS select `t`.`warehouse_id_out` AS `warehouse_id`,`t`.`shipment` AS `dat`,`m`.`Id_Article` AS `item_id`,-(`m`.`Cantidad`) AS `amount`,(`t`.`delivered` or ifnull(`co`.`valor`,0)) AS `delivered` from (((`Compres` `m` join `Entradas` `e` on((`m`.`Id_Entrada` = `e`.`Id_Entrada`))) join `travel` `t` on((`e`.`travel_id` = `t`.`id`))) left join `Compres_ok` `co` on(((`co`.`Id_Compra` = `m`.`Id_Compra`) and (`co`.`Id_Accion` = 3)))) where ((`e`.`Inventario` = 0) and (`e`.`Redada` = 0) and (`m`.`Cantidad` <> 0)) */; +/*!50001 VIEW `item_entry_out` AS select `t`.`warehouse_id_out` AS `warehouse_id`,`t`.`shipment` AS `dat`,`m`.`Id_Article` AS `item_id`,-(`m`.`Cantidad`) AS `amount`,(`t`.`delivered` or ifnull(`co`.`valor`,0)) AS `delivered` from (((`Compres` `m` join `Entradas` `e` on((`m`.`Id_Entrada` = `e`.`Id_Entrada`))) join `travel` `t` on((`e`.`travel_id` = `t`.`id`))) left join `Compres_ok` `co` on(((`co`.`Id_Compra` = `m`.`Id_Compra`) and (`co`.`Id_Accion` = 3) and (`co`.`valor` <> 0)))) where ((`e`.`Inventario` = 0) and (`e`.`Redada` = 0) and (`m`.`Cantidad` <> 0)) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -74089,7 +75183,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `item` AS select `t`.`Id_Article` AS `id`,`t`.`Article` AS `name`,`t`.`tipo_id` AS `typeFk`,`t`.`Medida` AS `size`,`t`.`Color` AS `inkFk`,`t`.`Categoria` AS `category`,`t`.`Tallos` AS `stems`,`t`.`id_origen` AS `originFk`,`t`.`description` AS `description`,`t`.`producer_id` AS `producerFk`,`t`.`Codintrastat` AS `intrastatFk`,`t`.`offer` AS `isOnOffer`,`t`.`expenceFk` AS `expenceFk`,`t`.`bargain` AS `isBargain`,`t`.`comments` AS `comment`,`t`.`relevancy` AS `relevancy`,`t`.`Foto` AS `image`,`t`.`generic` AS `generic`,`t`.`density` AS `density`,`t`.`iva_group_id` AS `taxClassFk`,`t`.`PVP` AS `minPrice`,`t`.`Min` AS `hasMinPrice`,`t`.`isActive` AS `isActive` from `vn2008`.`Articles` `t` */; +/*!50001 VIEW `item` AS select `t`.`Id_Article` AS `id`,`t`.`Article` AS `name`,`t`.`tipo_id` AS `typeFk`,`t`.`Medida` AS `size`,`t`.`Color` AS `inkFk`,`t`.`Categoria` AS `category`,`t`.`Tallos` AS `stems`,`t`.`id_origen` AS `originFk`,`t`.`description` AS `description`,`t`.`producer_id` AS `producerFk`,`t`.`Codintrastat` AS `intrastatFk`,`t`.`offer` AS `isOnOffer`,`t`.`expenceFk` AS `expenceFk`,`t`.`bargain` AS `isBargain`,`t`.`comments` AS `comment`,`t`.`relevancy` AS `relevancy`,`t`.`Foto` AS `image`,`t`.`generic` AS `generic`,`t`.`density` AS `density`,`t`.`iva_group_id` AS `taxClassFk`,`t`.`PVP` AS `minPrice`,`t`.`Min` AS `hasMinPrice`,`t`.`isActive` AS `isActive`,`t`.`longName` AS `longName`,`t`.`subName` AS `subName`,`t`.`tag5` AS `tag5`,`t`.`value5` AS `value5`,`t`.`tag6` AS `tag6`,`t`.`value6` AS `value6`,`t`.`tag7` AS `tag7`,`t`.`value7` AS `value7`,`t`.`tag8` AS `tag8`,`t`.`value8` AS `value8` from `vn2008`.`Articles` `t` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -74202,6 +75296,24 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `itemShelvingAvailable` +-- + +/*!50001 DROP VIEW IF EXISTS `itemShelvingAvailable`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8 */; +/*!50001 SET character_set_results = utf8 */; +/*!50001 SET collation_connection = utf8_general_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ +/*!50001 VIEW `itemShelvingAvailable` AS select `s`.`id` AS `saleFk`,`tst`.`updated` AS `Modificado`,`s`.`ticketFk` AS `ticketFk`,`s`.`isPicked` AS `isPicked`,`s`.`itemFk` AS `itemFk`,`s`.`quantity` AS `quantity`,`s`.`concept` AS `concept`,`i`.`size` AS `size`,`st`.`name` AS `Estado`,`st`.`order` AS `orden`,`its`.`available` AS `available`,`pk`.`sectorFk` AS `sectorFk`,`sh`.`code` AS `matricula`,`pk`.`id` AS `parking`,`its`.`id` AS `itemShelving` from (((((((`vn`.`sale` `s` join `vn`.`ticket` `t` on((`t`.`id` = `s`.`ticketFk`))) join `vn`.`ticketStateToday` `tst` on((`tst`.`ticket` = `t`.`id`))) join `vn`.`state` `st` on((`st`.`id` = `tst`.`state`))) join `vn`.`item` `i` on((`i`.`id` = `s`.`itemFk`))) join `vn`.`itemShelving` `its` on((`its`.`itemFk` = `s`.`itemFk`))) join `vn`.`shelving` `sh` on((`sh`.`code` = `its`.`shelvingFk`))) join `vn`.`parking` `pk` on((`pk`.`id` = `sh`.`parkingFk`))) where ((`t`.`shipped` between `util`.`yesterday`() and `util`.`dayend`(curdate())) and (`its`.`available` > 0) and (`st`.`order` between 3 and 6)) order by `st`.`order` desc,`tst`.`updated` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + -- -- Final view structure for view `itemTagged` -- @@ -74755,7 +75867,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `producer` AS select `p`.`producer_id` AS `id`,`p`.`name` AS `name` from `vn2008`.`producer` `p` */; +/*!50001 VIEW `producer` AS select `p`.`producer_id` AS `id`,`p`.`name` AS `name`,`p`.`visible` AS `isVisible` from `vn2008`.`producer` `p` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -74971,7 +76083,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `saleTracking` AS select `m`.`Id_Movimiento` AS `saleFk`,`m`.`valor` AS `isChecked`,`m`.`odbc_date` AS `created`,`m`.`original_quantity` AS `originalQuantity`,`m`.`Id_Trabajador` AS `workerFk`,`m`.`Id_Accion` AS `actionFk`,`m`.`Id_Movimiento_mark` AS `id` from `vn2008`.`Movimientos_mark` `m` */; +/*!50001 VIEW `saleTracking` AS select `m`.`Id_Movimiento` AS `saleFk`,`m`.`valor` AS `isChecked`,`m`.`odbc_date` AS `created`,`m`.`original_quantity` AS `originalQuantity`,`m`.`Id_Trabajador` AS `workerFk`,`m`.`Id_Accion` AS `actionFk`,`m`.`Id_Movimiento_mark` AS `id`,`m`.`stateFk` AS `stateFk` from `vn2008`.`Movimientos_mark` `m` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -75552,6 +76664,24 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `workerTimeJourneyNG` +-- + +/*!50001 DROP VIEW IF EXISTS `workerTimeJourneyNG`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8 */; +/*!50001 SET character_set_results = utf8 */; +/*!50001 SET collation_connection = utf8_general_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ +/*!50001 VIEW `workerTimeJourneyNG` AS select `wtc`.`userFk` AS `userFk`,cast(`wtc`.`timed` as date) AS `dated`,(if((`wtc`.`order` % 2),-(1),1) * (hour(`wtc`.`timed`) + (minute(`wtc`.`timed`) / 60))) AS `Journey`,dayname(`wtc`.`timed`) AS `dayName`,`w`.`name` AS `name`,`w`.`firstName` AS `firstname` from (`vn`.`workerTimeControl` `wtc` join `vn`.`worker` `w` on((`w`.`userFk` = `wtc`.`userFk`))) */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + -- -- Current Database: `edi` -- @@ -75600,6 +76730,24 @@ USE `bs`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `horasSilla` +-- + +/*!50001 DROP VIEW IF EXISTS `horasSilla`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8 */; +/*!50001 SET character_set_results = utf8 */; +/*!50001 SET collation_connection = utf8_general_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ +/*!50001 VIEW `horasSilla` AS select `wj`.`dated` AS `Fecha`,`d`.`name` AS `Departamento`,cast(sum(`wj`.`total`) as decimal(10,2)) AS `Horas`,cast(sum(((`wj`.`total` + `wj`.`lunch`) * `wj`.`priceOrdinaryHour`)) as decimal(10,2)) AS `Salarios` from ((`vn`.`workerJourney` `wj` join `postgresql`.`business_labour` `bl` on((`bl`.`business_id` = `wj`.`businessFk`))) join `postgresql`.`department` `d` on((`d`.`department_id` = `bl`.`department_id`))) where (`d`.`name` in ('CAMARA','ENCAJADO','PALETIZADORES','PRODUCCION','SACADORES')) group by `wj`.`dated`,`d`.`name` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + -- -- Final view structure for view `lastIndicators` -- @@ -75618,6 +76766,42 @@ USE `bs`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `m3Silla` +-- + +/*!50001 DROP VIEW IF EXISTS `m3Silla`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8 */; +/*!50001 SET character_set_results = utf8 */; +/*!50001 SET collation_connection = utf8_general_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ +/*!50001 VIEW `m3Silla` AS select `m3`.`fecha` AS `fecha`,`m3`.`year` AS `year`,`m3`.`month` AS `month`,`m3`.`week` AS `week`,`m3`.`day` AS `day`,`m3`.`dayName` AS `dayName`,cast(sum(`m3`.`m3`) as decimal(10,0)) AS `Volumen`,cast(sum(`m3`.`euros`) as decimal(10,0)) AS `Euros` from `m3` where (`m3`.`warehouseFk` in (1,44)) group by `m3`.`fecha` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `m3analisis` +-- + +/*!50001 DROP VIEW IF EXISTS `m3analisis`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8 */; +/*!50001 SET character_set_results = utf8 */; +/*!50001 SET collation_connection = utf8_general_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ +/*!50001 VIEW `m3analisis` AS select `m`.`fecha` AS `fecha`,`m`.`year` AS `year`,`m`.`month` AS `month`,`m`.`week` AS `week`,`m`.`day` AS `day`,`m`.`dayName` AS `dayName`,`m`.`Volumen` AS `Volumen`,`m`.`Euros` AS `Euros`,`h`.`Departamento` AS `Departamento`,`h`.`Horas` AS `Horas`,`h`.`Salarios` AS `Salarios`,(`h`.`Horas` / `m`.`Volumen`) AS `tiempoM3`,(`m`.`Euros` / `m`.`Volumen`) AS `valorM3`,(`h`.`Salarios` / `m`.`Volumen`) AS `costeLaboralM3`,(`h`.`Salarios` / `m`.`Euros`) AS `costeEuros`,(`h`.`Salarios` / `h`.`Horas`) AS `precioHora` from (`bs`.`m3Silla` `m` join `bs`.`horasSilla` `h` on((`h`.`Fecha` = `m`.`fecha`))) */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + -- -- Final view structure for view `manaSpellersExcluded` -- @@ -76232,4 +77416,4 @@ USE `stock`; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2018-07-04 9:12:43 +-- Dump completed on 2018-07-23 14:19:55 diff --git a/services/db/install/dump/fixtures.sql b/services/db/install/dump/fixtures.sql index d84810ef1..5bf576ad1 100644 --- a/services/db/install/dump/fixtures.sql +++ b/services/db/install/dump/fixtures.sql @@ -510,12 +510,12 @@ INSERT INTO `vn`.`saleComponent`(`saleFk`, `componentFk`, `value`) ( 4, 39, 5), ( 4, 37, 2); -INSERT INTO `vn`.`saleTracking`(`saleFk`, `isChecked`, `created`, `originalQuantity`, `workerFk`, `actionFk`, `id`) +INSERT INTO `vn`.`saleTracking`(`saleFk`, `isChecked`, `created`, `originalQuantity`, `workerFk`, `actionFk`, `id`, `stateFk`) VALUES - ( 1, 0, CURDATE(), 5, 40, 3, 1), - ( 1, 1, CURDATE(), 5, 40, 3, 2), - ( 2, 1, CURDATE(), 10, 40, 4, 3), - ( 3, 1, CURDATE(), 2, 40, 4, 4); + ( 1, 0, CURDATE(), 5, 40, 3, 1, 14), + ( 1, 1, CURDATE(), 5, 40, 3, 2, 14), + ( 2, 1, CURDATE(), 10, 40, 4, 3, 8), + ( 3, 1, CURDATE(), 2, 40, 4, 4, 8); INSERT INTO `vn`.`itemBarcode`(`id`, `itemFk`, `code`) VALUES diff --git a/services/loopback/common/models/item.json b/services/loopback/common/models/item.json index f167d16c4..3f6774325 100644 --- a/services/loopback/common/models/item.json +++ b/services/loopback/common/models/item.json @@ -7,42 +7,72 @@ } }, "properties": { - "id": { - "type": "Number", - "id": true, - "description": "Identifier" - }, - "name": { - "type": "String", - "required": true - }, - "size": { - "type": "Number" - }, - "category": { - "type": "String" - }, - "stems": { - "type": "Number" - }, - "description": { - "type": "String" - }, - "isOnOffer": { - "type": "Boolean" - }, - "isBargain": { - "type": "Boolean" - }, - "comment": { - "type": "String" - }, - "relevancy": { - "type": "Number" - }, - "image": { - "type": "String" - } + "id": { + "type": "Number", + "id": true, + "description": "Identifier" + }, + "name": { + "type": "String", + "required": true + }, + "size": { + "type": "Number" + }, + "category": { + "type": "String" + }, + "stems": { + "type": "Number" + }, + "description": { + "type": "String" + }, + "isOnOffer": { + "type": "Boolean" + }, + "isBargain": { + "type": "Boolean" + }, + "comment": { + "type": "String" + }, + "relevancy": { + "type": "Number" + }, + "image": { + "type": "String" + }, + "longName": { + "type": "String" + }, + "subName": { + "type": "String" + }, + "tag5": { + "type": "String" + }, + "value5": { + "type": "String" + }, + "tag6": { + "type": "String" + }, + "value6": { + "type": "String" + }, + "tag7": { + "type": "String" + }, + "value7": { + "type": "String" + }, + "tag8": { + "type": "String" + }, + "value8": { + "type": "String" + } }, "relations": { "itemType": {