salix/modules/client/front/balance/create/index.js

104 lines
2.3 KiB
JavaScript

import ngModule from '../../module';
import './style.scss';
class Controller {
constructor($scope, $state, $http, vnApp, $translate, vnConfig) {
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: vnConfig.companyFk,
bankFk: vnConfig.bankFk
};
}
set payed(value) {
this.receipt.payed = value;
}
set bankFk(value) {
this.receipt.bankFk = value;
}
set amountPaid(value) {
this.receipt.amountPaid = value;
}
get amountPaid() {
return this.receipt.amountPaid;
}
set clientFk(value) {
this.receipt.clientFk = value;
}
get clientFk() {
return this.receipt.clientFk;
}
set companyFk(value) {
this.receipt.companyFk = value;
this.getAmountPaid();
}
set description(value) {
this.receipt.description = value;
}
get description() {
return this.receipt.description;
}
getAmountPaid() {
let filter = {
where: {
clientFk: this.$state.params.id,
companyFk: this.receipt.companyFk
}
};
let query = `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 = `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', 'vnConfig'];
ngModule.component('vnClientBalanceCreate', {
template: require('./index.html'),
controller: Controller,
bindings: {
payed: '<?',
bankFk: '<?',
amountPaid: '<?',
onResponse: '&?',
companyFk: '<?',
description: '<?',
clientFk: '<?'
}
});