salix/modules/item/front/tax/index.js

49 lines
1.3 KiB
JavaScript

import ngModule from '../module';
export default class Controller {
constructor($stateParams, $http, $translate, vnApp) {
this.$http = $http;
this.$stateParams = $stateParams;
this._ = $translate;
this.vnApp = vnApp;
}
$onInit() {
this.getTaxes();
}
getTaxes() {
let filter = {
fields: ['id', 'countryFk', 'taxClassFk'],
include: [{
relation: 'country',
scope: {fields: ['country']}
}]
};
let urlFilter = encodeURIComponent(JSON.stringify(filter));
let url = `/item/api/Items/${this.$stateParams.id}/taxes?filter=${urlFilter}`;
this.$http.get(url).then(json => {
this.taxes = json.data;
});
}
submit() {
let data = [];
for (let tax of this.taxes)
data.push({id: tax.id, taxClassFk: tax.taxClassFk});
let url = `/item/api/Items/updateTaxes`;
this.$http.post(url, data).then(
() => this.vnApp.showSuccess(this._.instant('Data saved!'))
);
}
}
Controller.$inject = ['$stateParams', '$http', '$translate', 'vnApp'];
ngModule.component('vnItemTax', {
template: require('./index.html'),
controller: Controller
});