From 2f17257e46096cdb9049d276df9b1c29c7d3071b Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 5 Oct 2022 15:13:48 +0200 Subject: [PATCH] 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": [ {