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

104 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-10-24 12:10:48 +00:00
import ngModule from '../../module';
2019-02-05 15:46:02 +00:00
import './style.scss';
2018-10-24 12:10:48 +00:00
class Controller {
2019-02-05 15:46:02 +00:00
constructor($scope, $state, $http, vnApp, $translate) {
2018-10-24 12:10:48 +00:00
this.$http = $http;
this.$ = $scope;
this.$state = $state;
2019-02-05 15:46:02 +00:00
this.vnApp = vnApp;
this.$translate = $translate;
2018-10-24 12:10:48 +00:00
this.receipt = {
payed: new Date(),
clientFk: this.$state.params.id,
companyFk: window.localStorage.defaultCompanyFk,
bankFk: window.localStorage.defaultBankFk
};
2019-02-05 15:46:02 +00:00
}
2018-10-24 12:10:48 +00:00
2019-02-05 15:46:02 +00:00
set payed(value) {
this.receipt.payed = value;
}
2018-10-24 12:10:48 +00:00
2019-02-05 15:46:02 +00:00
set bankFk(value) {
this.receipt.bankFk = value;
}
2018-10-24 12:10:48 +00:00
2019-02-05 15:46:02 +00:00
set amountPaid(value) {
this.receipt.amountPaid = value;
}
2018-10-24 12:10:48 +00:00
2019-04-25 05:57:26 +00:00
get amountPaid() {
return this.receipt.amountPaid;
}
set clientFk(value) {
this.receipt.clientFk = value;
}
get clientFk() {
return this.receipt.clientFk;
}
2019-02-05 15:46:02 +00:00
set companyFk(value) {
this.receipt.companyFk = value;
this.getAmountPaid();
2018-10-24 12:10:48 +00:00
}
2019-04-25 05:57:26 +00:00
set description(value) {
this.receipt.description = value;
}
get description() {
return this.receipt.description;
}
2019-02-05 15:46:02 +00:00
getAmountPaid() {
2018-10-24 12:10:48 +00:00
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;
});
}
2019-02-05 15:46:02 +00:00
show() {
this.$.dialog.show();
2018-10-24 12:10:48 +00:00
}
2019-02-05 15:46:02 +00:00
hide() {
this.$.dialog.hide();
2018-10-24 12:10:48 +00:00
}
2019-02-05 15:46:02 +00:00
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();
});
2018-10-24 12:10:48 +00:00
}
}
2019-02-05 15:46:02 +00:00
Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate'];
2018-10-24 12:10:48 +00:00
2019-04-25 07:26:42 +00:00
ngModule.component('vnClientBalanceCreate', {
2018-10-24 12:10:48 +00:00
template: require('./index.html'),
2019-02-05 15:46:02 +00:00
controller: Controller,
bindings: {
payed: '<?',
bankFk: '<?',
amountPaid: '<?',
onResponse: '&?',
2019-04-25 05:57:26 +00:00
companyFk: '<?',
description: '<?',
clientFk: '<?'
2019-02-05 15:46:02 +00:00
}
2018-10-24 12:10:48 +00:00
});