import ngModule from '../../module'; import './style.scss'; class Controller { constructor($scope, $state, $http, vnApp, $translate) { this.$http = $http; this.$ = $scope; this.$state = $state; this.vnApp = vnApp; this.$translate = $translate; this.receipt = { payed: new Date(), clientFk: this.$state.params.id, companyFk: window.localStorage.defaultCompanyFk, bankFk: window.localStorage.defaultBankFk }; } set payed(value) { this.receipt.payed = value; } set bankFk(value) { this.receipt.bankFk = value; } set amountPaid(value) { this.receipt.amountPaid = value; } set companyFk(value) { this.receipt.companyFk = value; this.getAmountPaid(); } getAmountPaid() { let filter = { where: { clientFk: this.$state.params.id, companyFk: this.receipt.companyFk } }; let query = `/client/api/ClientRisks?filter=${JSON.stringify(filter)}`; this.$http.get(query).then(res => { this.receipt.amountPaid = (res.data.length && res.data[0].amount) || null; }); } show() { this.$.dialog.show(); } hide() { this.$.dialog.hide(); } save() { let query = `/client/api/receipts`; this.$http.post(query, this.receipt).then(() => { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); this.hide(); if (this.onResponse) this.onResponse(); }); } } Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate']; ngModule.component('vnClientBalanceCreate', { template: require('./index.html'), controller: Controller, bindings: { payed: '