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

101 lines
2.3 KiB
JavaScript

import ngModule from '../../module';
import Dialog from 'core/components/dialog';
class Controller extends Dialog {
constructor($element, $, $transclude) {
super($element, $, $transclude);
this.receipt = {
payed: new Date(),
clientFk: this.$params.id,
companyFk: this.vnConfig.companyFk,
bankFk: this.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;
}
get bankSelection() {
return this._bankSelection;
}
set bankSelection(value) {
this._bankSelection = value;
if (value) {
const accountingType = value.accountingType;
this.receipt.description = accountingType && accountingType.receiptDescription;
}
}
getAmountPaid() {
const filter = {
where: {
clientFk: this.$params.id,
companyFk: this.receipt.companyFk
}
};
this.$http.get(`ClientRisks`, {filter}).then(res => {
this.receipt.amountPaid = (res.data.length && res.data[0].amount) || null;
});
}
responseHandler(response) {
if (response !== 'accept')
return super.responseHandler(response);
return this.$http.post(`Receipts`, this.receipt)
.then(() => super.responseHandler(response))
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
}
}
ngModule.vnComponent('vnClientBalanceCreate', {
slotTemplate: require('./index.html'),
controller: Controller,
bindings: {
payed: '<?',
bankFk: '<?',
amountPaid: '<?',
companyFk: '<?',
description: '<?',
clientFk: '<?'
}
});