From 1cb94329223ac63c47d83e2c3973941ead19b512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Mon, 26 Mar 2018 11:43:17 +0200 Subject: [PATCH 01/13] Credit insurance validations fix --- services/client/common/models/credit-insurance.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/services/client/common/models/credit-insurance.js b/services/client/common/models/credit-insurance.js index 95902ab9c..155d4de44 100644 --- a/services/client/common/models/credit-insurance.js +++ b/services/client/common/models/credit-insurance.js @@ -1,22 +1,22 @@ module.exports = function(Self) { require('../methods/creditInsurance/filter.js')(Self); + Self.validateCredit = function(credit) { + return credit >= 0; + }; + Self.validateBinded('credit', Self.validateCredit, { message: 'The credit must be an integer greater than or equal to zero', allowNull: false, // FIXME: Ignored by loopback when it's false allowBlank: false }); - Self.validateCredit = function(credit) { - return (credit >= 0 && credit % 1 == 0); + Self.validateGrade = function(grade) { + return typeof grade === 'undefined' || grade >= 0; }; Self.validateBinded('grade', Self.validateGrade, { message: 'The grade must be an integer greater than or equal to zero', allowNull: true }); - - Self.validateGrade = function(grade) { - return (typeof grade === 'undefined' || (grade >= 0 && grade % 1 == 0)); - }; }; From e38999acfa05f2e88477912caaa81a627fe90538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Mon, 26 Mar 2018 12:24:34 +0200 Subject: [PATCH 02/13] Hide clear icon on disabled components autocomplete and textfield --- client/core/src/components/autocomplete/autocomplete.html | 1 + client/core/src/components/autocomplete/autocomplete.js | 4 ++-- client/core/src/components/textfield/textfield.html | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/client/core/src/components/autocomplete/autocomplete.html b/client/core/src/components/autocomplete/autocomplete.html index 4d04f884f..7e6580d78 100755 --- a/client/core/src/components/autocomplete/autocomplete.html +++ b/client/core/src/components/autocomplete/autocomplete.html @@ -8,6 +8,7 @@
clear From b3b874c39deb168a664bc34e5ae3ea03bb75280b Mon Sep 17 00:00:00 2001 From: Gerard Date: Mon, 26 Mar 2018 14:55:10 +0200 Subject: [PATCH 03/13] Solucionado problema con el filter --- client/ticket/src/sale/sale.html | 2 +- client/ticket/src/sale/sale.js | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/client/ticket/src/sale/sale.html b/client/ticket/src/sale/sale.html index 5fcee01e4..531819ccf 100644 --- a/client/ticket/src/sale/sale.html +++ b/client/ticket/src/sale/sale.html @@ -1,4 +1,4 @@ - + diff --git a/client/ticket/src/sale/sale.js b/client/ticket/src/sale/sale.js index feaafefbe..ddf0ee7ed 100644 --- a/client/ticket/src/sale/sale.js +++ b/client/ticket/src/sale/sale.js @@ -1,7 +1,17 @@ import ngModule from '../module'; import FilterTicketList from '../filter-ticket-list'; +class Controller extends FilterTicketList { + constructor($scope, $timeout, $state) { + super($scope, $timeout, $state); + + this.onOrder('quantity', 'ASC'); + } +} + +Controller.$inject = ['$scope', '$timeout', '$state']; + ngModule.component('vnTicketSale', { template: require('./sale.html'), - controller: FilterTicketList + controller: Controller }); From 5b558a9f79e9f53ae877cb68646cf3b7fa312da7 Mon Sep 17 00:00:00 2001 From: Gerard Date: Mon, 26 Mar 2018 14:59:14 +0200 Subject: [PATCH 04/13] Solucionado el problema de alineamiento de la columnas --- client/ticket/src/expedition/ticket-expedition.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/ticket/src/expedition/ticket-expedition.html b/client/ticket/src/expedition/ticket-expedition.html index c7be8da69..f85c4ca6f 100644 --- a/client/ticket/src/expedition/ticket-expedition.html +++ b/client/ticket/src/expedition/ticket-expedition.html @@ -18,13 +18,13 @@ vn-one class="list list-element text-center" pad-small-bottom ng-repeat="expedition in index.model.instances track by expedition.id"> - + delete - + {{expedition.itemFk}} {{expedition.item.name}} {{expedition.package.name}} From 2f052a9d28c9c83c6129576e75136144b98c256a Mon Sep 17 00:00:00 2001 From: Gerard Date: Mon, 26 Mar 2018 15:00:43 +0200 Subject: [PATCH 05/13] table width: 100% --- client/core/src/components/grid/style.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/client/core/src/components/grid/style.scss b/client/core/src/components/grid/style.scss index b46e94865..ce292e522 100644 --- a/client/core/src/components/grid/style.scss +++ b/client/core/src/components/grid/style.scss @@ -1,5 +1,6 @@ .vn-grid { border-collapse: collapse; + width: 100%; td, th{ text-align: left; padding: 10px; From d773082f822ab6c3012dcfa2eb429c778618f615 Mon Sep 17 00:00:00 2001 From: Gerard Date: Mon, 26 Mar 2018 15:02:26 +0200 Subject: [PATCH 06/13] solucionado checkbox sin tag utilizando 100 de su contenedor --- client/core/src/components/check/style.scss | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/core/src/components/check/style.scss b/client/core/src/components/check/style.scss index 1088ad05e..3ff40e1e7 100644 --- a/client/core/src/components/check/style.scss +++ b/client/core/src/components/check/style.scss @@ -1,3 +1,5 @@ vn-check { - float: left; + & > .mdl-checkbox { + width: initial; + } } \ No newline at end of file From a746d2d58fc33339815e3744d4f4c4b0ff3c13f1 Mon Sep 17 00:00:00 2001 From: Gerard Date: Mon, 26 Mar 2018 15:10:51 +0200 Subject: [PATCH 07/13] Listar modelo saleChecked --- client/ticket/routes.json | 12 +++++++ client/ticket/src/locale/es.yml | 8 +++++ .../ticket/src/sale-checked/sale-checked.html | 36 +++++++++++++++++++ .../ticket/src/sale-checked/sale-checked.js | 17 +++++++++ client/ticket/src/ticket.js | 1 + services/ticket/common/methods/sale/filter.js | 6 ++++ services/ticket/common/models/sale.json | 5 +++ 7 files changed, 85 insertions(+) create mode 100644 client/ticket/src/sale-checked/sale-checked.html create mode 100644 client/ticket/src/sale-checked/sale-checked.js diff --git a/client/ticket/routes.json b/client/ticket/routes.json index c602f8768..49cb84b9c 100644 --- a/client/ticket/routes.json +++ b/client/ticket/routes.json @@ -137,6 +137,18 @@ "description": "Sale", "icon": "icon-lines" } + }, + { + "url" : "/sale-checked", + "state": "ticket.card.saleChecked", + "component": "vn-ticket-sale-checked", + "params": { + "ticket": "$ctrl.ticket" + }, + "menu": { + "description": "Sale Checked", + "icon": "assignment" + } } ] } \ No newline at end of file diff --git a/client/ticket/src/locale/es.yml b/client/ticket/src/locale/es.yml index 5f4025588..a95164c74 100644 --- a/client/ticket/src/locale/es.yml +++ b/client/ticket/src/locale/es.yml @@ -19,3 +19,11 @@ Sale: Lineas del pedido Some fields are invalid: Algunos campos no son válidos The observation type must be unique: El tipo de observación debe ser único Tickets: Tickets +Date : Fecha +Employee : Empleado +State: Estado +Tracking: Revisión +Created : Añadido +New : Nuevo +New state: Nuevo estado +Sale Checked: Control clientes diff --git a/client/ticket/src/sale-checked/sale-checked.html b/client/ticket/src/sale-checked/sale-checked.html new file mode 100644 index 000000000..6785f3391 --- /dev/null +++ b/client/ticket/src/sale-checked/sale-checked.html @@ -0,0 +1,36 @@ + + + + + Sale checked + + + + + + + + + + + + + + + + + + +
Is checkedItemDescriptionQuantity
{{::sale.itemFk}} + + {{::sale.concept}} + + + {{::fetchedTag.tag.name}} {{::fetchedTag.value}} + + + + {{::sale.quantity}}
+
+
+
diff --git a/client/ticket/src/sale-checked/sale-checked.js b/client/ticket/src/sale-checked/sale-checked.js new file mode 100644 index 000000000..ff5bf01a4 --- /dev/null +++ b/client/ticket/src/sale-checked/sale-checked.js @@ -0,0 +1,17 @@ +import ngModule from '../module'; +import FilterTicketList from '../filter-ticket-list'; + +class Controller extends FilterTicketList { + constructor($scope, $timeout, $state) { + super($scope, $timeout, $state); + + this.onOrder('quantity', 'ASC'); + } +} + +Controller.$inject = ['$scope', '$timeout', '$state']; + +ngModule.component('vnTicketSaleChecked', { + template: require('./sale-checked.html'), + controller: Controller +}); diff --git a/client/ticket/src/ticket.js b/client/ticket/src/ticket.js index 132502666..5a84ce427 100644 --- a/client/ticket/src/ticket.js +++ b/client/ticket/src/ticket.js @@ -12,3 +12,4 @@ import './package/package'; import './sale/sale'; import './tracking/tracking'; import './fetched-tags/fetched-tags'; +import './sale-checked/sale-checked'; diff --git a/services/ticket/common/methods/sale/filter.js b/services/ticket/common/methods/sale/filter.js index b33d5f1b6..66d73b6b2 100644 --- a/services/ticket/common/methods/sale/filter.js +++ b/services/ticket/common/methods/sale/filter.js @@ -20,6 +20,12 @@ module.exports = Self => { } } } + }, + { + relation: "isChecked", + scope: { + fields: ["isChecked"] + } }] }; } diff --git a/services/ticket/common/models/sale.json b/services/ticket/common/models/sale.json index a7d75cf1e..f1bf0eab8 100644 --- a/services/ticket/common/models/sale.json +++ b/services/ticket/common/models/sale.json @@ -51,6 +51,11 @@ "model": "Ticket", "foreignKey": "ticketFk", "required": true + }, + "isChecked": { + "type": "hasOne", + "model": "SaleChecked", + "foreignKey": "saleFk" } } } From 56f774a07f051fcd7a529a22e63940f8c3624c72 Mon Sep 17 00:00:00 2001 From: Gerard Date: Tue, 27 Mar 2018 14:16:42 +0200 Subject: [PATCH 08/13] =?UTF-8?q?Bug=20#210=20=20A=C3=B1adir=20automaticam?= =?UTF-8?q?ente=20en=20el=20campo=20relevancy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/item/src/tags/item-tags.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/client/item/src/tags/item-tags.js b/client/item/src/tags/item-tags.js index f2a0b6e5d..de750b294 100644 --- a/client/item/src/tags/item-tags.js +++ b/client/item/src/tags/item-tags.js @@ -37,7 +37,7 @@ class ItemTags { addItemTag() { if (this.instancedItemTags) { - this.instancedItemTags.push({value: null, itemFk: this.params.id, tagFk: null, priority: null, showAddIcon: true}); + this.instancedItemTags.push({value: null, itemFk: this.params.id, tagFk: null, priority: this.getMaxPriority(this.instancedItemTags) + 1, showAddIcon: true}); this._setIconAdd(); } } @@ -54,6 +54,15 @@ class ItemTags { } } + getMaxPriority(instancedItemTags) { + let max = 0; + instancedItemTags.forEach(tag => { + if (tag.priority > max) + max = tag.priority; + }); + return max; + } + _equalItemTags(oldTag, newTag) { return oldTag.tagFk === newTag.tagFk && oldTag.value === newTag.value && oldTag.priority === newTag.priority; } From 4d1609c445d0f2912eb6d514bdd95c08c1609354 Mon Sep 17 00:00:00 2001 From: Gerard Date: Tue, 27 Mar 2018 14:24:47 +0200 Subject: [PATCH 09/13] Tarea #170 Mostrar modelo ticketTracking --- client/ticket/routes.json | 16 +++++++++++++++- client/ticket/src/ticket.js | 3 ++- .../src/tracking/{tracking.html => index.html} | 10 ++++------ .../src/tracking/{tracking.js => index.js} | 2 +- client/ticket/src/tracking/locale/es.yml | 5 ----- services/ticket/common/models/ticketTracking.js | 11 +++++++++++ .../ticket/common/models/ticketTracking.json | 3 ++- 7 files changed, 35 insertions(+), 15 deletions(-) rename client/ticket/src/tracking/{tracking.html => index.html} (90%) rename client/ticket/src/tracking/{tracking.js => index.js} (79%) delete mode 100644 client/ticket/src/tracking/locale/es.yml diff --git a/client/ticket/routes.json b/client/ticket/routes.json index 49cb84b9c..41cb8057b 100644 --- a/client/ticket/routes.json +++ b/client/ticket/routes.json @@ -107,8 +107,14 @@ } }, { - "url" : "/tracking", + "url": "/tracking", "state": "ticket.card.tracking", + "abstract": true, + "component": "ui-view" + }, + { + "url" : "/index", + "state": "ticket.card.tracking.index", "component": "vn-ticket-tracking", "params": { "ticket": "$ctrl.ticket" @@ -118,6 +124,14 @@ "icon": "remove_red_eye" } }, + { + "url": "/edit", + "state": "ticket.card.tracking.edit", + "component": "vn-ticket-tracking-edit", + "params": { + "ticket": "$ctrl.ticket" + } + }, { "url": "/create", "state": "ticket.card.tracking.create", diff --git a/client/ticket/src/ticket.js b/client/ticket/src/ticket.js index 5a84ce427..c90465231 100644 --- a/client/ticket/src/ticket.js +++ b/client/ticket/src/ticket.js @@ -10,6 +10,7 @@ import './expedition/ticket-expedition'; import './volume/ticket-volume'; import './package/package'; import './sale/sale'; -import './tracking/tracking'; +import './tracking/index'; +import './tracking/edit/edit'; import './fetched-tags/fetched-tags'; import './sale-checked/sale-checked'; diff --git a/client/ticket/src/tracking/tracking.html b/client/ticket/src/tracking/index.html similarity index 90% rename from client/ticket/src/tracking/tracking.html rename to client/ticket/src/tracking/index.html index ec827fac3..3d287d940 100644 --- a/client/ticket/src/tracking/tracking.html +++ b/client/ticket/src/tracking/index.html @@ -1,5 +1,5 @@ - + Tracking @@ -7,7 +7,6 @@ - {{::ticket.state.name}} - {{::ticket.worker.firstName}} {{::ticket.worker.name}} - {{::ticket.created | date:'dd/MM/yyyy HH:mm' }} - + {{::ticket.worker.firstName}} {{ticket.worker.name}} + {{::ticket.created | date:'dd/MM/yyyy HH:mm'}} No results @@ -26,6 +24,6 @@ - + \ No newline at end of file diff --git a/client/ticket/src/tracking/tracking.js b/client/ticket/src/tracking/index.js similarity index 79% rename from client/ticket/src/tracking/tracking.js rename to client/ticket/src/tracking/index.js index be147ed91..fc0777775 100644 --- a/client/ticket/src/tracking/tracking.js +++ b/client/ticket/src/tracking/index.js @@ -2,6 +2,6 @@ import ngModule from '../module'; import FilterTicketList from '../filter-ticket-list'; ngModule.component('vnTicketTracking', { - template: require('./tracking.html'), + template: require('./index.html'), controller: FilterTicketList }); diff --git a/client/ticket/src/tracking/locale/es.yml b/client/ticket/src/tracking/locale/es.yml deleted file mode 100644 index e61e1dd24..000000000 --- a/client/ticket/src/tracking/locale/es.yml +++ /dev/null @@ -1,5 +0,0 @@ -Date : Fecha -Employee : Empleado -State: Estado -Tracking: Revisión -Created : Añadido \ No newline at end of file diff --git a/services/ticket/common/models/ticketTracking.js b/services/ticket/common/models/ticketTracking.js index ab8a13f1e..91f890af5 100644 --- a/services/ticket/common/models/ticketTracking.js +++ b/services/ticket/common/models/ticketTracking.js @@ -1,3 +1,14 @@ module.exports = function(Self) { require('../methods/ticketTracking/filter')(Self); + + Self.observe('before save', function(ctx, next) { + let token = ctx.options.accessToken; + let userId = token && token.userId; + + Self.app.models.Worker.findOne({where: {userFk: userId}}, (err, user) => { + if (err) return next(err); + ctx.instance.workerFk = user.id; + next(); + }); + }); }; diff --git a/services/ticket/common/models/ticketTracking.json b/services/ticket/common/models/ticketTracking.json index b1f2769d4..176f84b27 100644 --- a/services/ticket/common/models/ticketTracking.json +++ b/services/ticket/common/models/ticketTracking.json @@ -3,7 +3,8 @@ "base": "VnModel", "options": { "mysql": { - "table": "ticketTracking" + "table": "ticketTracking", + "database": "vn" } }, "properties": { From 151a19b0bac3be14e0d0f134d623fb9f7d8e07f8 Mon Sep 17 00:00:00 2001 From: Gerard Date: Tue, 27 Mar 2018 14:26:20 +0200 Subject: [PATCH 10/13] =?UTF-8?q?Tarea=20#171=20A=C3=B1adir=20revision?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/ticket/src/tracking/edit/edit.html | 23 +++++++++++++++++++++ client/ticket/src/tracking/edit/edit.js | 25 +++++++++++++++++++++++ services/loopback/common/locale/en.json | 3 ++- 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 client/ticket/src/tracking/edit/edit.html create mode 100644 client/ticket/src/tracking/edit/edit.js diff --git a/client/ticket/src/tracking/edit/edit.html b/client/ticket/src/tracking/edit/edit.html new file mode 100644 index 000000000..ff5b0de40 --- /dev/null +++ b/client/ticket/src/tracking/edit/edit.html @@ -0,0 +1,23 @@ + + + +
+ + New state + + + + + + + + +
\ No newline at end of file diff --git a/client/ticket/src/tracking/edit/edit.js b/client/ticket/src/tracking/edit/edit.js new file mode 100644 index 000000000..2d1f5e5a0 --- /dev/null +++ b/client/ticket/src/tracking/edit/edit.js @@ -0,0 +1,25 @@ +import ngModule from '../../module'; + +export default class Controller { + constructor($scope, $state) { + this.$ = $scope; + this.$state = $state; + this.ticket = { + ticketFk: $state.params.id, + text: null + }; + } + onSubmit() { + this.$.watcher.submit().then( + () => { + this.$state.go('ticket.card.tracking.index'); + } + ); + } +} +Controller.$inject = ['$scope', '$state']; + +ngModule.component('vnTicketTrackingEdit', { + template: require('./edit.html'), + controller: Controller +}); diff --git a/services/loopback/common/locale/en.json b/services/loopback/common/locale/en.json index 35acd8506..288480f55 100644 --- a/services/loopback/common/locale/en.json +++ b/services/loopback/common/locale/en.json @@ -6,5 +6,6 @@ "Unable to default a disabled consignee": "Unable to default a disabled consignee", "El método de pago seleccionado requiere que se especifique el IBAN": "El método de pago seleccionado requiere que se especifique el IBAN", "Ya existe un usuario con ese nombre": "Ya existe un usuario con ese nombre", - "Quantity cannot be zero": "Quantity cannot be zero" + "Quantity cannot be zero": "Quantity cannot be zero", + "can't be blank": "can't be blank" } \ No newline at end of file From 6b390b72f85ed9515b800f09f79011f5d8372e60 Mon Sep 17 00:00:00 2001 From: Gerard Date: Tue, 27 Mar 2018 14:28:02 +0200 Subject: [PATCH 11/13] Tarea #212 Mostrar solo las agencias con el campo isActive(tpv) en TRUE --- .../src/address-create/address-create.html | 3 ++- services/db/changes/1.0.2/07-agencyMode.sql | 22 +++++++++++++++++++ .../loopback/common/models/agency-mode.json | 3 +++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 services/db/changes/1.0.2/07-agencyMode.sql diff --git a/client/client/src/address-create/address-create.html b/client/client/src/address-create/address-create.html index 712a771de..3d66656ae 100644 --- a/client/client/src/address-create/address-create.html +++ b/client/client/src/address-create/address-create.html @@ -33,7 +33,8 @@ url="/client/api/AgencyModes" show-field="name" value-field="id" - label="Agency"> + label="Agency" + where="{isActive: {neq: '0'}}"> diff --git a/services/db/changes/1.0.2/07-agencyMode.sql b/services/db/changes/1.0.2/07-agencyMode.sql new file mode 100644 index 000000000..268288135 --- /dev/null +++ b/services/db/changes/1.0.2/07-agencyMode.sql @@ -0,0 +1,22 @@ +USE `vn`; +CREATE + OR REPLACE ALGORITHM = UNDEFINED + DEFINER = `root`@`%` + SQL SECURITY DEFINER +VIEW `agencyMode` AS + SELECT + `a`.`Id_Agencia` AS `id`, + `a`.`Agencia` AS `name`, + `a`.`description` AS `description`, + `a`.`Vista` AS `deliveryMethodFk`, + `a`.`m3` AS `m3`, + `a`.`cod71` AS `cod71`, + `a`.`web` AS `web`, + `a`.`agency_id` AS `agencyFk`, + `a`.`agency_service_id` AS `agencyServiceFk`, + `a`.`inflacion` AS `inflation`, + `a`.`is_volumetric` AS `isVolumetric`, + `a`.`send_mail` AS `reportMail`, + `a`.`tpv` AS `isActive` + FROM + `vn2008`.`Agencias` `a`; diff --git a/services/loopback/common/models/agency-mode.json b/services/loopback/common/models/agency-mode.json index d29695ae3..86473cc5e 100644 --- a/services/loopback/common/models/agency-mode.json +++ b/services/loopback/common/models/agency-mode.json @@ -28,6 +28,9 @@ }, "reportMail": { "type": "string" + }, + "isActive":{ + "type": "Number" } }, "relations": { From 85810e2f7e45de53c15d1dd33d0fcc65c67208e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Tue, 27 Mar 2018 15:06:22 +0200 Subject: [PATCH 12/13] Client summary & package --- client/client/src/notes/notes.js | 1 - client/client/src/notes/style.css | 0 client/client/src/summary/client-summary.html | 52 +++++++------- client/client/src/summary/client-summary.js | 61 ++--------------- client/client/src/summary/locale/es.yml | 7 +- client/client/src/summary/style.scss | 3 + client/ticket/routes.json | 8 ++- .../src/package/{ => index}/locale/es.yml | 0 .../src/package/{ => index}/package.html | 0 .../ticket/src/package/{ => index}/package.js | 32 +++++++-- .../src/package/{ => index}/package.spec.js | 10 +-- client/ticket/src/ticket.js | 2 +- .../client/common/methods/greuge/sumAmount.js | 16 ++--- services/loopback/common/locale/es.json | 3 +- .../methods/client/getAverageInvoiced.js | 28 ++++++++ .../loopback/common/methods/client/getDebt.js | 5 +- .../loopback/common/methods/client/getMana.js | 28 ++++++++ .../loopback/common/methods/client/summary.js | 68 +++++++++++++++++++ services/loopback/common/models/client.js | 3 + 19 files changed, 217 insertions(+), 110 deletions(-) delete mode 100644 client/client/src/notes/style.css create mode 100644 client/client/src/summary/style.scss rename client/ticket/src/package/{ => index}/locale/es.yml (100%) rename client/ticket/src/package/{ => index}/package.html (100%) rename client/ticket/src/package/{ => index}/package.js (59%) rename client/ticket/src/package/{ => index}/package.spec.js (83%) create mode 100644 services/loopback/common/methods/client/getAverageInvoiced.js create mode 100644 services/loopback/common/methods/client/getMana.js create mode 100644 services/loopback/common/methods/client/summary.js diff --git a/client/client/src/notes/notes.js b/client/client/src/notes/notes.js index 7e0ec424a..119c983e2 100644 --- a/client/client/src/notes/notes.js +++ b/client/client/src/notes/notes.js @@ -1,5 +1,4 @@ import ngModule from '../module'; -import './style.css'; export default class Controller { constructor($http, $state) { diff --git a/client/client/src/notes/style.css b/client/client/src/notes/style.css deleted file mode 100644 index e69de29bb..000000000 diff --git a/client/client/src/summary/client-summary.html b/client/client/src/summary/client-summary.html index 8788464f3..71a1fcd52 100644 --- a/client/client/src/summary/client-summary.html +++ b/client/client/src/summary/client-summary.html @@ -105,9 +105,9 @@
Default address
-

