import ngModule from '../module'; import './style.scss'; class Controller { constructor($scope, $state, $http, vnApp, $translate) { this.$scope = $scope; this.vnApp = vnApp; this.$translate = $translate; this.$state = $state; this.$http = $http; this.idsToRemove = []; } $onInit() { this.getRows(); this.getVAT(); } getRows() { let filter = { where: {orderFk: this.$state.params.id}, include: [{ relation: 'item', scope: { include: { relation: 'tags', scope: { fields: ['tagFk', 'value'], include: { relation: 'tag', scope: { fields: ['name'] } } } }, fields: ['itemFk', 'name', 'image'] } }, {relation: 'warehouse'}] }; filter = encodeURIComponent(JSON.stringify(filter)); let query = `/order/api/OrderRows?filter=${filter}`; this.$http.get(query).then(res => { this.rows = res.data; }); } getVAT() { let query = `/order/api/Orders/${this.$state.params.id}/getVAT`; this.$http.get(query).then(res => { this.VAT = res.data; }); } removeRow(index) { let [lineRemoved] = this.rows.splice(index, 1); this.idsToRemove.push(lineRemoved.id); } // Item Descriptor showDescriptor(event, itemFk) { this.$scope.descriptor.itemFk = itemFk; this.$scope.descriptor.parent = event.target; this.$scope.descriptor.show(); } onDescriptorLoad() { this.$scope.popover.relocate(); } save() { let params = { rows: this.idsToRemove, actualOrderId: this.$state.params.id }; let query = `/order/api/OrderRows/removes`; this.$http.post(query, params).then(() => { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); }); } } Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate']; ngModule.component('vnOrderLine', { template: require('./index.html'), controller: Controller, bindings: { order: '<' } });