From af2fca38799aa88941a639103071ea9b9d428ffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Thu, 15 Mar 2018 14:36:09 +0100 Subject: [PATCH] Ticket packages, moved Item model to loopback service --- client/client/src/summary/client-summary.js | 83 +++++++------------ client/ticket/routes.json | 18 ++++ .../ticket/src/package/list/package-list.html | 56 +++++++++++++ .../ticket/src/package/list/package-list.js | 19 +++++ client/ticket/src/package/locale/es.yml | 6 ++ client/ticket/src/ticket.js | 1 + .../crudItemBarcodes.js | 0 .../spec}/crudItemBarcodes.spec.js | 0 .../methods/{item => item-log}/getLog.js | 0 .../{item => item-niche}/crudItemNiches.js | 0 .../spec}/crudItemNiches.spec.js | 0 .../{item => item-tag}/crudItemTags.js | 0 services/item/common/models/item-barcode.js | 2 +- services/item/common/models/item-log.js | 2 +- services/item/common/models/item-niche.js | 2 +- services/item/common/models/item-tag.js | 2 +- services/item/server/model-config.json | 21 ----- services/loopback/common/locale/es.json | 5 +- .../common/methods/item/clone.js | 4 +- .../common/methods/item/filter.js | 0 .../common/methods/item/updateTaxes.js | 0 .../common/models/expence.json | 0 .../{item => loopback}/common/models/ink.json | 0 .../common/models/intrastat.json | 0 .../common/models/item-type.json | 0 .../{item => loopback}/common/models/item.js | 2 +- .../common/models/item.json | 0 .../common/models/origin.json | 0 .../common/models/producer.json | 0 services/loopback/common/models/specie.json | 43 ++++++++++ services/loopback/common/models/ticket.json | 5 ++ services/loopback/server/model-config.json | 23 ++++- .../common/methods/packaging/listPackaging.js | 49 +++++++++++ services/ticket/common/models/packaging.js | 3 + services/ticket/common/models/packaging.json | 2 +- 35 files changed, 265 insertions(+), 83 deletions(-) create mode 100644 client/ticket/src/package/list/package-list.html create mode 100644 client/ticket/src/package/list/package-list.js create mode 100644 client/ticket/src/package/locale/es.yml rename services/item/common/methods/{item => item-barcode}/crudItemBarcodes.js (100%) rename services/item/common/methods/{item/specs => item-barcode/spec}/crudItemBarcodes.spec.js (100%) rename services/item/common/methods/{item => item-log}/getLog.js (100%) rename services/item/common/methods/{item => item-niche}/crudItemNiches.js (100%) rename services/item/common/methods/{item/specs => item-niche/spec}/crudItemNiches.spec.js (100%) rename services/item/common/methods/{item => item-tag}/crudItemTags.js (100%) rename services/{item => loopback}/common/methods/item/clone.js (90%) rename services/{item => loopback}/common/methods/item/filter.js (100%) rename services/{item => loopback}/common/methods/item/updateTaxes.js (100%) rename services/{item => loopback}/common/models/expence.json (100%) rename services/{item => loopback}/common/models/ink.json (100%) rename services/{item => loopback}/common/models/intrastat.json (100%) rename services/{item => loopback}/common/models/item-type.json (100%) rename services/{item => loopback}/common/models/item.js (92%) rename services/{item => loopback}/common/models/item.json (100%) rename services/{item => loopback}/common/models/origin.json (100%) rename services/{item => loopback}/common/models/producer.json (100%) create mode 100644 services/loopback/common/models/specie.json create mode 100644 services/ticket/common/methods/packaging/listPackaging.js create mode 100644 services/ticket/common/models/packaging.js diff --git a/client/client/src/summary/client-summary.js b/client/client/src/summary/client-summary.js index a3e7c7bae..2a6b9e3f3 100644 --- a/client/client/src/summary/client-summary.js +++ b/client/client/src/summary/client-summary.js @@ -1,53 +1,29 @@ import ngModule from '../module'; -class ClientSummary { +class Controller { constructor($http) { this.$http = $http; } - set client(value) { - if (!value) + $onChanges() { + if (!this.client || !this.client.id) return; + this.getSummary(); + this.getGreuse(); + this.getRecoveries(); + } + + getSummary() { let filter = { include: [ - { - relation: 'account', - scope: { - fields: ['name', 'active'] - } - }, - { - relation: 'salesPerson', - scope: { - fields: ['name'] - } - }, - { - relation: 'country', - scope: { - fields: ['country'] - } - }, - { - relation: 'province', - scope: { - fields: ['name'] - } - }, - { - relation: 'contactChannel', - scope: { - fields: ['name'] - } - }, - { - relation: 'payMethod', - scope: { - fields: ['name'] - } - }, + {relation: 'account', scope: {fields: ['name', 'active']}}, + {relation: 'salesPerson', scope: {fields: ['name']}}, + {relation: 'country', scope: {fields: ['country']}}, + {relation: 'province', scope: {fields: ['name']}}, + {relation: 'contactChannel', scope: {fields: ['name']}}, + {relation: 'payMethod', scope: {fields: ['name']}}, { relation: 'addresses', scope: { @@ -57,43 +33,46 @@ class ClientSummary { } ] }; + filter = encodeURIComponent(JSON.stringify(filter)); - let clientSummary = `/client/api/Clients/${value.id}?filter=${JSON.stringify(filter)}`; - - this.$http.get(encodeURIComponent(clientSummary)).then(res => { + let query = `/client/api/Clients/${this.client.id}?filter=${filter}`; + this.$http.get(query).then(res => { if (res.data) { this.summary = res.data; this.address = res.data.addresses[0]; } }); + } - let greugeSum = `/client/api/Greuges/${value.id}/sumAmount`; - - this.$http.get(encodeURIComponent(greugeSum)).then(res => { + getGreuse() { + let query = `/client/api/Greuges/${this.client.id}/sumAmount`; + this.$http.get(query).then(res => { if (res.data) this.greuge = res.data; }); + } - let recoveryFilter = { + getRecoveries() { + let filter = { where: { - and: [{clientFk: value.id}, {or: [{finished: null}, {finished: {gt: Date.now()}}]}] + and: [{clientFk: this.client.id}, {or: [{finished: null}, {finished: {gt: Date.now()}}]}] }, limit: 1 }; + filter = encodeURIComponent(JSON.stringify(filter)); - let recovery = `/client/api/Recoveries?filter=${JSON.stringify(recoveryFilter)}`; - - this.$http.get(encodeURIComponent(recovery)).then(res => { + let query = `/client/api/Recoveries?filter=${filter}`; + this.$http.get(query).then(res => { if (res.data) this.recovery = res.data[0]; }); } } -ClientSummary.$inject = ['$http']; +Controller.$inject = ['$http']; ngModule.component('vnClientSummary', { template: require('./client-summary.html'), - controller: ClientSummary, + controller: Controller, bindings: { client: '<' } diff --git a/client/ticket/routes.json b/client/ticket/routes.json index cfcdd0e4b..ed43ed6ec 100644 --- a/client/ticket/routes.json +++ b/client/ticket/routes.json @@ -45,6 +45,24 @@ "description": "Basic data", "icon": "settings" } + }, + { + "url" : "/package", + "abstract": true, + "state": "ticket.card.package", + "component": "ui-view" + }, + { + "url": "/list", + "state": "ticket.card.package.list", + "component": "vn-ticket-package-list", + "params": { + "ticket": "$ctrl.ticket" + }, + "menu": { + "description": "Packages", + "icon": "icon-bucket" + } } ] } \ No newline at end of file diff --git a/client/ticket/src/package/list/package-list.html b/client/ticket/src/package/list/package-list.html new file mode 100644 index 000000000..6a895361e --- /dev/null +++ b/client/ticket/src/package/list/package-list.html @@ -0,0 +1,56 @@ + + + + + Packages + + + + {{id}} : {{name}} + + + + + + + + + + + + + + + + diff --git a/client/ticket/src/package/list/package-list.js b/client/ticket/src/package/list/package-list.js new file mode 100644 index 000000000..f77a77418 --- /dev/null +++ b/client/ticket/src/package/list/package-list.js @@ -0,0 +1,19 @@ +import ngModule from '../../module'; + +class Controller { + + construct($http, $scope) { + this.$http = $http; + this.$ = $scope; + } +} + +Controller.$inject = ['$http', '$scope']; + +ngModule.component('vnTicketPackageList', { + template: require('./package-list.html'), + controller: Controller, + bindings: { + ticket: '<' + } +}); diff --git a/client/ticket/src/package/locale/es.yml b/client/ticket/src/package/locale/es.yml new file mode 100644 index 000000000..93ef2231d --- /dev/null +++ b/client/ticket/src/package/locale/es.yml @@ -0,0 +1,6 @@ +Packages: Embalajes +Package: Embalaje +Quantity: Cantidad +Added: Añadido +Add package: Añadir embalaje +Remove package: Quitar embalaje \ No newline at end of file diff --git a/client/ticket/src/ticket.js b/client/ticket/src/ticket.js index 12d84e555..50b8e5d8a 100644 --- a/client/ticket/src/ticket.js +++ b/client/ticket/src/ticket.js @@ -5,3 +5,4 @@ import './create/ticket-create'; import './card/ticket-card'; import './summary/ticket-summary'; import './data/ticket-data'; +import './package/list/package-list'; diff --git a/services/item/common/methods/item/crudItemBarcodes.js b/services/item/common/methods/item-barcode/crudItemBarcodes.js similarity index 100% rename from services/item/common/methods/item/crudItemBarcodes.js rename to services/item/common/methods/item-barcode/crudItemBarcodes.js diff --git a/services/item/common/methods/item/specs/crudItemBarcodes.spec.js b/services/item/common/methods/item-barcode/spec/crudItemBarcodes.spec.js similarity index 100% rename from services/item/common/methods/item/specs/crudItemBarcodes.spec.js rename to services/item/common/methods/item-barcode/spec/crudItemBarcodes.spec.js diff --git a/services/item/common/methods/item/getLog.js b/services/item/common/methods/item-log/getLog.js similarity index 100% rename from services/item/common/methods/item/getLog.js rename to services/item/common/methods/item-log/getLog.js diff --git a/services/item/common/methods/item/crudItemNiches.js b/services/item/common/methods/item-niche/crudItemNiches.js similarity index 100% rename from services/item/common/methods/item/crudItemNiches.js rename to services/item/common/methods/item-niche/crudItemNiches.js diff --git a/services/item/common/methods/item/specs/crudItemNiches.spec.js b/services/item/common/methods/item-niche/spec/crudItemNiches.spec.js similarity index 100% rename from services/item/common/methods/item/specs/crudItemNiches.spec.js rename to services/item/common/methods/item-niche/spec/crudItemNiches.spec.js diff --git a/services/item/common/methods/item/crudItemTags.js b/services/item/common/methods/item-tag/crudItemTags.js similarity index 100% rename from services/item/common/methods/item/crudItemTags.js rename to services/item/common/methods/item-tag/crudItemTags.js diff --git a/services/item/common/models/item-barcode.js b/services/item/common/models/item-barcode.js index be746ecb3..df121dcc3 100644 --- a/services/item/common/models/item-barcode.js +++ b/services/item/common/models/item-barcode.js @@ -1,3 +1,3 @@ module.exports = function(Self) { - require('../methods/item/crudItemBarcodes.js')(Self); + require('../methods/item-barcode/crudItemBarcodes.js')(Self); }; diff --git a/services/item/common/models/item-log.js b/services/item/common/models/item-log.js index 248cc6abd..a5ec25778 100644 --- a/services/item/common/models/item-log.js +++ b/services/item/common/models/item-log.js @@ -1,3 +1,3 @@ module.exports = function(Self) { - require('../methods/item/getLog.js')(Self); + require('../methods/item-log/getLog.js')(Self); }; diff --git a/services/item/common/models/item-niche.js b/services/item/common/models/item-niche.js index 8f9d85da7..edec4182e 100644 --- a/services/item/common/models/item-niche.js +++ b/services/item/common/models/item-niche.js @@ -1,3 +1,3 @@ module.exports = function(Self) { - require('../methods/item/crudItemNiches.js')(Self); + require('../methods/item-niche/crudItemNiches.js')(Self); }; diff --git a/services/item/common/models/item-tag.js b/services/item/common/models/item-tag.js index d4e768bdb..411528836 100644 --- a/services/item/common/models/item-tag.js +++ b/services/item/common/models/item-tag.js @@ -1,3 +1,3 @@ module.exports = function(Self) { - require('../methods/item/crudItemTags.js')(Self); + require('../methods/item-tag/crudItemTags.js')(Self); }; diff --git a/services/item/server/model-config.json b/services/item/server/model-config.json index 229054dd6..779816c19 100644 --- a/services/item/server/model-config.json +++ b/services/item/server/model-config.json @@ -1,22 +1,4 @@ { - "Item": { - "dataSource": "vn" - }, - "ItemType": { - "dataSource": "vn" - }, - "Ink": { - "dataSource": "vn" - }, - "Origin": { - "dataSource": "vn" - }, - "Producer": { - "dataSource": "vn" - }, - "Intrastat": { - "dataSource": "vn" - }, "TaxClass": { "dataSource": "vn" }, @@ -26,9 +8,6 @@ "TaxType": { "dataSource": "vn" }, - "Expence": { - "dataSource": "vn" - }, "ItemTag": { "dataSource": "vn" }, diff --git a/services/loopback/common/locale/es.json b/services/loopback/common/locale/es.json index d460ae82c..edf12882c 100644 --- a/services/loopback/common/locale/es.json +++ b/services/loopback/common/locale/es.json @@ -7,5 +7,8 @@ "El método de pago seleccionado requiere que se especifique el IBAN": "El método de pago seleccionado requiere que se especifique el IBAN", "can't be blank": "can't be blank", "DNI Incorrecto": "DNI Incorrecto", - "Ya existe un usuario con ese nombre": "Ya existe un usuario con ese nombre" + "Ya existe un usuario con ese nombre": "Ya existe un usuario con ese nombre", + "ValidationError: The `Item` instance is not valid. Details: `originFk` Cannot be blank (value: undefined).": "ValidationError: The `Item` instance is not valid. Details: `originFk` Cannot be blank (value: undefined).", + "Error: ER_NO_REFERENCED_ROW_2: Cannot add or update a child row: a foreign key constraint fails (`vn2008`.`Articles`, CONSTRAINT `Articles_ibfk_5` FOREIGN KEY (`tipo_id`) REFERENCES `Tipos` (`tipo_id`) ON UPDATE CASCADE)": "Error: ER_NO_REFERENCED_ROW_2: Cannot add or update a child row: a foreign key constraint fails (`vn2008`.`Articles`, CONSTRAINT `Articles_ibfk_5` FOREIGN KEY (`tipo_id`) REFERENCES `Tipos` (`tipo_id`) ON UPDATE CASCADE)", + "Error: ER_NO_REFERENCED_ROW_2: Cannot add or update a child row: a foreign key constraint fails (`vn2008`.`Articles`, CONSTRAINT `expenceFk` FOREIGN KEY (`expenceFk`) REFERENCES `Gastos` (`Id_Gasto`) ON UPDATE CASCADE)": "Error: ER_NO_REFERENCED_ROW_2: Cannot add or update a child row: a foreign key constraint fails (`vn2008`.`Articles`, CONSTRAINT `expenceFk` FOREIGN KEY (`expenceFk`) REFERENCES `Gastos` (`Id_Gasto`) ON UPDATE CASCADE)" } \ No newline at end of file diff --git a/services/item/common/methods/item/clone.js b/services/loopback/common/methods/item/clone.js similarity index 90% rename from services/item/common/methods/item/clone.js rename to services/loopback/common/methods/item/clone.js index f6f846751..a3e9e38fc 100644 --- a/services/item/common/methods/item/clone.js +++ b/services/loopback/common/methods/item/clone.js @@ -1,4 +1,4 @@ -var UserError = require('../../../../loopback/common/helpers').UserError; +var UserError = require('../../helpers').UserError; module.exports = Self => { Self.remoteMethod('clone', { @@ -27,7 +27,7 @@ module.exports = Self => { id: itemId }, include: [ - {relation: "itemTag", scope: {order: "priority ASC", include: {relation: "tag"}}} + {relation: 'itemTag', scope: {order: 'priority ASC', include: {relation: 'tag'}}} ] }; diff --git a/services/item/common/methods/item/filter.js b/services/loopback/common/methods/item/filter.js similarity index 100% rename from services/item/common/methods/item/filter.js rename to services/loopback/common/methods/item/filter.js diff --git a/services/item/common/methods/item/updateTaxes.js b/services/loopback/common/methods/item/updateTaxes.js similarity index 100% rename from services/item/common/methods/item/updateTaxes.js rename to services/loopback/common/methods/item/updateTaxes.js diff --git a/services/item/common/models/expence.json b/services/loopback/common/models/expence.json similarity index 100% rename from services/item/common/models/expence.json rename to services/loopback/common/models/expence.json diff --git a/services/item/common/models/ink.json b/services/loopback/common/models/ink.json similarity index 100% rename from services/item/common/models/ink.json rename to services/loopback/common/models/ink.json diff --git a/services/item/common/models/intrastat.json b/services/loopback/common/models/intrastat.json similarity index 100% rename from services/item/common/models/intrastat.json rename to services/loopback/common/models/intrastat.json diff --git a/services/item/common/models/item-type.json b/services/loopback/common/models/item-type.json similarity index 100% rename from services/item/common/models/item-type.json rename to services/loopback/common/models/item-type.json diff --git a/services/item/common/models/item.js b/services/loopback/common/models/item.js similarity index 92% rename from services/item/common/models/item.js rename to services/loopback/common/models/item.js index 35cff55d4..8eb0c16a1 100644 --- a/services/item/common/models/item.js +++ b/services/loopback/common/models/item.js @@ -1,4 +1,4 @@ -let UserError = require('../../../loopback/common/helpers').UserError; +let UserError = require('../helpers').UserError; module.exports = function(Self) { require('../methods/item/filter.js')(Self); diff --git a/services/item/common/models/item.json b/services/loopback/common/models/item.json similarity index 100% rename from services/item/common/models/item.json rename to services/loopback/common/models/item.json diff --git a/services/item/common/models/origin.json b/services/loopback/common/models/origin.json similarity index 100% rename from services/item/common/models/origin.json rename to services/loopback/common/models/origin.json diff --git a/services/item/common/models/producer.json b/services/loopback/common/models/producer.json similarity index 100% rename from services/item/common/models/producer.json rename to services/loopback/common/models/producer.json diff --git a/services/loopback/common/models/specie.json b/services/loopback/common/models/specie.json new file mode 100644 index 000000000..afa669af3 --- /dev/null +++ b/services/loopback/common/models/specie.json @@ -0,0 +1,43 @@ +{ + "name": "Specie", + "base": "VnModel", + "options": { + "mysql": { + "table": "specie" + } + }, + "properties": { + "specie_id": { + "type": "Number", + "id": true, + "description": "Identifier" + }, + "latin_species_name": { + "type": "String" + }, + "entry_date": { + "type": "date" + }, + "expiry_date": { + "type": "date" + }, + "change_date_time": { + "type": "date" + } + }, + "relations": { + "genus": { + "type": "belongsTo", + "model": "Genus", + "foreignKey": "genus_id" + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ] +} \ No newline at end of file diff --git a/services/loopback/common/models/ticket.json b/services/loopback/common/models/ticket.json index 493c18a78..cd50e1482 100644 --- a/services/loopback/common/models/ticket.json +++ b/services/loopback/common/models/ticket.json @@ -71,6 +71,11 @@ "model": "AgencyMode", "foreignKey": "agencyModeFk", "required": true + }, + "packages": { + "type": "hasMany", + "model": "TicketPackaging", + "foreignKey": "ticketFk" } } } \ No newline at end of file diff --git a/services/loopback/server/model-config.json b/services/loopback/server/model-config.json index b0d9eda0a..d04d34070 100644 --- a/services/loopback/server/model-config.json +++ b/services/loopback/server/model-config.json @@ -68,5 +68,26 @@ }, "TicketState":{ "dataSource": "vn" - } + }, + "Item": { + "dataSource": "vn" + }, + "Origin": { + "dataSource": "vn" + }, + "ItemType": { + "dataSource": "vn" + }, + "Expence": { + "dataSource": "vn" + }, + "Ink": { + "dataSource": "vn" + }, + "Intrastat": { + "dataSource": "vn" + }, + "Producer": { + "dataSource": "vn" + } } diff --git a/services/ticket/common/methods/packaging/listPackaging.js b/services/ticket/common/methods/packaging/listPackaging.js new file mode 100644 index 000000000..9aa1ad678 --- /dev/null +++ b/services/ticket/common/methods/packaging/listPackaging.js @@ -0,0 +1,49 @@ +module.exports = Self => { + Self.remoteMethod('listPackaging', { + description: 'Returns all packages including item', + accessType: 'READ', + accepts: [{ + arg: 'filter', + type: 'Object', + required: false, + description: 'Filter defining where and paginated data', + http: {source: 'query'} + }], + returns: { + type: ["Object"], + root: true + }, + http: { + path: `/listPackaging`, + verb: 'get' + } + }); + + Self.listPackaging = async filter => { + let where = ''; + let limit = ''; + let order = ''; + let params; + + if (filter) { + let connector = Self.dataSource.connector; + if (filter.where) { + if (filter.where.packagingFk) { + where = 'WHERE p.id = ?'; + params = [filter.where.packagingFk]; + } else { + let search = filter.where.name.regexp; + where = 'WHERE i.id REGEXP ? OR i.name REGEXP ?'; + params = [search, search]; + } + } + + limit = connector._buildLimit(null, filter.limit, filter.offset); + order = connector.buildOrderBy('Item', filter.order); + } + + let query = `SELECT i.name, i.id, p.id packagingFk FROM + item i JOIN packaging p ON i.id = p.itemFk ${where} ${order} ${limit}`; + return await Self.rawSql(query, params); + }; +}; diff --git a/services/ticket/common/models/packaging.js b/services/ticket/common/models/packaging.js new file mode 100644 index 000000000..c252d02ce --- /dev/null +++ b/services/ticket/common/models/packaging.js @@ -0,0 +1,3 @@ +module.exports = function(Self) { + require('../methods/packaging/listPackaging')(Self); +}; diff --git a/services/ticket/common/models/packaging.json b/services/ticket/common/models/packaging.json index 014730eab..9d5c098df 100644 --- a/services/ticket/common/models/packaging.json +++ b/services/ticket/common/models/packaging.json @@ -9,7 +9,7 @@ "properties": { "id": { "id": true, - "type": "Number", + "type": "String", "description": "Identifier" }, "volume": {