{{$ctrl.address.nickname}}

-

{{$ctrl.address.street}}

-

{{$ctrl.address.city}}

+

{{$ctrl.summary.addresses[0].nickname}}

+

{{$ctrl.summary.addresses[0].street}}

+

{{$ctrl.summary.addresses[0].city}}

Web access
@@ -122,34 +122,30 @@
Recovery
- -

Since {{$ctrl.recovery.started | date:'dd/MM/yyyy'}}

-

To {{$ctrl.recovery.finished | date:'dd/MM/yyyy'}}

-

Amount {{$ctrl.recovery.amount | currency:'€':2}}

-

Period {{$ctrl.recovery.period}}

+ +

Since {{$ctrl.summary.recovery.started | date:'dd/MM/yyyy'}}

+

To {{$ctrl.summary.recovery.finished | date:'dd/MM/yyyy'}}

+

Amount {{$ctrl.summary.recovery.amount | currency:'€ ':2}}

+

Period {{$ctrl.summary.recovery.period}}

- + +
Financial data
+

Mana {{$ctrl.summary.mana.mana | currency:'€ ':2}}

+

Risk {{$ctrl.summary.debt.debt | currency:'€ ':2}}

+

Average invoiced {{$ctrl.summary.averageInvoiced.invoiced | currency:'€ ':2}}

