diff --git a/client/core/src/components/dialog/dialog.spec.js b/client/core/src/components/dialog/dialog.spec.js index e81eb6445..8cb1ad4a9 100644 --- a/client/core/src/components/dialog/dialog.spec.js +++ b/client/core/src/components/dialog/dialog.spec.js @@ -39,14 +39,14 @@ describe('Component vnDialog', () => { describe('fireResponse()', () => { it(`should call onResponse()`, () => { - let resposneRes; + let responseRes; controller.onResponse = response => { - resposneRes = response; + responseRes = response; return false; }; let responseRet = controller.fireResponse('answer'); - expect(resposneRes).toEqual({response: 'answer'}); + expect(responseRes).toEqual({response: 'answer'}); expect(responseRet).toEqual(false); }); }); diff --git a/client/item/routes.json b/client/item/routes.json index 1a85e9504..0db762877 100644 --- a/client/item/routes.json +++ b/client/item/routes.json @@ -52,6 +52,15 @@ }, "acl": ["buyer"] }, + { + "url" : "/tax", + "state": "item.card.tax", + "component": "vn-item-tax", + "menu": { + "description": "Tax", + "icon": "folder" + } + }, { "url" : "/history", "state": "item.card.history", diff --git a/client/item/src/item.js b/client/item/src/item.js index ef5846179..504933d06 100644 --- a/client/item/src/item.js +++ b/client/item/src/item.js @@ -8,6 +8,7 @@ import './card/item-card'; import './descriptor/item-descriptor'; import './data/item-data'; import './tags/item-tags'; +import './tax/item-tax'; import './history/item-history'; import './niche/item-niche'; import './botanical/item-botanical'; diff --git a/client/item/src/locale/es.yml b/client/item/src/locale/es.yml index 07191a246..b96cb64b2 100644 --- a/client/item/src/locale/es.yml +++ b/client/item/src/locale/es.yml @@ -11,6 +11,7 @@ Basic data: Datos básicos History: Historial Item history: Historial del artículo Item tags: Tags del artículo +Tax: IVA Niche: Nicho Picture: Foto Barcode: Código barras diff --git a/client/item/src/tax/item-tax.html b/client/item/src/tax/item-tax.html new file mode 100644 index 000000000..9f542fbdf --- /dev/null +++ b/client/item/src/tax/item-tax.html @@ -0,0 +1,24 @@ +
+ + + Item tax + + + + + + + + + + + +
\ No newline at end of file diff --git a/client/item/src/tax/item-tax.js b/client/item/src/tax/item-tax.js new file mode 100644 index 000000000..71a54aa70 --- /dev/null +++ b/client/item/src/tax/item-tax.js @@ -0,0 +1,43 @@ +import ngModule from '../module'; + +export default class Controller { + constructor($stateParams, $http) { + this.$http = $http; + this.$stateParams = $stateParams; + + let filter = { + fields: ['id', 'countryFk', 'taxClassFk'], + include: [{ + relation: 'country', + scope: {fields: ['country']} + }] + }; + + let urlFilter = encodeURIComponent(JSON.stringify(filter)); + let url = `/item/api/Items/${$stateParams.id}/taxes?filter=${urlFilter}`; + $http.get(url).then(json => { + this.taxes = json.data; + }); + + $http.get(`/item/api/TaxClasses`).then(json => { + this.classes = json.data; + }); + } + submit() { + let data = []; + for (let tax of this.taxes) + data.push({id: tax.id, taxClassFk: tax.taxClassFk}); + + let url = `/item/api/Items/${this.$stateParams.id}/updateTaxes`; + this.$http.post(url, data); + } +} +Controller.$inject = ['$stateParams', '$http']; + +ngModule.component('vnItemTax', { + template: require('./item-tax.html'), + controller: Controller, + bindings: { + item: '<' + } +}); diff --git a/services/item/common/methods/item/updateTaxes.js b/services/item/common/methods/item/updateTaxes.js new file mode 100644 index 000000000..502b2763f --- /dev/null +++ b/services/item/common/methods/item/updateTaxes.js @@ -0,0 +1,38 @@ +module.exports = Self => { + Self.remoteMethod('updateTaxes', { + description: 'Updates the item taxes', + accessType: 'WRITE', + accepts: [{ + arg: 'id', + type: 'number', + required: true, + description: 'The item id', + http: {source: 'path'} + }, { + arg: 'niches', + type: ['object'], + required: true, + description: 'The list of taxes to update', + http: {source: 'body'} + }], + returns: { + type: 'boolean', + root: true + }, + http: { + path: `/:id/updateTaxes`, + verb: 'post' + } + }); + + Self.updateTaxes = async (id, taxes) => { + let promises = []; + for (let tax of taxes) + promises.push(Self.app.models.ItemTaxCountry.updateAll( + {id: tax.id}, + {taxClassFk: tax.taxClassFk} + )); + await Promise.all(promises); + return true; + }; +}; diff --git a/services/item/common/models/item-tax-country.json b/services/item/common/models/item-tax-country.json new file mode 100644 index 000000000..7f67a271e --- /dev/null +++ b/services/item/common/models/item-tax-country.json @@ -0,0 +1,36 @@ +{ + "name": "ItemTaxCountry", + "base": "VnModel", + "options": { + "mysql": { + "table": "itemTaxCountry" + } + }, + "properties": { + "id": { + "type": "Number", + "id": true, + "description": "Identifier" + }, + "effectived": { + "type": "Boolean" + } + }, + "relations": { + "item": { + "type": "belongsTo", + "model": "Item", + "foreignKey": "itemFk" + }, + "country": { + "type": "belongsTo", + "model": "Country", + "foreignKey": "countryFk" + }, + "taxClass": { + "type": "belongsTo", + "model": "TaxClass", + "foreignKey": "taxClassFk" + } + } +} \ No newline at end of file diff --git a/services/item/common/models/item.js b/services/item/common/models/item.js index af0b626f3..627b6993b 100644 --- a/services/item/common/models/item.js +++ b/services/item/common/models/item.js @@ -1,6 +1,7 @@ module.exports = function(Self) { require('../methods/item/filter.js')(Self); require('../methods/item/clone.js')(Self); + require('../methods/item/updateTaxes.js')(Self); Self.validatesPresenceOf('name', {message: 'Cannot be blank'}); Self.validatesPresenceOf('originFk', {message: 'Cannot be blank'}); diff --git a/services/item/common/models/item.json b/services/item/common/models/item.json index daff68084..ddb8ff4d3 100644 --- a/services/item/common/models/item.json +++ b/services/item/common/models/item.json @@ -85,6 +85,11 @@ "model": "ItemBarcode", "foreignKey": "itemFk" }, + "taxes": { + "type": "hasMany", + "model": "ItemTaxCountry", + "foreignKey": "itemFk" + }, "itemNiche": { "type": "hasMany", "model": "ItemNiche", diff --git a/services/item/server/model-config.json b/services/item/server/model-config.json index 83b473a5a..229054dd6 100644 --- a/services/item/server/model-config.json +++ b/services/item/server/model-config.json @@ -50,6 +50,9 @@ "ItemPlacement": { "dataSource": "vn" }, + "ItemTaxCountry": { + "dataSource": "vn" + }, "Warehouse": { "dataSource": "vn" },