From aecfe2b8a917de749643b46490f275898b7f38ac Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Thu, 20 Feb 2020 09:31:09 +0100 Subject: [PATCH 1/5] report entry-order --- db/dump/fixtures.sql | 26 ++-- .../reports/entry-order/assets/css/import.js | 9 ++ .../reports/entry-order/assets/css/style.css | 6 + .../reports/entry-order/entry-order.html | 140 ++++++++++++++++++ .../reports/entry-order/entry-order.js | 80 ++++++++++ .../reports/entry-order/locale/en.yml | 0 .../reports/entry-order/locale/es.yml | 16 ++ 7 files changed, 264 insertions(+), 13 deletions(-) create mode 100644 print/templates/reports/entry-order/assets/css/import.js create mode 100644 print/templates/reports/entry-order/assets/css/style.css create mode 100644 print/templates/reports/entry-order/entry-order.html create mode 100755 print/templates/reports/entry-order/entry-order.js create mode 100644 print/templates/reports/entry-order/locale/en.yml create mode 100644 print/templates/reports/entry-order/locale/es.yml diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index f7d5d94f1..7ef68f3a0 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -35,7 +35,7 @@ INSERT INTO `vn`.`packagingConfig`(`upperGap`) UPDATE `account`.`role` SET id = 100 WHERE id = 0; INSERT INTO `account`.`user`(`id`,`name`, `nickname`, `password`,`role`,`active`,`email`, `lang`) - SELECT id, name, CONCAT(name, 'Nick'),MD5('nightmare'), id, 1, CONCAT(name, '@mydomain.com'), 'EN' + SELECT id, name, CONCAT(name, 'Nick'),MD5('nightmare'), id, 1, CONCAT(name, '@mydomain.com'), 'en' FROM `account`.`role` WHERE id <> 20 ORDER BY id; @@ -55,18 +55,18 @@ INSERT INTO `hedera`.`tpvConfig`(`id`, `currency`, `terminal`, `transactionType` INSERT INTO `account`.`user`(`id`,`name`,`nickname`, `password`,`role`,`active`,`email`,`lang`) VALUES - (101, 'BruceWayne', 'Bruce Wayne', 'ac754a330530832ba1bf7687f577da91', 2, 1, 'BruceWayne@mydomain.com', 'ES'), - (102, 'PetterParker', 'Petter Parker', 'ac754a330530832ba1bf7687f577da91', 2, 1, 'PetterParker@mydomain.com', 'EN'), - (103, 'ClarkKent', 'Clark Kent', 'ac754a330530832ba1bf7687f577da91', 2, 1, 'ClarkKent@mydomain.com', 'FR'), - (104, 'TonyStark', 'Tony Stark', 'ac754a330530832ba1bf7687f577da91', 2, 1, 'TonyStark@mydomain.com', 'ES'), - (105, 'MaxEisenhardt', 'Max Eisenhardt', 'ac754a330530832ba1bf7687f577da91', 2, 1, 'MaxEisenhardt@mydomain.com', 'PT'), - (106, 'DavidCharlesHaller', 'David Charles Haller', 'ac754a330530832ba1bf7687f577da91', 1, 1, 'DavidCharlesHaller@mydomain.com', 'EN'), - (107, 'HankPym', 'Hank Pym', 'ac754a330530832ba1bf7687f577da91', 1, 1, 'HankPym@mydomain.com', 'EN'), - (108, 'CharlesXavier', 'Charles Xavier', 'ac754a330530832ba1bf7687f577da91', 1, 1, 'CharlesXavier@mydomain.com', 'EN'), - (109, 'BruceBanner', 'Bruce Banner', 'ac754a330530832ba1bf7687f577da91', 1, 1, 'BruceBanner@mydomain.com', 'EN'), - (110, 'JessicaJones', 'Jessica Jones', 'ac754a330530832ba1bf7687f577da91', 1, 1, 'JessicaJones@mydomain.com', 'EN'), - (111, 'Missing', 'Missing', 'ac754a330530832ba1bf7687f577da91', 2, 0, NULL, 'EN'), - (112, 'Trash', 'Trash', 'ac754a330530832ba1bf7687f577da91', 2, 0, NULL, 'EN'); + (101, 'BruceWayne', 'Bruce Wayne', 'ac754a330530832ba1bf7687f577da91', 2, 1, 'BruceWayne@mydomain.com', 'es'), + (102, 'PetterParker', 'Petter Parker', 'ac754a330530832ba1bf7687f577da91', 2, 1, 'PetterParker@mydomain.com', 'en'), + (103, 'ClarkKent', 'Clark Kent', 'ac754a330530832ba1bf7687f577da91', 2, 1, 'ClarkKent@mydomain.com', 'fr'), + (104, 'TonyStark', 'Tony Stark', 'ac754a330530832ba1bf7687f577da91', 2, 1, 'TonyStark@mydomain.com', 'es'), + (105, 'MaxEisenhardt', 'Max Eisenhardt', 'ac754a330530832ba1bf7687f577da91', 2, 1, 'MaxEisenhardt@mydomain.com', 'pt'), + (106, 'DavidCharlesHaller', 'David Charles Haller', 'ac754a330530832ba1bf7687f577da91', 1, 1, 'DavidCharlesHaller@mydomain.com', 'en'), + (107, 'HankPym', 'Hank Pym', 'ac754a330530832ba1bf7687f577da91', 1, 1, 'HankPym@mydomain.com', 'en'), + (108, 'CharlesXavier', 'Charles Xavier', 'ac754a330530832ba1bf7687f577da91', 1, 1, 'CharlesXavier@mydomain.com', 'en'), + (109, 'BruceBanner', 'Bruce Banner', 'ac754a330530832ba1bf7687f577da91', 1, 1, 'BruceBanner@mydomain.com', 'en'), + (110, 'JessicaJones', 'Jessica Jones', 'ac754a330530832ba1bf7687f577da91', 1, 1, 'JessicaJones@mydomain.com', 'en'), + (111, 'Missing', 'Missing', 'ac754a330530832ba1bf7687f577da91', 2, 0, NULL, 'en'), + (112, 'Trash', 'Trash', 'ac754a330530832ba1bf7687f577da91', 2, 0, NULL, 'en'); INSERT INTO `vn`.`worker`(`id`, `code`, `firstName`, `lastName`, `userFk`,`bossFk`, `phone`) VALUES diff --git a/print/templates/reports/entry-order/assets/css/import.js b/print/templates/reports/entry-order/assets/css/import.js new file mode 100644 index 000000000..fd8796c2b --- /dev/null +++ b/print/templates/reports/entry-order/assets/css/import.js @@ -0,0 +1,9 @@ +const Stylesheet = require(`${appPath}/core/stylesheet`); + +module.exports = new Stylesheet([ + `${appPath}/common/css/spacing.css`, + `${appPath}/common/css/misc.css`, + `${appPath}/common/css/layout.css`, + `${appPath}/common/css/report.css`, + `${__dirname}/style.css`]) + .mergeStyles(); diff --git a/print/templates/reports/entry-order/assets/css/style.css b/print/templates/reports/entry-order/assets/css/style.css new file mode 100644 index 000000000..4215e7181 --- /dev/null +++ b/print/templates/reports/entry-order/assets/css/style.css @@ -0,0 +1,6 @@ + + +h3 { + font-weight: 100; + color: #555 +} \ No newline at end of file diff --git a/print/templates/reports/entry-order/entry-order.html b/print/templates/reports/entry-order/entry-order.html new file mode 100644 index 000000000..170351cec --- /dev/null +++ b/print/templates/reports/entry-order/entry-order.html @@ -0,0 +1,140 @@ + + + + + + + + + +
+ +
+
+ + +
+
+ +
+
+
+
+
+
+

{{$t('title')}}

+ + + + + + + + + + + + + + + +
{{$t('entryId')}}{{entry.id}}
{{$t('date')}}{{entry.landed | date('%d-%m-%Y')}}
{{$t('ref')}}{{entry.ref}}
+
+
+
+
+
+
{{$t('supplierData')}}
+
+

{{supplier.name}}

+
+ {{supplier.street}} +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + +
{{$t('boxes')}}{{$t('packing')}}{{$t('concept')}}{{$t('quantity')}}{{$t('price')}}{{$t('amount')}}
+ {{$t('total')}} + {{getTotal() | currency('EUR', locale)}}
+ +
+
+
+
+

{{$t('notes')}}

+
+ {{entry.notes}} +
+
+
+
+
+
+
+ +
+
+ + +
+
+
+ + \ No newline at end of file diff --git a/print/templates/reports/entry-order/entry-order.js b/print/templates/reports/entry-order/entry-order.js new file mode 100755 index 000000000..6317871e4 --- /dev/null +++ b/print/templates/reports/entry-order/entry-order.js @@ -0,0 +1,80 @@ +const db = require(`${appPath}/core/database`); +const Component = require(`${appPath}/core/component`); +const reportHeader = new Component('report-header'); +const reportFooter = new Component('report-footer'); + +module.exports = { + name: 'entry-order', + async serverPrefetch() { + this.supplier = await this.fetchSupplier(this.entryId); + this.entry = await this.fetchEntry(this.entryId); + this.buys = await this.fetchBuys(this.entryId); + + if (!this.entry) + throw new Error('Something went wrong'); + }, + data() { + return {totalBalance: 0.00}; + }, + methods: { + fetchSupplier(entryId) { + return db.findOne( + `SELECT + s.name, + s.street + FROM supplier s + JOIN entry e ON e.supplierFk = s.id + WHERE e.id = ?`, [entryId]); + }, + fetchEntry(entryId) { + return db.findOne( + `SELECT + e.id, + e.ref, + e.notes, + c.code companyCode, + t.landed + FROM entry e + JOIN travel t ON t.id = e.travelFk + JOIN company c ON c.id = e.companyFk + WHERE e.id = ?`, [entryId]); + }, + fetchBuys(entryId) { + return db.rawSql( + `SELECT + b.itemFk, + b.quantity, + b.buyingValue, + b.stickers box, + b.packing, + i.name itemName, + i.tag5, + i.value5, + i.tag6, + i.value6, + i.tag7, + i.value7 + FROM buy b + JOIN item i ON i.id = b.itemFk + WHERE b.entryFk = ?`, [entryId]); + }, + getTotal() { + let total = 0.00; + this.buys.forEach(buy => { + total += buy.quantity * buy.buyingValue; + }); + + return total; + } + }, + components: { + 'report-header': reportHeader.build(), + 'report-footer': reportFooter.build() + }, + props: { + entryId: { + type: String, + required: true + } + } +}; diff --git a/print/templates/reports/entry-order/locale/en.yml b/print/templates/reports/entry-order/locale/en.yml new file mode 100644 index 000000000..e69de29bb diff --git a/print/templates/reports/entry-order/locale/es.yml b/print/templates/reports/entry-order/locale/es.yml new file mode 100644 index 000000000..dd4861f9d --- /dev/null +++ b/print/templates/reports/entry-order/locale/es.yml @@ -0,0 +1,16 @@ +title: Pedido +supplierName: Proveedor +supplierStreet: Dirección +entryId: Pedido nº +date: Fecha +ref: Referencia +boxes: Cajas +packing: U/C +quantity: Cantidad +price: Precio +amount: Importe +concept: Descripción +total: Total +entry: Entrada {0} +supplierData: Datos del proveedor +notes: Notas \ No newline at end of file From a8137c8a6b650bbae9c99cabeac052a8a4f91571 Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 20 Feb 2020 15:15:50 +0100 Subject: [PATCH 2/5] zoneClosure 3 --- db/changes/10141-zoneDoCalc/00-ticket.sql | 18 +--- .../01-ticketCreateWithUser.sql | 96 +++++++++++++++++++ .../01-ticket_componentUpdate.sql | 82 ++++++++++++++++ .../10141-zoneDoCalc/01-ticket_doCalc.sql | 56 ----------- .../01-zoneClosure_recalc.sql | 49 ++++++++++ .../10141-zoneDoCalc/02-insertPastTickets.sql | 8 +- .../03-zone_geShippedWarehouse.sql | 6 +- db/dump/fixtures.sql | 2 + modules/agency/back/model-config.json | 2 +- .../{zone-calc-ticket.js => zone-closure.js} | 10 +- ...one-calc-ticket.json => zone-closure.json} | 12 ++- 11 files changed, 255 insertions(+), 86 deletions(-) create mode 100644 db/changes/10141-zoneDoCalc/01-ticketCreateWithUser.sql create mode 100644 db/changes/10141-zoneDoCalc/01-ticket_componentUpdate.sql delete mode 100644 db/changes/10141-zoneDoCalc/01-ticket_doCalc.sql create mode 100644 db/changes/10141-zoneDoCalc/01-zoneClosure_recalc.sql rename modules/agency/back/models/{zone-calc-ticket.js => zone-closure.js} (61%) rename modules/agency/back/models/{zone-calc-ticket.json => zone-closure.json} (62%) diff --git a/db/changes/10141-zoneDoCalc/00-ticket.sql b/db/changes/10141-zoneDoCalc/00-ticket.sql index a756a11af..fa091f111 100644 --- a/db/changes/10141-zoneDoCalc/00-ticket.sql +++ b/db/changes/10141-zoneDoCalc/00-ticket.sql @@ -1,19 +1,3 @@ ALTER TABLE `vn`.`ticket` ADD COLUMN `zonePrice` DECIMAL(10,2) NULL DEFAULT NULL AFTER `collectionFk`, -ADD COLUMN `zoneBonus` DECIMAL(10,2) NULL DEFAULT NULL AFTER `zonePrice`, -ADD COLUMN `zoneClosure` TIME NULL AFTER `zoneBonus`; - -CREATE TABLE `vn`.`zoneCalcTicket` ( - `zoneFk` int(11) NOT NULL PRIMARY KEY, - CONSTRAINT `zoneCalcTicketfk_1` FOREIGN KEY (`zoneFk`) REFERENCES `vn`.`zone` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; - -DROP EVENT IF EXISTS vn.`zone_doCalc`; -CREATE DEFINER=`root`@`%` EVENT vn.`zone_doCalc` - ON SCHEDULE EVERY 15 SECOND STARTS '2020-01-31 11:32:30' - ON COMPLETION PRESERVE ENABLE - DO CALL util.procNoOverlap('vn.zone_doCalc'); - -DROP TABLE `vn`.`zoneConfig`; - -DROP procedure IF EXISTS vn.`zoneClosure_recalc`; \ No newline at end of file +ADD COLUMN `zoneBonus` DECIMAL(10,2) NULL DEFAULT NULL AFTER `zonePrice`; diff --git a/db/changes/10141-zoneDoCalc/01-ticketCreateWithUser.sql b/db/changes/10141-zoneDoCalc/01-ticketCreateWithUser.sql new file mode 100644 index 000000000..867cd1c0d --- /dev/null +++ b/db/changes/10141-zoneDoCalc/01-ticketCreateWithUser.sql @@ -0,0 +1,96 @@ +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 vZoneFk INT; + DECLARE vPrice DECIMAL(10,2); + DECLARE vBonus DECIMAL(10,2); + + 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 vAgencyModeFk IS NOT NULL THEN + + CALL vn.zone_getShippedWarehouse(vlanded, vAddressFk, vAgencyModeFk); + + SELECT zoneFk, price, bonus INTO vZoneFk, vPrice, vBonus + FROM tmp.zoneGetShipped + WHERE shipped = vShipped AND warehouseFk = vWarehouseFk LIMIT 1; + + IF vZoneFk IS NULL OR vZoneFk = 0 THEN + CALL util.throw ('NOT_ZONE_WITH_THIS_PARAMETERS'); + END IF; + END IF; + INSERT INTO ticket ( + clientFk, + shipped, + addressFk, + agencyModeFk, + nickname, + warehouseFk, + routeFk, + companyFk, + landed, + zoneFk, + zonePrice, + zoneBonus + ) + SELECT + vClientId, + vShipped, + a.id, + vAgencyModeFk, + a.nickname, + vWarehouseFk, + IF(vRouteFk,vRouteFk,NULL), + vCompanyFk, + vlanded, + vZoneFk, + vPrice, + vBonus + FROM address a + JOIN agencyMode am ON am.id = a.agencyModeFk + WHERE a.id = vAddressFk; + + SET vNewTicket = LAST_INSERT_ID(); + + INSERT INTO ticketObservation(ticketFk, observationTypeFk, description) + SELECT vNewTicket, ao.observationTypeFk, ao.description + FROM addressObservation ao + JOIN address a ON a.id = ao.addressFk + WHERE a.id = vAddressFk; + + INSERT INTO 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 ; + diff --git a/db/changes/10141-zoneDoCalc/01-ticket_componentUpdate.sql b/db/changes/10141-zoneDoCalc/01-ticket_componentUpdate.sql new file mode 100644 index 000000000..14ff6f484 --- /dev/null +++ b/db/changes/10141-zoneDoCalc/01-ticket_componentUpdate.sql @@ -0,0 +1,82 @@ +USE `vn`; +DROP procedure IF EXISTS `ticket_componentUpdate`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `ticket_componentUpdate`( + vTicketFk INT, + vClientFk INT, + vAgencyModeFk INT, + vAddressFk INT, + vZoneFk INT, + vWarehouseFk TINYINT, + vCompanyFk SMALLINT, + vShipped DATETIME, + vLanded DATE, + vIsDeleted BOOLEAN, + vHasToBeUnrouted BOOLEAN, + vOption INT) +BEGIN + DECLARE vPrice DECIMAL(10,2); + DECLARE vBonus DECIMAL(10,2); + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + + IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN + + UPDATE ticket t + JOIN address a ON a.id = vAddressFk + SET t.nickname = a.nickname + WHERE t.id = vTicketFk; + + END IF; + + CALL vn.zone_getShippedWarehouse(vlanded, vAddressFk, vAgencyModeFk); + + SELECT zoneFk, price, bonus INTO vZoneFk, vPrice, vBonus + FROM tmp.zoneGetShipped + WHERE shipped = vShipped AND warehouseFk = vWarehouseFk LIMIT 1; + + UPDATE ticket t + SET + t.clientFk = vClientFk, + t.agencyModeFk = vAgencyModeFk, + t.addressFk = vAddressFk, + t.zoneFk = vZoneFk, + t.zonePrice = vPrice, + t.zoneBonus = vBonus, + t.warehouseFk = vWarehouseFk, + t.companyFk = vCompanyFk, + t.landed = vLanded, + t.shipped = vShipped, + t.isDeleted = vIsDeleted + WHERE + t.id = vTicketFk; + + IF vHasToBeUnrouted THEN + UPDATE ticket t SET t.routeFk = NULL + WHERE t.id = vTicketFk; + END IF; + + IF vOption <> 8 THEN + DROP TEMPORARY TABLE IF EXISTS tmp.sale; + CREATE TEMPORARY TABLE tmp.sale + (PRIMARY KEY (saleFk)) + ENGINE = MEMORY + SELECT id AS saleFk, vWarehouseFk warehouseFk + FROM sale s WHERE s.ticketFk = vTicketFk; + + CALL ticketComponentUpdateSale (vOption); + + DROP TEMPORARY TABLE tmp.sale; + END IF; + COMMIT; +END$$ + +DELIMITER ; + diff --git a/db/changes/10141-zoneDoCalc/01-ticket_doCalc.sql b/db/changes/10141-zoneDoCalc/01-ticket_doCalc.sql deleted file mode 100644 index d7538ff84..000000000 --- a/db/changes/10141-zoneDoCalc/01-ticket_doCalc.sql +++ /dev/null @@ -1,56 +0,0 @@ -USE `vn`; -DROP procedure IF EXISTS `zone_doCalc`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `zone_doCalc`() -proc: BEGIN -/** - * Updates ticket fields related with zone - */ - DECLARE vDone BOOL; - DECLARE vTicketFk INT; - DECLARE vShipped DATE; - DECLARE vZoneFk INT; - - DECLARE cCur CURSOR FOR - SELECT t.id, t.shipped, t.zoneFk - FROM zoneCalcTicket zct - JOIN ticket t ON t.zoneFk = zct.zoneFk - WHERE shipped >= CURDATE(); - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; - - OPEN cCur; - - myLoop: LOOP - SET vDone = FALSE; - FETCH cCur INTO vTicketFk, vShipped, vZoneFk; - - IF vDone THEN - LEAVE myLoop; - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp.zone; - CREATE TEMPORARY TABLE tmp.zone - (INDEX (id)) - ENGINE = MEMORY - SELECT vZoneFk id; - - CALL zone_getOptionsForShipment(vShipped, TRUE); - - UPDATE ticket t - LEFT JOIN tmp.zoneOption zo ON TRUE - SET zonePrice = zo.price, zoneBonus = zo.bonus, zoneClosure = zo.`hour` - WHERE t.id = vTicketFk; - - END LOOP; - - CLOSE cCur; - - DELETE FROM zoneCalcTicket; -END$$ - -DELIMITER ; - diff --git a/db/changes/10141-zoneDoCalc/01-zoneClosure_recalc.sql b/db/changes/10141-zoneDoCalc/01-zoneClosure_recalc.sql new file mode 100644 index 000000000..b7dbf675a --- /dev/null +++ b/db/changes/10141-zoneDoCalc/01-zoneClosure_recalc.sql @@ -0,0 +1,49 @@ +USE `vn`; +DROP procedure IF EXISTS `zoneClosure_recalc`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `zoneClosure_recalc`() +proc: BEGIN +/** + * Recalculates the delivery time (hour) for every zone in days + scope in future + */ + DECLARE vScope INT; + DECLARE vCounter INT DEFAULT 0; + DECLARE vShipped DATE DEFAULT CURDATE(); + + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION + BEGIN + DO RELEASE_LOCK('vn.zoneClosure_recalc'); + RESIGNAL; + END; + + IF NOT GET_LOCK('vn.zoneClosure_recalc', 0) THEN + LEAVE proc; + END IF; + + SELECT scope INTO vScope + FROM zoneConfig; + + DROP TEMPORARY TABLE IF EXISTS tmp.zone; + CREATE TEMPORARY TABLE tmp.zone + (INDEX (id)) + ENGINE = MEMORY + SELECT id FROM zone; + + TRUNCATE TABLE zoneClosure; + + WHILE vCounter <= vScope DO + CALL zone_getOptionsForShipment(vShipped, TRUE); + INSERT INTO zoneClosure(zoneFk, dated, `hour`) + SELECT zoneFk, vShipped, `hour` FROM tmp.zoneOption; + + SET vCounter = vCounter + 1; + SET vShipped = TIMESTAMPADD(DAY, 1, vShipped); + END WHILE; + + DROP TEMPORARY TABLE tmp.zone; + DO RELEASE_LOCK('vn.zoneClosure_recalc'); +END$$ + +DELIMITER ; \ No newline at end of file diff --git a/db/changes/10141-zoneDoCalc/02-insertPastTickets.sql b/db/changes/10141-zoneDoCalc/02-insertPastTickets.sql index 4314e5d7d..864bf04c6 100644 --- a/db/changes/10141-zoneDoCalc/02-insertPastTickets.sql +++ b/db/changes/10141-zoneDoCalc/02-insertPastTickets.sql @@ -7,6 +7,7 @@ CREATE DEFINER=`root`@`%` PROCEDURE `zone_doCalcInitialize`() proc: BEGIN /** * Initialize ticket + * si en 01-07-20 aun esta este proc, kkear */ DECLARE vDone BOOL; DECLARE vTicketFk INT; @@ -16,7 +17,7 @@ proc: BEGIN DECLARE cCur CURSOR FOR SELECT t.id, t.landed, t.zoneFk FROM ticket t - WHERE (zonePrice IS NULL OR zoneBonus IS NULL OR zoneClosure IS NULL) + WHERE (zonePrice IS NULL OR zoneBonus IS NULL) AND landed >= '2019-01-01' AND shipped >= '2019-01-01' GROUP BY landed, zoneFk; @@ -43,12 +44,12 @@ proc: BEGIN UPDATE ticket t LEFT JOIN tmp.zoneOption zo ON TRUE - SET zonePrice = zo.price, zoneBonus = zo.bonus, zoneClosure = zo.`hour` + SET zonePrice = zo.price, zoneBonus = zo.bonus WHERE t.zoneFk = vZoneFk AND landed = vLanded; UPDATE ticket t LEFT JOIN vn.zone z ON z.id = t.zoneFk - SET zonePrice = z.price, zoneBonus = z.bonus, zoneClosure = z.`hour` + SET zonePrice = z.price, zoneBonus = z.bonus WHERE t.zonePrice IS NULL AND z.id = vZoneFk AND landed >= '2019-01-01' AND shipped >= '2019-01-01'; @@ -56,7 +57,6 @@ proc: BEGIN CLOSE cCur; - DELETE FROM zoneCalcTicket; END$$ DELIMITER ; \ No newline at end of file diff --git a/db/changes/10141-zoneDoCalc/03-zone_geShippedWarehouse.sql b/db/changes/10141-zoneDoCalc/03-zone_geShippedWarehouse.sql index 14d5d8cd9..b4605ec04 100644 --- a/db/changes/10141-zoneDoCalc/03-zone_geShippedWarehouse.sql +++ b/db/changes/10141-zoneDoCalc/03-zone_geShippedWarehouse.sql @@ -6,7 +6,7 @@ USE `vn`$$ CREATE DEFINER=`root`@`%` PROCEDURE `zone_getShippedWarehouse`(vLanded DATE, vAddressFk INT, vAgencyModeFk INT) BEGIN /** - * Devuelve la mínima fecha de envío para cada warehouse + * Devuelve la mínima fecha de envío para cada warehouse * * @param vLanded La fecha de recepcion * @param vAddressFk Id del consignatario @@ -25,7 +25,9 @@ BEGIN TIMESTAMPADD(DAY,-zo.travelingDays, vLanded) shipped, zo.`hour`, zw.warehouseFk, - z.agencyModeFk + z.agencyModeFk, + zo.price, + zo.bonus FROM tmp.zoneOption zo JOIN zoneWarehouse zw ON zw.zoneFk = zo.zoneFk JOIN zone z ON z.id = zo.zoneFk diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 87b915ec0..67db4dd77 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -497,6 +497,8 @@ INSERT INTO `vn`.`zoneWarehouse` (`id`, `zoneFk`, `warehouseFk`) (11, 11, 5), (12, 12, 4), (13, 13, 5); + +INSERT INTO `vn`.`zoneConfig` (`scope`) VALUES ('1'); INSERT INTO `vn`.`route`(`id`, `time`, `workerFk`, `created`, `vehicleFk`, `agencyModeFk`, `description`, `m3`, `cost`, `started`, `finished`, `zoneFk`) VALUES diff --git a/modules/agency/back/model-config.json b/modules/agency/back/model-config.json index c9a49ffe9..7638e3f6c 100644 --- a/modules/agency/back/model-config.json +++ b/modules/agency/back/model-config.json @@ -11,7 +11,7 @@ "Zone": { "dataSource": "vn" }, - "ZoneCalcTicket": { + "ZoneClosure": { "dataSource": "vn" }, "ZoneEvent": { diff --git a/modules/agency/back/models/zone-calc-ticket.js b/modules/agency/back/models/zone-closure.js similarity index 61% rename from modules/agency/back/models/zone-calc-ticket.js rename to modules/agency/back/models/zone-closure.js index c3633e8f4..d25d6f707 100644 --- a/modules/agency/back/models/zone-calc-ticket.js +++ b/modules/agency/back/models/zone-closure.js @@ -1,6 +1,5 @@ const app = require('vn-loopback/server/server'); - module.exports = Self => { app.on('started', function() { let models = ['Zone', 'ZoneEvent', 'ZoneExclusion']; @@ -14,10 +13,13 @@ module.exports = Self => { async function doCalc(ctx) { try { - await Self.create({zoneFk: ctx.instance.zoneFk || ctx.instance.id}); + await Self.rawSql(` + CREATE EVENT zoneClosure_doRecalc + ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 15 SECOND + DO CALL zoneClosure_recalc; + `); } catch (err) { - if (err.code != 'ER_DUP_ENTRY') - throw err; + if (err.code != 'ER_EVENT_ALREADY_EXISTS') throw err; } } }); diff --git a/modules/agency/back/models/zone-calc-ticket.json b/modules/agency/back/models/zone-closure.json similarity index 62% rename from modules/agency/back/models/zone-calc-ticket.json rename to modules/agency/back/models/zone-closure.json index 5083d08ed..895374838 100644 --- a/modules/agency/back/models/zone-calc-ticket.json +++ b/modules/agency/back/models/zone-closure.json @@ -1,15 +1,23 @@ { - "name": "ZoneCalcTicket", + "name": "ZoneClosure", "base": "VnModel", "options": { "mysql": { - "table": "zoneCalcTicket" + "table": "zoneClosure" } }, "properties": { "zoneFk": { "id": true, "type": "Number" + }, + "dated": { + "type": "Date", + "required": true + }, + "hour": { + "type": "date", + "required": true } }, "relations": { From 1908f454c10cb8695a05fdf5739ba676e6226e33 Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Fri, 21 Feb 2020 14:50:51 +0100 Subject: [PATCH 3/5] worker dms index --- modules/worker/front/dms/index/index.html | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/modules/worker/front/dms/index/index.html b/modules/worker/front/dms/index/index.html index 7859a50a4..2deffecf6 100644 --- a/modules/worker/front/dms/index/index.html +++ b/modules/worker/front/dms/index/index.html @@ -16,13 +16,10 @@ Id - Type - Order Reference Description Original File - Employee Created @@ -32,17 +29,6 @@ {{::document.dmsFk}} - - - {{::document.dms.dmsType.name}} - - - - - {{::document.dms.hardCopyNumber}} - - {{::document.dms.reference}} @@ -64,12 +50,6 @@ href="api/dms/{{::document.dmsFk}}/downloadFile?access_token={{::$ctrl.accessToken}}">{{::document.dms.file}} - - - {{::document.dms.worker.user.nickname | dashIfEmpty}} - - {{::document.dms.created | date:'dd/MM/yyyy HH:mm'}} From 005adc252d31cc2309c1bb6b742054fa0d53e130 Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Mon, 24 Feb 2020 08:05:26 +0100 Subject: [PATCH 4/5] worker dms index --- modules/worker/front/dms/index/index.html | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/modules/worker/front/dms/index/index.html b/modules/worker/front/dms/index/index.html index 7859a50a4..2deffecf6 100644 --- a/modules/worker/front/dms/index/index.html +++ b/modules/worker/front/dms/index/index.html @@ -16,13 +16,10 @@ Id - Type - Order Reference Description Original File - Employee Created @@ -32,17 +29,6 @@ {{::document.dmsFk}} - - - {{::document.dms.dmsType.name}} - - - - - {{::document.dms.hardCopyNumber}} - - {{::document.dms.reference}} @@ -64,12 +50,6 @@ href="api/dms/{{::document.dmsFk}}/downloadFile?access_token={{::$ctrl.accessToken}}">{{::document.dms.file}} - - - {{::document.dms.worker.user.nickname | dashIfEmpty}} - - {{::document.dms.created | date:'dd/MM/yyyy HH:mm'}} From c48da59314f64ed0729745f317d26c46949d8e3d Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Mon, 24 Feb 2020 08:44:43 +0100 Subject: [PATCH 5/5] report entry-order --- print/templates/reports/entry-order/entry-order.html | 6 ++++++ print/templates/reports/entry-order/entry-order.js | 7 ++++++- print/templates/reports/entry-order/locale/es.yml | 6 +++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/print/templates/reports/entry-order/entry-order.html b/print/templates/reports/entry-order/entry-order.html index 170351cec..cbb0de0d5 100644 --- a/print/templates/reports/entry-order/entry-order.html +++ b/print/templates/reports/entry-order/entry-order.html @@ -48,6 +48,12 @@
{{supplier.street}}
+
+ {{supplier.postCode}}, {{supplier.city}}, ({{supplier.province}}) +
+
+ {{supplier.nif}} +
diff --git a/print/templates/reports/entry-order/entry-order.js b/print/templates/reports/entry-order/entry-order.js index 6317871e4..55492fbaf 100755 --- a/print/templates/reports/entry-order/entry-order.js +++ b/print/templates/reports/entry-order/entry-order.js @@ -21,9 +21,14 @@ module.exports = { return db.findOne( `SELECT s.name, - s.street + s.street, + s.nif, + s.postCode, + s.city, + p.name province FROM supplier s JOIN entry e ON e.supplierFk = s.id + LEFT JOIN province p ON p.id = s.provinceFk WHERE e.id = ?`, [entryId]); }, fetchEntry(entryId) { diff --git a/print/templates/reports/entry-order/locale/es.yml b/print/templates/reports/entry-order/locale/es.yml index dd4861f9d..3c29d6401 100644 --- a/print/templates/reports/entry-order/locale/es.yml +++ b/print/templates/reports/entry-order/locale/es.yml @@ -1,11 +1,11 @@ title: Pedido supplierName: Proveedor supplierStreet: Dirección -entryId: Pedido nº +entryId: Referencia interna date: Fecha -ref: Referencia +ref: Nº Factura boxes: Cajas -packing: U/C +packing: U/C quantity: Cantidad price: Precio amount: Importe