50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
import ngModule from '../module';
|
|
|
|
export default class Controller {
|
|
constructor($stateParams, $http, $translate, $scope) {
|
|
this.$ = $scope;
|
|
this.$http = $http;
|
|
this.$stateParams = $stateParams;
|
|
this._ = $translate;
|
|
}
|
|
|
|
$onInit() {
|
|
this.getTaxes();
|
|
}
|
|
|
|
getTaxes() {
|
|
let filter = {
|
|
fields: ['id', 'countryFk', 'taxClassFk'],
|
|
include: [{
|
|
relation: 'country',
|
|
scope: {fields: ['country']}
|
|
}]
|
|
};
|
|
|
|
let url = `Items/${this.$stateParams.id}/taxes`;
|
|
this.$http.get(url, {params: {filter}}).then(json => {
|
|
this.taxes = json.data;
|
|
});
|
|
}
|
|
|
|
submit() {
|
|
let data = [];
|
|
for (let tax of this.taxes)
|
|
data.push({id: tax.id, taxClassFk: tax.taxClassFk});
|
|
|
|
this.$.watcher.check();
|
|
let url = `Items/updateTaxes`;
|
|
this.$http.post(url, data).then(() => {
|
|
this.$.watcher.notifySaved();
|
|
this.$.watcher.updateOriginalData();
|
|
});
|
|
}
|
|
}
|
|
|
|
Controller.$inject = ['$stateParams', '$http', '$translate', '$scope'];
|
|
|
|
ngModule.component('vnItemTax', {
|
|
template: require('./index.html'),
|
|
controller: Controller
|
|
});
|