88 lines
2.0 KiB
JavaScript
88 lines
2.0 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;
|
|
}
|
|
|
|
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: '<?'
|
|
}
|
|
});
|