diff --git a/db/changes/10480-june/00-itemType.sql b/db/changes/10480-june/00-itemType.sql deleted file mode 100644 index d201acf370..0000000000 --- a/db/changes/10480-june/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 diff --git a/db/changes/10500-november/00-itemShelvingACL.sql b/db/changes/10500-november/00-itemShelvingACL.sql new file mode 100644 index 0000000000..fc32fe1edc --- /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 0000000000..25eac8d518 --- /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'); + diff --git a/front/salix/locale/es.yml b/front/salix/locale/es.yml index e5dc82b164..d92c32b337 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/methods/item-shelving/deleteItemShelvings.js b/modules/item/back/methods/item-shelving/deleteItemShelvings.js new file mode 100644 index 0000000000..f534b4e9a2 --- /dev/null +++ b/modules/item/back/methods/item-shelving/deleteItemShelvings.js @@ -0,0 +1,51 @@ +module.exports = Self => { + Self.remoteMethod('deleteItemShelvings', { + description: 'Deletes the selected item shelvings', + 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 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(); + + 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 0000000000..b4113d7cf5 --- /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.length).toEqual(2); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/item/back/model-config.json b/modules/item/back/model-config.json index 9737d26fc0..40d73f1a61 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 0000000000..a54013e05b --- /dev/null +++ b/modules/item/back/models/item-shelving-placement-supply.json @@ -0,0 +1,36 @@ +{ + "name": "ItemShelvingPlacementSupplyStock", + "base": "VnModel", + "options": { + "mysql": { + "table": "itemShelvingPlacementSupplyStock" + } + }, + "properties": { + "itemShelvingFk": { + "type": "number", + "id": true + }, + "created": { + "type": "date" + }, + "itemFk": { + "type": "number" + }, + "longName": { + "type": "string" + }, + "parking": { + "type": "string" + }, + "shelving": { + "type": "string" + }, + "packing": { + "type": "number" + }, + "stock": { + "type": "number" + } + } +} \ No newline at end of file diff --git a/modules/item/back/models/item-shelving.js b/modules/item/back/models/item-shelving.js new file mode 100644 index 0000000000..5f372a3be4 --- /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/index.js b/modules/item/front/index.js index 6a8d1b3b78..d2ffcc8fb1 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 0000000000..fa7a705440 --- /dev/null +++ b/modules/item/front/item-shelving/index.html @@ -0,0 +1,118 @@ + + + + + +
+
+
Total
+ + +
+
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Created + + Item + + Concept + + Parking + + Shelving + + Etiqueta + + Packing +
+ + + {{::itemShelvingPlacementSupplyStock.created | date: 'dd/MM/yyyy'}} + {{::itemShelvingPlacementSupplyStock.itemFk}} + + + {{itemShelvingPlacementSupplyStock.longName}} + + + {{::itemShelvingPlacementSupplyStock.parking}} + + {{::itemShelvingPlacementSupplyStock.shelving}} + + {{(itemShelvingPlacementSupplyStock.stock / itemShelvingPlacementSupplyStock.packing).toFixed(2)}} + + {{::itemShelvingPlacementSupplyStock.packing}} +
+
+
+
+ + + + + \ No newline at end of file diff --git a/modules/item/front/item-shelving/index.js b/modules/item/front/item-shelving/index.js new file mode 100644 index 0000000000..b8584039b8 --- /dev/null +++ b/modules/item/front/item-shelving/index.js @@ -0,0 +1,89 @@ +import ngModule from '../module'; +import Section from 'salix/components/section'; + +export default class Controller extends Section { + constructor($element, $) { + super($element, $); + + this.smartTableOptions = { + activeButtons: { + search: true + }, + columns: [ + { + field: 'parking', + autocomplete: { + url: 'Parkings', + showField: 'code', + valueField: 'code' + } + }, + { + field: 'shelving', + autocomplete: { + url: 'Shelvings', + showField: 'code', + valueField: 'code' + } + }, + { + field: 'created', + searchable: false + }, + { + field: 'itemFk', + searchable: false + }, + { + field: 'longName', + searchable: false + } + ] + }; + } + + get checked() { + const itemShelvings = this.$.model.data || []; + const checkedLines = []; + for (let itemShelving of itemShelvings) { + if (itemShelving.checked) + checkedLines.push(itemShelving.itemShelvingFk); + } + + return checkedLines; + } + + calculateTotals() { + this.labelTotal = 0; + const itemShelvings = this.$.model.data || []; + itemShelvings.forEach(itemShelving => { + const label = itemShelving.stock / itemShelving.packing; + this.labelTotal += label; + }); + } + + 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(); + }); + } + + exprBuilder(param, value) { + switch (param) { + case 'parking': + case 'shelving': + case 'label': + case 'packing': + return {[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 0000000000..55df1c27dd --- /dev/null +++ b/modules/item/front/item-shelving/index.spec.js @@ -0,0 +1,81 @@ +import './index'; +import crudModel from 'core/mocks/crud-model'; + +describe('item shelving', () => { + describe('Component vnItemShelving', () => { + let controller; + let $httpBackend; + + beforeEach(ngModule('item')); + + beforeEach(inject(($componentController, _$httpBackend_) => { + $httpBackend = _$httpBackend_; + const $element = angular.element(''); + controller = $componentController('vnItemShelving', {$element}); + controller.$.model = crudModel; + controller.$.model.data = [ + {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 a the selected rows', () => { + const result = controller.checked; + + expect(result).toEqual(expect.arrayContaining([1, 2])); + }); + }); + + describe('calculateTotals()', () => { + it('should calculate the total of labels', () => { + controller.calculateTotals(); + + expect(controller.labelTotal).toEqual(1.0166666666666666); + }); + }); + + describe('onRemove()', () => { + it('shoud remove the selected lines', () => { + jest.spyOn(controller.$.model, 'refresh'); + const expectedParams = {itemShelvingIds: [1, 2]}; + + $httpBackend.expectPOST('ItemShelvings/deleteItemShelvings', expectedParams).respond(200); + controller.onRemove(); + $httpBackend.flush(); + + expect(controller.$.model.refresh).toHaveBeenCalled(); + }); + }); + + describe('exprBuilder()', () => { + it('should search by parking', () => { + const expr = controller.exprBuilder('parking', '700-01'); + + expect(expr).toEqual({'parking': '700-01'}); + }); + + it('should search by shelving', () => { + const expr = controller.exprBuilder('shelving', 'AAA'); + + expect(expr).toEqual({'shelving': 'AAA'}); + }); + + it('should search by label', () => { + const expr = controller.exprBuilder('label', 0.17); + + expect(expr).toEqual({'label': 0.17}); + }); + + it('should search by packing', () => { + const expr = controller.exprBuilder('packing', 10); + + expect(expr).toEqual({'packing': 10}); + }); + }); + }); +}); 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 0000000000..006363cfa1 --- /dev/null +++ b/modules/item/front/item-shelving/locale/es.yml @@ -0,0 +1,5 @@ +Shelving: Matrícula +Remove selected lines: Eliminar líneas seleccionadas +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 diff --git a/modules/item/front/locale/es.yml b/modules/item/front/locale/es.yml index 1b75e38021..88ab031e14 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 5743d0ce7f..3dea69ba1b 100644 --- a/modules/item/front/routes.json +++ b/modules/item/front/routes.json @@ -15,11 +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.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": [ @@ -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 b99ca4caca..09a8e389ba 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": "s", "state": "shelving.index"} - ], "routes": [ { "url": "/shelving",