From 2f17257e46096cdb9049d276df9b1c29c7d3071b Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 5 Oct 2022 15:13:48 +0200 Subject: [PATCH 1/9] feat: add new sub section itemShelving --- front/salix/locale/es.yml | 1 + modules/item/back/model-config.json | 3 + .../item-shelving-placement-supply.json | 29 +++ modules/item/front/index.js | 2 + modules/item/front/item-shelving/index.html | 172 ++++++++++++++++++ modules/item/front/item-shelving/index.js | 132 ++++++++++++++ .../item/front/item-shelving/index.spec.js | 121 ++++++++++++ .../item/front/item-shelving/locale/es.yml | 9 + modules/item/front/locale/es.yml | 1 + modules/item/front/routes.json | 13 +- modules/shelving/front/routes.json | 2 +- 11 files changed, 483 insertions(+), 2 deletions(-) create mode 100644 modules/item/back/models/item-shelving-placement-supply.json create mode 100644 modules/item/front/item-shelving/index.html create mode 100644 modules/item/front/item-shelving/index.js create mode 100644 modules/item/front/item-shelving/index.spec.js create mode 100644 modules/item/front/item-shelving/locale/es.yml diff --git a/front/salix/locale/es.yml b/front/salix/locale/es.yml index e5dc82b16..d92c32b33 100644 --- a/front/salix/locale/es.yml +++ b/front/salix/locale/es.yml @@ -51,6 +51,7 @@ Entries: Entradas Users: Usuarios Suppliers: Proveedores Monitors: Monitores +Shelvings: Carros # Common diff --git a/modules/item/back/model-config.json b/modules/item/back/model-config.json index 9737d26fc..40d73f1a6 100644 --- a/modules/item/back/model-config.json +++ b/modules/item/back/model-config.json @@ -53,6 +53,9 @@ "ItemShelvingSale": { "dataSource": "vn" }, + "ItemShelvingPlacementSupplyStock": { + "dataSource": "vn" + }, "ItemImageQueue": { "dataSource": "vn" }, diff --git a/modules/item/back/models/item-shelving-placement-supply.json b/modules/item/back/models/item-shelving-placement-supply.json new file mode 100644 index 000000000..11497b4fc --- /dev/null +++ b/modules/item/back/models/item-shelving-placement-supply.json @@ -0,0 +1,29 @@ +{ + "name": "ItemShelvingPlacementSupplyStock", + "base": "VnModel", + "options": { + "mysql": { + "table": "itemShelvingPlacementSupplyStock" + } + }, + "properties": { + "created": { + "type": "date" + }, + "itemFk": { + "type": "number" + }, + "concept": { + "type": "string" + }, + "parking": { + "type": "string" + }, + "shelving": { + "type": "string" + }, + "packing": { + "type": "number" + } + } +} \ No newline at end of file diff --git a/modules/item/front/index.js b/modules/item/front/index.js index 6a8d1b3b7..d2ffcc8fb 100644 --- a/modules/item/front/index.js +++ b/modules/item/front/index.js @@ -24,3 +24,5 @@ import './waste/detail'; import './fixed-price'; import './fixed-price-search-panel'; import './item-type'; +import './item-shelving'; + diff --git a/modules/item/front/item-shelving/index.html b/modules/item/front/item-shelving/index.html new file mode 100644 index 000000000..7949e73a3 --- /dev/null +++ b/modules/item/front/item-shelving/index.html @@ -0,0 +1,172 @@ + + + + + + + + + +
+
+
Total
+ + +
+
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Created + + Item + + Concept + + Parking + + Shelving + + Etiqueta + + Packing +
+ + + + + {{::defaulter.clientName}} + + + + {{::defaulter.salesPersonName | dashIfEmpty}} + + {{::defaulter.amount | currency: 'EUR': 2}} + + {{::defaulter.workerName | dashIfEmpty}} + + + + + + + {{::defaulter.created | date: 'dd/MM/yyyy'}} + + {{::defaulter.creditInsurance | currency: 'EUR': 2}}{{::defaulter.defaulterSinced | date: 'dd/MM/yyyy'}}
+
+
+
+ + + + + + + + + + + + +
+
{{$ctrl.$t('Add observation to all selected clients', {total: $ctrl.checked.length})}}
+ + + + +
+
+ + + + +
diff --git a/modules/item/front/item-shelving/index.js b/modules/item/front/item-shelving/index.js new file mode 100644 index 000000000..f51a1a65b --- /dev/null +++ b/modules/item/front/item-shelving/index.js @@ -0,0 +1,132 @@ +import ngModule from '../module'; +import Section from 'salix/components/section'; +import UserError from 'core/lib/user-error'; + +export default class Controller extends Section { + constructor($element, $) { + super($element, $); + this.defaulter = {}; + + this.smartTableOptions = { + activeButtons: { + search: true + }, + columns: [ + { + field: 'clientFk', + autocomplete: { + url: 'Clients', + showField: 'name', + valueField: 'id' + } + }, + { + field: 'salesPersonFk', + autocomplete: { + url: 'Workers/activeWithInheritedRole', + where: `{role: 'salesPerson'}`, + searchFunction: '{firstName: $search}', + showField: 'name', + valueField: 'id', + } + }, + { + field: 'workerFk', + autocomplete: { + url: 'Workers/activeWithInheritedRole', + searchFunction: '{firstName: $search}', + showField: 'name', + valueField: 'id', + } + }, + { + field: 'observation', + searchable: false + }, + { + field: 'created', + searchable: false + }, + { + field: 'defaulterSinced', + searchable: false + } + ] + }; + + this.getBalanceDueTotal(); + } + + get checked() { + const clients = this.$.model.data || []; + const checkedLines = []; + for (let defaulter of clients) { + if (defaulter.checked) + checkedLines.push(defaulter); + } + + return checkedLines; + } + + getBalanceDueTotal() { + this.$http.get('Defaulters/filter') + .then(res => { + if (!res.data) return 0; + + this.balanceDueTotal = res.data.reduce( + (accumulator, currentValue) => { + return accumulator + (currentValue['amount'] || 0); + }, 0); + }); + } + + chipColor(date) { + const day = 24 * 60 * 60 * 1000; + const today = new Date(); + today.setHours(0, 0, 0, 0); + + const observationShipped = new Date(date); + observationShipped.setHours(0, 0, 0, 0); + + const difference = today - observationShipped; + + if (difference > (day * 20)) + return 'alert'; + if (difference > (day * 10)) + return 'warning'; + } + + onResponse() { + if (!this.defaulter.observation) + throw new UserError(`The message can't be empty`); + + const params = []; + for (let defaulter of this.checked) { + params.push({ + text: this.defaulter.observation, + clientFk: defaulter.clientFk + }); + } + + this.$http.post(`ClientObservations`, params) .then(() => { + this.vnApp.showMessage(this.$t('Observation saved!')); + this.$state.reload(); + }); + } + + exprBuilder(param, value) { + switch (param) { + case 'creditInsurance': + case 'amount': + case 'clientFk': + case 'workerFk': + case 'salesPersonFk': + return {[`d.${param}`]: value}; + } + } +} + +ngModule.vnComponent('vnItemShelving', { + template: require('./index.html'), + controller: Controller +}); diff --git a/modules/item/front/item-shelving/index.spec.js b/modules/item/front/item-shelving/index.spec.js new file mode 100644 index 000000000..0732c68a1 --- /dev/null +++ b/modules/item/front/item-shelving/index.spec.js @@ -0,0 +1,121 @@ +import './index'; +import crudModel from 'core/mocks/crud-model'; + +describe('client defaulter', () => { + describe('Component vnClientDefaulter', () => { + let controller; + let $httpBackend; + + beforeEach(ngModule('client')); + + beforeEach(inject(($componentController, _$httpBackend_) => { + $httpBackend = _$httpBackend_; + const $element = angular.element(''); + controller = $componentController('vnClientDefaulter', {$element}); + controller.$.model = crudModel; + controller.$.model.data = [ + {clientFk: 1101, amount: 125}, + {clientFk: 1102, amount: 500}, + {clientFk: 1103, amount: 250} + ]; + })); + + describe('checked() getter', () => { + it('should return the checked lines', () => { + const data = controller.$.model.data; + data[1].checked = true; + data[2].checked = true; + + const checkedRows = controller.checked; + + const firstCheckedRow = checkedRows[0]; + const secondCheckedRow = checkedRows[1]; + + expect(firstCheckedRow.clientFk).toEqual(1102); + expect(secondCheckedRow.clientFk).toEqual(1103); + }); + }); + + describe('chipColor()', () => { + it('should return undefined when the date is the present', () => { + let today = new Date(); + let result = controller.chipColor(today); + + expect(result).toEqual(undefined); + }); + + it('should return warning when the date is 10 days in the past', () => { + let pastDate = new Date(); + pastDate = pastDate.setDate(pastDate.getDate() - 11); + let result = controller.chipColor(pastDate); + + expect(result).toEqual('warning'); + }); + + it('should return alert when the date is 20 days in the past', () => { + let pastDate = new Date(); + pastDate = pastDate.setDate(pastDate.getDate() - 21); + let result = controller.chipColor(pastDate); + + expect(result).toEqual('alert'); + }); + }); + + describe('onResponse()', () => { + it('should return error for empty message', () => { + let error; + try { + controller.onResponse(); + } catch (e) { + error = e; + } + + expect(error).toBeDefined(); + expect(error.message).toBe(`The message can't be empty`); + }); + + it('should return saved message', () => { + const data = controller.$.model.data; + data[1].checked = true; + controller.defaulter = {observation: 'My new observation'}; + + const params = [{text: controller.defaulter.observation, clientFk: data[1].clientFk}]; + + jest.spyOn(controller.vnApp, 'showMessage'); + $httpBackend.expect('GET', `Defaulters/filter`).respond(200); + $httpBackend.expect('POST', `ClientObservations`, params).respond(200, params); + + controller.onResponse(); + $httpBackend.flush(); + + expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Observation saved!'); + }); + }); + + describe('exprBuilder()', () => { + it('should search by sales person', () => { + const expr = controller.exprBuilder('salesPersonFk', '5'); + + expect(expr).toEqual({'d.salesPersonFk': '5'}); + }); + + it('should search by client', () => { + const expr = controller.exprBuilder('clientFk', '5'); + + expect(expr).toEqual({'d.clientFk': '5'}); + }); + }); + + describe('getBalanceDueTotal()', () => { + it('should return balance due total', () => { + const defaulters = controller.$.model.data; + $httpBackend.when('GET', `Defaulters/filter`).respond(defaulters); + + controller.getBalanceDueTotal(); + $httpBackend.flush(); + + expect(controller.balanceDueTotal).toEqual(875); + }); + }); + }); +}); diff --git a/modules/item/front/item-shelving/locale/es.yml b/modules/item/front/item-shelving/locale/es.yml new file mode 100644 index 000000000..c3e1d4e19 --- /dev/null +++ b/modules/item/front/item-shelving/locale/es.yml @@ -0,0 +1,9 @@ +Add observation: Añadir observación +Add observation to all selected clients: Añadir observación a {{total}} cliente(s) seleccionado(s) +Balance D.: Saldo V. +Credit I.: Crédito A. +Last observation: Última observación +L. O. Date: Fecha Ú. O. +Last observation date: Fecha última observación +Search client: Buscar clientes +Worker who made the last observation: Trabajador que ha realizado la última observación \ No newline at end of file diff --git a/modules/item/front/locale/es.yml b/modules/item/front/locale/es.yml index 1b75e3802..88ab031e1 100644 --- a/modules/item/front/locale/es.yml +++ b/modules/item/front/locale/es.yml @@ -54,6 +54,7 @@ Basic data: Datos básicos Tax: IVA History: Historial Botanical: Botánico +Shelvings: Carros Barcodes: Códigos de barras Diary: Histórico Item diary: Registro de compra-venta diff --git a/modules/item/front/routes.json b/modules/item/front/routes.json index 5743d0ce7..52cf5d2be 100644 --- a/modules/item/front/routes.json +++ b/modules/item/front/routes.json @@ -16,7 +16,8 @@ {"state": "item.card.basicData", "icon": "settings"}, {"state": "item.card.tags", "icon": "icon-tags"}, {"state": "item.card.tax", "icon": "icon-tax"}, - {"state": "item.card.botanical", "icon": "local_florist"}, + {"state": "item.card.botanical", "icon": "local_florist"}, + {"state": "item.card.shelving", "icon": "icon-inventory"}, {"state": "item.card.itemBarcode", "icon": "icon-barcode"}, {"state": "item.card.diary", "icon": "icon-transaction"}, {"state": "item.card.last-entries", "icon": "icon-regentry"}, @@ -92,6 +93,16 @@ }, "acl": ["buyer"] }, + { + "url" : "/shelving", + "state": "item.card.shelving", + "component": "vn-item-shelving", + "description": "Shelvings", + "params": { + "item": "$ctrl.item" + }, + "acl": ["employee"] + }, { "url" : "/barcode", "state": "item.card.itemBarcode", diff --git a/modules/shelving/front/routes.json b/modules/shelving/front/routes.json index b99ca4cac..0a05db9e3 100644 --- a/modules/shelving/front/routes.json +++ b/modules/shelving/front/routes.json @@ -14,7 +14,7 @@ ] }, "keybindings": [ - {"key": "s", "state": "shelving.index"} + {"key": "c", "state": "shelving.index"} ], "routes": [ { From ddbe1057ad9996e42100e156c188faafd40f1a3f Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 6 Oct 2022 09:47:53 +0200 Subject: [PATCH 2/9] feat: add new section --- .../10490-august/00-aclItemShelving.sql | 3 + ...00-aclItemShelvingPlacementSupply copy.sql | 3 + .../item-shelving-placement-supply.json | 9 +- modules/item/front/item-shelving/index.html | 132 +++++------------- modules/item/front/item-shelving/index.js | 106 ++++++-------- .../item/front/item-shelving/locale/es.yml | 12 +- 6 files changed, 95 insertions(+), 170 deletions(-) create mode 100644 db/changes/10490-august/00-aclItemShelving.sql create mode 100644 db/changes/10490-august/00-aclItemShelvingPlacementSupply copy.sql diff --git a/db/changes/10490-august/00-aclItemShelving.sql b/db/changes/10490-august/00-aclItemShelving.sql new file mode 100644 index 000000000..3995bbe49 --- /dev/null +++ b/db/changes/10490-august/00-aclItemShelving.sql @@ -0,0 +1,3 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('ItemShelving', '*', '*', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/db/changes/10490-august/00-aclItemShelvingPlacementSupply copy.sql b/db/changes/10490-august/00-aclItemShelvingPlacementSupply copy.sql new file mode 100644 index 000000000..cc589a58f --- /dev/null +++ b/db/changes/10490-august/00-aclItemShelvingPlacementSupply copy.sql @@ -0,0 +1,3 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('ItemShelvingPlacementSupplyStock', '*', '*', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/modules/item/back/models/item-shelving-placement-supply.json b/modules/item/back/models/item-shelving-placement-supply.json index 11497b4fc..a54013e05 100644 --- a/modules/item/back/models/item-shelving-placement-supply.json +++ b/modules/item/back/models/item-shelving-placement-supply.json @@ -7,13 +7,17 @@ } }, "properties": { + "itemShelvingFk": { + "type": "number", + "id": true + }, "created": { "type": "date" }, "itemFk": { "type": "number" }, - "concept": { + "longName": { "type": "string" }, "parking": { @@ -24,6 +28,9 @@ }, "packing": { "type": "number" + }, + "stock": { + "type": "number" } } } \ No newline at end of file diff --git a/modules/item/front/item-shelving/index.html b/modules/item/front/item-shelving/index.html index 7949e73a3..115829c8d 100644 --- a/modules/item/front/item-shelving/index.html +++ b/modules/item/front/item-shelving/index.html @@ -1,21 +1,10 @@ - - - - + ng-click="removeConfirm.show()" + vn-tooltip="Remove selected lines" + vn-acl="replenisherBos" + icon="delete"> @@ -50,123 +39,78 @@ model="model"> - + Created - + Item + field="longName"> Concept + field="parking"> Parking - + Shelving + field="label"> Etiqueta Packing - + - + {{::itemShelvingPlacementSupplyStock.created | date: 'dd/MM/yyyy'}} + + {{::itemShelvingPlacementSupplyStock.itemFk}} + + - {{::defaulter.clientName}} + {{itemShelvingPlacementSupplyStock.longName}} - - {{::defaulter.salesPersonName | dashIfEmpty}} - + {{::itemShelvingPlacementSupplyStock.parking}} - {{::defaulter.amount | currency: 'EUR': 2}} - - {{::defaulter.workerName | dashIfEmpty}} - + {{::itemShelvingPlacementSupplyStock.shelving}} - - - + + {{::itemShelvingPlacementSupplyStock.label}} - - - {{::defaulter.created | date: 'dd/MM/yyyy'}} - + + {{::itemShelvingPlacementSupplyStock.packing}} - {{::defaulter.creditInsurance | currency: 'EUR': 2}} - {{::defaulter.defaulterSinced | date: 'dd/MM/yyyy'}} - - - - - - - - + + - - - -
-
{{$ctrl.$t('Add observation to all selected clients', {total: $ctrl.checked.length})}}
- - - - -
-
- - - - -
+ + \ No newline at end of file diff --git a/modules/item/front/item-shelving/index.js b/modules/item/front/item-shelving/index.js index f51a1a65b..6fd8825aa 100644 --- a/modules/item/front/item-shelving/index.js +++ b/modules/item/front/item-shelving/index.js @@ -1,11 +1,9 @@ import ngModule from '../module'; import Section from 'salix/components/section'; -import UserError from 'core/lib/user-error'; export default class Controller extends Section { constructor($element, $) { super($element, $); - this.defaulter = {}; this.smartTableOptions = { activeButtons: { @@ -13,42 +11,31 @@ export default class Controller extends Section { }, columns: [ { - field: 'clientFk', + field: 'parking', autocomplete: { - url: 'Clients', - showField: 'name', - valueField: 'id' + url: 'Parkings', + showField: 'code', + valueField: 'code' } }, { - field: 'salesPersonFk', + field: 'shelving', autocomplete: { - url: 'Workers/activeWithInheritedRole', - where: `{role: 'salesPerson'}`, - searchFunction: '{firstName: $search}', - showField: 'name', - valueField: 'id', + url: 'Shelvings', + showField: 'code', + valueField: 'code' } }, - { - field: 'workerFk', - autocomplete: { - url: 'Workers/activeWithInheritedRole', - searchFunction: '{firstName: $search}', - showField: 'name', - valueField: 'id', - } - }, - { - field: 'observation', - searchable: false - }, { field: 'created', searchable: false }, { - field: 'defaulterSinced', + field: 'itemFk', + searchable: false + }, + { + field: 'longName', searchable: false } ] @@ -58,16 +45,24 @@ export default class Controller extends Section { } get checked() { - const clients = this.$.model.data || []; + const itemShelvings = this.$.model.data || []; const checkedLines = []; - for (let defaulter of clients) { - if (defaulter.checked) - checkedLines.push(defaulter); + for (let itemShelving of itemShelvings) { + if (itemShelving.checked) + checkedLines.push(itemShelving); } return checkedLines; } + get label() { + const itemShelvings = this.$.model.data || []; + for (let itemShelving of itemShelvings) + itemShelving.label = itemShelving.stock / itemShelving.packing; + + return true; + } + getBalanceDueTotal() { this.$http.get('Defaulters/filter') .then(res => { @@ -80,48 +75,27 @@ export default class Controller extends Section { }); } - chipColor(date) { - const day = 24 * 60 * 60 * 1000; - const today = new Date(); - today.setHours(0, 0, 0, 0); - - const observationShipped = new Date(date); - observationShipped.setHours(0, 0, 0, 0); - - const difference = today - observationShipped; - - if (difference > (day * 20)) - return 'alert'; - if (difference > (day * 10)) - return 'warning'; - } - - onResponse() { - if (!this.defaulter.observation) - throw new UserError(`The message can't be empty`); - + async onRemove() { const params = []; - for (let defaulter of this.checked) { - params.push({ - text: this.defaulter.observation, - clientFk: defaulter.clientFk - }); - } + for (let itemShelving of this.checked) + params.push(itemShelving.itemShelvingFk); - this.$http.post(`ClientObservations`, params) .then(() => { - this.vnApp.showMessage(this.$t('Observation saved!')); - this.$state.reload(); - }); + for (let id of params) { + await this.$http.delete(`ItemShelvings/${id}`) + .then(() => { + this.vnApp.showSuccess(this.$t('ItemShelving removed')); + this.$state.reload(); + }); + } } exprBuilder(param, value) { switch (param) { - case 'creditInsurance': - case 'amount': - case 'clientFk': - case 'workerFk': - case 'salesPersonFk': - return {[`d.${param}`]: value}; + case 'parking': + case 'shelving': + case 'label': + case 'packing': + return {[param]: value}; } } } diff --git a/modules/item/front/item-shelving/locale/es.yml b/modules/item/front/item-shelving/locale/es.yml index c3e1d4e19..00b6ffe58 100644 --- a/modules/item/front/item-shelving/locale/es.yml +++ b/modules/item/front/item-shelving/locale/es.yml @@ -1,9 +1,3 @@ -Add observation: Añadir observación -Add observation to all selected clients: Añadir observación a {{total}} cliente(s) seleccionado(s) -Balance D.: Saldo V. -Credit I.: Crédito A. -Last observation: Última observación -L. O. Date: Fecha Ú. O. -Last observation date: Fecha última observación -Search client: Buscar clientes -Worker who made the last observation: Trabajador que ha realizado la última observación \ No newline at end of file +Shelving: Matrícula +Remove selected lines: Eliminar líneas seleccionadas +Selected lines will be deleted: Las líneas seleccionadas serán eliminadas \ No newline at end of file From 9c52508a88a20d1d5d827b3c8c3e4d08494b32d0 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 11 Oct 2022 08:40:22 +0200 Subject: [PATCH 3/9] feat: add total labels --- .../00-aclItemShelving.sql | 0 .../00-aclItemShelvingPlacementSupply.sql} | 0 .../00-itemType.sql | 0 .../item-shelving/deleteItemShelvings.js | 47 +++++++++++++++++++ .../specs/deleteItemShelvings.spec.js | 21 +++++++++ modules/item/back/models/item-shelving.js | 3 ++ modules/item/front/item-shelving/index.html | 18 +++---- modules/item/front/item-shelving/index.js | 45 ++++++------------ .../item/front/item-shelving/locale/es.yml | 4 +- 9 files changed, 98 insertions(+), 40 deletions(-) rename db/changes/{10490-august => 10491-august}/00-aclItemShelving.sql (100%) rename db/changes/{10490-august/00-aclItemShelvingPlacementSupply copy.sql => 10491-august/00-aclItemShelvingPlacementSupply.sql} (100%) rename db/changes/{10480-june => 10491-august}/00-itemType.sql (100%) create mode 100644 modules/item/back/methods/item-shelving/deleteItemShelvings.js create mode 100644 modules/item/back/methods/item-shelving/specs/deleteItemShelvings.spec.js create mode 100644 modules/item/back/models/item-shelving.js diff --git a/db/changes/10490-august/00-aclItemShelving.sql b/db/changes/10491-august/00-aclItemShelving.sql similarity index 100% rename from db/changes/10490-august/00-aclItemShelving.sql rename to db/changes/10491-august/00-aclItemShelving.sql diff --git a/db/changes/10490-august/00-aclItemShelvingPlacementSupply copy.sql b/db/changes/10491-august/00-aclItemShelvingPlacementSupply.sql similarity index 100% rename from db/changes/10490-august/00-aclItemShelvingPlacementSupply copy.sql rename to db/changes/10491-august/00-aclItemShelvingPlacementSupply.sql diff --git a/db/changes/10480-june/00-itemType.sql b/db/changes/10491-august/00-itemType.sql similarity index 100% rename from db/changes/10480-june/00-itemType.sql rename to db/changes/10491-august/00-itemType.sql diff --git a/modules/item/back/methods/item-shelving/deleteItemShelvings.js b/modules/item/back/methods/item-shelving/deleteItemShelvings.js new file mode 100644 index 000000000..0b58970d8 --- /dev/null +++ b/modules/item/back/methods/item-shelving/deleteItemShelvings.js @@ -0,0 +1,47 @@ +module.exports = Self => { + Self.remoteMethod('deleteItemShelvings', { + description: 'Deletes the selected orders', + accessType: 'WRITE', + accepts: [{ + arg: 'itemShelvingIds', + type: ['number'], + required: true, + description: 'The itemShelving ids to delete' + }], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/deleteItemShelvings`, + verb: 'POST' + } + }); + + Self.deleteItemShelvings = async(itemShelvingIds, options) => { + const models = Self.app.models; + const myOptions = {}; + let tx; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const deletedItemShelvings = await models.ItemShelving.destroyAll({ + id: {inq: itemShelvingIds} + }, myOptions); + + if (tx) await tx.commit(); + + return deletedItemShelvings; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/item/back/methods/item-shelving/specs/deleteItemShelvings.spec.js b/modules/item/back/methods/item-shelving/specs/deleteItemShelvings.spec.js new file mode 100644 index 000000000..a152b5981 --- /dev/null +++ b/modules/item/back/methods/item-shelving/specs/deleteItemShelvings.spec.js @@ -0,0 +1,21 @@ +const models = require('vn-loopback/server/server').models; + +describe('ItemShelving deleteItemShelvings()', () => { + it('should return the deleted itemShelvings', async() => { + const tx = await models.Order.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const itemShelvingIds = [1, 2]; + const result = await models.ItemShelving.deleteItemShelvings(itemShelvingIds, options); + + expect(result.count).toEqual(2); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/item/back/models/item-shelving.js b/modules/item/back/models/item-shelving.js new file mode 100644 index 000000000..5f372a3be --- /dev/null +++ b/modules/item/back/models/item-shelving.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/item-shelving/deleteItemShelvings')(Self); +}; diff --git a/modules/item/front/item-shelving/index.html b/modules/item/front/item-shelving/index.html index 115829c8d..fa7a70544 100644 --- a/modules/item/front/item-shelving/index.html +++ b/modules/item/front/item-shelving/index.html @@ -2,7 +2,7 @@ vn-id="model" url="ItemShelvingPlacementSupplyStocks" link="{itemFk: $ctrl.$params.id}" - data="itemShelvingPlacementSupplyStocks" + data="$ctrl.itemShelvingPlacementSupplyStocks" auto-load="true"> @@ -15,18 +15,18 @@
Total
+ label="Total labels" + value="{{$ctrl.labelTotal.toFixed(2)}}">
+ vn-acl="replenisherBos">
@@ -68,7 +68,9 @@ - + - {{::itemShelvingPlacementSupplyStock.label}} + {{(itemShelvingPlacementSupplyStock.stock / itemShelvingPlacementSupplyStock.packing).toFixed(2)}} {{::itemShelvingPlacementSupplyStock.packing}} diff --git a/modules/item/front/item-shelving/index.js b/modules/item/front/item-shelving/index.js index 6fd8825aa..b8584039b 100644 --- a/modules/item/front/item-shelving/index.js +++ b/modules/item/front/item-shelving/index.js @@ -40,8 +40,6 @@ export default class Controller extends Section { } ] }; - - this.getBalanceDueTotal(); } get checked() { @@ -49,46 +47,31 @@ export default class Controller extends Section { const checkedLines = []; for (let itemShelving of itemShelvings) { if (itemShelving.checked) - checkedLines.push(itemShelving); + checkedLines.push(itemShelving.itemShelvingFk); } return checkedLines; } - get label() { + calculateTotals() { + this.labelTotal = 0; const itemShelvings = this.$.model.data || []; - for (let itemShelving of itemShelvings) - itemShelving.label = itemShelving.stock / itemShelving.packing; - - return true; + itemShelvings.forEach(itemShelving => { + const label = itemShelving.stock / itemShelving.packing; + this.labelTotal += label; + }); } - getBalanceDueTotal() { - this.$http.get('Defaulters/filter') - .then(res => { - if (!res.data) return 0; - - this.balanceDueTotal = res.data.reduce( - (accumulator, currentValue) => { - return accumulator + (currentValue['amount'] || 0); - }, 0); + onRemove() { + const params = {itemShelvingIds: this.checked}; + const query = `ItemShelvings/deleteItemShelvings`; + this.$http.post(query, params) + .then(() => { + this.vnApp.showSuccess(this.$t('ItemShelvings removed')); + this.$.model.refresh(); }); } - async onRemove() { - const params = []; - for (let itemShelving of this.checked) - params.push(itemShelving.itemShelvingFk); - - for (let id of params) { - await this.$http.delete(`ItemShelvings/${id}`) - .then(() => { - this.vnApp.showSuccess(this.$t('ItemShelving removed')); - this.$state.reload(); - }); - } - } - exprBuilder(param, value) { switch (param) { case 'parking': diff --git a/modules/item/front/item-shelving/locale/es.yml b/modules/item/front/item-shelving/locale/es.yml index 00b6ffe58..006363cfa 100644 --- a/modules/item/front/item-shelving/locale/es.yml +++ b/modules/item/front/item-shelving/locale/es.yml @@ -1,3 +1,5 @@ Shelving: Matrícula Remove selected lines: Eliminar líneas seleccionadas -Selected lines will be deleted: Las líneas seleccionadas serán eliminadas \ No newline at end of file +Selected lines will be deleted: Las líneas seleccionadas serán eliminadas +ItemShelvings removed: Carros eliminados +Total labels: Total etiquetas \ No newline at end of file From 1a38fc307f1364676adadf5feb02dc231daf10c4 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 11 Oct 2022 08:42:59 +0200 Subject: [PATCH 4/9] delete: duplicated keybinding --- modules/shelving/front/routes.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/modules/shelving/front/routes.json b/modules/shelving/front/routes.json index 0a05db9e3..09a8e389b 100644 --- a/modules/shelving/front/routes.json +++ b/modules/shelving/front/routes.json @@ -13,9 +13,6 @@ {"state": "shelving.card.log", "icon": "history"} ] }, - "keybindings": [ - {"key": "c", "state": "shelving.index"} - ], "routes": [ { "url": "/shelving", From bfefec397e68e86c2879bd1f89d3aacc8763a276 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 11 Oct 2022 09:13:29 +0200 Subject: [PATCH 5/9] feat: add testFront --- .../item/front/item-shelving/index.spec.js | 118 ++++++------------ 1 file changed, 39 insertions(+), 79 deletions(-) diff --git a/modules/item/front/item-shelving/index.spec.js b/modules/item/front/item-shelving/index.spec.js index 0732c68a1..55df1c27d 100644 --- a/modules/item/front/item-shelving/index.spec.js +++ b/modules/item/front/item-shelving/index.spec.js @@ -1,120 +1,80 @@ import './index'; import crudModel from 'core/mocks/crud-model'; -describe('client defaulter', () => { - describe('Component vnClientDefaulter', () => { +describe('item shelving', () => { + describe('Component vnItemShelving', () => { let controller; let $httpBackend; - beforeEach(ngModule('client')); + beforeEach(ngModule('item')); beforeEach(inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; - const $element = angular.element(''); - controller = $componentController('vnClientDefaulter', {$element}); + const $element = angular.element(''); + controller = $componentController('vnItemShelving', {$element}); controller.$.model = crudModel; controller.$.model.data = [ - {clientFk: 1101, amount: 125}, - {clientFk: 1102, amount: 500}, - {clientFk: 1103, amount: 250} + {itemShelvingFk: 1, packing: 10, stock: 1}, + {itemShelvingFk: 2, packing: 12, stock: 5}, + {itemShelvingFk: 4, packing: 20, stock: 10} ]; + const modelData = controller.$.model.data; + modelData[0].checked = true; + modelData[1].checked = true; })); describe('checked() getter', () => { - it('should return the checked lines', () => { - const data = controller.$.model.data; - data[1].checked = true; - data[2].checked = true; + it('should return a the selected rows', () => { + const result = controller.checked; - const checkedRows = controller.checked; - - const firstCheckedRow = checkedRows[0]; - const secondCheckedRow = checkedRows[1]; - - expect(firstCheckedRow.clientFk).toEqual(1102); - expect(secondCheckedRow.clientFk).toEqual(1103); + expect(result).toEqual(expect.arrayContaining([1, 2])); }); }); - describe('chipColor()', () => { - it('should return undefined when the date is the present', () => { - let today = new Date(); - let result = controller.chipColor(today); + describe('calculateTotals()', () => { + it('should calculate the total of labels', () => { + controller.calculateTotals(); - expect(result).toEqual(undefined); - }); - - it('should return warning when the date is 10 days in the past', () => { - let pastDate = new Date(); - pastDate = pastDate.setDate(pastDate.getDate() - 11); - let result = controller.chipColor(pastDate); - - expect(result).toEqual('warning'); - }); - - it('should return alert when the date is 20 days in the past', () => { - let pastDate = new Date(); - pastDate = pastDate.setDate(pastDate.getDate() - 21); - let result = controller.chipColor(pastDate); - - expect(result).toEqual('alert'); + expect(controller.labelTotal).toEqual(1.0166666666666666); }); }); - describe('onResponse()', () => { - it('should return error for empty message', () => { - let error; - try { - controller.onResponse(); - } catch (e) { - error = e; - } + describe('onRemove()', () => { + it('shoud remove the selected lines', () => { + jest.spyOn(controller.$.model, 'refresh'); + const expectedParams = {itemShelvingIds: [1, 2]}; - expect(error).toBeDefined(); - expect(error.message).toBe(`The message can't be empty`); - }); - - it('should return saved message', () => { - const data = controller.$.model.data; - data[1].checked = true; - controller.defaulter = {observation: 'My new observation'}; - - const params = [{text: controller.defaulter.observation, clientFk: data[1].clientFk}]; - - jest.spyOn(controller.vnApp, 'showMessage'); - $httpBackend.expect('GET', `Defaulters/filter`).respond(200); - $httpBackend.expect('POST', `ClientObservations`, params).respond(200, params); - - controller.onResponse(); + $httpBackend.expectPOST('ItemShelvings/deleteItemShelvings', expectedParams).respond(200); + controller.onRemove(); $httpBackend.flush(); - expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Observation saved!'); + expect(controller.$.model.refresh).toHaveBeenCalled(); }); }); describe('exprBuilder()', () => { - it('should search by sales person', () => { - const expr = controller.exprBuilder('salesPersonFk', '5'); + it('should search by parking', () => { + const expr = controller.exprBuilder('parking', '700-01'); - expect(expr).toEqual({'d.salesPersonFk': '5'}); + expect(expr).toEqual({'parking': '700-01'}); }); - it('should search by client', () => { - const expr = controller.exprBuilder('clientFk', '5'); + it('should search by shelving', () => { + const expr = controller.exprBuilder('shelving', 'AAA'); - expect(expr).toEqual({'d.clientFk': '5'}); + expect(expr).toEqual({'shelving': 'AAA'}); }); - }); - describe('getBalanceDueTotal()', () => { - it('should return balance due total', () => { - const defaulters = controller.$.model.data; - $httpBackend.when('GET', `Defaulters/filter`).respond(defaulters); + it('should search by label', () => { + const expr = controller.exprBuilder('label', 0.17); - controller.getBalanceDueTotal(); - $httpBackend.flush(); + expect(expr).toEqual({'label': 0.17}); + }); - expect(controller.balanceDueTotal).toEqual(875); + it('should search by packing', () => { + const expr = controller.exprBuilder('packing', 10); + + expect(expr).toEqual({'packing': 10}); }); }); }); From 8a3573474a99de0a60a330ab00c0fd106273c406 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 25 Oct 2022 07:40:32 +0200 Subject: [PATCH 6/9] refactor: move 'lastEntries' to thrid position in descriptor --- modules/item/front/routes.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/item/front/routes.json b/modules/item/front/routes.json index 52cf5d2be..3dea69ba1 100644 --- a/modules/item/front/routes.json +++ b/modules/item/front/routes.json @@ -15,12 +15,12 @@ "card": [ {"state": "item.card.basicData", "icon": "settings"}, {"state": "item.card.tags", "icon": "icon-tags"}, + {"state": "item.card.last-entries", "icon": "icon-regentry"}, {"state": "item.card.tax", "icon": "icon-tax"}, {"state": "item.card.botanical", "icon": "local_florist"}, {"state": "item.card.shelving", "icon": "icon-inventory"}, {"state": "item.card.itemBarcode", "icon": "icon-barcode"}, {"state": "item.card.diary", "icon": "icon-transaction"}, - {"state": "item.card.last-entries", "icon": "icon-regentry"}, {"state": "item.card.log", "icon": "history"} ], "itemType": [ From 7f1dd801a55aff414fbaf06eacbbdb8bf25039ad Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 25 Oct 2022 07:56:17 +0200 Subject: [PATCH 7/9] refactor: change ACLs --- db/changes/10491-august/00-aclItemShelving.sql | 3 --- db/changes/10491-august/00-aclItemShelvingPlacementSupply.sql | 3 --- db/changes/10500-november/00-itemShelvingACL.sql | 4 ++++ .../10500-november/00-itemShelvingPlacementSupplyStockACL.sql | 4 ++++ 4 files changed, 8 insertions(+), 6 deletions(-) delete mode 100644 db/changes/10491-august/00-aclItemShelving.sql delete mode 100644 db/changes/10491-august/00-aclItemShelvingPlacementSupply.sql create mode 100644 db/changes/10500-november/00-itemShelvingACL.sql create mode 100644 db/changes/10500-november/00-itemShelvingPlacementSupplyStockACL.sql diff --git a/db/changes/10491-august/00-aclItemShelving.sql b/db/changes/10491-august/00-aclItemShelving.sql deleted file mode 100644 index 3995bbe49..000000000 --- a/db/changes/10491-august/00-aclItemShelving.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('ItemShelving', '*', '*', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/db/changes/10491-august/00-aclItemShelvingPlacementSupply.sql b/db/changes/10491-august/00-aclItemShelvingPlacementSupply.sql deleted file mode 100644 index cc589a58f..000000000 --- a/db/changes/10491-august/00-aclItemShelvingPlacementSupply.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES - ('ItemShelvingPlacementSupplyStock', '*', '*', 'ALLOW', 'ROLE', 'employee'); \ No newline at end of file diff --git a/db/changes/10500-november/00-itemShelvingACL.sql b/db/changes/10500-november/00-itemShelvingACL.sql new file mode 100644 index 000000000..fc32fe1ed --- /dev/null +++ b/db/changes/10500-november/00-itemShelvingACL.sql @@ -0,0 +1,4 @@ +INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) +VALUES + ('ItemShelving', '*', 'READ', 'ALLOW', 'ROLE', 'employee'), + ('ItemShelving', '*', 'WRITE', 'ALLOW', 'ROLE', 'production'); \ No newline at end of file diff --git a/db/changes/10500-november/00-itemShelvingPlacementSupplyStockACL.sql b/db/changes/10500-november/00-itemShelvingPlacementSupplyStockACL.sql new file mode 100644 index 000000000..25eac8d51 --- /dev/null +++ b/db/changes/10500-november/00-itemShelvingPlacementSupplyStockACL.sql @@ -0,0 +1,4 @@ +INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) +VALUES + ('ItemShelvingPlacementSupplyStock', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); + From 07a18dc736048fd3f6304daa80a9ef0fcf985e0c Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 26 Oct 2022 08:05:11 +0200 Subject: [PATCH 8/9] delete sql --- db/changes/10491-august/00-itemType.sql | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 db/changes/10491-august/00-itemType.sql diff --git a/db/changes/10491-august/00-itemType.sql b/db/changes/10491-august/00-itemType.sql deleted file mode 100644 index d201acf37..000000000 --- a/db/changes/10491-august/00-itemType.sql +++ /dev/null @@ -1,5 +0,0 @@ -ALTER TABLE `vn`.`itemType` CHANGE `transaction` transaction__ tinyint(4) DEFAULT 0 NOT NULL; -ALTER TABLE `vn`.`itemType` CHANGE location location__ varchar(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL; -ALTER TABLE `vn`.`itemType` CHANGE hasComponents hasComponents__ tinyint(1) DEFAULT 1 NOT NULL; -ALTER TABLE `vn`.`itemType` CHANGE warehouseFk warehouseFk__ smallint(6) unsigned DEFAULT 60 NOT NULL; -ALTER TABLE `vn`.`itemType` CHANGE compression compression__ decimal(5,2) DEFAULT 1.00 NULL; \ No newline at end of file From 21e2945d4f6b59df9b239fd197b8845dbda7f8ef Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 26 Oct 2022 09:30:17 +0200 Subject: [PATCH 9/9] refactor: delete destroyAll --- .../methods/item-shelving/deleteItemShelvings.js | 12 ++++++++---- .../item-shelving/specs/deleteItemShelvings.spec.js | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/item/back/methods/item-shelving/deleteItemShelvings.js b/modules/item/back/methods/item-shelving/deleteItemShelvings.js index 0b58970d8..f534b4e9a 100644 --- a/modules/item/back/methods/item-shelving/deleteItemShelvings.js +++ b/modules/item/back/methods/item-shelving/deleteItemShelvings.js @@ -1,6 +1,6 @@ module.exports = Self => { Self.remoteMethod('deleteItemShelvings', { - description: 'Deletes the selected orders', + description: 'Deletes the selected item shelvings', accessType: 'WRITE', accepts: [{ arg: 'itemShelvingIds', @@ -32,9 +32,13 @@ module.exports = Self => { } try { - const deletedItemShelvings = await models.ItemShelving.destroyAll({ - id: {inq: itemShelvingIds} - }, myOptions); + const promises = []; + for (let itemShelvingId of itemShelvingIds) { + const itemShelvingToDelete = models.ItemShelving.destroyById(itemShelvingId, myOptions); + promises.push(itemShelvingToDelete); + } + + const deletedItemShelvings = await Promise.all(promises); if (tx) await tx.commit(); diff --git a/modules/item/back/methods/item-shelving/specs/deleteItemShelvings.spec.js b/modules/item/back/methods/item-shelving/specs/deleteItemShelvings.spec.js index a152b5981..b4113d7cf 100644 --- a/modules/item/back/methods/item-shelving/specs/deleteItemShelvings.spec.js +++ b/modules/item/back/methods/item-shelving/specs/deleteItemShelvings.spec.js @@ -10,7 +10,7 @@ describe('ItemShelving deleteItemShelvings()', () => { const itemShelvingIds = [1, 2]; const result = await models.ItemShelving.deleteItemShelvings(itemShelvingIds, options); - expect(result.count).toEqual(2); + expect(result.length).toEqual(2); await tx.rollback(); } catch (e) {