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

120 lines
2.8 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
};
}
set payed(value) {
this.receipt.payed = value;
}
set amountPaid(value) {
this.receipt.amountPaid = value;
this.amountToReturn = this.deliveredAmount - 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;
}
}
set deliveredAmount(value) {
this._deliveredAmount = value;
this.amountToReturn = value - this.receipt.amountPaid;
}
get deliveredAmount() {
return this._deliveredAmount;
}
get bankFk() {
if (!this.receipt.bankFk)
this.receipt.bankFk = this.vnConfig.bankFk;
return this.receipt.bankFk;
}
set bankFk(value) {
this.receipt.bankFk = value;
}
accountShortToStandard(value) {
this.receipt.compensationAccount = value.replace('.', '0'.repeat(11 - value.length));
}
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.$params.id}/createReceipt`, 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: '<?'
}
});