+

Total greuge {{$ctrl.summary.totalGreuge | currency:'€ ':2}}

+

+ Credit + {{$ctrl.summary.credit | currency:'€ ':2}} +

+

+ Secured credit + - + {{$ctrl.summary.creditInsurance | currency:'€ ':2}} +

+
- - -
Total greuge
-

Total {{$ctrl.greuge.sumAmount | currency:'€':2}}

-
- - -
Credit
-

- Credit - {{$ctrl.summary.credit | currency:'€':2}} -

-

- Secured credit - - - {{$ctrl.summary.creditInsurance | currency:'€':2}} -

-
-
\ No newline at end of file diff --git a/client/client/src/summary/client-summary.js b/client/client/src/summary/client-summary.js index 2a6b9e3f3..9a10cb7a1 100644 --- a/client/client/src/summary/client-summary.js +++ b/client/client/src/summary/client-summary.js @@ -1,73 +1,22 @@ import ngModule from '../module'; +import './style.scss'; class Controller { - constructor($http) { this.$http = $http; } $onChanges() { - if (!this.client || !this.client.id) + if (!this.client) 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: 'addresses', - scope: { - where: {isDefaultAddress: true}, - fields: ['nickname', 'street', 'city', 'postalCode'] - } - } - ] - }; - filter = encodeURIComponent(JSON.stringify(filter)); - - let query = `/client/api/Clients/${this.client.id}?filter=${filter}`; - this.$http.get(query).then(res => { - if (res.data) { + this.$http.get(`/client/api/Clients/${this.client.id}/summary`).then(res => { + if (res && res.data) this.summary = res.data; - this.address = res.data.addresses[0]; - } - }); - } - - getGreuse() { - let query = `/client/api/Greuges/${this.client.id}/sumAmount`; - this.$http.get(query).then(res => { - if (res.data) - this.greuge = res.data; - }); - } - - getRecoveries() { - let filter = { - where: { - and: [{clientFk: this.client.id}, {or: [{finished: null}, {finished: {gt: Date.now()}}]}] - }, - limit: 1 - }; - filter = encodeURIComponent(JSON.stringify(filter)); - - let query = `/client/api/Recoveries?filter=${filter}`; - this.$http.get(query).then(res => { - if (res.data) - this.recovery = res.data[0]; }); } } + Controller.$inject = ['$http']; ngModule.component('vnClientSummary', { diff --git a/client/client/src/summary/locale/es.yml b/client/client/src/summary/locale/es.yml index 27ebf6e37..081ae70b8 100644 --- a/client/client/src/summary/locale/es.yml +++ b/client/client/src/summary/locale/es.yml @@ -1,2 +1,7 @@ Default address: Consignatario pred. -Total greuge: Greuge total \ No newline at end of file +Total greuge: Greuge total +Financial data: Datos financieros +Mana: Maná +Risk: Riesgo +Secured credit: Crédito asegurado +Average invoiced: Consumo medio \ No newline at end of file diff --git a/client/client/src/summary/style.scss b/client/client/src/summary/style.scss new file mode 100644 index 000000000..0769fb51d --- /dev/null +++ b/client/client/src/summary/style.scss @@ -0,0 +1,3 @@ +vn-dialog vn-one { + min-width: 200px +} \ No newline at end of file diff --git a/client/ticket/routes.json b/client/ticket/routes.json index 41cb8057b..e27853dfa 100644 --- a/client/ticket/routes.json +++ b/client/ticket/routes.json @@ -96,8 +96,14 @@ }, { "url" : "/package", + "abstract": true, "state": "ticket.card.package", - "component": "vn-ticket-package", + "component": "ui-view" + }, + { + "url" : "/index", + "state": "ticket.card.package.index", + "component": "vn-ticket-package-index", "params": { "ticket": "$ctrl.ticket" }, diff --git a/client/ticket/src/package/locale/es.yml b/client/ticket/src/package/index/locale/es.yml similarity index 100% rename from client/ticket/src/package/locale/es.yml rename to client/ticket/src/package/index/locale/es.yml diff --git a/client/ticket/src/package/package.html b/client/ticket/src/package/index/package.html similarity index 100% rename from client/ticket/src/package/package.html rename to client/ticket/src/package/index/package.html diff --git a/client/ticket/src/package/package.js b/client/ticket/src/package/index/package.js similarity index 59% rename from client/ticket/src/package/package.js rename to client/ticket/src/package/index/package.js index 6cb749517..78b3bca94 100644 --- a/client/ticket/src/package/package.js +++ b/client/ticket/src/package/index/package.js @@ -1,4 +1,4 @@ -import ngModule from '../module'; +import ngModule from '../../module'; class Controller { @@ -8,7 +8,6 @@ class Controller { this.$translate = $translate; this.vnApp = vnApp; this.removedPackages = []; - this.updatedPackages = []; } submit() { @@ -23,10 +22,16 @@ class Controller { if (typeof item.id === 'undefined') packagesObj.create.push(item); - if (typeof item.id !== 'undefined' && angular.equals(item, this.oldPackages[item.id])) + if (typeof item.id !== 'undefined' && !this.packageEquals(item, this.oldPackages[item.id])) packagesObj.update.push(item); }); + if (this.$.form.$invalid) + return this.vnApp.showMessage(this.$translate.instant('Some fields are invalid')); + + if (!this.hasChanges(packagesObj)) + return this.vnApp.showMessage(this.$translate.instant('No changes to save')); + this.$http.post(query, packagesObj).then(res => { this.$.index.accept(); }); @@ -55,16 +60,31 @@ class Controller { } setOldPackages() { + if (this.oldPackages && !this.$.watcher.dataChanged()) + return; + this.oldPackages = []; + this.removedPackages = []; this.packages.forEach(item => { - this.oldPackages[item.id] = item; + this.oldPackages[item.id] = Object.assign({}, item); }); } + + packageEquals(newPackage, oldPackage) { + return newPackage.packagingFk === oldPackage.packagingFk && newPackage.quantity == oldPackage.quantity; + } + + hasChanges(packagesObj) { + if (packagesObj.create.length || packagesObj.update.length || packagesObj.delete.length) + return true; + + return false; + } } -Controller.$inject = ['$http', '$scope']; +Controller.$inject = ['$http', '$scope', '$translate', 'vnApp']; -ngModule.component('vnTicketPackage', { +ngModule.component('vnTicketPackageIndex', { template: require('./package.html'), controller: Controller, bindings: { diff --git a/client/ticket/src/package/package.spec.js b/client/ticket/src/package/index/package.spec.js similarity index 83% rename from client/ticket/src/package/package.spec.js rename to client/ticket/src/package/index/package.spec.js index b9b7c310a..1ff444227 100644 --- a/client/ticket/src/package/package.spec.js +++ b/client/ticket/src/package/index/package.spec.js @@ -1,7 +1,7 @@ import './package.js'; describe('Ticket', () => { - describe('Component vnTicketPackage', () => { + describe('Component vnTicketPackageIndex', () => { let $componentController; let controller; let $httpBackend; @@ -19,7 +19,7 @@ describe('Ticket', () => { accept: function() {} } }; - controller = $componentController('vnTicketPackage', {$scope: $scope}); + controller = $componentController('vnTicketPackageIndex', {$scope: $scope}); })); describe('removePackage()', () => { @@ -37,11 +37,11 @@ describe('Ticket', () => { let query = '/ticket/api/TicketPackagings/crudTicketPackaging'; controller.removedPackages = []; controller.oldPackages = [ - {id: 1, quantity: 5, ticketFk: 1} + {id: 1, packagingFk: 1, quantity: 5, ticketFk: 1} ]; controller.packages = [ - {quantity: 5, ticketFk: 1}, - {id: 1, quantity: 25, ticketFk: 1} + {quantity: 5, packagingFk: 2, ticketFk: 1}, + {id: 1, packagingFk: 1, quantity: 25, ticketFk: 1} ]; let packagesObj = { delete: controller.removedPackages, diff --git a/client/ticket/src/ticket.js b/client/ticket/src/ticket.js index c90465231..6cf8be337 100644 --- a/client/ticket/src/ticket.js +++ b/client/ticket/src/ticket.js @@ -8,7 +8,7 @@ import './data/ticket-data'; import './note/ticket-observation'; import './expedition/ticket-expedition'; import './volume/ticket-volume'; -import './package/package'; +import './package/index/package'; import './sale/sale'; import './tracking/index'; import './tracking/edit/edit'; diff --git a/services/client/common/methods/greuge/sumAmount.js b/services/client/common/methods/greuge/sumAmount.js index 0fa8d9034..dcc780168 100644 --- a/services/client/common/methods/greuge/sumAmount.js +++ b/services/client/common/methods/greuge/sumAmount.js @@ -18,14 +18,14 @@ module.exports = Self => { } }); - Self.sumAmount = (clientFk, callback) => { + Self.sumAmount = async clientFk => { let query = `SELECT SUM(amount) AS sumAmount FROM vn.greuge WHERE clientFk = ?`; - Self.rawSql(query, [clientFk]) - .then(response => { - callback(null, response.length ? response[0].sumAmount : 0); - }) - .catch(err => { - callback(err); - }); + try { + let [response] = await Self.rawSql(query, [clientFk]); + + return response ? response.sumAmount : 0; + } catch (e) { + throw new Error(e); + } }; }; diff --git a/services/loopback/common/locale/es.json b/services/loopback/common/locale/es.json index 791d0bc53..f4442b3c6 100644 --- a/services/loopback/common/locale/es.json +++ b/services/loopback/common/locale/es.json @@ -9,5 +9,6 @@ "DNI Incorrecto": "DNI Incorrecto", "Ya existe un usuario con ese nombre": "Ya existe un usuario con ese nombre", "is invalid": "is invalid", - "Quantity cannot be zero": "La cantidad no puede ser cero" + "Quantity cannot be zero": "La cantidad no puede ser cero", + "Package cannot be blank": "Package cannot be blank" } \ No newline at end of file diff --git a/services/loopback/common/methods/client/getAverageInvoiced.js b/services/loopback/common/methods/client/getAverageInvoiced.js new file mode 100644 index 000000000..94ec033ed --- /dev/null +++ b/services/loopback/common/methods/client/getAverageInvoiced.js @@ -0,0 +1,28 @@ +module.exports = Self => { + Self.remoteMethod('getAverageInvoiced', { + description: 'Returns the annual average invoiced of a client', + accessType: 'READ', + accepts: [{ + arg: 'id', + type: 'number', + required: true, + description: 'client id', + http: {source: 'path'} + }], + returns: { + type: 'number', + root: true + }, + http: { + path: `/:id/getAverageInvoiced`, + verb: 'GET' + } + }); + + Self.getAverageInvoiced = async clientFk => { + let query = `SELECT invoiced FROM vn.annualAverageInvoiced WHERE clientFk = ?`; + let [invoiced] = await Self.rawSql(query, [clientFk]); + + return invoiced; + }; +}; \ No newline at end of file diff --git a/services/loopback/common/methods/client/getDebt.js b/services/loopback/common/methods/client/getDebt.js index c04c208b8..c4f167731 100644 --- a/services/loopback/common/methods/client/getDebt.js +++ b/services/loopback/common/methods/client/getDebt.js @@ -21,7 +21,8 @@ module.exports = Self => { Self.getDebt = async clientFk => { let query = `SELECT vn.clientGetDebt(?, CURDATE()) AS debt`; - let response = await Self.rawSql(query, [clientFk]); - return response[0]; + let [debt] = await Self.rawSql(query, [clientFk]); + + return debt; }; }; diff --git a/services/loopback/common/methods/client/getMana.js b/services/loopback/common/methods/client/getMana.js new file mode 100644 index 000000000..88e337e32 --- /dev/null +++ b/services/loopback/common/methods/client/getMana.js @@ -0,0 +1,28 @@ +module.exports = Self => { + Self.remoteMethod('getMana', { + description: 'Returns the boolean mana of a client', + accessType: 'READ', + accepts: [{ + arg: 'id', + type: 'number', + required: true, + description: 'client id', + http: {source: 'path'} + }], + returns: { + type: 'number', + root: true + }, + http: { + path: `/:id/getMana`, + verb: 'GET' + } + }); + + Self.getMana = async clientFk => { + let query = `SELECT vn.clientGetMana(?) AS mana`; + let [mana] = await Self.rawSql(query, [clientFk]); + + return mana; + }; +}; diff --git a/services/loopback/common/methods/client/summary.js b/services/loopback/common/methods/client/summary.js new file mode 100644 index 000000000..ea3ab3ec1 --- /dev/null +++ b/services/loopback/common/methods/client/summary.js @@ -0,0 +1,68 @@ +module.exports = Self => { + Self.remoteMethod('summary', { + description: 'Returns a client summary', + accessType: 'READ', + accepts: [{ + arg: 'id', + type: 'number', + required: true, + description: 'client id', + http: {source: 'path'} + }], + returns: { + type: [this.modelName], + root: true + }, + http: { + path: `/:id/summary`, + verb: 'GET' + } + }); + + Self.summary = async clientFk => { + let models = Self.app.models; + let summaryObj = await getSummary(models.Client, clientFk); + + summaryObj.mana = await models.Client.getMana(clientFk); + summaryObj.debt = await models.Client.getDebt(clientFk); + summaryObj.averageInvoiced = await models.Client.getAverageInvoiced(clientFk); + summaryObj.totalGreuge = await models.Greuge.sumAmount(clientFk); + summaryObj.recovery = await getRecoveries(models.Recovery, clientFk); + + return summaryObj; + }; + + async function getSummary(client, clientId) { + 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: 'addresses', + scope: { + where: {isDefaultAddress: true}, + fields: ['nickname', 'street', 'city', 'postalCode'] + } + } + ], + where: {id: clientId} + }; + + return await client.findOne(filter); + } + + async function getRecoveries(recovery, clientId) { + let filter = { + where: { + and: [{clientFk: clientId}, {or: [{finished: null}, {finished: {gt: Date.now()}}]}] + }, + limit: 1 + }; + + return await recovery.findOne(filter); + } +}; diff --git a/services/loopback/common/models/client.js b/services/loopback/common/models/client.js index eee710035..7114aef9a 100644 --- a/services/loopback/common/models/client.js +++ b/services/loopback/common/models/client.js @@ -16,6 +16,9 @@ module.exports = function(Self) { require('../methods/client/activeSalesPerson')(Self); require('../methods/client/addressesPropagateRe')(Self); require('../methods/client/getDebt')(Self); + require('../methods/client/getMana')(Self); + require('../methods/client/getAverageInvoiced')(Self); + require('../methods/client/summary')(Self); // Validations From 28c80d9ed378cf2bdf875c2b27c210486c4831b8 Mon Sep 17 00:00:00 2001 From: Gerard Date: Wed, 28 Mar 2018 09:30:33 +0200 Subject: [PATCH 13/13] Tarea #212 Mostrar solo las agencias con el campo isActive(tpv) en TRUE --- client/client/src/address-create/address-create.html | 5 ++--- services/loopback/common/models/agency-mode.json | 7 +++++-- services/loopback/common/models/warehouse.json | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/client/client/src/address-create/address-create.html b/client/client/src/address-create/address-create.html index 3d66656ae..1d9ddac6e 100644 --- a/client/client/src/address-create/address-create.html +++ b/client/client/src/address-create/address-create.html @@ -30,11 +30,10 @@ + label="Agency"> diff --git a/services/loopback/common/models/agency-mode.json b/services/loopback/common/models/agency-mode.json index 86473cc5e..cff8b2f1e 100644 --- a/services/loopback/common/models/agency-mode.json +++ b/services/loopback/common/models/agency-mode.json @@ -30,7 +30,7 @@ "type": "string" }, "isActive":{ - "type": "Number" + "type": "boolean" } }, "relations": { @@ -52,5 +52,8 @@ "principalId": "$everyone", "permission": "ALLOW" } - ] + ], + "scopes" : { + "active" : {"where": {"isActive": {"neq": false}}} + } } diff --git a/services/loopback/common/models/warehouse.json b/services/loopback/common/models/warehouse.json index 7b6fef1cd..789d5c7f8 100644 --- a/services/loopback/common/models/warehouse.json +++ b/services/loopback/common/models/warehouse.json @@ -20,7 +20,7 @@ "type": "Number" }, "isManaged":{ - "type":"boolean" + "type": "boolean" } }, "acls": [