import ngModule from '../module'; import FilterTicketList from '../filter-ticket-list'; class Controller extends FilterTicketList { constructor($scope, $timeout, $stateParams, $http) { super($scope, $timeout, $stateParams); this.$ = $scope; this.$timeout = $timeout; this.onOrder('itemFk', 'ASC'); this.$http = $http; } get isChecked() { let data = this.$.index.model.instances; if (data) for (let instance of data) if (instance.checked) return true; return false; } onStateOkClick() { let filter = {where: {code: "OK"}, fields: ["id"]}; let json = encodeURIComponent(JSON.stringify(filter)); this.$http.get(`/ticket/api/States?filter=${json}`).then(res => { this.onStateChange(res.data[0].id); }); } onStateChange(value) { let params = {ticketFk: this.$state.params.id, stateFk: value}; this.$http.post(`/ticket/api/TicketTrackings`, params).then(() => { this.card.reload(); }); } onRemoveLinesClick() { let lines = { delete: [] }; let data = this.$.index.model.instances; if (data) for (let i = 0; i < data.length;) { if (data[i].checked) { lines.delete.push(data[i].id); data.splice(i, 1); } else { i++; } } let query = `/ticket/api/Sales/crudSale`; this.$http.post(query, lines); } showDescriptor(event, itemFk) { this.$.descriptor.itemFk = itemFk; this.$.descriptor.parent = event.target; this.$.descriptor.show(); } onDescriptorLoad() { this.$.popover.relocate(); } } Controller.$inject = ['$scope', '$timeout', '$state', '$http']; ngModule.component('vnTicketSale', { template: require('./sale.html'), controller: Controller, bindings: { ticket: '<' }, require: { card: '^vnTicketCard' } });