import ngModule from '../module'; class Controller { constructor($scope, $http, vnApp, $translate, $state) { this.$scope = $scope; this.$http = $http; this.translate = $translate; this.vnApp = vnApp; this.order = {}; this.$state = $state; } set order(value) { if (value) { this._order = value; } } get order() { return this._order; } set clientFk(value) { this.order.clientFk = value; this.addressFk = null; } get clientFk() { return this.order.clientFk; } set addressFk(value) { this.order.addressFk = value; this.getAvailableAgencies(); } get addressFk() { return this.order.addressFk; } set landed(value) { this.order.landed = value; this.getAvailableAgencies(); } get landed() { return this.order.landed; } get warehouseFk() { return this.order.warehouseFk; } getAvailableAgencies() { this.order.agencyModeFk = null; if (this.order.landed && this.order.addressFk) { let filter = {addressFk: this.order.addressFk, landed: this.order.landed}; filter = encodeURIComponent(JSON.stringify(filter)); let query = `/api/Agencies/landsThatDay?filter=${filter}`; this.$http.get(query).then(res => { this._availableAgencies = res.data[0]; }); } } onSubmit() { this.createOrder(); } createOrder() { let params = { landed: this.order.landed, addressFk: this.order.addressFk, agencyModeFk: this.order.agencyModeFk }; this.$http.post(`order/api/Orders/new`, params).then(res => { this.vnApp.showSuccess(this.translate.instant('Data saved!')); this.$state.go("order.card.catalogue", {id: res.data}); }).catch(e => { this.vnApp.showError(this.translate.instant(e.data.error.message)); }); } } Controller.$inject = ['$scope', '$http', 'vnApp', '$translate', '$state']; ngModule.component('vnOrderCreateCard', { template: require('./card.html'), controller: Controller, bindings: { order: '