diff --git a/db/routines/vn/procedures/ticket_setVolume.sql b/db/routines/vn/procedures/ticket_setVolume.sql new file mode 100644 index 000000000..060a6fa57 --- /dev/null +++ b/db/routines/vn/procedures/ticket_setVolume.sql @@ -0,0 +1,24 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setVolume`( + vSelf INT +) +BEGIN +/** + * Update the volume ticket + * + * @param vSelf Ticket id + */ + DECLARE vVolume DECIMAL(10,6); + + SELECT SUM(s.quantity * ic.cm3delivery / 1000000) INTO vVolume + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN itemCost ic ON ic.itemFk = s.itemFk + AND ic.warehouseFk = t.warehouseFk + WHERE t.id = vSelf; + + UPDATE ticket + SET volume = vVolume + WHERE id = vSelf; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_setVolumeItemCost.sql b/db/routines/vn/procedures/ticket_setVolumeItemCost.sql new file mode 100644 index 000000000..f266cd769 --- /dev/null +++ b/db/routines/vn/procedures/ticket_setVolumeItemCost.sql @@ -0,0 +1,29 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setVolumeItemCost`( + vItemFk INT +) +BEGIN +/** + * Update the volume tickets of item + * + * @param vSelf Ticket id + */ + CREATE OR REPLACE TEMPORARY TABLE tTicket + (PRIMARY KEY (id)) + ENGINE = MEMORY + SELECT t.id, SUM(s.quantity * ic.cm3delivery / 1000000) volume + FROM sale s + JOIN ticket t ON t.id = s.ticketFk + JOIN itemCost ic ON ic.itemFk = s.itemFk + AND ic.warehouseFk = t.warehouseFk + WHERE s.itemFk = vItemFk + AND t.shipped >= util.VN_CURDATE() + GROUP BY t.id; + + UPDATE ticket t + JOIN tTicket tt ON tt.id = t.id + SET t.volume = tt.volume; + + DROP TEMPORARY TABLE tTicket; +END$$ +DELIMITER ; diff --git a/db/versions/11124-greenBamboo/00-firstScript.sql b/db/versions/11124-greenBamboo/00-firstScript.sql new file mode 100644 index 000000000..6f47cbc21 --- /dev/null +++ b/db/versions/11124-greenBamboo/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.ticket ADD volume decimal(10,6) DEFAULT NULL NULL COMMENT 'Unidad en m3'; diff --git a/db/versions/11124-greenBamboo/01-firstScript.sql b/db/versions/11124-greenBamboo/01-firstScript.sql new file mode 100644 index 000000000..9cacbd5ff --- /dev/null +++ b/db/versions/11124-greenBamboo/01-firstScript.sql @@ -0,0 +1,16 @@ +-- Calculamos todos los volumenes de todos los tickets una sola vez +CREATE OR REPLACE TEMPORARY TABLE tmp.tTicketVolume + (PRIMARY KEY (id)) + ENGINE = MEMORY + SELECT t.id, SUM(s.quantity * ic.cm3delivery / 1000000) volume + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.itemCost ic ON ic.itemFk = s.itemFk + AND ic.warehouseFk = t.warehouseFk + GROUP BY t.id; + +UPDATE vn.ticket t + JOIN tmp.tTicketVolume tv ON tv.id = t.id + SET t.volume = tv.volume; + +DROP TEMPORARY TABLE tmp.tTicketVolume; diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index dcb1e3158..776544bc6 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -109,6 +109,11 @@ module.exports = Self => { arg: 'days', type: 'number', description: `N days interval` + }, + { + arg: 'invoiceAmount', + type: 'number', + description: `The invoice amount` } ], returns: { @@ -192,6 +197,7 @@ module.exports = Self => { e.companyFk, e.gestDocFk, e.invoiceInFk, + e.invoiceAmount, t.landed, s.name supplierName, s.nickname supplierAlias, diff --git a/modules/entry/back/models/entry.json b/modules/entry/back/models/entry.json index 833edf14d..383585fce 100644 --- a/modules/entry/back/models/entry.json +++ b/modules/entry/back/models/entry.json @@ -74,6 +74,9 @@ }, "observationEditorFk": { "type": "number" + }, + "invoiceAmount": { + "type": "number" } }, "relations": { @@ -108,4 +111,4 @@ "foreignKey": "typeFk" } } -} \ No newline at end of file +} diff --git a/modules/travel/back/methods/travel/filter.js b/modules/travel/back/methods/travel/filter.js index 3fa1d65f9..9f26423ce 100644 --- a/modules/travel/back/methods/travel/filter.js +++ b/modules/travel/back/methods/travel/filter.js @@ -71,7 +71,15 @@ module.exports = Self => { arg: 'continent', type: 'string', description: 'The continent code' - }, + }, { + arg: 'shipmentHour', + type: 'string', + description: 'The shipment hour' + }, { + arg: 'landingHour', + type: 'string', + description: 'The landing hour' + } ], returns: { type: ['Object'], @@ -130,6 +138,8 @@ module.exports = Self => { t.isReceived, t.m3, t.kg, + t.shipmentHour, + t.landingHour, t.cargoSupplierFk, t.totalEntries, am.name agencyModeName, diff --git a/modules/travel/back/models/travel.json b/modules/travel/back/models/travel.json index 701894a76..0ebf683e7 100644 --- a/modules/travel/back/models/travel.json +++ b/modules/travel/back/models/travel.json @@ -44,6 +44,12 @@ }, "agencyModeFk": { "type": "number" + }, + "shipmentHour": { + "type": "string" + }, + "landingHour": { + "type": "string" } }, "relations": { @@ -64,3 +70,4 @@ } } } +