diff --git a/back/methods/dms/downloadFile.js b/back/methods/dms/downloadFile.js index 523bd39bd..72090f33b 100644 --- a/back/methods/dms/downloadFile.js +++ b/back/methods/dms/downloadFile.js @@ -1,5 +1,4 @@ const UserError = require('vn-loopback/util/user-error'); -const fs = require('fs-extra'); module.exports = Self => { Self.remoteMethodCtx('downloadFile', { @@ -8,7 +7,7 @@ module.exports = Self => { accepts: [ { arg: 'id', - type: 'String', + type: 'Number', description: 'The document id', http: {source: 'path'} } diff --git a/back/methods/dms/uploadFile.js b/back/methods/dms/uploadFile.js index 2d4cc94da..9ef60c005 100644 --- a/back/methods/dms/uploadFile.js +++ b/back/methods/dms/uploadFile.js @@ -1,6 +1,5 @@ const UserError = require('vn-loopback/util/user-error'); const fs = require('fs-extra'); -const md5 = require('md5'); module.exports = Self => { Self.remoteMethodCtx('uploadFile', { diff --git a/db/changes/10031-zone/00-device.sql b/db/changes/10031-zone/00-device.sql deleted file mode 100644 index 665d2c8e7..000000000 --- a/db/changes/10031-zone/00-device.sql +++ /dev/null @@ -1,15 +0,0 @@ -CREATE TABLE `vn`.`device` ( - `id` INT NOT NULL, - `sn` VARCHAR(50) NULL, - `model` VARCHAR(50) NULL, - `userFk` INT(10) UNSIGNED NOT NULL, - PRIMARY KEY (`id`), - INDEX `device_fk1_idx` (`userFk` ASC), - CONSTRAINT `device_fk1` - FOREIGN KEY (`userFk`) - REFERENCES `account`.`user` (`id`) - ON DELETE NO ACTION - ON UPDATE NO ACTION); - -ALTER TABLE `vn`.`device` -CHANGE COLUMN `id` `id` INT(11) NOT NULL AUTO_INCREMENT ; diff --git a/db/changes/10031-zone/00-nodeAdd.sql b/db/changes/10031-zone/00-nodeAdd.sql deleted file mode 100644 index 2c6165ac0..000000000 --- a/db/changes/10031-zone/00-nodeAdd.sql +++ /dev/null @@ -1,74 +0,0 @@ -USE `nst`; -DROP procedure IF EXISTS `nodeAdd`; - -DELIMITER $$ -USE `nst`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `nodeAdd`(IN `vScheme` VARCHAR(45), IN `vTable` VARCHAR(45), IN `vParentFk` INT, IN `vChild` VARCHAR(100)) -BEGIN - DECLARE vSql TEXT; - DECLARE vTableClone VARCHAR(45); - - SET vTableClone = CONCAT(vTable, 'Clone'); - - CALL util.exec(CONCAT('DROP TEMPORARY TABLE IF EXISTS tmp.', vTableClone)); - CALL util.exec(CONCAT( - 'CREATE TEMPORARY TABLE tmp.', vTableClone, - ' ENGINE = MEMORY', - ' SELECT * FROM ', vScheme, '.', vTable - )); - - CALL util.exec(CONCAT( - 'SELECT COUNT(c.id) INTO @childs', - ' FROM ', vScheme, '.', vTable, ' p', - ' LEFT JOIN tmp.', vTableClone, ' c ON c.lft', - ' BETWEEN p.lft AND p.rgt AND c.id != ', vParentFk, - ' WHERE p.id = ', vParentFk - )); - - IF @childs = 0 THEN - CALL util.exec(CONCAT( - 'SELECT lft INTO @vLeft', - ' FROM ', vScheme, '.', vTable, - ' WHERE id = ', vParentFk - )); - ELSE - CALL util.exec(CONCAT( - 'SELECT c.rgt INTO @vLeft', - ' FROM ', vScheme, '.', vTable, ' p', - ' JOIN tmp.', vTableClone, ' c ON c.depth = p.depth + 1' - ' AND c.lft BETWEEN p.lft AND p.rgt', - ' WHERE p.id = ', vParentFk, - ' ORDER BY c.lft', - ' DESC LIMIT 1' - )); - END IF; - - CALL util.exec(CONCAT( - 'UPDATE ', vScheme, '.', vTable, ' SET rgt = rgt + 2', - ' WHERE rgt > @vLeft', - ' ORDER BY rgt DESC' - )); - CALL util.exec(CONCAT( - 'UPDATE ', vScheme, '.', vTable, ' SET lft = lft + 2', - ' WHERE lft > @vLeft', - ' ORDER BY lft DESC' - )); - - SET vChild = REPLACE(vChild, "'", "\\'"); - - CALL util.exec(CONCAT( - 'INSERT INTO ', vScheme, '.', vTable, ' (name, lft, rgt)', - ' VALUES ("', vChild, '", @vLeft + 1, @vLeft + 2)' - )); - - -- CALL util.exec(CONCAT( - -- 'SELECT id, name, lft, rgt, depth, sons', - -- ' FROM ', vScheme, '.', vTable, - -- ' WHERE id = LAST_INSERT_ID()' - -- )); - - CALL util.exec(CONCAT('DROP TEMPORARY TABLE tmp.', vTableClone)); -END$$ - -DELIMITER ; - diff --git a/db/changes/10031-zone/00-zone.sql b/db/changes/10031-zone/00-zone.sql deleted file mode 100644 index 5cc2b8ccb..000000000 --- a/db/changes/10031-zone/00-zone.sql +++ /dev/null @@ -1,2533 +0,0 @@ --- Kkear agencyHourGetShipped --------------------------------------------------------------- - -USE `vn`; -DROP procedure IF EXISTS `vn`.`agencyHourGetShipped`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `agencyHourGetShippedKk`(vLanded DATE, vAddressFk INT, vAgencyFk INT) -BEGIN -/** - * DEPRECATED usar zoneGetShipped - * Devuelve las posibles fechas de envío de un ticket - * - * @param vLanded La fecha de recepcion - * @param vAddressFk Id del consignatario - * @param vAgencyFk Id de la agencia - * @return tmp.agencyHourGetShipped - */ - DECLARE vDone BOOL; - DECLARE vWarehouseFk SMALLINT; - - DECLARE vCur CURSOR FOR - SELECT w.id warehouseFk - FROM vn.warehouse w - WHERE w.hasAvailable; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - DROP TEMPORARY TABLE IF EXISTS tmp.agencyHourGetShipped; - CREATE TEMPORARY TABLE tmp.agencyHourGetShipped - ( - warehouseFk TINYINT NOT NULL PRIMARY KEY, - shipped DATE NOT NULL, - landed DATE NOT NULL - ) - ENGINE = MEMORY; - - OPEN vCur; - - l: LOOP - SET vDone = FALSE; - FETCH vCur INTO vWarehouseFk; - - IF vDone THEN - LEAVE l; - END IF; - INSERT INTO tmp.agencyHourGetShipped (warehouseFk, shipped, landed) - SELECT vWarehouseFk, shipping, vLanded FROM ( - SELECT TIMESTAMPADD(DAY, -ah.substractDay, vLanded) shipping, ah.maxHour - FROM agencyHour ah - LEFT JOIN address a ON a.id = vAddressFk - WHERE ah.warehouseFk = vWarehouseFk - AND (weekDay = WEEKDAY(vLanded) - OR weekDay IS NULL) - AND (ah.agencyFk = vAgencyFk - OR ah.agencyFk IS NULL) - AND (ah.provinceFk = a.provinceFk - OR ah.provinceFk IS NULL - OR vAddressFk IS NULL) - ORDER BY ( - (ah.weekDay IS NOT NULL) + - (ah.agencyFk IS NOT NULL) + - ((ah.provinceFk IS NOT NULL) * 3) - ) DESC - LIMIT 1 - ) t - WHERE t.shipping >= CURDATE() - AND IF(t.shipping = CURDATE(), t.maxHour > HOUR(NOW()), TRUE); - END LOOP; - - CLOSE vCur; -END$$ - -DELIMITER ; -; - --- ticketCalculateClon----------------------------------------------------------------------- -USE `vn`; -DROP procedure IF EXISTS `ticketCalculateClon`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `ticketCalculateClon`(IN vTicketNew INT, vTicketOld INT) -BEGIN - /* - * @vTicketNew id del nuevo ticket clonado - * @vTicketOld id ticket original, a partir del qual se clonara el nuevo - * Este procedimiento "rebioniza" una linea, eliminando los componentes existentes e insertandolos de nuevo - */ - DECLARE vShipped DATE; - DECLARE vClient INT; - DECLARE vWarehouse SMALLINT; - DECLARE vAgencyMode INT; - DECLARE vAddress INT; - DECLARE vLanded DATE; - DECLARE vAgency INT; - - REPLACE INTO orderTicket(orderFk,ticketFk) - SELECT orderFk, vTicketNew - FROM orderTicket - WHERE ticketFk = vTicketOld; - - SELECT t.clientFk, t.warehouseFk, date(t.shipped), t.addressFk, t.agencyModeFk, t.landed, a.agencyFk - INTO vClient, vWarehouse, vShipped, vAddress, vAgencyMode, vLanded, vAgency - FROM vn.agencyMode a - JOIN vn.ticket t ON t.agencyModeFk = a.id - WHERE t.id = vTicketNew; - - DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetShipped; - CALL zoneGetShippedWarehouse(vLanded, vAddress, vAgencyMode); - DELETE FROM tmp.zoneGetShipped WHERE warehouseFk <> vWarehouse; - - CALL buyUltimate(vWarehouse, vShipped); -- rellena la tabla tmp.buyUltimate con la ultima compra - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; - CREATE TEMPORARY TABLE tmp.ticketLot - SELECT vWarehouse warehouseFk, NULL available, s.itemFk, bu.buyFk - FROM sale s - LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk - WHERE s.ticketFk = vTicketOld GROUP BY s.itemFk; - - CALL ticketComponentCalculate(vAddress,vAgencyMode); - - -- Bionizamos lineas con Preu = 0 - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - CREATE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) ENGINE = MEMORY - SELECT s.id saleFk, vWarehouse warehouseFk - FROM sale s - JOIN ticket t on t.id = s.ticketFk WHERE s.ticketFk = vTicketNew AND s.price = 0; - - CALL ticketComponentUpdateSale(1); - - -- Bionizamos lineas con Preu > 0 - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - CREATE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) ENGINE = MEMORY - SELECT s.id saleFk, vWarehouse warehouseFk - FROM sale s - JOIN ticket t on t.id = s.ticketFk WHERE s.ticketFk = vTicketNew - AND s.price > 0; - - CALL ticketComponentUpdateSale(6); - - IF vLanded IS NULL THEN - CALL zoneGetLanded(vShipped, vAddress, vAgency,vWarehouse); - UPDATE ticket t - JOIN tmp.zoneGetLanded zgl ON t.warehouseFk = zgl.warehouseFk - SET t.landed = zgl.landed - WHERE t.id = vTicketNew; - END IF; - - -- Log - CALL `logAdd`(vTicketNew, 'update', ' ticket' , 'Bioniza Ticket'); - - -- Limpieza - DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimate; - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; - DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetLanded; -END$$ - -DELIMITER ; --- ------------------------------------------------------------------------------------------ - -DROP VIEW IF EXISTS `vn`.`agencyWeekDayBonus` ; - -DROP VIEW IF EXISTS `vn`.`agencyHour` ; - -ALTER TABLE `vn2008`.`agency_weekday_bonus` -RENAME TO `vn2008`.`agency_weekday_bonusKk` ; - -ALTER TABLE `vn2008`.`preparation_percentage` -RENAME TO `vn2008`.`preparation_percentageKk` ; - -DROP VIEW IF EXISTS `vn`.`preparationPercentage` ; - -ALTER TABLE `vn2008`.`agency_hour` -RENAME TO `vn2008`.`agency_hourKk` ; - - --- clonWeeklyTickets----------------------------------------------------------------------- -USE `vn2008`; -DROP procedure IF EXISTS `clonWeeklyTickets`; - -DELIMITER $$ -USE `vn2008`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `clonWeeklyTickets`(IN vWeek INT) -BEGIN - DECLARE done BIT DEFAULT 0; - DECLARE vLanding DATE; - DECLARE vShipment DATE; - DECLARE vWarehouse INT; - DECLARE vTicket INT; - DECLARE vWeekDay INT; - DECLARE vClient INT; - DECLARE vEmpresa INT; - DECLARE vConsignatario INT; - DECLARE vAgencia INT; - DECLARE vNewTicket INT; - DECLARE vYear INT; - - DECLARE rsTicket CURSOR FOR - SELECT tt.Id_Ticket, weekDay, Id_Cliente, warehouse_id, empresa_id, Id_Consigna, Id_Agencia - FROM Tickets_turno tt - JOIN Tickets t ON tt.Id_Ticket = t.Id_Ticket; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; - - SET done = 0; - SET vYear = YEAR(CURDATE()) + IF(vWeek < WEEK(CURDATE()),1, 0); - - OPEN rsTicket; - - FETCH rsTicket INTO vTicket, vWeekDay, vClient, vWarehouse, vEmpresa, vConsignatario, vAgencia; - - WHILE NOT done DO - - SELECT date INTO vShipment - FROM time - WHERE year = vYear AND week = vWeek - AND WEEKDAY(date) = vWeekDay; - - -- busca si el ticket ya ha sido clonado - IF (select count(*) FROM Tickets t JOIN ticket_observation tob ON t.Id_Ticket = tob.Id_Ticket - WHERE Id_Consigna = vConsignatario AND Fecha = vShipment AND tob.text LIKE CONCAT('%',vTicket,'%')) = 0 - THEN - - IF (SELECT COUNT(*) FROM Agencias WHERE Id_Agencia = vAgencia AND Agencia LIKE '%turno%') THEN - SET vAgencia = NULL; - END IF; - - CALL vn.ticketCreate(vClient, vShipment, vWarehouse, vEmpresa, vConsignatario, vAgencia, NULL, vLanding, vNewTicket); - - INSERT INTO Movimientos (Id_Ticket, Id_Article, Concepte, Cantidad, Preu, Descuento, CostFixat, PrecioFijado) - SELECT vNewTicket, Id_Article, Concepte, Cantidad, Preu, Descuento, CostFixat, PrecioFijado - FROM Movimientos WHERE Id_Ticket = vTicket; - - INSERT INTO Ordenes (orden,datorden,datticket,codvendedor,codcomprador,cantidad,preciomax,preu,id_article,id_cliente,comentario, - ok, total,datcompra,ko,id_movimiento) - SELECT o.orden,o.datorden,vShipment,o.codvendedor,o.codcomprador,o.cantidad,o.preciomax,o.preu,o.id_article,o.id_cliente,o.comentario, - o.ok, o.total,o.datcompra,o.ko,m2.Id_Movimiento - FROM Movimientos m JOIN Ordenes o ON o.Id_Movimiento = m.Id_Movimiento - JOIN Movimientos m2 ON m.Concepte = m2.Concepte AND m.Cantidad = m2.Cantidad AND m.Id_Article = m2.Id_Article - WHERE m.Id_Ticket = vTicket AND m2.Id_Ticket = vNewTicket; - - INSERT INTO ticket_observation(Id_Ticket,observation_type_id,text) VALUES(vNewTicket,4,CONCAT('turno desde ticket: ',vTicket)) - ON DUPLICATE KEY UPDATE text = CONCAT(ticket_observation.text,VALUES(text),' '); - - INSERT INTO ticket_observation(Id_Ticket,observation_type_id,text) VALUES(vNewTicket,1,'ATENCION: Contiene lineas de TURNO') - ON DUPLICATE KEY UPDATE text = CONCAT(ticket_observation.text,VALUES(text),' '); - - CALL vn.ticketCalculateClon(vNewTicket, vTicket); - END IF; - FETCH rsTicket INTO vTicket, vWeekDay, vClient, vWarehouse, vEmpresa, vConsignatario, vAgencia; - - END WHILE; - - CLOSE rsTicket; - -END$$ - -DELIMITER ; - - --- ticketComponentCalculate----------------------------------------------------------------------- -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(itemFk, warehouseFk, available, rate2, rate3, minPrice, - * packing, grouping, groupingMode, buyFk, typeFk) - * @return tmp.ticketComponentPrice (warehouseFk, itemFk, rate, grouping, price) - */ - - DECLARE vClientFk INT; - DECLARE vGeneralInflationCoefficient INT DEFAULT 1; - DECLARE vMinimumDensityWeight INT DEFAULT 167; - DECLARE vBoxFreightItem INT DEFAULT 71; - DECLARE vBoxVolume BIGINT; -- DEFAULT 138000; - DECLARE vSpecialPriceComponent INT DEFAULT 10; - 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; - - - SELECT volume INTO vBoxVolume - FROM vn.packaging - WHERE id = '94'; - - 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.zoneGetShipped 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(( - i.compression - * r.cm3 - * IF(am.deliveryMethodFk = 1, (GREATEST(i.density, vMinimumDensityWeight) / vMinimumDensityWeight), 1) - * IFNULL((z.price - z.bonus) - * 1/*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 tmp.zoneGetShipped zgs ON zgs.warehouseFk = tcc.warehouseFk - JOIN zone z ON z.id = zgs.id - LEFT JOIN bi.rotacion r ON r.warehouse_id = tcc.warehouseFk - AND r.Id_Article = tcc.itemFk - HAVING cost <> 0; - - 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; - - 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, - CAST(SUM(tcs.sumCost) AS DECIMAL(10,2)) 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 ; - --- bionic_calc_clon----------------------------------------------------------------------- - - -USE `vn2008`; -DROP procedure IF EXISTS `vn2008`.`bionic_calc_clon`; - -DELIMITER $$ -USE `vn2008`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `bionic_calc_clonKk`(IN v_ticket BIGINT) -BEGIN - -/* -* DEPRECATED vn.ticketCalculateClon -* -Este procedimiento "rebioniza" una linea, eliminando los componentes existentes e insertandolos de nuevo -*/ - DECLARE v_shipment DATE; - DECLARE v_customer INT; - DECLARE v_wh SMALLINT; - DECLARE v_agencia INT; - DECLARE v_consigna INT; - DECLARE v_landing DATE; - DECLARE v_agency INT; - - REPLACE order_Tickets(order_id,Id_Ticket) VALUES(48, v_ticket); - - SELECT t.Id_Cliente , t.warehouse_id, date(t.Fecha), t.Id_Consigna, t.Id_Agencia, t.landing, a.agency_id - INTO v_customer, v_wh, v_shipment, v_consigna, v_agencia, v_landing, v_agency - FROM vn2008.Agencias a - JOIN vn2008.Tickets t ON t.Id_Agencia = a.Id_Agencia - WHERE t.Id_Ticket = v_ticket; - - DROP TEMPORARY TABLE IF EXISTS tmp.agencyHourGetShipped; - CREATE TEMPORARY TABLE tmp.agencyHourGetShipped ENGINE = MEMORY - SELECT v_wh warehouseFk, v_shipment shipped, v_landing landed; - - CALL item_last_buy_ (v_wh, v_shipment); -- rellena la tabla t_item_last_buy con la ultima compra - - DROP TEMPORARY TABLE IF EXISTS tmp.bionic_lot; - CREATE TEMPORARY TABLE tmp.bionic_lot - SELECT v_wh warehouse_id,NULL available, - m.Id_Article item_id,ilb.buy_id - FROM Movimientos m - LEFT JOIN t_item_last_buy ilb ON ilb.item_id = m.Id_Article - WHERE m.Id_Ticket = v_ticket GROUP BY m.Id_Article; - - CALL bionic_calc_component(v_consigna,v_agencia); - - -- Bionizamos lineas con Preu = 0 - DROP TEMPORARY TABLE IF EXISTS tmp.movement; - CREATE TEMPORARY TABLE tmp.movement - (PRIMARY KEY (Id_Movimiento)) ENGINE = MEMORY - SELECT Id_Movimiento, v_wh warehouse_id FROM Movimientos m - JOIN Tickets t on t.Id_Ticket = m.Id_Ticket WHERE m.Id_Ticket = v_ticket AND Preu = 0; - - CALL bionic_movement_update(1); - - -- Bionizamos lineas con Preu > 0 - DROP TEMPORARY TABLE IF EXISTS tmp.movement; - CREATE TEMPORARY TABLE tmp.movement - (PRIMARY KEY (Id_Movimiento)) ENGINE = MEMORY - SELECT Id_Movimiento, v_wh warehouse_id FROM Movimientos m - JOIN Tickets t on t.Id_Ticket = m.Id_Ticket WHERE m.Id_Ticket = v_ticket AND Preu > 0; - CALL bionic_movement_update(6); - - IF v_landing IS NULL THEN - CALL travel_tree_shipment(v_shipment, v_consigna, v_agency,v_wh); - UPDATE Tickets t - JOIN travel_tree_shipment tts ON t.warehouse_id = tts.warehouse_id - SET t.landing = tts.landing - WHERE Id_Ticket = v_ticket; - END IF; - - -- Log - call Ditacio(v_ticket - ,'Bioniza Ticket' - ,'T' - , 20 - , 'proc bionic_calc_clon' - , NULL); - - -- Limpieza - DROP TEMPORARY TABLE t_item_last_buy; -END$$ - -DELIMITER ; - - --- bionic_calc_component----------------------------------------------------------------------- - - -USE `vn2008`; -DROP procedure IF EXISTS `vn2008`.`bionic_calc_component`; - -DELIMITER $$ -USE `vn2008`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `bionic_calc_component`(IN `v_consigna` INT, IN `v_agencia` INT) -proc: BEGIN - - DECLARE v_customer INT; - DECLARE COEFICIENTE_DE_INFLACION_GENERAL INT DEFAULT 1.0; - DECLARE DENSIDAD_MINIMA_PESO_VOLUMETRICO INT DEFAULT 167; - DECLARE VOLUMEN_CAJA_VERDNATURA BIGINT; -- DEFAULT 138000; - -- DECLARE vValorEmbolsado DOUBLE DEFAULT 0.04; - - SELECT Volumen INTO VOLUMEN_CAJA_VERDNATURA - FROM Cubos - WHERE Id_Cubo = '94'; - - SELECT Id_Cliente INTO v_customer FROM Consignatarios WHERE Id_Consigna = v_consigna; - SET @rate2 := 0; - SET @rate3 := 0; - - DROP TEMPORARY TABLE IF EXISTS t_bionic_temp; - CREATE TEMPORARY TABLE t_bionic_temp - (PRIMARY KEY (item_id,warehouse_id)) - ENGINE = MEMORY - SELECT - b.item_id, b.warehouse_id,available, - IF((@rate2 := IFNULL(pf.rate_2,c.Tarifa2)) < a.PVP AND a.`Min`, a.PVP, @rate2) * 1.0 rate_2, - IF((@rate3 := IFNULL(pf.rate_3,c.Tarifa3)) < a.PVP AND a.`Min`, a.PVP, @rate3) * 1.0 rate_3, - ifnull(pf.rate_3,0) AS min_price, - IFNULL(pf.Packing,c.Packing) packing, - IFNULL(pf.`grouping`,c.`grouping`) `grouping`, - ABS(IFNULL(pf.caja,c.caja)) box, - b.buy_id, a.tipo_id - FROM tmp.bionic_lot b - JOIN vn2008.Compres c ON b.buy_id = c.Id_Compra - JOIN vn2008.Articles a ON b.item_id = a.Id_Article - JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id - LEFT JOIN vn2008.reinos r ON r.id = t.reino_id - LEFT JOIN vn2008.PreciosEspeciales p ON a.Id_Article = p.Id_Article AND p.Id_Cliente = v_customer - LEFT JOIN ( - SELECT * FROM ( - SELECT p.item_id, p.`grouping`, p.Packing, p.caja, p.rate_2, p.rate_3, zgs.warehouseFk AS warehouse_id - FROM vn2008.price_fixed p - JOIN tmp.zoneGetShipped zgs ON zgs.warehouseFk = p.warehouse_id OR p.warehouse_id = 0 - WHERE zgs.shipped BETWEEN p.date_start AND p.date_end ORDER BY p.item_id, p.warehouse_id DESC - ) t - GROUP BY item_id, warehouse_id - ) pf ON pf.item_id = b.item_id AND pf.warehouse_id = b.warehouse_id - -- descartamos articulos con coste menor de 0.01 - WHERE Costefijo + Portefijo + Embalajefijo + Comisionfija > 0.01 AND r.display <> 0; - - -- Creamos la tabla tmp.bionic_component - DROP TEMPORARY TABLE IF EXISTS tmp.bionic_component; - CREATE TEMPORARY TABLE tmp.bionic_component LIKE - template_bionic_component; - - -- Componentes del precio, valores absolutos - INSERT INTO tmp.bionic_component ( warehouse_id, item_id, component_id, cost) - SELECT b.warehouse_id, b.item_id, 29, rate_3 - Costefijo - Portefijo - Embalajefijo - Comisionfija - FROM t_bionic_temp b - JOIN vn2008.Compres c ON b.buy_id = c.Id_Compra; - - INSERT INTO tmp.bionic_component ( warehouse_id, item_id, component_id, cost) - SELECT b.warehouse_id, b.item_id, 28, Costefijo + Portefijo + Embalajefijo + Comisionfija - FROM t_bionic_temp b - JOIN vn2008.Compres c ON b.buy_id = c.Id_Compra; - - -- Ahora los valores en funcion de la base - - DROP TEMPORARY TABLE IF EXISTS t_components_base; - - CREATE TEMPORARY TABLE t_components_base - SELECT bc.item_id, ROUND(SUM(cost), 4) AS base, bc.warehouse_id - FROM tmp.bionic_component bc - GROUP BY bc.item_id,warehouse_id; - - -- La ratio se calcula teniendo en cuenta el valor de las reclamaciones y el saldo de greuge - - INSERT INTO tmp.bionic_component - SELECT cb.warehouse_id, item_id, 17, ROUND(base * LEAST(recobro,0.25), 3) - FROM t_components_base cb - JOIN bi.claims_ratio ON Id_Cliente = v_customer - WHERE recobro > 0.009; - - -- PAK 2016-08-31 Componente de maná automático, en función del maná acumulado por el comercial. - - INSERT INTO tmp.bionic_component - SELECT cb.warehouse_id, item_id, 39, ROUND(base * (0.01 + prices_modifier_rate), 3) as manaAuto - FROM t_components_base cb - JOIN Clientes c on c.Id_Cliente = v_customer - JOIN bs.mana_spellers ms ON c.Id_Trabajador = ms.Id_Trabajador - WHERE ms.prices_modifier_activated - AND c.Id_Trabajador != 196 -- Ruben Espinosa - HAVING manaAuto <> 0 ; - - -/* - -- Vendedor variable - INSERT INTO tmp.bionic_component - SELECT cb.warehouse_id, item_id, Id_Componente, IFNULL(ROUND(base * tax,4), 0) - FROM t_components_base cb - JOIN bi.tarifa_componentes - WHERE tarifa_componentes_series_id = 2 and IFNULL(tax, 0) > 0; - */ - - --- ******* Inicio Bloque para componentes con tarifa_class diferente de NULL - -- Descuento por ultimas unidades - INSERT INTO tmp.bionic_component - SELECT cb.warehouse_id, b.item_id, Id_Componente, GREATEST(IFNULL(ROUND(base * tax,4), 0), b.min_price - b.rate_3) - FROM t_components_base cb - JOIN bi.tarifa_componentes - JOIN t_bionic_temp b ON b.item_id = cb.item_id AND b.warehouse_id = cb.warehouse_id - LEFT JOIN PreciosEspeciales pe ON pe.Id_Cliente = v_customer AND pe.Id_Article = b.item_id - WHERE Id_Componente = 32 AND tax <> 0 AND b.min_price < b.rate_3 AND PrecioEspecial IS NULL; - - -- Incremento por paquete suelto - INSERT INTO tmp.bionic_component - SELECT b.warehouse_id, b.item_id, 22, rate_2 - rate_3 - FROM t_bionic_temp b - JOIN vn2008.Compres c ON b.buy_id = c.Id_Compra - LEFT JOIN PreciosEspeciales pe ON pe.Id_Cliente = v_customer AND pe.Id_Article = b.item_id - WHERE PrecioEspecial IS NULL; - --- ******* Fin Bloque para componentes con tarifa_class diferente de NULL - - -- Reparto - INSERT INTO tmp.bionic_component - SELECT b.warehouse_id - , b.item_id - , 15 - , COEFICIENTE_DE_INFLACION_GENERAL - * ROUND( - r.cm3 - * art.compression - * IF(a.Vista = 1, (GREATEST(art.density,DENSIDAD_MINIMA_PESO_VOLUMETRICO) / DENSIDAD_MINIMA_PESO_VOLUMETRICO ) , 1) - * IFNULL(az.price - * az.inflacion ,50) - / VOLUMEN_CAJA_VERDNATURA, 4 - ) cost - FROM t_bionic_temp b - JOIN vn2008.Articles art ON art.Id_Article = b.item_id - JOIN vn2008.Agencias a ON a.Id_Agencia = v_agencia - JOIN vn2008.Consignatarios c ON c.Id_Consigna = v_consigna - JOIN vn2008.Agencias_province ap ON ap.agency_id = a.agency_id AND ap.warehouse_id = b.warehouse_id AND ap.province_id = c.province_id - JOIN vn2008.Agencias_zonas az ON az.Id_Agencia = v_agencia AND az.zona = ap.zona AND az.Id_Article = 71 AND az.warehouse_id = b.warehouse_id - LEFT JOIN bi.rotacion r ON r.warehouse_id = b.warehouse_id AND r.Id_Article = b.item_id - HAVING cost <> 0; - --- Reparto bonificado - INSERT INTO tmp.bionic_component - SELECT b.warehouse_id - , b.item_id - , 41 - , COEFICIENTE_DE_INFLACION_GENERAL - * ROUND( - r.cm3 - * art.compression - * IF(a.Vista = 1, (GREATEST(art.density,DENSIDAD_MINIMA_PESO_VOLUMETRICO) / DENSIDAD_MINIMA_PESO_VOLUMETRICO ) , 1) - * awb.bonus - * az.inflacion - / VOLUMEN_CAJA_VERDNATURA, 4 - ) cost - FROM t_bionic_temp b - JOIN vn2008.Articles art ON art.Id_Article = b.item_id - JOIN vn2008.Agencias a ON a.Id_Agencia = v_agencia - JOIN vn2008.Consignatarios c ON c.Id_Consigna = v_consigna - JOIN vn2008.Agencias_province ap ON ap.agency_id = a.agency_id AND ap.warehouse_id = b.warehouse_id AND ap.province_id = c.province_id - JOIN vn2008.Agencias_zonas az ON az.Id_Agencia = v_agencia AND az.zona = ap.zona AND az.Id_Article = 71 AND az.warehouse_id = b.warehouse_id - JOIN vn2008.agency_weekday_bonus awb ON awb.warehouse_id = az.warehouse_id AND awb.zona = az.zona AND a.agency_id = awb.agency_id - LEFT JOIN bi.rotacion r ON r.warehouse_id = b.warehouse_id AND r.Id_Article = b.item_id - JOIN tmp.agencyHourGetShipped ah ON ah.warehouseFk = awb.warehouse_id AND weekday(ah.landed) = awb.weekDay - HAVING cost <> 0 - LIMIT 1; - --- PAK 12-05-2015 - -- EMBOLSADO - IF (SELECT COUNT(*) FROM vn.addressForPackaging WHERE addressFk = v_consigna) THEN - - -- IF v_consigna IN (13690, 3402, 5661, 4233) THEN - - INSERT INTO tmp.bionic_component - SELECT b.warehouse_id, b.item_id, 38, ap.packagingValue cost - FROM t_bionic_temp b - JOIN vn.addressForPackaging ap - WHERE ap.addressFk = v_consigna; - - END IF; - - -- JGF 14-08-2015 - -- Modificacion de precio por dia de preparacion del pedido - INSERT INTO tmp.bionic_component - SELECT cb.warehouse_id, cb.item_id, 14, cb.base * (IFNULL(pe.percentage,pp.percentage)/100) - FROM t_components_base cb - JOIN tmp.agencyHourGetShipped ah ON ah.warehouseFk = cb.warehouse_id - LEFT JOIN vn2008.preparation_percentage pp ON pp.week_day = weekday(ah.shipped) AND cb.warehouse_id = IFNULL(pp.warehouse_id,cb.warehouse_id) - LEFT JOIN vn2008.preparation_exception pe ON pe.exception_day = ah.shipped AND cb.warehouse_id = IFNULL(pe.warehouse_id,cb.warehouse_id) - WHERE IFNULL(pe.percentage,pp.percentage); - - -- Creamos la tabla tmp.bionic_component_copy por que mysql no puede reabrir una tabla temporal - DROP TEMPORARY TABLE IF EXISTS tmp.bionic_component_copy; - CREATE TEMPORARY TABLE tmp.bionic_component_copy - SELECT * FROM tmp.bionic_component; - - -- JGF 19-01-2016 - -- Precios especiales - INSERT INTO tmp.bionic_component - SELECT b.warehouse_id, b.item_id, 10, pe.PrecioEspecial - SUM(cost) sum_cost - FROM tmp.bionic_component_copy b - JOIN bi.tarifa_componentes t ON b.component_id = t.Id_Componente - JOIN PreciosEspeciales pe ON pe.Id_Cliente = v_customer AND pe.Id_Article = b.item_id - WHERE t.tarifa_class IS NULL - GROUP BY b.item_id, b.warehouse_id - HAVING ABS(sum_cost) > 0.001; - - -- Lotes - DROP TEMPORARY TABLE IF EXISTS t_component_sum; - CREATE TEMPORARY TABLE t_component_sum - (INDEX (item_id, warehouse_id)) - ENGINE = MEMORY - SELECT SUM(cost) sum_cost, b.item_id, b.warehouse_id, t.tarifa_class - FROM tmp.bionic_component b - JOIN bi.tarifa_componentes t ON b.component_id = t.Id_Componente - GROUP BY b.item_id, b.warehouse_id, t.tarifa_class; - - -- ***** Inicia Modifica t_bionic_rate las diferentes tarifas - -- Tarifa por unidad minima - DROP TEMPORARY TABLE IF EXISTS t_bionic_rate; - CREATE TEMPORARY TABLE t_bionic_rate - ENGINE = MEMORY - SELECT b.warehouse_id, item_id, 1 rate, - IF(box = 1, `grouping`, 1) `grouping`, SUM(sum_cost) price - FROM t_bionic_temp b - JOIN t_component_sum cs USING(item_id, warehouse_id) - WHERE IFNULL(cs.tarifa_class,1) = 1 AND box < 2 AND (packing > `grouping` or box = 0) - GROUP BY warehouse_id, item_id; - - -- Tarifa por caja - INSERT INTO t_bionic_rate (warehouse_id, item_id, rate, `grouping`, price) - SELECT b.warehouse_id, item_id, 2 rate, packing `grouping`, - SUM(sum_cost) price - FROM t_bionic_temp b - JOIN t_component_sum cs USING(item_id, warehouse_id) - WHERE available IS NULL OR (IFNULL(cs.tarifa_class,2) = 2 AND packing > 0 AND available >= packing) - GROUP BY warehouse_id, item_id; - - -- Tarifa para toda la cantidad disponible - INSERT INTO t_bionic_rate (warehouse_id, item_id, rate, `grouping`, price) - SELECT b.warehouse_id, item_id, 3 rate, available `grouping`, - SUM(sum_cost) price - FROM t_bionic_temp b - JOIN t_component_sum cs USING(item_id, warehouse_id) - WHERE IFNULL(cs.tarifa_class,3) = 3 - GROUP BY warehouse_id, item_id; - - -- ***** Fin Modifica t_bionic_rate las diferentes tarifas - - DROP TEMPORARY TABLE IF EXISTS tmp.bionic_price; - CREATE TEMPORARY TABLE tmp.bionic_price - LIKE template_bionic_price; - - INSERT INTO tmp.bionic_price (warehouse_id, item_id, rate, `grouping`, price) - SELECT * FROM ( - SELECT * FROM t_bionic_rate ORDER BY price - ) t - GROUP BY item_id, warehouse_id, `grouping`; - - - DROP TEMPORARY TABLE IF EXISTS tmp.travel_tree; - CREATE TEMPORARY TABLE tmp.travel_tree - ENGINE = MEMORY - SELECT * FROM tmp.agencyHourGetShipped; - - -- Limpieza - - DROP TEMPORARY TABLE tmp.agencyHourGetShipped; - DROP TEMPORARY TABLE t_bionic_temp; - DROP TEMPORARY TABLE t_component_sum; - DROP TEMPORARY TABLE t_components_base; - DROP TEMPORARY TABLE t_bionic_rate; - DROP TEMPORARY TABLE tmp.bionic_component_copy; -END$$ - -DELIMITER ; - --- ALTER TABLE `vn2008`.`Tickets`----------------------------------------------------------------------- -/* -ALTER TABLE `vn2008`.`Tickets` -ADD COLUMN `zoneFk` INT(11) NULL DEFAULT NULL AFTER `isDeleted`, -ADD INDEX `Tickets_zoneFk_fk_idx` (`zoneFk` ASC); -; -ALTER TABLE `vn2008`.`Tickets` -ADD CONSTRAINT `Tickets_zoneFk_fk` - FOREIGN KEY (`zoneFk`) - REFERENCES `vn`.`zone` (`id`) - ON DELETE RESTRICT - ON UPDATE CASCADE; -*/ - --- ticketCreateWithUser ----------------------------------------------------------------------- -USE `vn`; -DROP procedure IF EXISTS `ticketCreateWithUser`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `ticketCreateWithUser`( - vClientId INT - ,vShipped DATE - ,vWarehouseFk INT - ,vCompanyFk INT - ,vAddressFk INT - ,vAgencyModeFk INT - ,vRouteFk INT - ,vlanded DATE - ,vUserId INT - ,OUT vNewTicket INT) -BEGIN - - DECLARE vCount INT; - - IF vClientId IS NULL THEN - CALL util.throw ('CLIENT_NOT_ESPECIFIED'); - END IF; - - IF NOT vAddressFk OR vAddressFk IS NULL THEN - SELECT id INTO vAddressFk - FROM address - WHERE clientFk = vClientId AND isDefaultAddress; - END IF; - - IF NOT vAgencyModeFk OR vAgencyModeFk IS NULL THEN - SELECT agencyModeFk INTO vAgencyModeFk - FROM address - WHERE clientFk = vClientId AND isDefaultAddress; - END IF; - - CALL vn.zoneGetLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk); - - SELECT COUNT(*) INTO vCount FROM tmp.zoneGetLanded - WHERE landed = vlanded; - - IF vCount IS NULL OR vCount = 0 THEN - CALL util.throw ('NO_ZONE_FOR_THIS_PARAMETERS'); - END IF; - - INSERT INTO vn2008.Tickets ( - Id_Cliente, - Fecha, - Id_Consigna, - Id_Agencia, - Alias, - warehouse_id, - Id_Ruta, - empresa_id, - landing - ) - SELECT - vClientId, - vShipped, - a.id, - IF(vAgencyModeFk, vAgencyModeFk, a.agencyModeFk), - a.nickname, - vWarehouseFk, - 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; - - -- CALL logAddWithUser(vNewTicket, vUserId, 'insert', 'ticket', CONCAT('Ha creado el ticket', ' ', vNewTicket)); - INSERT INTO vn.ticketLog - SET originFk = vNewTicket, userFk = vUserId, `action` = 'insert', description = CONCAT('Ha creado el ticket:', ' ', vNewTicket); - - IF (SELECT ct.isCreatedAsServed FROM vn.clientType ct JOIN vn.client c ON c.typeFk = ct.code WHERE c.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 ; - --- hasZone ----------------------------------------------------------------------- - -USE `vn`; -DROP function IF EXISTS `hasZone`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` FUNCTION `hasZone`(vLanded DATE, vAddress INT, vAgencyModeFk INT) RETURNS tinyint(1) - DETERMINISTIC -BEGIN - DECLARE vHasZone BOOLEAN DEFAULT FALSE; - DECLARE vPostalCode varchar(10); - - SELECT postalCode INTO vPostalCode - FROM address WHERE id = vAddress; - - SELECT COUNT(*), id zoneFk, isIncluded INTO vHasZone, @trash, @trash FROM ( - SELECT z.id, - TIMESTAMPADD(DAY,-z.travelingDays, vLanded) shipped, - vLanded landed, - zi.isIncluded - FROM zoneGeo zgSon - JOIN zoneGeo zgFather ON zgSon.lft BETWEEN zgFather.lft AND zgFather.rgt - JOIN zoneIncluded zi ON zi.geoFk = zgFather.id - JOIN zone z ON z.id = zi.zoneFk - JOIN zoneCalendar zc ON zc.zoneFk = z.id - AND zc.delivered = vLanded - AND z.agencyModeFk = vAgencyModeFk - AND IF(TIMESTAMPADD(DAY,-z.travelingDays, vLanded) = CURDATE(), hour(now()) < hour(z.`hour`),TRUE) - ORDER BY z.id, landed ASC, zgFather.depth DESC) t - GROUP BY id - HAVING isIncluded > 0 LIMIT 1; - RETURN vHasZone; -END$$ - -DELIMITER ; - --- zoneGetShippedWarehouse ----------------------------------------------------------------------- - -USE `vn`; -DROP procedure IF EXISTS `zoneGetShippedWarehouse`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `zoneGetShippedWarehouse`(vLanded DATE, vAddressFk INT, vAgencyModeFk INT) -BEGIN -/** - * Devuelve la mínima fecha de envío para cada warehouse - * - * @param vLanded La fecha de recepcion - * @param vAddressFk Id del consignatario - * @param vAgencyModeFk Id de la agencia - * @return tmp.zoneGetShipped - */ - - DECLARE vPostalCode varchar(10); - - SELECT postalCode INTO vPostalCode - FROM address WHERE id = vAddressFk; - - DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetShipped; - CREATE TEMPORARY TABLE tmp.zoneGetShipped - ENGINE = MEMORY - SELECT * FROM ( - SELECT z.id, - TIMESTAMPADD(DAY,-z.travelingDays, vLanded) shipped, - zi.isIncluded,z.warehouseFk - FROM zoneGeo zgSon - JOIN zoneGeo zgFather ON zgSon.lft BETWEEN zgFather.lft AND zgFather.rgt - JOIN zoneIncluded zi ON zi.geoFk = zgFather.id - JOIN zone z ON z.id = zi.zoneFk - JOIN zoneCalendar zc ON zc.zoneFk = z.id - WHERE zgSon.`name` LIKE vPostalCode - AND zc.delivered = vLanded - AND z.agencyModeFk = vAgencyModeFk - AND IF(TIMESTAMPADD(DAY,-z.travelingDays, vLanded) = CURDATE(), hour(now()) < hour(z.`hour`),TRUE) - ORDER BY z.id, shipped ASC, zgFather.depth DESC) t - GROUP BY warehouseFk - HAVING isIncluded > 0; -END$$ - -DELIMITER ; - - --- bionic_calc ----------------------------------------------------------------------- - -USE `vn2008`; -DROP procedure IF EXISTS `bionic_calc`; - -DELIMITER $$ -USE `vn2008`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `bionic_calc`( - vLanded DATE, - vAddress INT, - vAgency INT) -proc: BEGIN --- @DEPRECATED use vn.ticketCalculate - DECLARE vAvailableCalc INT; - DECLARE vShipped DATE; - DECLARE vCustomer INT; - DECLARE vWh SMALLINT; - DECLARE vDone BOOL; - DECLARE cTravelTree CURSOR FOR - SELECT warehouseFk, shipped FROM tmp.zoneGetShippedWarehouse; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - DROP TEMPORARY TABLE IF EXISTS - tmp.bionic_item, - tmp.bionic_component, - tmp.bionic_lot, - tmp.bionic_price; - - -- Establece los almacenes y las fechas que van a entrar al disponible - - SELECT Id_Cliente INTO vCustomer FROM Consignatarios WHERE Id_Consigna = vAddress; - - CALL vn.zoneGetShippedWarehouse(vLanded, vAddress, vAgency); - - -- Crea la tabla temporal que almacenará los lotes - - CREATE TEMPORARY TABLE tmp.bionic_lot LIKE - template_bionic_lot; - - OPEN cTravelTree; - - l: LOOP - SET vDone = FALSE; - FETCH cTravelTree INTO vWh, vShipped; - - IF vDone THEN - LEAVE l; - END IF; - - CALL `cache`.available_refresh (vAvailableCalc, FALSE, vWh, vShipped); - CALL item_last_buy_ (vWh, vShipped); - - INSERT INTO tmp.bionic_lot (warehouse_id, item_id, available, buy_id) - SELECT - vWh, - i.item_id, - IFNULL(i.available, 0), - ilb.buy_id - FROM `cache`.available i - JOIN tmp.bionic_calc br ON br.item_id = i.item_id - LEFT JOIN Articles a ON a.Id_Article = i.item_id - LEFT JOIN t_item_last_buy ilb ON ilb.item_id = i.item_id - WHERE i.calc_id = vAvailableCalc - AND a.Id_Article != 100 - AND i.available > 0; - - DROP TEMPORARY TABLE t_item_last_buy; - END LOOP; - - CLOSE cTravelTree; - - CALL bionic_calc_component(vAddress, vAgency); - - CREATE TEMPORARY TABLE tmp.bionic_item - ENGINE = MEMORY - SELECT b.item_id, SUM(b.available) available, p.name producer, - a.Article item, a.Medida size, a.Tallos stems, a.Categoria category, - a.Color, a.Foto image, o.Abreviatura origin, bl.min_price price - FROM tmp.bionic_lot b - JOIN Articles a ON b.item_id = a.Id_Article - LEFT JOIN producer p ON p.producer_id = a.producer_id AND p.visible - JOIN Origen o ON o.id = a.id_origen - JOIN ( - SELECT MIN(price) min_price, item_id - FROM tmp.bionic_price - GROUP BY item_id - ) bl ON bl.item_id = b.item_id - GROUP BY b.item_id; - - DROP TEMPORARY TABLE tmp.zoneGetShippedWarehouse; -END$$ - -DELIMITER ; - --- bionic_calc_component ----------------------------------------------------------------------- - -USE `vn2008`; -DROP procedure IF EXISTS `bionic_calc_component`; - -DELIMITER $$ -USE `vn2008`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `bionic_calc_component`(IN `v_consigna` INT, IN `v_agencia` INT) -proc: BEGIN - - DECLARE v_customer INT; - DECLARE COEFICIENTE_DE_INFLACION_GENERAL INT DEFAULT 1.0; - DECLARE DENSIDAD_MINIMA_PESO_VOLUMETRICO INT DEFAULT 167; - DECLARE VOLUMEN_CAJA_VERDNATURA BIGINT; -- DEFAULT 138000; - -- DECLARE vValorEmbolsado DOUBLE DEFAULT 0.04; - - SELECT Volumen INTO VOLUMEN_CAJA_VERDNATURA - FROM Cubos - WHERE Id_Cubo = '94'; - - SELECT Id_Cliente INTO v_customer FROM Consignatarios WHERE Id_Consigna = v_consigna; - SET @rate2 := 0; - SET @rate3 := 0; - - DROP TEMPORARY TABLE IF EXISTS t_bionic_temp; - CREATE TEMPORARY TABLE t_bionic_temp - (PRIMARY KEY (item_id,warehouse_id)) - ENGINE = MEMORY - SELECT - b.item_id, b.warehouse_id,available, - IF((@rate2 := IFNULL(pf.rate_2,c.Tarifa2)) < a.PVP AND a.`Min`, a.PVP, @rate2) * 1.0 rate_2, - IF((@rate3 := IFNULL(pf.rate_3,c.Tarifa3)) < a.PVP AND a.`Min`, a.PVP, @rate3) * 1.0 rate_3, - ifnull(pf.rate_3,0) AS min_price, - IFNULL(pf.Packing,c.Packing) packing, - IFNULL(pf.`grouping`,c.`grouping`) `grouping`, - ABS(IFNULL(pf.caja,c.caja)) box, - b.buy_id, a.tipo_id - FROM tmp.bionic_lot b - JOIN vn2008.Compres c ON b.buy_id = c.Id_Compra - JOIN vn2008.Articles a ON b.item_id = a.Id_Article - JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id - LEFT JOIN vn2008.reinos r ON r.id = t.reino_id - LEFT JOIN vn2008.PreciosEspeciales p ON a.Id_Article = p.Id_Article AND p.Id_Cliente = v_customer - LEFT JOIN ( - SELECT * FROM ( - SELECT p.item_id, p.`grouping`, p.Packing, p.caja, p.rate_2, p.rate_3, zgs.warehouseFk AS warehouse_id - FROM vn2008.price_fixed p - JOIN tmp.zoneGetShipped zgs ON zgs.warehouseFk = p.warehouse_id OR p.warehouse_id = 0 - WHERE zgs.shipped BETWEEN p.date_start AND p.date_end ORDER BY p.item_id, p.warehouse_id DESC - ) t - GROUP BY item_id, warehouse_id - ) pf ON pf.item_id = b.item_id AND pf.warehouse_id = b.warehouse_id - -- descartamos articulos con coste menor de 0.01 - WHERE Costefijo + Portefijo + Embalajefijo + Comisionfija > 0.01 AND r.display <> 0; - - -- Creamos la tabla tmp.bionic_component - DROP TEMPORARY TABLE IF EXISTS tmp.bionic_component; - CREATE TEMPORARY TABLE tmp.bionic_component LIKE - template_bionic_component; - - -- Componentes del precio, valores absolutos - INSERT INTO tmp.bionic_component ( warehouse_id, item_id, component_id, cost) - SELECT b.warehouse_id, b.item_id, 29, rate_3 - Costefijo - Portefijo - Embalajefijo - Comisionfija - FROM t_bionic_temp b - JOIN vn2008.Compres c ON b.buy_id = c.Id_Compra; - - INSERT INTO tmp.bionic_component ( warehouse_id, item_id, component_id, cost) - SELECT b.warehouse_id, b.item_id, 28, Costefijo + Portefijo + Embalajefijo + Comisionfija - FROM t_bionic_temp b - JOIN vn2008.Compres c ON b.buy_id = c.Id_Compra; - - -- Ahora los valores en funcion de la base - - DROP TEMPORARY TABLE IF EXISTS t_components_base; - - CREATE TEMPORARY TABLE t_components_base - SELECT bc.item_id, ROUND(SUM(cost), 4) AS base, bc.warehouse_id - FROM tmp.bionic_component bc - GROUP BY bc.item_id,warehouse_id; - - -- La ratio se calcula teniendo en cuenta el valor de las reclamaciones y el saldo de greuge - - INSERT INTO tmp.bionic_component - SELECT cb.warehouse_id, item_id, 17, ROUND(base * LEAST(recobro,0.25), 3) - FROM t_components_base cb - JOIN bi.claims_ratio ON Id_Cliente = v_customer - WHERE recobro > 0.009; - - -- PAK 2016-08-31 Componente de maná automático, en función del maná acumulado por el comercial. - - INSERT INTO tmp.bionic_component - SELECT cb.warehouse_id, item_id, 39, ROUND(base * (0.01 + prices_modifier_rate), 3) as manaAuto - FROM t_components_base cb - JOIN Clientes c on c.Id_Cliente = v_customer - JOIN bs.mana_spellers ms ON c.Id_Trabajador = ms.Id_Trabajador - WHERE ms.prices_modifier_activated - AND c.Id_Trabajador != 196 -- Ruben Espinosa - HAVING manaAuto <> 0 ; - - -/* - -- Vendedor variable - INSERT INTO tmp.bionic_component - SELECT cb.warehouse_id, item_id, Id_Componente, IFNULL(ROUND(base * tax,4), 0) - FROM t_components_base cb - JOIN bi.tarifa_componentes - WHERE tarifa_componentes_series_id = 2 and IFNULL(tax, 0) > 0; - */ - - --- ******* Inicio Bloque para componentes con tarifa_class diferente de NULL - -- Descuento por ultimas unidades - INSERT INTO tmp.bionic_component - SELECT cb.warehouse_id, b.item_id, Id_Componente, GREATEST(IFNULL(ROUND(base * tax,4), 0), b.min_price - b.rate_3) - FROM t_components_base cb - JOIN bi.tarifa_componentes - JOIN t_bionic_temp b ON b.item_id = cb.item_id AND b.warehouse_id = cb.warehouse_id - LEFT JOIN PreciosEspeciales pe ON pe.Id_Cliente = v_customer AND pe.Id_Article = b.item_id - WHERE Id_Componente = 32 AND tax <> 0 AND b.min_price < b.rate_3 AND PrecioEspecial IS NULL; - - -- Incremento por paquete suelto - INSERT INTO tmp.bionic_component - SELECT b.warehouse_id, b.item_id, 22, rate_2 - rate_3 - FROM t_bionic_temp b - JOIN vn2008.Compres c ON b.buy_id = c.Id_Compra - LEFT JOIN PreciosEspeciales pe ON pe.Id_Cliente = v_customer AND pe.Id_Article = b.item_id - WHERE PrecioEspecial IS NULL; - --- ******* Fin Bloque para componentes con tarifa_class diferente de NULL - - -- Reparto - INSERT INTO tmp.bionic_component - SELECT b.warehouse_id - , b.item_id - , 15 - , COEFICIENTE_DE_INFLACION_GENERAL - * ROUND( - r.cm3 - * art.compression - * IF(a.Vista = 1, (GREATEST(art.density,DENSIDAD_MINIMA_PESO_VOLUMETRICO) / DENSIDAD_MINIMA_PESO_VOLUMETRICO ) , 1) - * IFNULL(az.price - * az.inflacion ,50) - / VOLUMEN_CAJA_VERDNATURA, 4 - ) cost - FROM t_bionic_temp b - JOIN vn2008.Articles art ON art.Id_Article = b.item_id - JOIN vn2008.Agencias a ON a.Id_Agencia = v_agencia - JOIN vn2008.Consignatarios c ON c.Id_Consigna = v_consigna - JOIN vn2008.Agencias_province ap ON ap.agency_id = a.agency_id AND ap.warehouse_id = b.warehouse_id AND ap.province_id = c.province_id - JOIN vn2008.Agencias_zonas az ON az.Id_Agencia = v_agencia AND az.zona = ap.zona AND az.Id_Article = 71 AND az.warehouse_id = b.warehouse_id - LEFT JOIN bi.rotacion r ON r.warehouse_id = b.warehouse_id AND r.Id_Article = b.item_id - HAVING cost <> 0; - --- Reparto bonificado - INSERT INTO tmp.bionic_component - SELECT b.warehouse_id - , b.item_id - , 41 - , COEFICIENTE_DE_INFLACION_GENERAL - * ROUND( - r.cm3 - * art.compression - * IF(a.Vista = 1, (GREATEST(art.density,DENSIDAD_MINIMA_PESO_VOLUMETRICO) / DENSIDAD_MINIMA_PESO_VOLUMETRICO ) , 1) - -- * awb.bonus - * az.inflacion - / VOLUMEN_CAJA_VERDNATURA, 4 - ) cost - FROM t_bionic_temp b - JOIN vn2008.Articles art ON art.Id_Article = b.item_id - JOIN vn2008.Agencias a ON a.Id_Agencia = v_agencia - JOIN vn2008.Consignatarios c ON c.Id_Consigna = v_consigna - JOIN vn2008.Agencias_province ap ON ap.agency_id = a.agency_id AND ap.warehouse_id = b.warehouse_id AND ap.province_id = c.province_id - JOIN vn2008.Agencias_zonas az ON az.Id_Agencia = v_agencia AND az.zona = ap.zona AND az.Id_Article = 71 AND az.warehouse_id = b.warehouse_id - -- JOIN vn2008.agency_weekday_bonus awb ON awb.warehouse_id = az.warehouse_id AND awb.zona = az.zona AND a.agency_id = awb.agency_id - LEFT JOIN bi.rotacion r ON r.warehouse_id = b.warehouse_id AND r.Id_Article = b.item_id - JOIN tmp.agencyHourGetShipped ah ON ah.warehouseFk = awb.warehouse_id AND weekday(ah.landed) = awb.weekDay - HAVING cost <> 0 - LIMIT 1; - --- PAK 12-05-2015 - -- EMBOLSADO - IF (SELECT COUNT(*) FROM vn.addressForPackaging WHERE addressFk = v_consigna) THEN - - -- IF v_consigna IN (13690, 3402, 5661, 4233) THEN - - INSERT INTO tmp.bionic_component - SELECT b.warehouse_id, b.item_id, 38, ap.packagingValue cost - FROM t_bionic_temp b - JOIN vn.addressForPackaging ap - WHERE ap.addressFk = v_consigna; - - END IF; - - -- JGF 14-08-2015 - -- Modificacion de precio por dia de preparacion del pedido - INSERT INTO tmp.bionic_component - SELECT cb.warehouse_id, cb.item_id, 14, cb.base * (IFNULL(pe.percentage,pp.percentage)/100) - FROM t_components_base cb - JOIN tmp.agencyHourGetShipped ah ON ah.warehouseFk = cb.warehouse_id - LEFT JOIN vn2008.preparation_percentage pp ON pp.week_day = weekday(ah.shipped) AND cb.warehouse_id = IFNULL(pp.warehouse_id,cb.warehouse_id) - LEFT JOIN vn2008.preparation_exception pe ON pe.exception_day = ah.shipped AND cb.warehouse_id = IFNULL(pe.warehouse_id,cb.warehouse_id) - WHERE IFNULL(pe.percentage,pp.percentage); - - -- Creamos la tabla tmp.bionic_component_copy por que mysql no puede reabrir una tabla temporal - DROP TEMPORARY TABLE IF EXISTS tmp.bionic_component_copy; - CREATE TEMPORARY TABLE tmp.bionic_component_copy - SELECT * FROM tmp.bionic_component; - - -- JGF 19-01-2016 - -- Precios especiales - INSERT INTO tmp.bionic_component - SELECT b.warehouse_id, b.item_id, 10, pe.PrecioEspecial - SUM(cost) sum_cost - FROM tmp.bionic_component_copy b - JOIN bi.tarifa_componentes t ON b.component_id = t.Id_Componente - JOIN PreciosEspeciales pe ON pe.Id_Cliente = v_customer AND pe.Id_Article = b.item_id - WHERE t.tarifa_class IS NULL - GROUP BY b.item_id, b.warehouse_id - HAVING ABS(sum_cost) > 0.001; - - -- Lotes - DROP TEMPORARY TABLE IF EXISTS t_component_sum; - CREATE TEMPORARY TABLE t_component_sum - (INDEX (item_id, warehouse_id)) - ENGINE = MEMORY - SELECT SUM(cost) sum_cost, b.item_id, b.warehouse_id, t.tarifa_class - FROM tmp.bionic_component b - JOIN bi.tarifa_componentes t ON b.component_id = t.Id_Componente - GROUP BY b.item_id, b.warehouse_id, t.tarifa_class; - - -- ***** Inicia Modifica t_bionic_rate las diferentes tarifas - -- Tarifa por unidad minima - DROP TEMPORARY TABLE IF EXISTS t_bionic_rate; - CREATE TEMPORARY TABLE t_bionic_rate - ENGINE = MEMORY - SELECT b.warehouse_id, item_id, 1 rate, - IF(box = 1, `grouping`, 1) `grouping`, SUM(sum_cost) price - FROM t_bionic_temp b - JOIN t_component_sum cs USING(item_id, warehouse_id) - WHERE IFNULL(cs.tarifa_class,1) = 1 AND box < 2 AND (packing > `grouping` or box = 0) - GROUP BY warehouse_id, item_id; - - -- Tarifa por caja - INSERT INTO t_bionic_rate (warehouse_id, item_id, rate, `grouping`, price) - SELECT b.warehouse_id, item_id, 2 rate, packing `grouping`, - SUM(sum_cost) price - FROM t_bionic_temp b - JOIN t_component_sum cs USING(item_id, warehouse_id) - WHERE available IS NULL OR (IFNULL(cs.tarifa_class,2) = 2 AND packing > 0 AND available >= packing) - GROUP BY warehouse_id, item_id; - - -- Tarifa para toda la cantidad disponible - INSERT INTO t_bionic_rate (warehouse_id, item_id, rate, `grouping`, price) - SELECT b.warehouse_id, item_id, 3 rate, available `grouping`, - SUM(sum_cost) price - FROM t_bionic_temp b - JOIN t_component_sum cs USING(item_id, warehouse_id) - WHERE IFNULL(cs.tarifa_class,3) = 3 - GROUP BY warehouse_id, item_id; - - -- ***** Fin Modifica t_bionic_rate las diferentes tarifas - - DROP TEMPORARY TABLE IF EXISTS tmp.bionic_price; - CREATE TEMPORARY TABLE tmp.bionic_price - LIKE template_bionic_price; - - INSERT INTO tmp.bionic_price (warehouse_id, item_id, rate, `grouping`, price) - SELECT * FROM ( - SELECT * FROM t_bionic_rate ORDER BY price - ) t - GROUP BY item_id, warehouse_id, `grouping`; - - - DROP TEMPORARY TABLE IF EXISTS tmp.travel_tree; - CREATE TEMPORARY TABLE tmp.travel_tree - ENGINE = MEMORY - SELECT * FROM tmp.agencyHourGetShipped; - - -- Limpieza - - DROP TEMPORARY TABLE tmp.agencyHourGetShipped; - DROP TEMPORARY TABLE t_bionic_temp; - DROP TEMPORARY TABLE t_component_sum; - DROP TEMPORARY TABLE t_components_base; - DROP TEMPORARY TABLE t_bionic_rate; - DROP TEMPORARY TABLE tmp.bionic_component_copy; -END$$ - -DELIMITER ; - -/* -- bionic_from_ticket ----------------------------------------------------------------------- -USE `vn2008`; -DROP procedure IF EXISTS `bionic_from_ticket`; - -DELIMITER $$ -USE `vn2008`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `bionic_from_ticket`( - -- DEPRECATED use vn.ticketComponentPreview - vLanded DATE, -- fecha de recepcion de mercancia - v_consigna INT, - v_agencia INT, - v_ticket INT) -BEGIN - DECLARE vWarehouseFk INT; - DECLARE vShipped DATE; - - SELECT warehouse_id INTO vWarehouseFk FROM Tickets WHERE Id_Ticket = v_ticket; - - CALL bionic_free(); - CALL vn.zoneGetShippedWarehouse(vLanded,v_consigna, v_agencia); - - SELECT shipped INTO vShipped FROM tmp.zoneGetShipped WHERE warehouseFk = vWarehouseFk; - - CALL item_last_buy_ (vWarehouseFk, vShipped); - - DROP TEMPORARY TABLE IF EXISTS tmp.bionic_lot; - CREATE TEMPORARY TABLE tmp.bionic_lot - SELECT ilb.warehouse_id, NULL available, - m.Id_Article item_id, ilb.buy_id - FROM Movimientos m - LEFT JOIN t_item_last_buy ilb ON ilb.item_id = m.Id_Article - WHERE m.Id_Ticket = v_ticket - AND m.Id_Article != 100 - GROUP BY warehouse_id, item_id; - - DROP TEMPORARY TABLE t_item_last_buy; - - CALL bionic_calc_component ( v_consigna, v_agencia); - - REPLACE INTO tmp.bionic_component (warehouse_id, item_id, component_id, cost) - SELECT t.warehouse_id, m.Id_Article, mc.Id_Componente, mc.Valor - FROM Movimientos_componentes mc - JOIN Movimientos m ON m.Id_Movimiento = mc.Id_Movimiento - JOIN Tickets t ON t.Id_Ticket = m.Id_Ticket - JOIN tarifa_componentes tc ON tc.Id_componente = mc.Id_Componente - WHERE m.Id_Ticket = v_ticket AND tc.is_renewable = FALSE; - - -- para recuperar el shipment en caso de que se necesite - - SET @shipment = vShipped; - DROP TEMPORARY TABLE tmp.bionic_lot; - - IF IFNULL(vShipped,CURDATE() - 1) < CURDATE() THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'No se puede realizar el cambio'; - END IF; -END$$ - -DELIMITER ; - */ --- ticketCalculate ---------------------------------------------------------------------- - -USE `vn`; -DROP procedure IF EXISTS `ticketCalculate`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `ticketCalculate`( - vLanded DATE, - vAddressFk INT, - vAgencyModeFk INT) -proc: BEGIN -/** - * Calcula los articulos disponibles y sus precios - * - * @table tmp.item(itemFk) Listado de artículos a calcular - * @param vLanded Fecha de recepcion de mercancia - * @param vAddressFk Id del consignatario - * @param vAgencyModeFk Id de la agencia - * @return tmp.ticketCalculateItem(itemFk, available, producer, - * item, size, stems, category, inkFk, image, origin, price) - * @return tmp.ticketLot(warehouseFk, itemFk, available, buyFk) - * @return tmp.ticketComponent - * @return tmp.ticketComponentPrice - * @return tmp.zoneGetShipped - - **/ - - DECLARE vAvailableCalc INT; - DECLARE vShipment DATE; - DECLARE vClient INT; - DECLARE vWarehouseFk SMALLINT; - DECLARE vDone BOOL; - DECLARE cTravelTree CURSOR FOR - SELECT warehouseFk, shipped FROM tmp.zoneGetShipped; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - -- Establece los almacenes y las fechas que van a entrar al disponible - - SELECT clientFk INTO vClient - FROM address WHERE id = vAddressFk; - - CALL vn.zoneGetShippedWarehouse(vLanded, vAddressFk, vAgencyModeFk); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; - CREATE TEMPORARY TABLE tmp.ticketLot( - `warehouseFk` smallint(5) unsigned NOT NULL, - `itemFk` int(11) NOT NULL, - `available` double DEFAULT NULL, - `buyFk` int(11) DEFAULT NULL, - `fix` tinyint(3) unsigned DEFAULT '0', - KEY `itemFk` (`itemFk`), - KEY `item_warehouse` (`itemFk`,`warehouseFk`) USING HASH - ) ENGINE=MEMORY DEFAULT CHARSET=utf8; - - OPEN cTravelTree; - - l: LOOP - SET vDone = FALSE; - FETCH cTravelTree INTO vWarehouseFk, vShipment; - - IF vDone THEN - LEAVE l; - END IF; - - CALL `cache`.available_refresh (vAvailableCalc, FALSE, vWarehouseFk, vShipment); - CALL buyUltimate (vWarehouseFk, vShipment); - - INSERT INTO tmp.ticketLot (warehouseFk, itemFk, available, buyFk) - SELECT vWarehouseFk, - i.item_id, - IFNULL(i.available, 0), - bu.buyFk - FROM `cache`.available i - JOIN tmp.item br ON br.itemFk = i.item_id - LEFT JOIN item it ON it.id = i.item_id - LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = i.item_id - WHERE i.calc_id = vAvailableCalc - AND it.id != 100 - AND i.available > 0; - - DROP TEMPORARY TABLE tmp.buyUltimate; - END LOOP; - - CLOSE cTravelTree; - - CALL vn.ticketComponentCalculate(vAddressFk, vAgencyModeFk); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketCalculateItem; - CREATE TEMPORARY TABLE tmp.ticketCalculateItem - ENGINE = MEMORY - SELECT - b.itemFk, - SUM(b.available) available, - p.name producer, - i.name item, - i.size size, - i.stems, - i.category, - i.inkFk, - i.image, - o.code origin, bl.price - FROM tmp.ticketLot b - JOIN item i ON b.itemFk = i.id - LEFT JOIN producer p ON p.id = i.producerFk AND p.isVisible - JOIN origin o ON o.id = i.originFk - JOIN ( - SELECT MIN(price) price, itemFk - FROM tmp.ticketComponentPrice - GROUP BY itemFk - ) bl ON bl.itemFk = b.itemFk - GROUP BY b.itemFk; - -END$$ - -DELIMITER ; - --- ticketCalculateSale ---------------------------------------------------------------------- - -USE `vn`; -DROP procedure IF EXISTS `ticketCalculateSale`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `ticketCalculateSale`(IN vSale BIGINT) -proc: BEGIN - - DECLARE vShipped DATE; - DECLARE vWarehouse SMALLINT; - DECLARE vAgencyMode INT; - DECLARE vAddress INT; - DECLARE vTicket BIGINT; - DECLARE vItem BIGINT; - DECLARE vLanded DATE; - DECLARE vTicketFree BOOLEAN DEFAULT TRUE; - - SELECT FALSE - INTO vTicketFree - FROM vn.ticket t - JOIN vn.sale s ON s.ticketFk = t.id - LEFT JOIN vn.ticketState ts ON ts.ticketFk = t.id - WHERE s.id = vSale - AND (t.refFk != "" OR (ts.alertLevel > 0 AND s.price != 0)) - LIMIT 1; - - SELECT ticketFk, itemFk - INTO vTicket, vItem - FROM sale - WHERE id = vSale; - - SELECT t.warehouseFk, DATE(t.shipped), t.addressFk, t.agencyModeFk, t.landed - INTO vWarehouse, vShipped, vAddress, vAgencyMode, vLanded - FROM agencyMode a - JOIN ticket t ON t.agencyModeFk = a.id - WHERE t.id = vTicket; - - DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetShipped; - CREATE TEMPORARY TABLE tmp.zoneGetShipped ENGINE = MEMORY - SELECT vWarehouse warehouseFk, vShipped shipped, vLanded landed; - - CALL buyUltimate (vWarehouse, vShipped); - - DELETE FROM tmp.buyUltimate WHERE itemFk != vItem; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; - CREATE TEMPORARY TABLE tmp.ticketLot - SELECT vWarehouse warehouseFk, NULL available, vItem itemFk, buyFk - FROM tmp.buyUltimate - WHERE itemFk = vItem; - - CALL ticketComponentCalculate(vAddress, vAgencyMode); - - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - CREATE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) ENGINE = MEMORY - SELECT vSale saleFk,vWarehouse warehouseFk; - - CALL ticketComponentUpdateSale(IF(vTicketFree,1,6)); - - INSERT INTO vn.ticketLog (originFk, userFk, `action`, description) - VALUES (vTicket, account.userGetId(), 'update', CONCAT('Bionizo linea id ', vSale)); - - DROP TEMPORARY TABLE tmp.buyUltimate; -END$$ - -DELIMITER ; - --- zoneGetAgency --------------------------------------------------------------------------------- -USE `vn`; -DROP procedure IF EXISTS `zoneGetAgency`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `zoneGetAgency`(vAddress INT, vLanded DATE) -BEGIN -/** - * Devuelve el listado de agencias disponibles para la fecha - * y dirección pasadas. - * - * @param vAddress Id de dirección de envío, %NULL si es recogida - * @param vDate Fecha de recogida - * @select Listado de agencias disponibles - */ - - DECLARE vPostalCode varchar(10); - - SELECT postalCode INTO vPostalCode - FROM address WHERE id = vAddress; - - DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetAgency; - CREATE TEMPORARY TABLE tmp.zoneGetAgency - (INDEX (agencyModeFk)) ENGINE = MEMORY - SELECT * FROM ( - SELECT am.id agencyModeFk, - am.name agencyMode, - am.description, - am.deliveryMethodFk, - TIMESTAMPADD(DAY,-z.travelingDays, vLanded) shipped, - zi.isIncluded, - z.warehouseFk - FROM zoneGeo zgSon - JOIN zoneGeo zgFather ON zgSon.lft BETWEEN zgFather.lft AND zgFather.rgt - JOIN zoneIncluded zi ON zi.geoFk = zgFather.id - JOIN zone z ON z.id = zi.zoneFk - JOIN zoneCalendar zc ON zc.zoneFk = z.id - JOIN agencyMode am ON am.id = z.agencyModeFk - WHERE zgSon.`name` LIKE vPostalCode - AND zc.delivered = vLanded - AND IF(TIMESTAMPADD(DAY,-z.travelingDays, vLanded) = CURDATE(), hour(now()) < hour(z.`hour`),TRUE) - ORDER BY zgFather.depth DESC) t - GROUP BY agencyModeFk - HAVING isIncluded > 0; - -END$$ - -DELIMITER ; - --- bionic_available_type_filters --------------------------------------------------------------------- -USE `vn2008`; -DROP procedure IF EXISTS `bionic_available_types_filter`; - -DELIMITER $$ - -CREATE DEFINER=`root`@`%` PROCEDURE `bionic_available_types_filter`( - v_date DATE, - v_consigna INT, - v_agencia INT) -BEGIN -/** - * Este procedimiento devuelve una tabla t_bionic_available_types - * que debe de ser borrar por quien la llame, y se conecta con la tabla articlelist - * que tambien hay que eliminar. - * - * @param vDatefecha de recepcion de mercancia - * @table t_bionic_available_types - */ - - CALL vn.ticketCalculate(v_date, v_consigna, v_agencia); - - -- Introducimos los valores en una tabla temporal - DROP TEMPORARY TABLE IF EXISTS t_bionic_available_types; - - CALL check_table_existence('articlelist'); - - IF @table_exists THEN - call util.throw('No usar articlelist'); - -- SET v_list = 'JOIN vn2008.articlelist AL ON AL.Id_Article = a.Id_Article '; - END IF; - - CREATE TEMPORARY TABLE t_bionic_available_types - SELECT a.tipo_id, t.Tipo, r.reino, count(*) as item_count - FROM tmp.ticketCalculateItem tci - JOIN vn2008.Articles a ON tci.itemFk = a.Id_Article - JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id - JOIN vn2008.reinos r ON r.id = t.reino_id - WHERE tci.available > 0 - GROUP BY a.tipo_id; - - DROP TEMPORARY TABLE tmp.ticketCalculateItem; -END$$ - -DELIMITER ; --- ticketCalculateFromType --------------------------------------------------------------------- -USE `vn`; -DROP procedure IF EXISTS `ticketCalculateFromType`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `ticketCalculateFromType`( vLanded DATE, - vAddressFk INT, - vAgencyModeFk INT, - vTypeFk INT) -BEGIN - DROP TEMPORARY TABLE IF EXISTS tmp.item; - CREATE TEMPORARY TABLE tmp.item - (INDEX (itemFk)) - ENGINE = MEMORY - SELECT id itemFk FROM vn.item - WHERE typeFk = vTypeFk; - - CALL ticketCalculate(vLanded, vAddressFk, vAgencyModeFk); - DROP TEMPORARY TABLE tmp.item; - DROP TEMPORARY TABLE tmp.ticketLot; - -END$$ - -DELIMITER ; - --- order_confirmWithUser` --------------------------------------------------------------------- - -USE `hedera`; -DROP PROCEDURE IF EXISTS `orderConfirm`; -DROP procedure IF EXISTS `order_confirm_bionic`; -DROP procedure IF EXISTS `orderConfirmWithUser`; - -DROP procedure IF EXISTS `order_confirmWithUser`; -DELIMITER $$ -USE `hedera`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `order_confirmWithUser`(IN `vOrder` INT, IN `vUserId` INT) -BEGIN -/** - * Confirms an order, creating each of its tickets on the corresponding - * date, store and user. - * - * @param vOrder The order identifier - * @param vUser The user identifier - */ - DECLARE vOk BOOL; - DECLARE vDone BOOL DEFAULT FALSE; - DECLARE vWarehouse INT; - DECLARE vShipment DATETIME; - DECLARE vTicket INT; - DECLARE vNotes VARCHAR(255); - DECLARE vItem INT; - DECLARE vConcept VARCHAR(30); - DECLARE vAmount INT; - DECLARE vPrice DECIMAL(10,2); - DECLARE vSale INT; - DECLARE vRate INT; - DECLARE vRowId INT; - DECLARE vDelivery DATE; - DECLARE vAddress INT; - DECLARE vIsConfirmed BOOL; - DECLARE vClientId INT; - DECLARE vCompanyId INT; - DECLARE vAgencyModeId INT; - - DECLARE TICKET_FREE INT DEFAULT 2; - DECLARE SYSTEM_WORKER INT DEFAULT 20; - - DECLARE cDates CURSOR FOR - SELECT zgs.shipped, r.warehouse_id - FROM `order` o - JOIN order_row r ON r.order_id = o.id - LEFT JOIN tmp.zoneGetShipped zgs ON zgs.warehouseFk = r.warehouse_id - WHERE o.id = vOrder AND r.amount != 0 - GROUP BY r.warehouse_id; - - DECLARE cRows CURSOR FOR - SELECT r.id, r.item_id, a.Article, r.amount, r.price, r.rate - FROM order_row r - JOIN vn2008.Articles a ON a.Id_Article = r.item_id - WHERE r.amount != 0 - AND r.warehouse_id = vWarehouse - AND r.order_id = vOrder - ORDER BY r.rate DESC; - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - -- Carga los datos del pedido - - SELECT o.date_send, o.address_id, o.note, - o.confirmed, cs.Id_Cliente, o.company_id, o.agency_id - INTO vDelivery, vAddress, vNotes, - vIsConfirmed, vClientId, vCompanyId, vAgencyModeId - FROM hedera.`order` o - JOIN vn2008.Consignatarios cs ON cs.Id_Consigna = o.address_id - WHERE id = vOrder; - - -- Comprueba que el pedido no está confirmado - - IF vIsConfirmed THEN - CALL util.throw ('ORDER_ALREADY_CONFIRMED'); - END IF; - - -- Comprueba que el pedido no está vacío - - SELECT COUNT(*) > 0 INTO vOk - FROM order_row WHERE order_id = vOrder AND amount > 0; - - IF !vOk THEN - CALL util.throw ('ORDER_EMPTY'); - END IF; - - -- Carga las fechas de salida de cada almacén - - CALL vn.zoneGetShippedWarehouse (vDelivery, vAddress, vAgencyModeId); - - -- Trabajador que realiza la acción - - IF vUserId IS NULL THEN - SELECT employeeFk INTO vUserId FROM orderConfig; - END IF; - - -- Crea los tickets del pedido - - START TRANSACTION; - - OPEN cDates; - - lDates: - LOOP - SET vTicket = NULL; - SET vDone = FALSE; - FETCH cDates INTO vShipment, vWarehouse; - - IF vDone THEN - LEAVE lDates; - END IF; - - -- Busca un ticket existente que coincida con los parametros - - SELECT Id_Ticket INTO vTicket - FROM vn2008.Tickets t - LEFT JOIN vn.ticketState tls on tls.ticket = t.Id_Ticket - JOIN `order` o - ON o.address_id = t.Id_Consigna - AND vWarehouse = t.warehouse_id - AND o.agency_id = t.Id_Agencia - AND t.landing = o.date_send - AND vShipment = DATE(t.Fecha) - WHERE o.id = vOrder - AND t.Factura IS NULL - AND IFNULL(tls.alertLevel,0) = 0 - AND t.Id_Cliente <> 1118 - LIMIT 1; - - -- Crea el ticket en el caso de no existir uno adecuado - - IF vTicket IS NULL - THEN - CALL vn.ticketCreateWithUser( - vClientId, - IFNULL(vShipment, CURDATE()), - vWarehouse, - vCompanyId, - vAddress, - vAgencyModeId, - NULL, - vDelivery, - vUserId, - vTicket - ); - ELSE - INSERT INTO vncontrol.inter - SET Id_Ticket = vTicket, - Id_Trabajador = SYSTEM_WORKER, - state_id = TICKET_FREE; - END IF; - - INSERT IGNORE INTO vn2008.order_Tickets - SET order_id = vOrder, - Id_Ticket = vTicket; - - -- Añade las notas - - IF vNotes IS NOT NULL AND vNotes != '' - THEN - INSERT INTO vn2008.ticket_observation SET - Id_Ticket = vTicket, - observation_type_id = 4 /* salesperson */, - `text` = vNotes - ON DUPLICATE KEY UPDATE - `text` = CONCAT(VALUES(`text`),'. ', `text`); - END IF; - - -- Añade los movimientos y sus componentes - - OPEN cRows; - - lRows: - LOOP - SET vDone = FALSE; - FETCH cRows INTO vRowId, vItem, vConcept, vAmount, vPrice, vRate; - - IF vDone THEN - LEAVE lRows; - END IF; - - INSERT INTO vn2008.Movimientos - SET - Id_Article = vItem, - Id_Ticket = vTicket, - Concepte = vConcept, - Cantidad = vAmount, - Preu = vPrice, - CostFixat = 0, - PrecioFijado = TRUE; - - SET vSale = LAST_INSERT_ID(); - - INSERT INTO vn2008.Movimientos_componentes - (Id_Movimiento, Id_Componente, Valor) - SELECT vSale, cm.component_id, cm.price - FROM order_component cm - JOIN bi.tarifa_componentes tc - ON tc.Id_Componente = cm.component_id - WHERE cm.order_row_id = vRowId - GROUP BY vSale, cm.component_id; - - UPDATE order_row SET Id_Movimiento = vSale - WHERE id = vRowId; - - END LOOP; - - CLOSE cRows; - - -- Fija el coste - - DROP TEMPORARY TABLE IF EXISTS tComponents; - CREATE TEMPORARY TABLE tComponents - (INDEX (saleFk)) - ENGINE = MEMORY - SELECT SUM(mc.Valor) valueSum, mc.Id_Movimiento saleFk - FROM vn2008.Movimientos_componentes mc - JOIN bi.tarifa_componentes tc USING(Id_Componente) - JOIN bi.tarifa_componentes_series tcs - ON tcs.tarifa_componentes_series_id = tc.tarifa_componentes_series_id - AND tcs.base - JOIN vn2008.Movimientos m - ON m.Id_Movimiento = mc.Id_Movimiento - WHERE m.Id_Ticket = vTicket - GROUP BY mc.Id_Movimiento; - - UPDATE vn2008.Movimientos m - JOIN tComponents mc ON mc.saleFk = m.Id_Movimiento - SET m.CostFixat = valueSum; - - DROP TEMPORARY TABLE tComponents; - END LOOP; - - CLOSE cDates; - - DELETE FROM basketOrder WHERE orderFk = vOrder; - UPDATE `order` SET confirmed = TRUE, confirm_date = NOW() - WHERE id = vOrder; - - COMMIT; -END$$ - -DELIMITER ; - --- orderConfirmWithUser` --------------------------------------------------------------------- - -USE `vn`; -DROP procedure IF EXISTS `vn`.`agencyHourGetAgency`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `agencyHourGetAgencyKk`(vAddress INT, vDate DATE) -BEGIN -/** - * DEPRECATED usar zoneGetAgency - * Devuelve el listado de agencias disponibles para la fecha - * y dirección pasadas. - * - * @param vAddress Id de dirección de envío, %NULL si es recogida - * @param vDate Fecha de recogida - * @table agencyModeList Listado de agencias disponibles - */ - DECLARE vAgency INT; - DECLARE vDone BOOL DEFAULT FALSE; - - DECLARE vCur CURSOR FOR - SELECT DISTINCT a.id - FROM agency a - JOIN agencyHour ah ON ah.agencyFk = a.id; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - DROP TEMPORARY TABLE IF EXISTS agencyModeList; - CREATE TEMPORARY TABLE agencyModeList ( - id INT NOT NULL, - agency VARCHAR(20), - description VARCHAR(45), - deliveryMethodFk VARCHAR(45), - shipped DATE, - warehouse VARCHAR(45), - PRIMARY KEY(id) - ) - ENGINE = MEMORY; - - OPEN vCur; - FETCH vCur INTO vAgency; - - WHILE NOT vDone - DO - CALL vn.agencyHourGetShipped(vDate, vAddress, vAgency); - INSERT INTO agencyModeList - SELECT a.id, a.name, a.description, - a.deliveryMethodFk, ah.shipped, w.name - FROM agencyMode a - JOIN tmp.agencyHourGetShipped ah - JOIN warehouse w on w.id = ah.warehouseFk - WHERE a.agencyFk = vAgency - AND a.web - ON DUPLICATE KEY UPDATE - warehouse = CONCAT(warehouse, ', ', w.name); - - FETCH vCur INTO vAgency; - END WHILE; - - CLOSE vCur; - - DROP TEMPORARY TABLE tmp.agencyHourGetShipped; - SELECT * FROM agencyModeList; - DROP TEMPORARY TABLE IF EXISTS agencyModeList; -END$$ - -DELIMITER ; - --- ticketComponentPreview` --------------------------------------------------------------------- -USE `vn`; -DROP procedure IF EXISTS `ticketComponentPreview`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentPreview`( - vTicketFk INT, - vLanded DATE, - vAddressFk INT, - vAgencyModeFk INT, - vWarehouseFk SMALLINT) -BEGIN - - DECLARE vShipped DATE; - DECLARE vBuyOrderItem INT DEFAULT 100; - - DECLARE vHasDataChanged BOOL DEFAULT FALSE; - DECLARE vHasAddressChanged BOOL; - DECLARE vHasAgencyModeChanged BOOL DEFAULT FALSE; - DECLARE vHasWarehouseChanged BOOL DEFAULT FALSE; - - DECLARE vAddressTypeRateFk INT DEFAULT NULL; - DECLARE vAgencyModeTypeRateFk INT DEFAULT NULL; - - DECLARE vHasChangeAll BOOL DEFAULT FALSE; - - SELECT DATE(landed) <> vLanded, - addressFk <> vAddressFk, - agencyModeFk <> vAgencyModeFk, - warehouseFk <> vWarehouseFk - INTO - vHasDataChanged, - vHasAddressChanged, - vHasAgencyModeChanged, - vHasWarehouseChanged - FROM vn.ticket t - WHERE t.id = vTicketFk; - - IF vHasDataChanged OR vHasWarehouseChanged THEN - SET vHasChangeAll = TRUE; - END IF; - - IF vHasAddressChanged THEN - SET vAddressTypeRateFk = 5; - END IF; - - IF vHasAgencyModeChanged THEN - SET vAgencyModeTypeRateFk = 6; - END IF; - - CALL zoneGetShippedWarehouse(vLanded, vAddressFk, vAgencyModeFk); - - SELECT shipped INTO vShipped - FROM tmp.zoneGetShipped - WHERE warehouseFk = vWarehouseFk; - - CALL buyUltimate(vWarehouseFk, vShipped); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; - CREATE TEMPORARY TABLE tmp.ticketLot ENGINE = MEMORY ( - SELECT - vWarehouseFk AS warehouseFk, - NULL AS available, - s.itemFk, - bu.buyFk - FROM sale s - LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk - WHERE s.ticketFk = vTicketFk - AND s.itemFk != vBuyOrderItem - GROUP BY bu.warehouseFk, bu.itemFk); - - CALL ticketComponentCalculate(vAddressFk, vAgencyModeFk); - - REPLACE INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost) - SELECT t.warehouseFk, s.itemFk, sc.componentFk, sc.value - FROM saleComponent sc - JOIN sale s ON s.id = sc.saleFk - JOIN ticket t ON t.id = s.ticketFk - JOIN componentRate cr ON cr.id = sc.componentFk - WHERE s.ticketFk = vTicketFk - AND (cr.isRenewable = FALSE - OR - (NOT vHasChangeAll - AND (NOT (cr.componentTypeRate <=> vAddressTypeRateFk - OR cr.componentTypeRate <=> vAgencyModeTypeRateFk)))); - - SET @shipped = vShipped; - - DROP TEMPORARY TABLE - tmp.zoneGetShipped, - tmp.buyUltimate, - tmp.ticketLot; - - IF IFNULL(vShipped, CURDATE() - 1) < CURDATE() THEN - CALL util.throw('NO_AGENCY_AVAILABLE'); - END IF; -END$$ - -DELIMITER ; - --- orderCheckConfig` --------------------------------------------------------------------- - -USE `hedera`; -DROP procedure IF EXISTS `orderCheckConfig`; - -DELIMITER $$ -USE `hedera`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `orderCheckConfig`(vOrder INT) -proc: BEGIN -/** - * Comprueba que la configuración del pedido es correcta. - * - * @param vOrder Identificador del pedido - */ - DECLARE vDeliveryMethod VARCHAR(255); - DECLARE vLanded DATE; - DECLARE vAgencyMode INT; - DECLARE vAddress INT; - DECLARE vIsAvailable BOOL; - - -- Obtiene los datos del pedido - - SELECT d.code, o.date_send, o.agency_id, o.address_id - INTO vDeliveryMethod, vLanded, vAgencyMode, vAddress - FROM `order` o - JOIN vn.deliveryMethod d ON d.id = o.delivery_method_id - WHERE o.id = vOrder; - - -- Comprueba que se ha seleccionado una dirección - - IF vDeliveryMethod IN ('AGENCY', 'DELIVERY') - && vAddress IS NULL - THEN - CALL util.throw ('ORDER_EMPTY_ADDRESS'); - END IF; - - -- Comprueba que la agencia es correcta - - CALL vn.zoneGetAgency(vAddress, vLanded); - - SELECT COUNT(*) > 0 INTO vIsAvailable - FROM tmp.zoneGetAgency - WHERE agencyModeFk = vAgencyMode; - - IF !vIsAvailable THEN - CALL util.throw ('ORDER_INVALID_AGENCY'); - END IF; - - DROP TEMPORARY TABLE tmp.zoneGetAgency; -END$$ - -DELIMITER ; - --- agencyListAvailable` --------------------------------------------------------------------- - -DROP procedure IF EXISTS `vn`.`agencyListAvailable`; -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`__agencyListAvailable`(vDate DATE, vAddress INT) - READS SQL DATA -BEGIN -/** - * DEPRECATED usar zoneGetAgency - * Devuelve la lista de almacenes disponibles y la fecha de - * envío desde cada uno. - * - * @param vDate Fecha de recepción de mercancía - * @param vAddress Id consignatario, %NULL para recogida - * @return agencyAvailable Lista de almacenes disponibles - */ - DECLARE vMaxDays INT DEFAULT DATEDIFF(vDate, CURDATE()); - DECLARE vWday TINYINT DEFAULT WEEKDAY(vDate); - DECLARE vHour TINYINT DEFAULT HOUR(NOW()); - DECLARE vProvince INT; - - SELECT provinceFk INTO vProvince - FROM address - WHERE id = vAddress; - - DROP TEMPORARY TABLE IF EXISTS tmp.agencyAvailable; - CREATE TEMPORARY TABLE tmp.agencyAvailable - (INDEX (agencyFk)) - ENGINE = MEMORY - SELECT agencyFk, warehouseFk - FROM agencyHour h - WHERE (provinceFk = vProvince - OR provinceFk IS NULL) - AND (weekDay = vWday - OR weekDay IS NULL) - AND (substractDay < vMaxDays - OR (substractDay = vMaxDays AND maxHour > vHour)); -END$$ -DELIMITER ; - --- agencyIsAvailable` --------------------------------------------------------------------- - -DROP function IF EXISTS `vn`.`agencyIsAvailable`; -DELIMITER $$ -CREATE DEFINER=`root`@`%` FUNCTION `vn`.`__agencyIsAvailable`(vAgency INT, vDate DATE, vAddress INT) - RETURNS tinyint(1) - READS SQL DATA -BEGIN -/** - * Comprueba si la agencia esta disponible para la fecha y - * dirección dadas, es decir, si es posible enviar mercancía - * desde al menos uno de los almacenes por la agencia, fecha - * y direcciones especificadas. - * - * @param vAgency Id de agencia - * @param vDate Fecha de recepción de mercancía - * @param vAddress Id consignatario, %NULL para recogida - * @return %TRUE si la agencia esta disponible, %FALSE en caso contrario - */ - DECLARE vMaxDays INT DEFAULT DATEDIFF(vDate, CURDATE()); - DECLARE vWday TINYINT DEFAULT WEEKDAY(vDate); - DECLARE vHour TINYINT DEFAULT HOUR(NOW()); - DECLARE vProvince INT; - DECLARE isAvailable BOOL; - - SELECT provinceFk INTO vProvince - FROM address - WHERE id = vAddress; - - SELECT COUNT(*) > 0 INTO isAvailable - FROM agencyHour h - JOIN agencyMode a - ON a.agencyFk = h.agencyFk - WHERE (h.provinceFk = vProvince - OR h.provinceFk IS NULL) - AND (h.weekDay = vWday - OR h.weekDay IS NULL) - AND (h.substractDay < vMaxDays - OR (h.substractDay = vMaxDays AND h.maxHour > vHour)) - AND a.id = vAgency; - - RETURN isAvailable; -END$$ -DELIMITER ; - --- ticket_recalcComponents` --------------------------------------------------------------------- - -USE `vn2008`; -DROP procedure IF EXISTS `vn2008`.`bionic_calc_ticket`; -USE `vn`; -DROP procedure IF EXISTS `ticket_recalcComponents`; - -USE `vn`; -DROP procedure IF EXISTS `ticket_recalcComponents`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `ticket_recalcComponents`(IN vTicketFk BIGINT ) -proc: BEGIN - -/** - * Este procedimiento trata de "rebionizar" un ticket, - * eliminando los componentes existentes e insertandolos de nuevo - * - * @param vTicketFk Id del ticket - * @return tmp.buyUltimate - */ - DECLARE vShipped DATE; - DECLARE vWarehouseFk SMALLINT; - DECLARE vAgencyModeFk INT; - DECLARE vAddressFk INT; - DECLARE vLanded DATE; - DECLARE vIsTicketEditable BOOLEAN; - - SELECT (IFNULL(ts.alertLevel,0) >0 or IFNULL(t.refFk,"") != "") = FALSE - INTO vIsTicketEditable - FROM ticket t LEFT JOIN ticketState ts ON t.id = ts.ticket - WHERE id = vTicketFk; - - SELECT warehouseFk, date(shipped), addressFk, agencyModeFk, landed - INTO vWarehouseFk, vShipped, vAddressFk, vAgencyModeFk, vLanded - FROM ticket - WHERE id = vTicketFk; - - CALL zoneGetShippedWarehouse(vLanded, vAddressFk , vAgencyModeFk); - - CALL vn.buyUltimate (vWarehouseFk, vShipped); -- rellena la tabla buyUltimate con la ultima compra - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; - CREATE TEMPORARY TABLE tmp.ticketLot - SELECT vWarehouseFk warehouseFk, NULL available, - s.itemFk, bu.buyFk - FROM sale s - LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk - WHERE s.ticketFk = vTicketFk - GROUP BY s.itemFk; - - CALL vn.ticketComponentCalculate(vAddressFk,vAgencyModeFk); - - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - CREATE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) ENGINE = MEMORY - SELECT id saleFk, vWarehouseFk warehouseFk - FROM sale s - WHERE s.ticketFk = vTicketFk; - - CALL vn.ticketComponentUpdateSale(IF(vIsTicketEditable,1,6)); -- si el ticket esta facturado, respeta los precios - - IF vLanded IS NULL THEN - - CALL zoneGetLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk); - - UPDATE vn2008.Tickets t - SET t.landing = (SELECT landed FROM tmp.zoneGetLanded) - WHERE Id_Ticket = vTicketFk; - - DROP TEMPORARY TABLE tmp.zoneGetLanded; - - END IF; - - DROP TEMPORARY TABLE tmp.buyUltimate; - DROP TEMPORARY TABLE tmp.ticketComponentPrice; - DROP TEMPORARY TABLE tmp.ticketComponent; - DROP TEMPORARY TABLE tmp.sale; -END$$ - --- ticketCalculatePurge` --------------------------------------------------------------------- - -DELIMITER ; - -USE `vn`; -DROP procedure IF EXISTS `ticketCalculatePurge`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `ticketCalculatePurge`() -BEGIN - DROP TEMPORARY TABLE - tmp.ticketCalculateItem, - tmp.ticketComponentPrice, - tmp.ticketComponent, - tmp.ticketLot, - tmp.zoneGetShipped; -END$$ - -DELIMITER ; - --- `vn`.`component` ----------------------------------------------- - -CREATE OR REPLACE - ALGORITHM = UNDEFINED - DEFINER = `root`@`%` - SQL SECURITY DEFINER -VIEW `vn`.`component` AS - SELECT - `t`.`Id_Componente` AS `id`, - `t`.`Componente` AS `name`, - `t`.`tarifa_componentes_series_id` AS `typeFk`, - `t`.`tarifa_class` AS `classRate`, - `t`.`tax` AS `tax`, - `t`.`is_renewable` AS `isRenewable` - FROM - `bi`.`tarifa_componentes` `t`; - --- componentType -------------------------------------------------------- - -CREATE OR REPLACE - ALGORITHM = UNDEFINED - DEFINER = `root`@`%` - SQL SECURITY DEFINER -VIEW `vn`.`componentType` AS - SELECT - `t`.`tarifa_componentes_series_id` AS `id`, - `t`.`Serie` AS `type`, - `t`.`base` AS `base` - FROM - `bi`.`tarifa_componentes_series` `t`; \ No newline at end of file diff --git a/db/changes/10031-zone/00-zoneNest.sql b/db/changes/10031-zone/00-zoneNest.sql deleted file mode 100644 index 2691aa8a9..000000000 --- a/db/changes/10031-zone/00-zoneNest.sql +++ /dev/null @@ -1,28 +0,0 @@ -DROP procedure IF EXISTS `vn`.`zoneNest`; - -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`zoneNest`() -BEGIN - DROP TEMPORARY TABLE IF EXISTS tmp.zoneGeo; - CREATE TEMPORARY TABLE tmp.zoneGeo - (id INT AUTO_INCREMENT PRIMARY KEY) - ENGINE = MEMORY - SELECT * FROM vn.zoneGeo; - - DROP TEMPORARY TABLE IF EXISTS tmp.country; - CREATE TEMPORARY TABLE tmp.country - SELECT id FROM country - WHERE country IN('España exento'); - - CALL vn.zoneNestCountry(); - CALL vn.zoneNestProvince(); - CALL vn.zoneNestTown(); - CALL vn.zoneNestPostcode(); - CALL vn.nestTree('tmp', 'zoneGeo', 'vn', 'zoneGeo'); - - DROP TEMPORARY TABLE - tmp.zoneGeo, - tmp.country; -END$$ - -DELIMITER ; diff --git a/db/changes/10031-zone/00-zoneNestCountry.sql b/db/changes/10031-zone/00-zoneNestCountry.sql deleted file mode 100644 index acc3a4d12..000000000 --- a/db/changes/10031-zone/00-zoneNestCountry.sql +++ /dev/null @@ -1,55 +0,0 @@ -DROP procedure IF EXISTS `vn`.`zoneNestCountry`; - -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`zoneNestCountry`() -BEGIN - - DECLARE vDone BOOL; - DECLARE vParent INT DEFAULT 1; - DECLARE vGeoFk INT; - DECLARE vChildFk INT; - DECLARE vChildName VARCHAR(100); - DECLARE countryCur CURSOR FOR - SELECT 1, c.id, c.`country` - FROM vn.country c - JOIN tmp.country tc ON tc.id = c.id - ORDER BY c.`country`; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - -- Remove existing countries - DELETE zg FROM vn.country c - JOIN tmp.country tc ON tc.id = c.id - JOIN tmp.zoneGeo zg ON zg.id = c.geoFk; - - -- Reset country geoFk - UPDATE vn.country c - JOIN tmp.country tc ON tc.id = c.id - SET c.geoFk = NULL - WHERE c.geoFk IS NOT NULL; - - -- > Country cursor start - OPEN countryCur; - - countryLoop: LOOP - SET vDone = FALSE; - - FETCH countryCur INTO vParent, vChildFk, vChildName; - - IF vDone THEN - LEAVE countryLoop; - END IF; - - CALL nst.nodeAdd('tmp', 'zoneGeo', vParent, vChildName); - END LOOP; - CLOSE countryCur; - -- < Country cursor end - - UPDATE country c - JOIN tmp.zoneGeo z ON z.name = c.country - SET c.geoFk = z.id - WHERE c.geoFk IS NULL; -END$$ - -DELIMITER ; - diff --git a/db/changes/10031-zone/00-zoneNestPostcode.sql b/db/changes/10031-zone/00-zoneNestPostcode.sql deleted file mode 100644 index cd62deee8..000000000 --- a/db/changes/10031-zone/00-zoneNestPostcode.sql +++ /dev/null @@ -1,61 +0,0 @@ -DROP procedure IF EXISTS `vn`.`zoneNestPostcode`; - -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`zoneNestPostcode`() -BEGIN - - DECLARE vDone BOOL; - DECLARE vParent INT DEFAULT 1; - DECLARE vGeoFk INT; - DECLARE vChildFk INT; - DECLARE vChildName VARCHAR(100); - DECLARE postcodeCur CURSOR FOR - SELECT t.geoFk, pc.`code`, pc.`code` - FROM vn.postCode pc - JOIN vn.town t ON t.id = pc.townFk - JOIN vn.province p ON p.id = t.provinceFk - JOIN tmp.country tc ON tc.id = p.countryFk - ORDER BY t.geoFk, pc.`code`; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - -- Remove existing postCodes from zoneGeo - DELETE zg FROM vn.postCode pc - JOIN vn.town t ON t.id = pc.townFk - JOIN vn.province p ON p.id = t.provinceFk - JOIN tmp.country tc ON tc.id = p.countryFk - JOIN tmp.zoneGeo zg ON zg.id = pc.geoFk; - - -- Reset town geoFk - UPDATE vn.postCode pc - JOIN vn.town t ON t.id = pc.townFk - JOIN vn.province p ON p.id = t.provinceFk - JOIN tmp.country tc ON tc.id = p.countryFk - SET pc.geoFk = NULL - WHERE pc.geoFk IS NOT NULL; - - -- > Postcode cursor start - OPEN postcodeCur; - - postcodeLoop: LOOP - SET vDone = FALSE; - - FETCH postcodeCur INTO vParent, vChildFk, vChildName; - - IF vDone THEN - LEAVE postcodeLoop; - END IF; - - CALL nst.nodeAdd('tmp', 'zoneGeo', vParent, vChildName); - END LOOP; - CLOSE postcodeCur; - -- < Postcode cursor end - - UPDATE postCode p - JOIN tmp.zoneGeo z ON z.name = p.code - SET p.geoFk = z.id - WHERE p.geoFk IS NULL; -END$$ - -DELIMITER ; - diff --git a/db/changes/10031-zone/00-zoneNestProvince.sql b/db/changes/10031-zone/00-zoneNestProvince.sql deleted file mode 100644 index 4467e0c46..000000000 --- a/db/changes/10031-zone/00-zoneNestProvince.sql +++ /dev/null @@ -1,56 +0,0 @@ -DROP procedure IF EXISTS `vn`.`zoneNestProvince`; - -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`zoneNestProvince`() -BEGIN - - DECLARE vDone BOOL; - DECLARE vParent INT DEFAULT 1; - DECLARE vGeoFk INT; - DECLARE vChildFk INT; - DECLARE vChildName VARCHAR(100); - DECLARE provinceCur CURSOR FOR - SELECT c.geoFk, p.id, p.`name` - FROM province p - JOIN tmp.country tc ON tc.id = p.countryFk - JOIN vn.country c ON c.id = tc.id - ORDER BY c.geoFk, p.`name`; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - -- Remove existing provinces from zoneGeo - DELETE zg FROM vn.province p - JOIN tmp.country tc ON tc.id = p.countryFk - JOIN tmp.zoneGeo zg ON zg.id = p.geoFk; - - -- Reset country geoFk - UPDATE vn.province p - JOIN tmp.country tc ON tc.id = p.countryFk - SET p.geoFk = NULL - WHERE p.geoFk IS NOT NULL; - - -- > Province cursor start - OPEN provinceCur; - - provinceLoop: LOOP - SET vDone = FALSE; - - FETCH provinceCur INTO vParent, vChildFk, vChildName; - - IF vDone THEN - LEAVE provinceLoop; - END IF; - - CALL nst.nodeAdd('tmp', 'zoneGeo', vParent, vChildName); - END LOOP; - CLOSE provinceCur; - -- < Province cursor end - - UPDATE province p - JOIN tmp.zoneGeo z ON z.name = p.name - SET p.geoFk = z.id - WHERE p.geoFk IS NULL; -END$$ - -DELIMITER ; - diff --git a/db/changes/10031-zone/00-zoneNestTown.sql b/db/changes/10031-zone/00-zoneNestTown.sql deleted file mode 100644 index 8ca1a426c..000000000 --- a/db/changes/10031-zone/00-zoneNestTown.sql +++ /dev/null @@ -1,59 +0,0 @@ -DROP procedure IF EXISTS `vn`.`zoneNestTown`; - -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`zoneNestTown`() -BEGIN - - DECLARE vDone BOOL; - DECLARE vParent INT DEFAULT 1; - DECLARE vGeoFk INT; - DECLARE vChildFk INT; - DECLARE vChildName VARCHAR(100); - DECLARE townCur CURSOR FOR - SELECT p.geoFk, t.id, t.`name` - FROM vn.town t - JOIN vn.province p ON p.id = t.provinceFk - JOIN tmp.country tc ON tc.id = p.countryFk - ORDER BY p.geoFk, t.`name`; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - -- Remove existing towns from zoneGeo - DELETE zg FROM vn.town t - JOIN vn.province p ON p.id = t.provinceFk - JOIN tmp.country tc ON tc.id = p.countryFk - JOIN tmp.zoneGeo zg ON zg.id = t.geoFk; - - -- Reset town geoFk - UPDATE vn.town t - JOIN vn.province p ON p.id = t.provinceFk - JOIN tmp.country tc ON tc.id = p.countryFk - SET t.geoFk = NULL - WHERE t.geoFk IS NOT NULL; - - -- > Town cursor start - OPEN townCur; - - townLoop: LOOP - SET vDone = FALSE; - - FETCH townCur INTO vParent, vChildFk, vChildName; - - IF vDone THEN - LEAVE townLoop; - END IF; - - CALL nst.nodeAdd('tmp', 'zoneGeo', vParent, vChildName); - END LOOP; - CLOSE townCur; - -- < Town cursor end - - UPDATE town t - JOIN tmp.zoneGeo z ON z.name = t.name - LEFT JOIN province p ON p.geoFk = z.id - SET t.geoFk = z.id - WHERE p.geoFk IS NULL; -END$$ - -DELIMITER ; - diff --git a/db/changes/10031-zone/01-ticketGetVolume.sql b/db/changes/10031-zone/01-ticketGetVolume.sql deleted file mode 100644 index e8443fb8e..000000000 --- a/db/changes/10031-zone/01-ticketGetVolume.sql +++ /dev/null @@ -1,19 +0,0 @@ - -CREATE - OR REPLACE ALGORITHM = UNDEFINED - DEFINER = `root`@`%` - SQL SECURITY DEFINER -VIEW `vn`.`ticketGetVolume` AS - SELECT - `s`.`ticketFk` AS `ticketFk`, - `t`.`routeFk` AS `routeFk`, - `s`.`id` AS `saleFk`, - `t`.`shipped` AS `Fecha`, - (((`s`.`quantity` * `r`.`cm3`) * `i`.`compression`) / 1000000) AS `volume` - FROM - (((`vn`.`sale` `s` - JOIN `vn`.`item` `i` ON ((`i`.`id` = `s`.`itemFk`))) - JOIN `vn`.`ticket` `t` ON ((`t`.`id` = `s`.`ticketFk`))) - JOIN `bi`.`rotacion` `r` ON (((`r`.`Id_Article` = `s`.`itemFk`) - AND (`r`.`warehouse_id` = `t`.`warehouseFk`)))); - diff --git a/db/changes/10031-zone/02-ticketTotalVolume.sql b/db/changes/10031-zone/02-ticketTotalVolume.sql deleted file mode 100644 index ff4b5c080..000000000 --- a/db/changes/10031-zone/02-ticketTotalVolume.sql +++ /dev/null @@ -1,30 +0,0 @@ - -DROP function IF EXISTS `vn`.`ticketTotalVolume`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` FUNCTION `ticketTotalVolume`(vTicketId INT) RETURNS decimal(10,3) - READS SQL DATA -BEGIN - -- Devuelte el volumen total del ticket sumado - -- DECLARE vWarehouseId INTEGER; - -- DECLARE vShippedDate DATE; - DECLARE vVolume DECIMAL(10,3); - /* - SELECT warehouseFk, shipped INTO vWarehouseId,vShippedDate FROM vn.ticket WHERE id = vTicketId; - - SELECT IFNULL(SUM(s.quantity * i.compression * r.cm3)/1000000,0) INTO vVolume - FROM sale s - JOIN vn.item i ON i.id = s.itemFk - JOIN bi.rotacion r on r.Id_Article = s.itemFk AND r.warehouse_id = vWarehouseId - WHERE s.ticketFk = vTicketId; - */ - SELECT sum(volume) INTO vVolume - FROM ticketGetVolume - WHERE ticketFk = vTicketId; - RETURN vVolume; - -END$$ - -DELIMITER ; - diff --git a/db/changes/10032-webZone/00-available_calc.sql b/db/changes/10032-webZone/00-available_calc.sql deleted file mode 100644 index 0a2429cdc..000000000 --- a/db/changes/10032-webZone/00-available_calc.sql +++ /dev/null @@ -1,61 +0,0 @@ - -DROP procedure IF EXISTS `vn`.`available_calc`; -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`available_calc`( - vDate DATE, - vAddress INT, - vAgencyMode INT) -BEGIN -/** - * Calculates the available for all available stores - * according to the given parameters. - * - * @param vDate The delivery date - * @param vAddress The delivery address id - * @param vAgencyMode The shipping agency - * @return tmp.availableCalc(calcFk) The available cache ids - */ - DECLARE vCalcFk INT; - DECLARE vShipment DATE; - DECLARE vWarehouse INT; - DECLARE vDone BOOL; - - DECLARE cWarehouses CURSOR FOR - SELECT warehouseFk, shipped FROM tmp.zoneGetShipped; - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; - - -- Establecemos los almacenes y las fechas que van a entrar al disponible - - CALL vn.zoneGetShippedWarehouse(vDate, vAddress, vAgencyMode); - - DROP TEMPORARY TABLE IF EXISTS tmp.availableCalc; - CREATE TEMPORARY TABLE tmp.availableCalc( - calcFk INT UNSIGNED, - PRIMARY KEY (calcFk) - ) - ENGINE = MEMORY; - - OPEN cWarehouses; - - l: LOOP - SET vDone = FALSE; - FETCH cWarehouses INTO vWarehouse, vShipment; - - IF vDone THEN - LEAVE l; - END IF; - - CALL `cache`.available_refresh(vCalcFk, FALSE, vWarehouse, vShipment); - - INSERT IGNORE INTO tmp.availableCalc - SET calcFk = vCalcFk; - END LOOP; - - CLOSE cWarehouses; - DROP TEMPORARY TABLE tmp.zoneGetShipped; -END$$ - -DELIMITER ; - diff --git a/db/changes/10032-webZone/00-catalog_calcFromItem.sql b/db/changes/10032-webZone/00-catalog_calcFromItem.sql deleted file mode 100644 index 03823d65c..000000000 --- a/db/changes/10032-webZone/00-catalog_calcFromItem.sql +++ /dev/null @@ -1,28 +0,0 @@ - -DROP procedure IF EXISTS `vn`.`catalog_calcFromItem`; -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`catalog_calcFromItem`( - vLanded DATE, - vAddressFk INT, - vAgencyModeFk INT, - vItemFk INT) -BEGIN -/** - * Calculates available and price for a single item. - * - * @param vItemFk The item id - * @return tmp.ticketCalculateItem - * @return tmp.ticketComponentPrice - * @return tmp.ticketComponent - * @return tmp.ticketLot - * @return tmp.zoneGetShipped - */ - DROP TEMPORARY TABLE IF EXISTS tmp.item; - CREATE TEMPORARY TABLE tmp.item - ENGINE = MEMORY - SELECT vItemFk itemFk; - - CALL ticketCalculate(vLanded, vAddressFk, vAgencyModeFk); - DROP TEMPORARY TABLE tmp.item; -END$$ -DELIMITER ; diff --git a/db/changes/10032-webZone/00-catalog_calcFromMyAddress.sql b/db/changes/10032-webZone/00-catalog_calcFromMyAddress.sql deleted file mode 100644 index ee2996bd6..000000000 --- a/db/changes/10032-webZone/00-catalog_calcFromMyAddress.sql +++ /dev/null @@ -1,41 +0,0 @@ - -DROP procedure IF EXISTS `hedera`.`catalog_calcFromMyAddress`; -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE `hedera`.`catalog_calcFromMyAddress`(vDelivery DATE, vAddress INT) -BEGIN -/** - * Gets the available items list. - * - * @param vDelivery Delivery date - * @param vAddress Address id - * @return tmp.ticketCalculateItem - * @return tmp.ticketComponentPrice - * @return tmp.ticketComponent - * @return tmp.ticketLot - * @return tmp.zoneGetShipped - */ - DECLARE vAgencyMode INT; - - SELECT a.agencyModeFk - INTO vAgencyMode - FROM myClient c - JOIN vn.address a ON a.clientFk = c.id - WHERE a.id = vAddress; - - CALL vn.available_calc(vDelivery, vAddress, vAgencyMode); - - DROP TEMPORARY TABLE IF EXISTS tmp.item; - CREATE TEMPORARY TABLE tmp.item - (INDEX (itemFk)) - ENGINE = MEMORY - SELECT c.item_id itemFk - FROM `cache`.available c - JOIN tmp.availableCalc a ON a.calcFk = c.calc_id - WHERE c.available > 0 - GROUP BY c.item_id; - - CALL vn.ticketCalculate(vDelivery, vAddress, vAgencyMode); - - DROP TEMPORARY TABLE tmp.item; -END$$ -DELIMITER ; diff --git a/db/changes/10032-webZone/00-deprecate.sql b/db/changes/10032-webZone/00-deprecate.sql deleted file mode 100644 index 373cb7ccb..000000000 --- a/db/changes/10032-webZone/00-deprecate.sql +++ /dev/null @@ -1,398 +0,0 @@ - -USE `vn2008`; -DROP procedure IF EXISTS `vn2008`.`bionic_available_`; - -DELIMITER $$ -USE `vn2008`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `__bionic_available_`( - vDate DATE, - vAddress INT, - vAgency INT) -BEGIN -/** - * Calcula el disponible para un conjunto de almacenes y fechas - * devueltos por el procedimiento agencyHourGetShipped() - * - * @deprecated Use vn.available_calc() - * @table t_bionic_available Tabla con los ids de cache - */ - DECLARE vAvailableCalc INT; - DECLARE vShipment DATE; - DECLARE vAgencyId INT; - DECLARE vWh INT; - DECLARE vDone BOOL; - DECLARE cTravelTree CURSOR FOR - SELECT warehouseFk, shipped FROM tmp.agencyHourGetShipped; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - -- Establecemos los almacenes y las fechas que van a entrar al disponible - - SELECT agency_id INTO vAgencyId - FROM Agencias WHERE Id_Agencia = vAgency; - - CALL vn.agencyHourGetShipped (vDate, vAddress, vAgencyId); - - DROP TEMPORARY TABLE IF EXISTS t_bionic_available; - CREATE TEMPORARY TABLE t_bionic_available( - calc_id INT UNSIGNED, - PRIMARY KEY (calc_id) - ) - ENGINE = MEMORY; - - OPEN cTravelTree; - l: LOOP - SET vDone = FALSE; - FETCH cTravelTree INTO vWh, vShipment; - - IF vDone THEN - LEAVE l; - END IF; - - CALL `cache`.available_refresh (vAvailableCalc, FALSE, vWh, vShipment); - - INSERT IGNORE INTO t_bionic_available - SET calc_id = vAvailableCalc; - END LOOP; - - CLOSE cTravelTree; - DROP TEMPORARY TABLE tmp.agencyHourGetShipped; -END$$ - -DELIMITER ; -; - - -USE `hedera`; -DROP procedure IF EXISTS `hedera`.`bionic_from_item`; - -DELIMITER $$ -USE `hedera`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `__bionic_from_item`(vItem INT) -BEGIN - DECLARE vDate DATE; - DECLARE vAddress INT; - DECLARE vAgencyMode INT; - - SELECT sent, addressFk, agencyModeFk - INTO vDate, vAddress, vAgencyMode - FROM myBasket; - - CALL vn2008.bionic_from_item(vDate, vAddress, vAgencyMode, vItem); -END$$ - -DELIMITER ; -; - - -USE `vn2008`; -DROP procedure IF EXISTS `vn2008`.`bionic_from_order`; - -DELIMITER $$ -USE `vn2008`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `__bionic_from_order`( - v_date DATE, -- fecha de recepcion de mercancia - v_consigna INT, - v_agencia INT, - v_order INT) -BEGIN - DROP TEMPORARY TABLE IF EXISTS tmp.bionic_calc; - CREATE TEMPORARY TABLE tmp.bionic_calc - (PRIMARY KEY (item_id)) - ENGINE = MEMORY - SELECT item_id FROM order_row - WHERE order_id = v_order GROUP BY item_id; - - CALL bionic_calc (v_date, v_consigna, v_agencia); - DROP TEMPORARY TABLE tmp.bionic_calc; -END$$ - -DELIMITER ; -; - - -USE `hedera`; -DROP procedure IF EXISTS `hedera`.`bionicCalcWithDate`; - -DELIMITER $$ -USE `hedera`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `__bionicCalcWithDate`(vDate DATE) -BEGIN - DECLARE vMyAddressFk INTEGER; - DECLARE vMyAgencyModeFk INTEGER; - - SELECT id, agencyModeFk INTO vMyAddressFk, vMyAgencyModeFk - FROM myAddress - WHERE isDefaultAddress; - - CALL vn2008.bionic_calc(vDate, vMyAddressFk, vMyAgencyModeFk); -END$$ - -DELIMITER ; -; - - -USE `hedera`; -DROP procedure IF EXISTS `hedera`.`bionic_calc`; - -DELIMITER $$ -USE `hedera`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `__bionic_calc`() -BEGIN - DECLARE vDate DATE; - DECLARE vAddress INT; - DECLARE vAgencyMode INT; - - SELECT sent, addressFk, agencyModeFk - INTO vDate, vAddress, vAgencyMode - FROM myBasket; - - CALL vn2008.bionic_calc(vDate, vAddress, vAgencyMode); - - IF account.myUserGetName() = 'visitor' - THEN - DROP TEMPORARY TABLE tmp.bionic_component; - UPDATE tmp.bionic_item SET price = NULL; - END IF; -END$$ - -DELIMITER ; -; - - -USE `hedera`; -DROP procedure IF EXISTS `hedera`.`itemGetAvailableOrder`; - -DELIMITER $$ -USE `hedera`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `__itemGetAvailableOrder`(vOrder INT) -BEGIN -/** - * Gets the available items list with an order params. - * - * @table tmp.itemAvailable - */ - DECLARE vDelivery DATE; - DECLARE vAddress INT; - DECLARE vAgency INT; - - SELECT landed, addressFk, agencyModeFk - INTO vDelivery, vAddress, vAgency - FROM myOrder - WHERE id = vOrder; - - CALL vn2008.bionic_available_ (vDelivery, vAddress, vAgency); - - DROP TEMPORARY TABLE IF EXISTS tmp.itemAvailable; - CREATE TEMPORARY TABLE tmp.itemAvailable - (INDEX (id)) - ENGINE = MEMORY - SELECT c.item_id id - FROM cache.available c - JOIN vn2008.t_bionic_available a ON c.calc_id = a.calc_id - WHERE c.available > 0 - GROUP BY c.item_id; - - DROP TEMPORARY TABLE vn2008.t_bionic_available; - -END$$ - -DELIMITER ; -; - - -USE `hedera`; -DROP procedure IF EXISTS `hedera`.`itemGetAvailable`; - -DELIMITER $$ -USE `hedera`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `__itemGetAvailable`() -BEGIN -/** - * Gets the available items list. - * - * @table tmp.itemAvailable - */ - DECLARE vDelivery DATE; - DECLARE vAddress INT; - DECLARE vAgency INT; - - SELECT sent, addressFk, agencyModeFk - INTO vDelivery, vAddress, vAgency - FROM myBasket; - - CALL vn2008.bionic_available_ (vDelivery, vAddress, vAgency); - - DROP TEMPORARY TABLE IF EXISTS tmp.itemAvailable; - CREATE TEMPORARY TABLE tmp.itemAvailable - (INDEX (id)) - ENGINE = MEMORY - SELECT c.item_id id - FROM cache.available c - JOIN vn2008.t_bionic_available a ON c.calc_id = a.calc_id - WHERE c.available > 0 - GROUP BY c.item_id; - - DROP TEMPORARY TABLE vn2008.t_bionic_available; -END$$ - -DELIMITER ; -; - - -USE `hedera`; -DROP procedure IF EXISTS `hedera`.`myItemGetAvailableFromDate`; - -DELIMITER $$ -USE `hedera`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `__myItemGetAvailableFromDate`(vDelivery DATE) -BEGIN -/** - * Gets the available items list. - * - * @deprecated Use item_calcCatalogFromMyAddress() - * @param vDelivery Delivery date - */ - DECLARE vAddress INT; - DECLARE vAgencyMode INT; - - SELECT a.agencyModeFk, a.id - INTO vAgencyMode, vAddress - FROM myClient c - JOIN vn.address a ON a.id = c.defaultAddressFk; - - CALL vn2008.bionic_available_ (vDelivery, vAddress, vAgencyMode); - - DROP TEMPORARY TABLE IF EXISTS tmp.item; - CREATE TEMPORARY TABLE tmp.item - (INDEX (itemFk)) - ENGINE = MEMORY - SELECT c.item_id itemFk - FROM cache.available c - JOIN vn2008.t_bionic_available a ON c.calc_id = a.calc_id - WHERE c.available > 0 - GROUP BY c.item_id; - - CALL vn.ticketCalculate(vDelivery, vAddress, vAgencyMode); --- ------------------- - /*SELECT b.itemFk, b.item, b.available, b.price - FROM tmp.ticketCalculateItem b - JOIN vn.item i ON i.id = b.itemFk - WHERE b.available > 0 - ORDER BY i.relevancy DESC, i.name, i.size; - - select * from tmp.ticketComponentPrice;*/ --- ------------------- - DROP TEMPORARY TABLE vn2008.t_bionic_available; -END$$ - -DELIMITER ; -; - - -USE `hedera`; -DROP procedure IF EXISTS `hedera`.`myItemGetAvailable`; - -DELIMITER $$ -USE `hedera`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `__myItemGetAvailable`(vDelivery DATE, vAddress INT) -BEGIN -/** - * Gets the available items list. - * - * @deprecated Use item_calcCatalogFromMyAddress() - * @param vDelivery Delivery date - * @param vAddress Id Address - */ - DECLARE vAgencyMode INT; - - SELECT a.agencyModeFk - INTO vAgencyMode - FROM myClient c - JOIN vn.address a ON a.clientFk = c.id - WHERE a.id = vAddress; - - CALL vn2008.bionic_available_ (vDelivery, vAddress, vAgencyMode); - - DROP TEMPORARY TABLE IF EXISTS tmp.item; - CREATE TEMPORARY TABLE tmp.item - (INDEX (itemFk)) - ENGINE = MEMORY - SELECT c.item_id itemFk - FROM cache.available c - JOIN vn2008.t_bionic_available a ON c.calc_id = a.calc_id - WHERE c.available > 0 - GROUP BY c.item_id; - - CALL vn.ticketCalculate(vDelivery, vAddress, vAgencyMode); --- ------------------- - /*SELECT b.itemFk, b.item, b.available, b.price - FROM tmp.ticketCalculateItem b - JOIN vn.item i ON i.id = b.itemFk - WHERE b.available > 0 - ORDER BY i.relevancy DESC, i.name, i.size; - - select * from tmp.ticketComponentPrice;*/ --- ------------------- - DROP TEMPORARY TABLE vn2008.t_bionic_available; -END$$ - -DELIMITER ; -; - - -USE `hedera`; -DROP procedure IF EXISTS `hedera`.`myOrderAddItem`; - -DELIMITER $$ -USE `hedera`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `__myOrderAddItem`( - vSelf INT, - vWarehouse INT, - vItem INT, - vAmount INT) -BEGIN -/** - * @deprecated Use myOrder_addItem() - */ - CALL myOrder_addItem(vSelf, vWarehouse, vItem, vAmount); -END$$ - -DELIMITER ; -; - - -USE `hedera`; -DROP procedure IF EXISTS `hedera`.`myOrderConfirm`; - -DELIMITER $$ -USE `hedera`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `__myOrderConfirm`(vSelf INT) -BEGIN -/** - * @deprecated Use myOrder_confirm() - */ - CALL myOrder_confirm(vSelf); -END$$ - -DELIMITER ; -; - - -USE `hedera`; -DROP procedure IF EXISTS `hedera`.`myOrderNewFromDate`; - -DELIMITER $$ -USE `hedera`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `__myOrderNewFromDate`( - OUT vSelf INT, - vLandingDate DATE) -BEGIN -/** - * @deprecated Use myOrder_newWithDate() - */ - CALL myOrder_newWithDate(vSelf, vLandingDate); -END$$ - -DELIMITER ; -; diff --git a/db/changes/10032-webZone/00-myBasket_calcCatalogFromItem.sql b/db/changes/10032-webZone/00-myBasket_calcCatalogFromItem.sql deleted file mode 100644 index edde8f389..000000000 --- a/db/changes/10032-webZone/00-myBasket_calcCatalogFromItem.sql +++ /dev/null @@ -1,19 +0,0 @@ - -DROP procedure IF EXISTS `hedera`.`myBasket_calcCatalogFromItem`; -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE `hedera`.`myBasket_calcCatalogFromItem`(vItem INT) -BEGIN -/** - * Gets the availability and prices for the given item - * using current user basket parameters. - * - * @table tmp.item(itemFk) - * @return tmp.ticketCalculateItem - * @return tmp.ticketComponentPrice - * @return tmp.ticketComponent - * @return tmp.ticketLot - * @return tmp.zoneGetShipped - */ - CALL order_calcCatalogFromItem(myBasket_getId(), vItem); -END$$ -DELIMITER ; diff --git a/db/changes/10032-webZone/00-myBasket_calcCatalogFull.sql b/db/changes/10032-webZone/00-myBasket_calcCatalogFull.sql deleted file mode 100644 index 8e182faa9..000000000 --- a/db/changes/10032-webZone/00-myBasket_calcCatalogFull.sql +++ /dev/null @@ -1,19 +0,0 @@ - -DROP procedure IF EXISTS `hedera`.`myBasket_calcCatalogFull`; -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE `hedera`.`myBasket_calcCatalogFull`() -BEGIN -/** - * Gets the availability and prices for the given items - * using current user basket parameters. - * - * @table tmp.item(itemFk) - * @return tmp.ticketCalculateItem - * @return tmp.ticketComponentPrice - * @return tmp.ticketComponent - * @return tmp.ticketLot - * @return tmp.zoneGetShipped - */ - CALL order_calcCatalogFull(myBasket_getId()); -END$$ -DELIMITER ; diff --git a/db/changes/10032-webZone/00-myBasket_getAvailable.sql b/db/changes/10032-webZone/00-myBasket_getAvailable.sql deleted file mode 100644 index 246bbb567..000000000 --- a/db/changes/10032-webZone/00-myBasket_getAvailable.sql +++ /dev/null @@ -1,14 +0,0 @@ - -DROP procedure IF EXISTS `hedera`.`myBasket_getAvailable`; -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE `hedera`.`myBasket_getAvailable`() -BEGIN -/** - * Gets the available items list. - * - * @table tmp.itemAvailable - */ - CALL order_getAvailable(myBasket_getId()); -END$$ -DELIMITER ; - diff --git a/db/changes/10032-webZone/00-myOrder_getAvailable.sql b/db/changes/10032-webZone/00-myOrder_getAvailable.sql deleted file mode 100644 index 01ceb0228..000000000 --- a/db/changes/10032-webZone/00-myOrder_getAvailable.sql +++ /dev/null @@ -1,22 +0,0 @@ - -DROP procedure IF EXISTS `hedera`.`myOrder_getAvailable`; -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE `hedera`.`myOrder_getAvailable`(vSelf INT) -BEGIN -/** - * Gets the available items list. - * - * @param vSelf The order id - * @table tmp.itemAvailable - */ - DECLARE isMine BOOL; - - SELECT COUNT(*) INTO isMine - FROM myOrder - WHERE id = vSelf; - - IF isMine THEN - CALL order_getAvailable(vSelf); - END IF; -END$$ -DELIMITER ; diff --git a/db/changes/10032-webZone/00-order_addItem.sql b/db/changes/10032-webZone/00-order_addItem.sql deleted file mode 100644 index 90a4efaad..000000000 --- a/db/changes/10032-webZone/00-order_addItem.sql +++ /dev/null @@ -1,105 +0,0 @@ - -DROP procedure IF EXISTS `hedera`.`order_addItem`; -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE `hedera`.`order_addItem`( - vSelf INT, - vWarehouse INT, - vItem INT, - vAmount INT) -BEGIN -/** - * Adds an item to the order, checking availability and grouping. - * - * @param vSelf The order id - * @param vWarehouse The warehouse id - * @param vItem The item id - * @param vAmount The amount to add - */ - DECLARE vRow INT; - DECLARE vAdd INT; - DECLARE vAvailable INT; - DECLARE vDone BOOL; - DECLARE vGrouping INT; - DECLARE vRate INT; - DECLARE vShipment DATE; - DECLARE vPrice DECIMAL(10,2); - DECLARE cur CURSOR FOR - SELECT `grouping`, price, rate - FROM tmp.ticketComponentPrice - WHERE warehouseFk = vWarehouse - AND itemFk = vItem - ORDER BY `grouping` DESC; - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - CALL order_calcCatalogFromItem(vSelf, vItem); - START TRANSACTION; - - SELECT shipped INTO vShipment - FROM tmp.zoneGetShipped - WHERE warehouseFk = vWarehouse; - - SELECT available INTO vAvailable - FROM tmp.ticketLot - WHERE warehouseFk = vWarehouse - AND itemFk = vItem; - - IF vAmount > IFNULL(vAvailable, 0) THEN - CALL util.throw ('ORDER_ROW_UNAVAILABLE'); - END IF; - - OPEN cur; - - l: LOOP - SET vDone = FALSE; - FETCH cur INTO vGrouping, vPrice, vRate; - - IF vDone THEN - LEAVE l; - END IF; - - SET vAdd = vAmount - MOD(vAmount, vGrouping); - SET vAmount = vAmount - vAdd; - - IF vAdd = 0 THEN - ITERATE l; - END IF; - - INSERT INTO orderRow SET - orderFk = vSelf, - itemFk = vItem, - warehouseFk = vWarehouse, - shipment = vShipment, - rate = vRate, - amount = vAdd, - price = vPrice; - - SET vRow = LAST_INSERT_ID(); - - INSERT INTO orderRowComponent (rowFk, componentFk, price) - SELECT vRow, c.componentFk, c.cost - FROM tmp.ticketComponent c - JOIN vn.component t - ON t.id = c.componentFk - AND (t.classRate IS NULL OR t.classRate = vRate) - WHERE c.warehouseFk = vWarehouse - AND c.itemFk = vItem; - END LOOP; - - CLOSE cur; - - IF vAmount > 0 THEN - CALL util.throw ('AMOUNT_NOT_MATCH_GROUPING'); - END IF; - - COMMIT; - CALL vn.ticketCalculatePurge; -END$$ -DELIMITER ; diff --git a/db/changes/10032-webZone/00-order_calcCatalog.sql b/db/changes/10032-webZone/00-order_calcCatalog.sql deleted file mode 100644 index 2a50d747b..000000000 --- a/db/changes/10032-webZone/00-order_calcCatalog.sql +++ /dev/null @@ -1,36 +0,0 @@ - -DROP procedure IF EXISTS `hedera`.`order_calcCatalog`; -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE `hedera`.`order_calcCatalog`(vSelf INT) -BEGIN -/** - * Gets the availability and prices for order items. - * - * @param vSelf The order id - * @return tmp.ticketCalculateItem - * @return tmp.ticketComponentPrice - * @return tmp.ticketComponent - * @return tmp.ticketLot - */ - DECLARE vDate DATE; - DECLARE vAddress INT; - DECLARE vAgencyMode INT; - - SELECT date_send, address_id, agency_id - INTO vDate, vAddress, vAgencyMode - FROM `order` - WHERE id = vSelf; - - DROP TEMPORARY TABLE IF EXISTS tmp.item; - CREATE TEMPORARY TABLE tmp.item - (PRIMARY KEY (itemFk)) - ENGINE = MEMORY - SELECT itemFk FROM orderRow - WHERE orderFk = vSelf - GROUP BY itemFk; - - CALL vn.ticketCalculate(vDate, vAddress, vAgencyMode); - - DROP TEMPORARY TABLE tmp.item; -END$$ -DELIMITER ; diff --git a/db/changes/10032-webZone/00-order_calcCatalogFromItem.sql b/db/changes/10032-webZone/00-order_calcCatalogFromItem.sql deleted file mode 100644 index 8f4ca6012..000000000 --- a/db/changes/10032-webZone/00-order_calcCatalogFromItem.sql +++ /dev/null @@ -1,30 +0,0 @@ - -DROP procedure IF EXISTS `hedera`.`order_calcCatalogFromItem`; -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE `hedera`.`order_calcCatalogFromItem`(vSelf INT, vItem INT) -BEGIN -/** - * Gets the availability and prices for the given item - * using the order parameters. - * - * @param vSelf The order id - * @table tmp.item(itemFk) - * @return tmp.ticketCalculateItem - * @return tmp.ticketComponentPrice - * @return tmp.ticketComponent - * @return tmp.ticketLot - * @return tmp.zoneGetShipped - */ - DECLARE vDate DATE; - DECLARE vAddress INT; - DECLARE vAgencyMode INT; - - SELECT date_send, address_id, agency_id - INTO vDate, vAddress, vAgencyMode - FROM `order` - WHERE id = vSelf; - - CALL vn.catalog_calcFromItem(vDate, vAddress, vAgencyMode, vItem); -END$$ -DELIMITER ; - diff --git a/db/changes/10032-webZone/00-order_calcCatalogFull.sql b/db/changes/10032-webZone/00-order_calcCatalogFull.sql deleted file mode 100644 index 7d57be472..000000000 --- a/db/changes/10032-webZone/00-order_calcCatalogFull.sql +++ /dev/null @@ -1,35 +0,0 @@ - -DROP procedure IF EXISTS `hedera`.`order_calcCatalogFull`; -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE `hedera`.`order_calcCatalogFull`(vSelf INT) -BEGIN -/** - * Gets the availability and prices for the given items - * using the order parameters. - * - * @param vSelf The order id - * @table tmp.item(itemFk) - * @return tmp.ticketCalculateItem - * @return tmp.ticketComponentPrice - * @return tmp.ticketComponent - * @return tmp.ticketLot - * @return tmp.zoneGetShipped - */ - DECLARE vDate DATE; - DECLARE vAddress INT; - DECLARE vAgencyMode INT; - - SELECT date_send, address_id, agency_id - INTO vDate, vAddress, vAgencyMode - FROM `order` - WHERE id = vSelf; - - CALL vn.ticketCalculate(vDate, vAddress, vAgencyMode); - - IF account.myUserGetName() = 'visitor' - THEN - DROP TEMPORARY TABLE tmp.ticketComponent; - UPDATE tmp.ticketCalculateItem SET price = NULL; - END IF; -END$$ -DELIMITER ; diff --git a/db/changes/10032-webZone/00-order_getAvailable.sql b/db/changes/10032-webZone/00-order_getAvailable.sql deleted file mode 100644 index 1182b4840..000000000 --- a/db/changes/10032-webZone/00-order_getAvailable.sql +++ /dev/null @@ -1,34 +0,0 @@ -DROP procedure IF EXISTS `hedera`.`order_getAvailable`; -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE `hedera`.`order_getAvailable`(vSelf INT) -BEGIN -/** - * Gets the available items list. - * - * @param vSelf The order id - * @table tmp.itemAvailable - */ - DECLARE vDelivery DATE; - DECLARE vAddress INT; - DECLARE vAgencyMode INT; - - SELECT date_send, address_id, agency_id - INTO vDelivery, vAddress, vAgencyMode - FROM `order` - WHERE id = vSelf; - - CALL vn.available_calc(vDelivery, vAddress, vAgencyMode); - - DROP TEMPORARY TABLE IF EXISTS tmp.itemAvailable; - CREATE TEMPORARY TABLE tmp.itemAvailable - (INDEX (id)) - ENGINE = MEMORY - SELECT DISTINCT a.item_id id - FROM `cache`.available a - JOIN tmp.availableCalc c ON c.calcFk = a.calc_id - WHERE a.available > 0; - - DROP TEMPORARY TABLE tmp.availableCalc; -END$$ - -DELIMITER ; \ No newline at end of file diff --git a/db/changes/10032-webZone/00-order_update.sql b/db/changes/10032-webZone/00-order_update.sql deleted file mode 100644 index 23e4045e5..000000000 --- a/db/changes/10032-webZone/00-order_update.sql +++ /dev/null @@ -1,71 +0,0 @@ - -DROP procedure IF EXISTS `hedera`.`order_update`; -DELIMITER $$ -CREATE DEFINER=`root`@`%` PROCEDURE `hedera`.`order_update`(vSelf INT) -proc: BEGIN -/** - * Actualiza las líneas de un pedido. - * - * @param vSelf Id del pedido - */ - DECLARE vDate DATE; - DECLARE vAddress INT; - DECLARE vAgencyMode INT; - DECLARE vNRows INT; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - START TRANSACTION; - - SELECT COUNT(*) INTO vNRows - FROM orderRow WHERE orderFk = vSelf; - - IF vNRows > 0 - THEN - CALL order_calcCatalog(vSelf); - - DELETE c - FROM orderRow r - JOIN orderRowComponent c ON c.rowFk = r.id - WHERE r.orderFk = vSelf; - - UPDATE orderRow r - LEFT JOIN tmp.ticketComponentPrice p - ON p.warehouseFk = r.warehouseFk - AND p.itemFk = r.itemFk - AND p.rate = r.rate - LEFT JOIN tmp.zoneGetShipped t - ON t.warehouseFk = r.warehouseFk - SET - r.price = p.price, - r.amount = IF(p.itemFk IS NOT NULL, - r.amount + IF(@m := MOD(r.amount, p.`grouping`), p.`grouping` - @m, 0), 0), - r.shipment = t.shipped - WHERE r.orderFk = vSelf; - - INSERT INTO orderRowComponent(rowFk, componentFk, price) - SELECT r.id, c.componentFk, c.cost - FROM orderRow r - JOIN tmp.ticketComponent c - ON c.warehouseFk = r.warehouseFk - AND c.itemFk = r.itemFk - JOIN vn.component t - ON t.id = c.componentFk - AND (t.classRate IS NULL OR t.classRate = r.rate) - WHERE r.orderFk = vSelf; - - CALL vn.ticketCalculatePurge; - END IF; - - UPDATE `order` SET date_make = NOW() - WHERE id = vSelf; - - COMMIT; -END$$ - -DELIMITER ; - diff --git a/db/changes/10032-webZone/98-rename.sql b/db/changes/10032-webZone/98-rename.sql deleted file mode 100644 index d0799b6e6..000000000 --- a/db/changes/10032-webZone/98-rename.sql +++ /dev/null @@ -1 +0,0 @@ -RENAME TABLE hedera.myOrderMyTicket TO hedera.myOrderTicket; \ No newline at end of file diff --git a/db/changes/10032-webZone/99-privs.sql b/db/changes/10032-webZone/99-privs.sql deleted file mode 100644 index 477a7f0d4..000000000 --- a/db/changes/10032-webZone/99-privs.sql +++ /dev/null @@ -1,10 +0,0 @@ -GRANT EXECUTE ON PROCEDURE vn.zoneGetAgency TO `account`@`%`; -GRANT EXECUTE ON PROCEDURE hedera.myBasket_calcCatalogFromItem TO `guest`@`%`; -GRANT EXECUTE ON PROCEDURE hedera.myBasket_calcCatalogFull TO `guest`@`%`; -GRANT EXECUTE ON PROCEDURE hedera.myBasket_getAvailable TO `guest`@`%`; -GRANT EXECUTE ON PROCEDURE hedera.myOrder_getAvailable TO `guest`@`%`; -GRANT EXECUTE ON PROCEDURE hedera.catalog_calcFromMyAddress TO account@'%'; -REVOKE SELECT ON TABLE hedera.myOrderMyTicket FROM account@'%'; -GRANT SELECT ON TABLE hedera.myOrderTicket TO account@'%'; - -CALL account.privSync; diff --git a/db/changes/10060-summer/01-ticketGetProblems.sql b/db/changes/10060-summer/01-ticketGetProblems.sql new file mode 100644 index 000000000..9bc8b5e2d --- /dev/null +++ b/db/changes/10060-summer/01-ticketGetProblems.sql @@ -0,0 +1,139 @@ +DROP procedure IF EXISTS `vn`.`ticketGetProblems`; + +DELIMITER $$ +CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`ticketGetProblems`() +BEGIN + + DECLARE vWarehouse INT; + DECLARE vDate DATE; + DECLARE vAvailableCache INT; + DECLARE vVisibleCache INT; + DECLARE vDone INT DEFAULT 0; + + DECLARE vCursor CURSOR FOR + SELECT DISTINCT tt.warehouseFk, date(tt.shipped) + FROM tmp.ticketGetProblems tt + WHERE DATE(tt.shipped) BETWEEN CURDATE() + AND TIMESTAMPADD(DAY, 1.9, CURDATE()); + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = 1; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketProblems; + CREATE TEMPORARY TABLE tmp.ticketProblems ( + ticketFk INT(11) PRIMARY KEY, + isFreezed INTEGER(1) DEFAULT 0, + risk DECIMAL(10,2) DEFAULT 0, + hasTicketRequest INTEGER(1) DEFAULT 0, + isAvailable INTEGER(1) DEFAULT 1 + ) ENGINE = MEMORY; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketList; + CREATE TEMPORARY TABLE tmp.ticketList + (PRIMARY KEY (ticketFk)) + ENGINE = MEMORY + SELECT tp.ticketFk, c.id clientFk + FROM tmp.ticketGetProblems tp + JOIN vn.client c ON c.id = tp.clientFk; + + + INSERT INTO tmp.ticketProblems(ticketFk, isFreezed) + SELECT DISTINCT tl.ticketFk, 1 + FROM tmp.ticketList tl + JOIN vn.client c ON c.id = tl.clientFk + WHERE c.isFreezed; + + DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt; + CREATE TEMPORARY TABLE tmp.clientGetDebt + (PRIMARY KEY (clientFk)) + ENGINE = MEMORY + SELECT DISTINCT clientFk + FROM tmp.ticketList; + + CALL clientGetDebt(CURDATE()); + + + INSERT INTO tmp.ticketProblems(ticketFk, risk) + SELECT DISTINCT tl.ticketFk, r.risk + FROM tmp.ticketList tl + JOIN vn.ticket t ON t.id = tl.ticketFk + JOIN vn.agencyMode a ON t.agencyModeFk = a.id + JOIN tmp.risk r ON r.clientFk = t.clientFk + JOIN vn.client c ON c.id = t.clientFk + WHERE r.risk > c.credit + 10 + AND a.deliveryMethodFk != 3 + ON DUPLICATE KEY UPDATE + risk = r.risk; + + INSERT INTO tmp.ticketProblems(ticketFk, hasTicketRequest) + SELECT DISTINCT tl.ticketFk, 1 + FROM tmp.ticketList tl + JOIN vn.ticketRequest tr ON tr.ticketFk = tl.ticketFk + WHERE tr.isOK IS NULL + ON DUPLICATE KEY UPDATE + hasTicketRequest = 1; + + OPEN vCursor; + + WHILE NOT vDone + DO + FETCH vCursor INTO vWarehouse, vDate; + + CALL cache.visible_refresh(vVisibleCache, FALSE, vWarehouse); + CALL cache.available_refresh(vAvailableCache, FALSE, vWarehouse, vDate); + + + INSERT INTO tmp.ticketProblems(ticketFk, isAvailable) + SELECT tl.ticketFk, 0 + FROM tmp.ticketList tl + JOIN vn.ticket t ON t.id = tl.ticketFk + LEFT JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it on it.id = i.typeFk + LEFT JOIN cache.available av ON av.item_id = i.id + AND av.calc_id = vAvailableCache + WHERE date(t.shipped) = vDate + AND categoryFk != 6 + AND IFNULL(av.available, 0) < 0 + AND s.isPicked = FALSE + AND NOT i.generic + AND vWarehouse = t.warehouseFk + GROUP BY tl.ticketFk + ON DUPLICATE KEY UPDATE + isAvailable = 0; + + INSERT INTO tmp.ticketProblems(ticketFk, isAvailable) + SELECT tl.ticketFk, 0 + FROM tmp.ticketList tl + JOIN vn.ticket t ON t.id = tl.ticketFk + LEFT JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it on it.id = i.typeFk + LEFT JOIN cache.visible v ON i.id = v.item_id AND v.calc_id = vVisibleCache + LEFT JOIN cache.available av ON av.item_id = i.id AND av.calc_id = vAvailableCache + WHERE IFNULL(av.available, 0) >= 0 + AND s.quantity > IFNULL(v.visible, 0) + AND s.isPicked = FALSE + AND s.reserved = FALSE + AND it.categoryFk != 6 + AND date(t.shipped) = vDate + AND NOT i.generic + AND CURDATE() = vDate + AND t.warehouseFk = vWarehouse + GROUP BY tl.ticketFk + ON DUPLICATE KEY UPDATE + isAvailable = 0; + + END WHILE; + + CLOSE vCursor; + + SELECT * FROM tmp.ticketProblems; + + DROP TEMPORARY TABLE + tmp.clientGetDebt, + tmp.ticketList; + +END$$ + +DELIMITER ; + diff --git a/db/changes/10060-verano/00-zoneCalendar.sql b/db/changes/10060-verano/00-zoneCalendar.sql new file mode 100644 index 000000000..a3c091643 --- /dev/null +++ b/db/changes/10060-verano/00-zoneCalendar.sql @@ -0,0 +1,3 @@ +ALTER TABLE `vn`.`zoneCalendar` +ADD COLUMN `price` DOUBLE NOT NULL AFTER `delivered`, +ADD COLUMN `bonus` DOUBLE NOT NULL AFTER `price`; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 470002d21..1b2caad96 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -190,7 +190,7 @@ INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city (102, 'Petter Parker', '87945234L', 'Spider-Man', 'Aunt May', '20 Ingram Street', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'PetterParker@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), (103, 'Clark Kent', '06815934E', 'Super-Man', 'lois lane', '344 Clinton Street', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'ClarkKent@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 0, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), (104, 'Tony Stark', '06089160W', 'Iron-Man', 'Pepper Potts', '10880 Malibu Point', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'TonyStark@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), - (105, 'Max Eisenhardt', '251628698', 'Magneto', 'Rogue', 'Unknown Whereabouts', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'MaxEisenhardt@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, NULL, 0, 1), + (105, 'Max Eisenhardt', '251628698', 'Magneto', 'Rogue', 'Unknown Whereabouts', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'MaxEisenhardt@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 18, 0, 1), (106, 'DavidCharlesHaller', '53136686Q', 'Legion', 'Charles Xavier', 'Evil hideout', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'DavidCharlesHaller@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 0, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 19, 0, 1), (107, 'Hank Pym', '09854837G', 'Ant-Man', 'Hawk', 'Anthill', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'HankPym@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, 19, 0, 1), (108, 'Charles Xavier', '22641921P', 'Professor X', 'Beast', '3800 Victory Pkwy, Cincinnati, OH 45207, USA', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'CharlesXavier@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 19, 0, 1), @@ -352,7 +352,7 @@ INSERT INTO `vn`.`creditInsurance`(`id`, `creditClassification`, `credit`, `crea INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agencyModeFk`, `description`, `m3`, `cost`, `started`, `finished`) VALUES - (1, '1899-12-30 12:15:00', 56, CURDATE(), 1, 7, 'first route', 0.1, 10, CURDATE(), CURDATE()), + (1, '1899-12-30 12:15:00', 56, CURDATE(), 1, 7, 'first route', 0.3, 10, CURDATE(), CURDATE()), (2, '1899-12-30 13:20:00', 56, CURDATE(), 1, 7, 'second route', 0.1, 20, CURDATE(), CURDATE()), (3, '1899-12-30 14:30:00', 56, CURDATE(), 2, 7, 'third route', 0.1, 30, CURDATE(), CURDATE()), (4, '1899-12-30 15:45:00', 56, CURDATE(), 3, 7, 'fourth route', 0.1, 40, CURDATE(), CURDATE()), @@ -425,8 +425,8 @@ INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeF VALUES (1 , 3, 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 101, 'Bat cave', 121, 'T1111111', 0, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), (2 , 1, 1, 1, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 104, 'Stark tower', 124, 'T1111111', 0, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), - (3 , 1, 2, 2, 1, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -2 MONTH), INTERVAL +1 DAY), 104, 'Stark tower', 124, 'T2222222', 0, DATE_ADD(CURDATE(), INTERVAL -2 MONTH)), - (4 , 3, 2, 2, 1, DATE_ADD(CURDATE(), INTERVAL -3 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -3 MONTH), INTERVAL +1 DAY), 104, 'Stark tower', 124, 'T3333333', 0, DATE_ADD(CURDATE(), INTERVAL -3 MONTH)), + (3 , 1, 2, 1, 1, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -2 MONTH), INTERVAL +1 DAY), 104, 'Stark tower', 124, 'T2222222', 0, DATE_ADD(CURDATE(), INTERVAL -2 MONTH)), + (4 , 3, 2, 1, 1, DATE_ADD(CURDATE(), INTERVAL -3 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -3 MONTH), INTERVAL +1 DAY), 104, 'Stark tower', 124, 'T3333333', 0, DATE_ADD(CURDATE(), INTERVAL -3 MONTH)), (5 , 3, 3, 3, 1, DATE_ADD(CURDATE(), INTERVAL -4 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -4 MONTH), INTERVAL +1 DAY), 104, 'Stark tower', 124, 'T4444444', 0, DATE_ADD(CURDATE(), INTERVAL -4 MONTH)), (6 , 1, 3, 3, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -1 MONTH), INTERVAL +1 DAY), 101, 'Mountain Drive Gotham', 1, 'A1111111', 0, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), (7 , NULL, 7, 1, 2, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 101, 'Mountain Drive Gotham', 1, NULL, 0, CURDATE()), @@ -435,8 +435,8 @@ INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeF (10, 1, 1, 5, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 102, 'Ingram Street', 2, NULL, 0, CURDATE()), (11, 1, 7, 1, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 102, 'NY roofs', 122, NULL, 0, CURDATE()), (12, 1, 1, 1, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 103, 'Phone Box', 123, NULL, 0, CURDATE()), - (13, 1, 1, 2, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 103, 'Phone Box', 123, NULL, 0, CURDATE()), - (14, 1, 2, 2, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 104, 'Malibu Point', 4, NULL, 0, CURDATE()), + (13, 1, 1, 1, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 103, 'Phone Box', 123, NULL, 0, CURDATE()), + (14, 1, 2, 1, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 104, 'Malibu Point', 4, NULL, 0, CURDATE()), (15, 1, 7, 1, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 105, 'Plastic Cell', 125, NULL, 0, CURDATE()), (16, 1, 7, 1, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 106, 'Many Places', 126, NULL, 0, CURDATE()), (17, 1, 7, 1, 3, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 106, 'Many Places', 126, NULL, 0, CURDATE()), @@ -1027,15 +1027,20 @@ INSERT INTO `vn`.`travel`(`id`,`shipped`, `landed`, `warehouseInFk`, `warehouseO (1, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), DATE_ADD(CURDATE(), INTERVAL -2 MONTH), 1, 2, 1, 100.00, 1000), (2, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 1, 2, 1, 150, 2000), (3, CURDATE(), CURDATE(), 1, 2, 1, 0.00, 0.00), - (4, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 1, 2, 1, 50.00, 500); + (4, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 1, 2, 1, 50.00, 500), + (5, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 3, 2, 1, 50.00, 500), + (6, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 4, 2, 1, 50.00, 500), + (7, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 5, 2, 1, 50.00, 500); INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `companyFk`,`ref`) VALUES (1, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 1, 442, 'Movimiento 1'), (2, 2, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 2, 442, 'Movimiento 2'), (3, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 3, 442, 'Movimiento 3'), - (4, 2, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 4, 69, 'Movimiento 4'); - + (4, 2, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 4, 69, 'Movimiento 4'), + (5, 2, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 5, 442, 'Movimiento 5'), + (6, 2, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 6, 442, 'Movimiento 6'), + (7, 2, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 7, 442, 'Movimiento 7'); INSERT INTO `bi`.`claims_ratio`(`id_Cliente`, `Consumo`, `Reclamaciones`, `Ratio`, `recobro`, `inflacion`) VALUES @@ -1046,14 +1051,21 @@ INSERT INTO `bi`.`claims_ratio`(`id_Cliente`, `Consumo`, `Reclamaciones`, `Ratio INSERT INTO `vn`.`buy`(`id`,`entryFk`,`itemFk`,`buyingValue`,`quantity`,`packageFk`,`stickers`,`freightValue`,`packageValue`,`comissionValue`,`packing`,`grouping`,`groupingMode`,`location`,`price1`,`price2`,`price3`,`minPrice`,`producer`,`printedStickers`,`isChecked`,`isIgnored`, `created`) VALUES - (1, 1, 1, 2.5, 5000, 1, 1, 0.350, 0.050, 0.000, 10, 10, 1, NULL, 0.00, 1.30, 1.25, 1.00, NULL, 0, 1, 0, DATE_ADD(CURDATE(), INTERVAL -2 MONTH)), - (2, 2, 1, 20 , 100, 1, 1, 0.700, 0.020, 0.000, 5, 5, 1, NULL, 0.00, 2.50, 2.00, 0.50, NULL, 0, 1, 0, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), - (3, 3, 1, 20 , 100, 1, 1, 0.700, 0.020, 0.000, 1, 1, 0, NULL, 0.00, 2.50, 2.00, 0.50, NULL, 0, 1, 0, CURDATE()), - (4, 2, 2, 5 , 450, 1, 1, 0.500, 0.100, 0.000, 10, 10, 0, NULL, 0.00, 1.30, 1.00, 0.00, NULL, 0, 1, 0, CURDATE()), - (5, 3, 3, 10 , 500, 1, 1, 1.000, 0.050, 0.000, 10, 10, 0, NULL, 0.00, 2.50, 1.00, 0.00, NULL, 0, 1, 0, CURDATE()), - (6, 4, 8, 20 , 1000, 1, 1, 0.700, 0.020, 0.000, 10, 10, 1, NULL, 0.00, 2.50, 1.00, 0.00, NULL, 0, 1, 0, CURDATE()), - (7, 4, 9, 20 , 1000, 1, 1, 0.700, 0.020, 0.000, 10, 10, 1, NULL, 0.00, 2.50, 1.00, 0.00, NULL, 0, 1, 0, CURDATE()), - (8, 4, 4, 20 , 1000, 1, 1, 0.700, 0.020, 0.000, 10, 10, 1, NULL, 0.00, 2.50, 1.00, 0.00, NULL, 0, 1, 0, CURDATE()); + (1, 1, 1, 2.5, 5000, 1, 1, 0.350, 0.050, 0.000, 10, 10, 1, NULL, 0.00, 1.30, 1.25, 1.00, NULL, 0, 1, 0, DATE_ADD(CURDATE(), INTERVAL -2 MONTH)), + (2, 2, 1, 20, 100, 1, 1, 0.700, 0.020, 0.000, 5, 5, 1, NULL, 0.00, 2.50, 2.00, 0.50, NULL, 0, 1, 0, DATE_ADD(CURDATE(), INTERVAL -1 MONTH)), + (3, 3, 1, 20, 100, 1, 1, 0.700, 0.020, 0.000, 1, 1, 0, NULL, 0.00, 2.50, 2.00, 0.50, NULL, 0, 1, 0, CURDATE()), + (4, 2, 2, 5, 450, 1, 1, 0.500, 0.100, 0.000, 10, 10, 0, NULL, 0.00, 1.30, 1.00, 0.00, NULL, 0, 1, 0, CURDATE()), + (5, 3, 3, 10, 500, 1, 1, 1.000, 0.050, 0.000, 10, 10, 0, NULL, 0.00, 2.50, 1.00, 0.00, NULL, 0, 1, 0, CURDATE()), + (6, 4, 8, 20, 1000, 1, 1, 0.700, 0.020, 0.000, 10, 10, 1, NULL, 0.00, 2.50, 1.00, 0.00, NULL, 0, 1, 0, CURDATE()), + (7, 4, 9, 20, 1000, 1, 1, 0.700, 0.020, 0.000, 10, 10, 1, NULL, 0.00, 2.50, 1.00, 0.00, NULL, 0, 1, 0, CURDATE()), + (8, 4, 4, 20, 1000, 1, 1, 0.700, 0.020, 0.000, 10, 10, 1, NULL, 0.00, 2.50, 1.00, 0.00, NULL, 0, 1, 0, CURDATE()), + (9, 4, 4, 20, 1000, 1, 1, 0.700, 0.020, 0.000, 10, 10, 1, NULL, 0.00, 2.50, 1.00, 0.00, NULL, 0, 1, 0, CURDATE()), + (10, 5, 1, 2, 10, 1, 1, 0.700, 0.020, 0.000, 10, 10, 1, NULL, 0.00, 2.50, 1.00, 0.00, NULL, 0, 1, 0, CURDATE()), + (11, 5, 4, 3, 10, 1, 1, 0.700, 0.020, 0.000, 10, 10, 1, NULL, 0.00, 2.50, 1.00, 0.00, NULL, 0, 1, 0, CURDATE()), + (12, 6, 4, 2, 1000, 1, 1, 0.700, 0.020, 0.000, 10, 10, 1, NULL, 0.00, 2.50, 1.00, 0.00, NULL, 0, 1, 0, CURDATE()), + (13, 7, 1, 2, 1000, 1, 1, 0.700, 0.020, 0.000, 10, 10, 1, NULL, 0.00, 2.50, 1.00, 0.00, NULL, 0, 1, 0, CURDATE()), + (14, 7, 2, 5, 1000, 1, 1, 0.700, 0.020, 0.000, 10, 10, 1, NULL, 0.00, 2.50, 1.00, 0.00, NULL, 0, 1, 0, CURDATE()), + (15, 7, 4, 1, 1000, 1, 1, 0.700, 0.020, 0.000, 10, 10, 1, NULL, 0.00, 2.50, 1.00, 0.00, NULL, 0, 1, 0, CURDATE()); INSERT INTO `vn2008`.`tblContadores`(`id`,`FechaInventario`) VALUES diff --git a/e2e/paths/03-worker-module/02_time_control.spec.js b/e2e/paths/03-worker-module/02_time_control.spec.js index 0e72f40d9..d53a02056 100644 --- a/e2e/paths/03-worker-module/02_time_control.spec.js +++ b/e2e/paths/03-worker-module/02_time_control.spec.js @@ -385,6 +385,7 @@ describe('Worker time control path', () => { it('should Hank Pym check his hours are alright', async() => { const wholeWeekHours = await nightmare + .waitForTextInElement(selectors.workerTimeControl.weekWorkedHours, '56:00 Hours') .waitToGetProperty(selectors.workerTimeControl.weekWorkedHours, 'innerText'); expect(wholeWeekHours).toEqual('56:00 Hours'); diff --git a/front/core/components/calendar/index.html b/front/core/components/calendar/index.html index e505bfad9..189e9b4eb 100644 --- a/front/core/components/calendar/index.html +++ b/front/core/components/calendar/index.html @@ -26,37 +26,55 @@ -
+
L
-
+
M
-
+
X
-
+
J
-
+
V
-
+
S
-
+
D
-
- - {{::day.dated | date: 'd'}} - - {{::day.dated | date: 'd'}} +
+
+
+ {{::day.dated | date: 'd'}} +
+
+
+ + {{::event.name}} + +
+
+
diff --git a/front/core/components/calendar/index.js b/front/core/components/calendar/index.js index ada238d67..9e920eea2 100644 --- a/front/core/components/calendar/index.js +++ b/front/core/components/calendar/index.js @@ -13,6 +13,23 @@ export default class Calendar extends Component { this.defaultDate = new Date(); this.displayControls = true; this.skip = 1; + + this.window.addEventListener('resize', () => { + this.checkSize(); + }); + } + + /** + * Resizes the calendar + * based on component height + */ + checkSize() { + const height = this.$element[0].clientHeight; + + if (height < 530) + this.$element.addClass('small'); + else + this.$element.removeClass('small'); } /** @@ -49,8 +66,10 @@ export default class Calendar extends Component { this.addEvent(event); }); - if (value.length && this.defaultDate) + if (value.length && this.defaultDate) { this.repaint(); + this.checkSize(); + } } /** @@ -165,16 +184,28 @@ export default class Calendar extends Component { * @param {Date} dated - Date of month * @param {String} className - Default class style */ - insertDay(dated, className = '') { - let event = this.events.find(event => { + insertDay(dated) { + let events = this.events.filter(event => { return event.dated >= dated && event.dated <= dated; }); - // Weeekends - if (dated.getMonth() === this.currentMonth.getMonth() && dated.getDay() == 0) - className = 'red'; + const params = {dated, events}; - this.days.push({dated, className, event}); + const isSaturday = dated.getDay() === 6; + const isSunday = dated.getDay() === 0; + const isCurrentMonth = dated.getMonth() === this.currentMonth.getMonth(); + const hasEvents = events.length > 0; + + if (isCurrentMonth && isSunday && !hasEvents) + params.style = {color: '#f42121'}; + + if (isCurrentMonth && isSaturday && !hasEvents) + params.style = {color: '#666666'}; + + if (!isCurrentMonth && !hasEvents) + params.style = {color: '#9b9b9b'}; + + this.days.push(params); } /** @@ -182,7 +213,7 @@ export default class Calendar extends Component { * * @param {Object} options - Event params * @param {Date} options.dated - Day to add event - * @param {String} options.title - Tooltip description + * @param {String} options.name - Tooltip description * @param {String} options.className - ClassName style * @param {Object} options.style - Style properties * @param {Boolean} options.isRemovable - True if is removable by users @@ -194,12 +225,7 @@ export default class Calendar extends Component { options.dated = new Date(options.dated); options.dated.setHours(0, 0, 0, 0); - const event = this.events.findIndex(event => { - return event.dated >= options.dated && event.dated <= options.dated; - }); - - if (event < 0) - this.events.push(options); + this.events.push(options); } /** @@ -274,6 +300,16 @@ export default class Calendar extends Component { } this.emit('selection', {values: selected}); } + + renderStyle(style) { + if (style) { + return { + 'background-color': style.backgroundColor, + 'font-weight': style.fontWeight, + 'color': style.color + }; + } + } } Calendar.$inject = ['$element', '$scope']; diff --git a/front/core/components/calendar/index.spec.js b/front/core/components/calendar/index.spec.js index 6a082a236..86bf3c240 100644 --- a/front/core/components/calendar/index.spec.js +++ b/front/core/components/calendar/index.spec.js @@ -20,8 +20,8 @@ describe('Component vnCalendar', () => { let currentDate = new Date().toString(); controller.data = [ - {dated: currentDate, title: 'Event 1'}, - {dated: currentDate, title: 'Event 2'}, + {dated: currentDate, name: 'Event 1'}, + {dated: currentDate, name: 'Event 2'}, ]; expect(controller.events[0].dated instanceof Object).toBeTruthy(); @@ -34,12 +34,11 @@ describe('Component vnCalendar', () => { controller.events = []; controller.addEvent({ dated: new Date(), - title: 'My event', - className: 'color' + name: 'My event' }); const firstEvent = controller.events[0]; - expect(firstEvent.title).toEqual('My event'); + expect(firstEvent.name).toEqual('My event'); expect(firstEvent.isRemovable).toBeDefined(); expect(firstEvent.isRemovable).toBeTruthy(); }); @@ -50,19 +49,17 @@ describe('Component vnCalendar', () => { controller.events = [{ dated: curDate, - title: 'My event 1', - className: 'color' + name: 'My event 1' }]; controller.addEvent({ dated: curDate, - title: 'My event 2', - className: 'color' + name: 'My event 2' }); const firstEvent = controller.events[0]; - expect(controller.events.length).toEqual(1); - expect(firstEvent.title).toEqual('My event 1'); + expect(controller.events.length).toEqual(2); + expect(firstEvent.name).toEqual('My event 1'); }); }); @@ -71,7 +68,7 @@ describe('Component vnCalendar', () => { const curDate = new Date(); controller._events = [{ dated: curDate, - title: 'My event 1', + name: 'My event 1', className: 'color' }]; controller.removeEvent(curDate); diff --git a/front/core/components/calendar/style.scss b/front/core/components/calendar/style.scss index 6baaa0f65..333bfb428 100644 --- a/front/core/components/calendar/style.scss +++ b/front/core/components/calendar/style.scss @@ -1,143 +1,123 @@ @import "variables"; +vn-calendar.small { + .events { + display: none + } +} + vn-calendar { display: block; - max-width: 250px; .header vn-one { text-align: center; - padding: 0.2em 0 + padding: 0.2em 0; + height: 1.5em } - .body { - .days { - justify-content: flex-start; - align-items: flex-start; - flex-wrap: wrap; + + .weekdays { + color: $color-font-secondary; + margin-bottom: 0.5em; + padding: 0.5em 0; + font-weight: bold; + font-size: 0.8em; + } + + .weekdays section { + cursor: pointer + } + + .weekdays section, .day { + position: relative; + text-align: center; + box-sizing: border-box; + width: 14.28%; + outline: 0; + } + + .days { + justify-content: flex-start; + align-items: flex-start; + flex-wrap: wrap; + } + + + .day { + .content { + position: absolute; + bottom: 0; + right: 0; + left: 0; + top: 0 } - .weekdays { - border-bottom: 1px solid $color-hover-cd; - border-top: 1px solid $color-hover-cd; - color: $color-font-secondary; - font-weight: bold + .day-number { + transition: background-color 0.3s; + text-align:center; + float:inline-end; + margin: 0 auto; + border-radius: 50%; + font-size: 0.85em; + width:2.2em; + height: 1.2em; + padding: 0.5em 0; + cursor: pointer; + outline: 0 } - .day { - box-sizing: border-box; - padding: 0.1em; - width: 14.2857143%; - line-height: 1.5em; - outline: 0; - - span { - transition: background-color 0.3s; - text-align: center; - font-size: .8em; - border-radius: 50%; - display: block; - padding: 0.2em; - cursor: pointer - } + .day-number:hover { + background-color: lighten($color-font-secondary, 20%); + opacity: 0.8 } + } - .day:hover span { - background-color: #DDD + .day::after { + content: ""; + display: block; + padding-top: 100%; + } + + .day.primary .day-number { + background-color: $color-main; + color: $color-font-bg; + } + + .events { + margin-top: 0.5em; + font-size: 0.6em + } + + + .events { + color: $color-font-secondary; + + .event { + margin-bottom: .1em; } + } - .day.gray { + .chip { + background-color: $color-main; + color: $color-font-bg; + display: inline-block; + border-radius: .3em; + padding: 0.3em .8em; + max-width: 5em; + } + + .day.gray { + .day-number { color: $color-font-secondary } + } - .day.orange { - font-weight: bold; - color: $color-main; - } - - .day.orange-circle { - color: $color-font; - & > span { - background-color: $color-main - } - } + - .day.orange-circle:hover { - & > span { - background-color: $color-main-medium - } - } - - .day.light-orange { - color: $color-main-medium - } - - .day.green { - font-weight: bold; - color: $color-success; - } - - .day.green-circle { - color: $color-font; - & > span { - background-color: $color-success - } - } - - .day.green-circle:hover { - & > span { - background-color: $color-success-medium - } - } - - .day.light-green { - font-weight: bold; - color: $color-success-medium - } - - .day.blue { - font-weight: bold; - color: $color-notice; - } - - .day.blue-circle { - color: $color-font; - & > span { - background-color: $color-notice - } - } - - .day.blue-circle:hover { - & > span { - background-color: $color-notice-medium - } - } - - .day.light-blue { - font-weight: bold; - color: $color-notice-medium - } - - .day.red { - font-weight: bold; - color: $color-alert - } - - .day.red-circle { - color: $color-font; - & > span { - background-color: $color-alert - } - } - - .day.red-circle:hover { - & > span { - background-color: $color-alert-medium - } - } - - .day.light-red { - font-weight: bold; - color: $color-alert-medium; + .day.sunday { + .day-number { + color: $color-alert; + font-weight: bold } } } diff --git a/front/core/components/dialog/dialog.js b/front/core/components/dialog/dialog.js index 7ea588a27..4c4535b4c 100644 --- a/front/core/components/dialog/dialog.js +++ b/front/core/components/dialog/dialog.js @@ -45,8 +45,7 @@ export default class Dialog extends Component { this.element.style.display = 'flex'; this.transitionTimeout = setTimeout(() => this.$element.addClass('shown'), 30); - if (this.onOpen) - this.onOpen(); + this.emit('open'); } /** @@ -55,6 +54,7 @@ export default class Dialog extends Component { hide() { this.fireResponse(); this.realHide(); + this.emit('close'); } /** @@ -120,7 +120,6 @@ ngModule.component('vnDialog', { buttons: '?tplButtons' }, bindings: { - onOpen: '&?', onResponse: '&?' }, controller: Dialog diff --git a/front/core/components/dialog/dialog.spec.js b/front/core/components/dialog/dialog.spec.js index 4937fdba3..b889f1bc0 100644 --- a/front/core/components/dialog/dialog.spec.js +++ b/front/core/components/dialog/dialog.spec.js @@ -7,7 +7,7 @@ describe('Component vnDialog', () => { beforeEach(angular.mock.inject($componentController => { $element = angular.element(''); controller = $componentController('vnDialog', {$element, $transclude: null}); - controller.onOpen = jasmine.createSpy('onOpen'); + controller.emit = jasmine.createSpy('emit'); })); describe('show()', () => { @@ -17,15 +17,15 @@ describe('Component vnDialog', () => { controller.show(); expect(controller.element.style.display).toEqual('none'); - expect(controller.onOpen).not.toHaveBeenCalledWith(); + expect(controller.emit).not.toHaveBeenCalledWith('open'); }); - it(`should set shown on the controller, set style.display on the element and call onOpen()`, () => { + it(`should set shown on the controller, set style.display on the element and emit onOpen() event`, () => { controller.show(); expect(controller.element.style.display).toEqual('flex'); expect(controller.shown).toBeTruthy(); - expect(controller.onOpen).toHaveBeenCalledWith(); + expect(controller.emit).toHaveBeenCalledWith('open'); }); }); diff --git a/front/core/components/index.js b/front/core/components/index.js index d626470c3..09ee97963 100644 --- a/front/core/components/index.js +++ b/front/core/components/index.js @@ -20,7 +20,7 @@ import './multi-check/multi-check'; import './date-picker/date-picker'; import './button/button'; import './check/check'; -import './radio/radio'; +import './radio-group/radio-group'; import './textarea/textarea'; import './icon-button/icon-button'; import './submit/submit'; diff --git a/front/core/components/input-number/index.html b/front/core/components/input-number/index.html index cb3f24bd5..9fd024280 100644 --- a/front/core/components/input-number/index.html +++ b/front/core/components/input-number/index.html @@ -22,7 +22,10 @@ ng-focus="$ctrl.hasFocus = true" ng-blur="$ctrl.hasFocus = false" tabindex="{{$ctrl.input.tabindex}}"/> - +
diff --git a/front/core/components/input-number/index.js b/front/core/components/input-number/index.js index 7eb8cbd54..6c9f378e8 100644 --- a/front/core/components/input-number/index.js +++ b/front/core/components/input-number/index.js @@ -192,6 +192,7 @@ ngModule.component('vnInputNumber', { label: '@?', name: '@?', disabled: ' + + {{::option.label}} + + \ No newline at end of file diff --git a/front/core/components/radio-group/radio-group.js b/front/core/components/radio-group/radio-group.js new file mode 100644 index 000000000..80c77a7e2 --- /dev/null +++ b/front/core/components/radio-group/radio-group.js @@ -0,0 +1,41 @@ +import ngModule from '../../module'; +import Component from '../../lib/component'; +import './style.scss'; + +export default class Controller extends Component { + constructor($element, $scope, $attrs) { + super($element, $scope); + this.hasInfo = Boolean($attrs.info); + this.info = $attrs.info || null; + } + + get model() { + return this._model; + } + + set model(value) { + this._model = value; + } + + get field() { + return this._model; + } + + set field(value) { + this._model = value; + } +} + +Controller.$inject = ['$element', '$scope', '$attrs']; + +ngModule.component('vnRadioGroup', { + template: require('./radio-group.html'), + controller: Controller, + + bindings: { + field: '=?', + options: ' -*[text]* diff --git a/front/core/components/radio/radio.js b/front/core/components/radio/radio.js deleted file mode 100644 index 70dbc059d..000000000 --- a/front/core/components/radio/radio.js +++ /dev/null @@ -1,15 +0,0 @@ -import ngModule from '../../module'; -import template from './radio.html'; - -directive.$inject = ['vnTemplate']; -export default function directive(vnTemplate) { - return { - restrict: 'E', - template: (_, $attrs) => - vnTemplate.get(template, $attrs, { - enabled: 'true', - className: 'mdl-radio mdl-js-radio mdl-js-ripple-effect' - }) - }; -} -ngModule.directive('vnRadio', directive); diff --git a/front/core/components/textfield/textfield.html b/front/core/components/textfield/textfield.html index 0c1058148..22756497f 100644 --- a/front/core/components/textfield/textfield.html +++ b/front/core/components/textfield/textfield.html @@ -16,7 +16,7 @@ tabindex="{{$ctrl.input.tabindex}}"/>
diff --git a/front/salix/styles/variables.scss b/front/salix/styles/variables.scss index 732389fb9..5fd31a8c6 100644 --- a/front/salix/styles/variables.scss +++ b/front/salix/styles/variables.scss @@ -52,6 +52,8 @@ $color-hover-cd: rgba(0, 0, 0, .1); $color-hover-dc: .7; $color-disabled: .6; +$color-font-link-medium: lighten($color-font-link, 20%); +$color-font-link-light: lighten($color-font-link, 35%); $color-main-medium: lighten($color-main, 20%); $color-main-light: lighten($color-main, 35%); $color-success-medium: lighten($color-success, 20%); diff --git a/modules/agency/back/methods/zone/editPrices.js b/modules/agency/back/methods/zone/editPrices.js new file mode 100644 index 000000000..b0203dc4b --- /dev/null +++ b/modules/agency/back/methods/zone/editPrices.js @@ -0,0 +1,81 @@ +const mergeFilters = require('vn-loopback/util/filter').mergeFilters; + +module.exports = Self => { + Self.remoteMethod('editPrices', { + description: 'Changes the price and bonus of a delivery day', + accessType: 'WRITE', + accepts: [{ + arg: 'id', + type: 'Number', + description: 'The zone id', + http: {source: 'path'} + }, + { + arg: 'delivered', + type: 'Date', + required: true, + }, + { + arg: 'price', + type: 'Number', + required: true, + }, + { + arg: 'bonus', + type: 'Number', + required: true, + }, + { + arg: 'option', + type: 'String', + required: true, + }], + returns: { + type: 'object', + root: true + }, + http: { + path: `/:id/editPrices`, + verb: 'POST' + } + }); + + Self.editPrices = async(id, delivered, price, bonus, option) => { + const models = Self.app.models; + + let filter = { + where: { + zoneFk: id + } + }; + + let where; + let shouldPropagate = true; + + if (option == 'Only this day') { + shouldPropagate = false; + where = {delivered}; + } else if (option == 'From this day') { + where = { + delivered: { + gte: delivered + } + }; + } + + filter = mergeFilters(filter, {where}); + + const days = await models.ZoneCalendar.find(filter); + const areAllFromSameZone = days.every(day => day.zoneFk === id); + + if (!areAllFromSameZone) + throw new UserError('All delivery days must belong to the same zone'); + + if (shouldPropagate) { + const zone = await models.Zone.findById(id); + zone.updateAttributes({price, bonus}); + } + + return models.ZoneCalendar.updateAll(filter.where, {price, bonus}); + }; +}; diff --git a/modules/agency/back/methods/zone/specs/editPrices.spec.js b/modules/agency/back/methods/zone/specs/editPrices.spec.js new file mode 100644 index 000000000..610496425 --- /dev/null +++ b/modules/agency/back/methods/zone/specs/editPrices.spec.js @@ -0,0 +1,84 @@ +const app = require('vn-loopback/server/server'); + +describe('agency editPrices()', () => { + const zoneId = 1; + let originalZone; + + beforeAll(async done => { + originalZone = await app.models.Zone.findById(zoneId); + done(); + }); + + afterAll(async done => { + await await app.models.ZoneCalendar.updateAll({zoneFk: zoneId}, { + price: originalZone.price, + bonus: originalZone.bonus + }); + done(); + }); + + it('should apply price and bonus for a selected day', async() => { + const delivered = new Date(); + delivered.setHours(0, 0, 0, 0); + delivered.setDate(delivered.getDate() + 1); + await app.models.Zone.editPrices(zoneId, delivered, 4.00, 2.00, 'Only this day'); + + const editedDays = await app.models.ZoneCalendar.find({ + where: { + zoneFk: zoneId, + delivered: delivered + } + }); + const firstEditedDay = editedDays[0]; + + expect(editedDays.length).toEqual(1); + expect(firstEditedDay.price).toEqual(4.00); + expect(firstEditedDay.bonus).toEqual(2.00); + }); + + it('should apply price and bonus for all delivery days starting from selected day', async() => { + const delivered = new Date(); + delivered.setHours(0, 0, 0, 0); + delivered.setDate(delivered.getDate() + 1); + await app.models.Zone.editPrices(1, delivered, 5.50, 1.00, 'From this day'); + + const editedDays = await app.models.ZoneCalendar.find({ + where: { + zoneFk: zoneId, + delivered: { + gte: delivered + } + } + }); + const firstEditedDay = editedDays[0]; + const lastEditedDay = editedDays[editedDays.length - 1]; + + expect(editedDays.length).toEqual(4); + expect(firstEditedDay.price).toEqual(5.50); + expect(firstEditedDay.bonus).toEqual(1.00); + expect(lastEditedDay.price).toEqual(5.50); + expect(lastEditedDay.bonus).toEqual(1.00); + }); + + it('should apply price and bonus for all delivery days', async() => { + const delivered = new Date(); + delivered.setHours(0, 0, 0, 0); + delivered.setDate(delivered.getDate() + 1); + await app.models.Zone.editPrices(1, delivered, 7.00, 0.00, 'All days'); + + const editedDays = await app.models.ZoneCalendar.find({ + where: { + zoneFk: zoneId + } + }); + const firstEditedDay = editedDays[0]; + const lastEditedDay = editedDays[editedDays.length - 1]; + + expect(editedDays.length).toEqual(5); + expect(firstEditedDay.price).toEqual(7.00); + expect(firstEditedDay.bonus).toEqual(0.00); + expect(lastEditedDay.price).toEqual(7.00); + expect(lastEditedDay.bonus).toEqual(0.00); + }); +}); + diff --git a/modules/agency/back/models/zone-calendar.json b/modules/agency/back/models/zone-calendar.json index 35926a0db..bed9a8011 100644 --- a/modules/agency/back/models/zone-calendar.json +++ b/modules/agency/back/models/zone-calendar.json @@ -14,6 +14,12 @@ "delivered": { "id": true, "type": "Date" + }, + "price": { + "type": "Number" + }, + "bonus": { + "type": "Number" } }, "relations": { diff --git a/modules/agency/back/models/zone.js b/modules/agency/back/models/zone.js index d282224b9..c7ba642f3 100644 --- a/modules/agency/back/models/zone.js +++ b/modules/agency/back/models/zone.js @@ -1,5 +1,6 @@ module.exports = Self => { require('../methods/zone/clone')(Self); + require('../methods/zone/editPrices')(Self); Self.validatesPresenceOf('warehouseFk', { message: `Warehouse cannot be blank` diff --git a/modules/agency/front/calendar/index.html b/modules/agency/front/calendar/index.html index d02be3059..0a86d2254 100644 --- a/modules/agency/front/calendar/index.html +++ b/modules/agency/front/calendar/index.html @@ -1,21 +1,74 @@ - - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + +
Edit price
+ + + + + + + + + + +
+ + + + +
\ No newline at end of file diff --git a/modules/agency/front/calendar/index.js b/modules/agency/front/calendar/index.js index bf1625585..5e6cb19b9 100644 --- a/modules/agency/front/calendar/index.js +++ b/modules/agency/front/calendar/index.js @@ -1,49 +1,26 @@ import ngModule from '../module'; +import './style.scss'; class Controller { - constructor($element, $scope, $stateParams, $http) { + constructor($element, $scope, $http, $filter, $translate, $stateParams, vnApp) { this.$element = $element; - this.$stateParams = $stateParams; - this.$scope = $scope; + this.$ = $scope; this.$http = $http; + this.$filter = $filter; + this.$translate = $translate; + this.$stateParams = $stateParams; + this.vnApp = vnApp; this.stMonthDate = new Date(); this.ndMonthDate = new Date(); this.ndMonthDate.setMonth(this.ndMonthDate.getMonth() + 1); + this.selectedDay = {}; } $postLink() { - this.stMonth = this.$scope.stMonth; - this.ndMonth = this.$scope.ndMonth; + this.stMonth = this.$.stMonth; + this.ndMonth = this.$.ndMonth; } - // Disabled until implementation - // of holidays by node - /* get zone() { - return this._zone; - } - - set zone(value) { - this._zone = value; - - if (!value) return; - - let query = '/agency/api/LabourHolidays/getByWarehouse'; - this.$http.get(query, {params: {warehouseFk: value.warehouseFk}}).then(res => { - if (!res.data) return; - const events = []; - res.data.forEach(holiday => { - events.push({ - date: holiday.dated, - className: 'red', - title: holiday.description || holiday.name, - isRemovable: false - }); - }); - - this.events = this.events.concat(events); - }); - } */ - get data() { return this._data; } @@ -52,97 +29,106 @@ class Controller { this._data = value; if (!value) return; + const events = []; value.forEach(event => { events.push({ + name: `P: ${this.$filter('currency')(event.price)}`, + description: 'Price', dated: event.delivered, - className: 'green-circle', - title: 'Has delivery' + style: {backgroundColor: '#a3d131'}, + data: {price: event.price} + }); + events.push({ + name: `B: ${this.$filter('currency')(event.bonus)}`, + description: 'Bonus', + dated: event.delivered, + data: {bonus: event.bonus} }); }); this.events = events; } - onSelection(calendar, values) { - let totalEvents = 0; - values.forEach(day => { - const exists = calendar.events.findIndex(event => { - return event.dated >= day.dated && event.dated <= day.dated - && event.isRemovable; - }); + onSelection(values) { + if (values.length > 1) return false; - if (exists > -1) totalEvents++; + this.options = [ + {label: 'Only this day', value: 'Only this day'}, + {label: 'From this day', value: 'From this day'}, + {label: 'All days', value: 'All days'} + ]; + const selection = values[0]; + const events = selection.events; + const hasEvents = events.length > 0; + + if (!hasEvents) + return this.vnApp.showMessage(this.$translate.instant(`There's no delivery for this day`)); + + this.selectedDay = { + delivered: selection.dated, + option: 'Only this day' + }; + + events.forEach(event => { + this.selectedDay = Object.assign(this.selectedDay, event.data); }); - - if (totalEvents > (values.length / 2)) - this.removeEvents(calendar, values); - else - this.insertEvents(calendar, values); + this.$.priceDialog.show(); } - insertEvents(calendar, days) { - days.forEach(day => { - const event = calendar.events.find(event => { - return event.dated >= day.dated && event.dated <= day.dated; - }); + onResponse(response) { + if (response == 'ACCEPT') { + try { + const data = { + delivered: this.selectedDay.delivered, + price: this.selectedDay.price, + bonus: this.selectedDay.bonus, + option: this.selectedDay.option + }; - if (event) return false; + this.$.watcher.check(); - this.$scope.model.insert({ - zoneFk: this.zone.id, - delivered: day.dated - }); - - calendar.addEvent({ - dated: day.dated, - className: 'green-circle', - title: 'Has delivery' - }); - }); - - this.$scope.model.save().then(() => { - this.events = calendar.events; - }); - } - - removeEvents(calendar, days) { - let dates = []; - days.forEach(day => { - const event = calendar.events.find(event => { - return event.dated >= day.dated && event.dated <= day.dated; - }); - - if (event && !event.isRemovable) + const path = `/api/Zones/${this.zone.id}/editPrices`; + this.$http.post(path, data).then(() => { + this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.$.model.refresh(); + this.card.reload(); + }); + } catch (e) { + this.vnApp.showError(this.$translate.instant(e.message)); return false; + } + } - dates.push(day.dated); + return this.onClose(); + } - calendar.removeEvent(day.dated); - }); + onClose() { + this.$.watcher.updateOriginalData(); + } - if (dates.length == 0) return; - const params = {zoneFk: this.zone.id, dates}; - this.$http.post('/agency/api/zoneCalendars/removeByDate', params).then(() => { - this.events = calendar.events; + onMoveNext(calendars) { + calendars.forEach(calendar => { + calendar.moveNext(2); }); } - onMoveNext(calendar) { - calendar.moveNext(2); - } - - onMovePrevious(calendar) { - calendar.movePrevious(2); + onMovePrevious(calendars) { + calendars.forEach(calendar => { + calendar.movePrevious(2); + }); } } -Controller.$inject = ['$element', '$scope', '$stateParams', '$http']; +Controller.$inject = ['$element', '$scope', '$http', '$filter', '$translate', '$stateParams', 'vnApp']; ngModule.component('vnZoneCalendar', { template: require('./index.html'), controller: Controller, bindings: { zone: '<' + }, + require: { + card: '^vnZoneCard' } }); diff --git a/modules/agency/front/calendar/locale/es.yml b/modules/agency/front/calendar/locale/es.yml new file mode 100644 index 000000000..a37eeb272 --- /dev/null +++ b/modules/agency/front/calendar/locale/es.yml @@ -0,0 +1,6 @@ +Prices: Precios +Edit price: Modificar precio +Only this day: Solo este día +From this day: A partir de este día +All days: Todos los días +There's no delivery for this day: No hay reparto para este día \ No newline at end of file diff --git a/modules/agency/front/calendar/style.scss b/modules/agency/front/calendar/style.scss new file mode 100644 index 000000000..783bad77d --- /dev/null +++ b/modules/agency/front/calendar/style.scss @@ -0,0 +1,3 @@ +vn-calendar:nth-child(2n + 1) { + border-right:1px solid #ddd +} \ No newline at end of file diff --git a/modules/agency/front/index.js b/modules/agency/front/index.js index f58cc8f60..5e4103b43 100644 --- a/modules/agency/front/index.js +++ b/modules/agency/front/index.js @@ -8,4 +8,5 @@ import './search-panel'; import './create'; import './basic-data'; import './location'; +import './location/calendar'; import './calendar'; diff --git a/modules/agency/front/location/calendar.html b/modules/agency/front/location/calendar.html new file mode 100644 index 000000000..a1db6f08a --- /dev/null +++ b/modules/agency/front/location/calendar.html @@ -0,0 +1,21 @@ + + + + + + \ No newline at end of file diff --git a/modules/agency/front/location/calendar.js b/modules/agency/front/location/calendar.js new file mode 100644 index 000000000..802a9946e --- /dev/null +++ b/modules/agency/front/location/calendar.js @@ -0,0 +1,150 @@ +import ngModule from '../module'; + +class Controller { + constructor($element, $scope, $stateParams, $http) { + this.$element = $element; + this.$stateParams = $stateParams; + this.$scope = $scope; + this.$http = $http; + this.stMonthDate = new Date(); + this.ndMonthDate = new Date(); + this.ndMonthDate.setMonth(this.ndMonthDate.getMonth() + 1); + } + + $postLink() { + this.stMonth = this.$scope.stMonth; + this.ndMonth = this.$scope.ndMonth; + } + + // Disabled until implementation + // of holidays by node + /* get zone() { + return this._zone; + } + + set zone(value) { + this._zone = value; + + if (!value) return; + + let query = '/agency/api/LabourHolidays/getByWarehouse'; + this.$http.get(query, {params: {warehouseFk: value.warehouseFk}}).then(res => { + if (!res.data) return; + const events = []; + res.data.forEach(holiday => { + events.push({ + date: holiday.dated, + className: 'red', + title: holiday.description || holiday.name, + isRemovable: false + }); + }); + + this.events = this.events.concat(events); + }); + } */ + + get data() { + return this._data; + } + + set data(value) { + this._data = value; + + if (!value) return; + const events = []; + value.forEach(event => { + events.push({ + name: 'Has delivery', + dated: event.delivered, + style: {backgroundColor: '#a3d131'} + }); + }); + + this.events = events; + } + + onSelection(values, calendar) { + let totalEvents = 0; + values.forEach(day => { + const exists = calendar.events.findIndex(event => { + return event.dated >= day.dated && event.dated <= day.dated + && event.isRemovable; + }); + + if (exists > -1) totalEvents++; + }); + + if (totalEvents > (values.length / 2)) + this.removeEvents(calendar, values); + else + this.insertEvents(calendar, values); + } + + insertEvents(calendar, days) { + days.forEach(day => { + const event = calendar.events.find(event => { + return event.dated >= day.dated && event.dated <= day.dated; + }); + + if (event) return false; + + this.$scope.model.insert({ + zoneFk: this.zone.id, + delivered: day.dated, + price: this.zone.price, + bonus: this.zone.bonus + }); + + calendar.addEvent({ + name: 'Has delivery', + dated: day.dated, + style: {backgroundColor: '#a3d131'} + }); + }); + + this.$scope.model.save().then(() => { + this.events = calendar.events; + }); + } + + removeEvents(calendar, days) { + let dates = []; + days.forEach(day => { + const event = calendar.events.find(event => { + return event.dated >= day.dated && event.dated <= day.dated; + }); + + if (event && !event.isRemovable) + return false; + + dates.push(day.dated); + + calendar.removeEvent(day.dated); + }); + + if (dates.length == 0) return; + const params = {zoneFk: this.zone.id, dates}; + this.$http.post('/agency/api/zoneCalendars/removeByDate', params).then(() => { + this.events = calendar.events; + }); + } + + onMoveNext(calendar) { + calendar.moveNext(2); + } + + onMovePrevious(calendar) { + calendar.movePrevious(2); + } +} + +Controller.$inject = ['$element', '$scope', '$stateParams', '$http']; + +ngModule.component('vnZoneLocationCalendar', { + template: require('./calendar.html'), + controller: Controller, + bindings: { + zone: '<' + } +}); diff --git a/modules/agency/front/location/index.html b/modules/agency/front/location/index.html index 42662ef2b..fb9bf863c 100644 --- a/modules/agency/front/location/index.html +++ b/modules/agency/front/location/index.html @@ -18,6 +18,6 @@ - + \ No newline at end of file diff --git a/modules/agency/front/routes.json b/modules/agency/front/routes.json index fe4e74707..2125b1172 100644 --- a/modules/agency/front/routes.json +++ b/modules/agency/front/routes.json @@ -6,7 +6,8 @@ "dependencies": ["worker"], "menu": [ {"state": "zone.card.basicData", "icon": "settings"}, - {"state": "zone.card.location", "icon": "my_location"} + {"state": "zone.card.location", "icon": "my_location"}, + {"state": "zone.card.calendar"} ], "routes": [ { @@ -15,27 +16,31 @@ "abstract": true, "component": "ui-view", "description": "Zones" - }, { + }, + { "url": "/index?q", "state": "zone.index", "component": "vn-zone-index", "description": "Zones" - }, { + }, + { "url": "/create", "state": "zone.create", "component": "vn-zone-create", "description": "New zone" - }, { + }, + { "url": "/:id", "state": "zone.card", "component": "vn-zone-card", "abstract": true, "description": "Detail" - }, { - "url": "/location?q", - "state": "zone.card.location", - "component": "vn-zone-location", - "description": "Locations", + }, + { + "url": "/summary", + "state": "zone.card.summary", + "component": "vn-zone-summary", + "description": "Summary", "params": { "zone": "$ctrl.zone" } @@ -50,10 +55,19 @@ } }, { - "url": "/summary", - "state": "zone.card.summary", - "component": "vn-zone-summary", - "description": "Summary", + "url": "/location?q", + "state": "zone.card.location", + "component": "vn-zone-location", + "description": "Locations", + "params": { + "zone": "$ctrl.zone" + } + }, + { + "url": "/calendar", + "state": "zone.card.calendar", + "component": "vn-zone-calendar", + "description": "Prices", "params": { "zone": "$ctrl.zone" } diff --git a/modules/client/back/models/defaulter.json b/modules/client/back/models/defaulter.json index b002fcca6..8d50356f1 100644 --- a/modules/client/back/models/defaulter.json +++ b/modules/client/back/models/defaulter.json @@ -27,6 +27,5 @@ "model": "Client", "foreignKey": "clientFk" } - }, - "scope" : {"where": {"amount": {"gt": 0}}} + } } \ No newline at end of file diff --git a/modules/client/front/summary/index.html b/modules/client/front/summary/index.html index f3fbc9753..37bee2814 100644 --- a/modules/client/front/summary/index.html +++ b/modules/client/front/summary/index.html @@ -186,7 +186,7 @@ info="Invoices minus payments"> diff --git a/modules/item/back/methods/item/specs/getDiary.spec.js b/modules/item/back/methods/item/specs/getDiary.spec.js index 4800fa3a9..1bbb2c536 100644 --- a/modules/item/back/methods/item/specs/getDiary.spec.js +++ b/modules/item/back/methods/item/specs/getDiary.spec.js @@ -1,11 +1,14 @@ const app = require('vn-loopback/server/server'); describe('item getDiary()', () => { - it('should return 2 entries, the first one with the property balance -100', async() => { + it('should check the property balance of the 4 resultant entries', async() => { let params = {where: {itemFk: 1, warehouseFk: 2}}; let result = await app.models.Item.getDiary(params); - expect(result.length).toBe(2); - expect(result[0].balance).toBe(-100); + expect(result.length).toBe(4); + expect(result[0].balance).toBe(-1000); + expect(result[1].balance).toBe(-1100); + expect(result[2].balance).toBe(-1110); + expect(result[3].balance).toBe(-1210); }); }); diff --git a/modules/item/back/methods/item/specs/getLastEntries.spec.js b/modules/item/back/methods/item/specs/getLastEntries.spec.js index 5147dd126..5c996d8e3 100644 --- a/modules/item/back/methods/item/specs/getLastEntries.spec.js +++ b/modules/item/back/methods/item/specs/getLastEntries.spec.js @@ -9,7 +9,7 @@ describe('item getLastEntries()', () => { expect(result.length).toEqual(1); }); - it('should return three entries for a given item', async() => { + it('should return five entries for a given item', async() => { let date = new Date(); date.setMonth(date.getMonth() - 2, 1); @@ -17,6 +17,6 @@ describe('item getLastEntries()', () => { let filter = {where: {itemFk: 1, date: date}}; let result = await app.models.Item.getLastEntries(filter); - expect(result.length).toEqual(3); + expect(result.length).toEqual(5); }); }); diff --git a/modules/route/back/methods/route/specs/filter.spec.js b/modules/route/back/methods/route/specs/filter.spec.js index 01ad20d2b..820ecf291 100644 --- a/modules/route/back/methods/route/specs/filter.spec.js +++ b/modules/route/back/methods/route/specs/filter.spec.js @@ -51,7 +51,7 @@ describe('Route filter()', () => { let result = await app.models.Route.filter(ctx); - expect(result.length).toEqual(4); + expect(result.length).toEqual(3); }); it('should return the routes matching "description"', async() => { diff --git a/modules/route/back/methods/route/specs/updateVolume.spec.js b/modules/route/back/methods/route/specs/updateVolume.spec.js index 38e165090..eea3ed773 100644 --- a/modules/route/back/methods/route/specs/updateVolume.spec.js +++ b/modules/route/back/methods/route/specs/updateVolume.spec.js @@ -10,7 +10,7 @@ describe('route updateVolume()', () => { afterAll(async done => { - await originalRoute.updateAttributes({m3: 0.1}); + await originalRoute.updateAttributes({m3: 0.3}); await ticketToRestore.updateAttributes({routeFk: 2}); await app.models.RouteLog.destroyById(logIdToDestroy); done(); @@ -19,7 +19,7 @@ describe('route updateVolume()', () => { it('should confirm the original volume of the route is the expected', async() => { originalRoute = await app.models.Route.findById(routeId); - expect(originalRoute.m3).toEqual(0.1); + expect(originalRoute.m3).toEqual(0.3); }); it('should confirm the route volume is updated when a ticket is added', async() => { @@ -37,7 +37,7 @@ describe('route updateVolume()', () => { it('should confirm the change is logged', async() => { let logs = await app.models.RouteLog.find({fields: ['id', 'newInstance']}); let m3Log = logs.filter(log => { - return log.newInstance.m3 === 0.2; + return log.newInstance.m3 === 0.4; }); logIdToDestroy = m3Log[0].id; diff --git a/modules/ticket/back/methods/ticket/specs/getSalespersonMana.spec.js b/modules/ticket/back/methods/ticket/specs/getSalespersonMana.spec.js index 868366787..b337248e8 100644 --- a/modules/ticket/back/methods/ticket/specs/getSalespersonMana.spec.js +++ b/modules/ticket/back/methods/ticket/specs/getSalespersonMana.spec.js @@ -4,7 +4,7 @@ describe('ticket getSalesPersonMana()', () => { it('should get the mana of a salesperson of a given ticket', async() => { let mana = await app.models.Ticket.getSalesPersonMana(1); - expect(mana).toEqual(261); + expect(mana).toEqual(301); }); it('should return 0 if the given ticket does not exist', async() => { diff --git a/modules/worker/back/methods/worker-mana/specs/getCurrentWorkerMana.spec.js b/modules/worker/back/methods/worker-mana/specs/getCurrentWorkerMana.spec.js index d897f464c..dfb96190b 100644 --- a/modules/worker/back/methods/worker-mana/specs/getCurrentWorkerMana.spec.js +++ b/modules/worker/back/methods/worker-mana/specs/getCurrentWorkerMana.spec.js @@ -4,7 +4,7 @@ describe('workerMana getCurrentWorkerMana()', () => { it('should get the mana of the logged worker', async() => { let mana = await app.models.WorkerMana.getCurrentWorkerMana({req: {accessToken: {userId: 18}}}); - expect(mana).toEqual(261); + expect(mana).toEqual(301); }); it('should return 0 if the user doesnt uses mana', async() => { diff --git a/modules/worker/front/calendar/index.html b/modules/worker/front/calendar/index.html index 9952e1d81..9427ca9e8 100644 --- a/modules/worker/front/calendar/index.html +++ b/modules/worker/front/calendar/index.html @@ -3,7 +3,7 @@ data="$ctrl.absenceTypes" auto-load="true">
- +
{ const absenceType = absence.absenceType; events.push({ + name: absenceType.name, + description: absenceType.name, dated: absence.dated, - title: absenceType.name, - style: { - background: absenceType.rgb - } + style: {backgroundColor: absenceType.rgb} }); }); this.events = this.events.concat(events); diff --git a/modules/worker/front/calendar/index.spec.js b/modules/worker/front/calendar/index.spec.js index 194ea8f8b..f29b8fecc 100644 --- a/modules/worker/front/calendar/index.spec.js +++ b/modules/worker/front/calendar/index.spec.js @@ -93,7 +93,7 @@ describe('Worker', () => { controller.setHolidays(data); expect(controller.events.length).toEqual(2); - expect(controller.events[0].title).toEqual('New year'); + expect(controller.events[0].name).toEqual('New year'); expect(controller.events[0].isRemovable).toEqual(false); }); }); @@ -107,9 +107,9 @@ describe('Worker', () => { controller.setWorkerCalendar(data); expect(controller.events.length).toEqual(2); - expect(controller.events[0].title).toEqual('Holiday'); + expect(controller.events[0].name).toEqual('Holiday'); expect(controller.events[0].style).toBeDefined(); - expect(controller.events[1].title).toEqual('Leave'); + expect(controller.events[1].name).toEqual('Leave'); expect(controller.events[1].style).toBeDefined(); }); }); diff --git a/modules/worker/front/calendar/style.scss b/modules/worker/front/calendar/style.scss index 70503336a..5028edf32 100644 --- a/modules/worker/front/calendar/style.scss +++ b/modules/worker/front/calendar/style.scss @@ -1,5 +1,13 @@ @import "variables"; +.calendar-list .calendar { + border-bottom:1px solid #ddd +} + +.calendar-list .calendar:nth-child(2n + 1) { + border-right:1px solid #ddd +} + .calendar-list { align-items: flex-start; flex-wrap: wrap; @@ -9,7 +17,7 @@ box-sizing: border-box; padding: $pad-medium; overflow: hidden; - width: 20em + width: 50% } }