2018-02-23 12:04:44 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
|
|
|
|
export default class Controller {
|
2018-05-31 09:52:39 +00:00
|
|
|
constructor($stateParams, $http, $translate, vnApp) {
|
2018-02-23 12:04:44 +00:00
|
|
|
this.$http = $http;
|
|
|
|
this.$stateParams = $stateParams;
|
2018-05-31 09:52:39 +00:00
|
|
|
this._ = $translate;
|
|
|
|
this.vnApp = vnApp;
|
2018-08-09 11:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$onInit() {
|
|
|
|
this.getTaxes();
|
|
|
|
}
|
2018-02-23 12:04:44 +00:00
|
|
|
|
2018-08-09 11:13:50 +00:00
|
|
|
getTaxes() {
|
2018-02-23 12:04:44 +00:00
|
|
|
let filter = {
|
|
|
|
fields: ['id', 'countryFk', 'taxClassFk'],
|
|
|
|
include: [{
|
|
|
|
relation: 'country',
|
|
|
|
scope: {fields: ['country']}
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
|
|
|
let urlFilter = encodeURIComponent(JSON.stringify(filter));
|
2018-08-09 11:13:50 +00:00
|
|
|
let url = `/item/api/Items/${this.$stateParams.id}/taxes?filter=${urlFilter}`;
|
|
|
|
this.$http.get(url).then(json => {
|
2018-02-23 12:04:44 +00:00
|
|
|
this.taxes = json.data;
|
|
|
|
});
|
|
|
|
}
|
2018-05-31 09:52:39 +00:00
|
|
|
|
2018-02-23 12:04:44 +00:00
|
|
|
submit() {
|
|
|
|
let data = [];
|
|
|
|
for (let tax of this.taxes)
|
|
|
|
data.push({id: tax.id, taxClassFk: tax.taxClassFk});
|
|
|
|
|
2018-08-30 05:09:06 +00:00
|
|
|
let url = `/item/api/Items/updateTaxes`;
|
2018-05-31 09:52:39 +00:00
|
|
|
this.$http.post(url, data).then(
|
2018-07-09 11:01:46 +00:00
|
|
|
() => this.vnApp.showSuccess(this._.instant('Data saved!'))
|
2018-05-31 09:52:39 +00:00
|
|
|
);
|
2018-02-23 12:04:44 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-25 08:03:45 +00:00
|
|
|
|
2018-05-31 09:52:39 +00:00
|
|
|
Controller.$inject = ['$stateParams', '$http', '$translate', 'vnApp'];
|
2018-02-23 12:04:44 +00:00
|
|
|
|
|
|
|
ngModule.component('vnItemTax', {
|
2018-05-25 08:03:45 +00:00
|
|
|
template: require('./index.html'),
|
2018-08-09 11:13:50 +00:00
|
|
|
controller: Controller
|
2018-02-23 12:04:44 +00:00
|
|
|
});
|