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

90 lines
2.0 KiB
JavaScript
Raw Normal View History

2018-10-24 12:10:48 +00:00
import ngModule from '../../module';
2020-03-30 15:30:03 +00:00
import Dialog from 'core/components/dialog';
import template from './index.html';
class Controller extends Dialog {
constructor($element, $, $transclude) {
super($element, $, $transclude);
this.fillSlots(template);
2018-10-24 12:10:48 +00:00
this.receipt = {
payed: new Date(),
2020-03-18 07:35:59 +00:00
clientFk: this.$params.id,
companyFk: this.vnConfig.companyFk,
bankFk: this.vnConfig.bankFk
2018-10-24 12:10:48 +00:00
};
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() {
2020-03-30 15:30:03 +00:00
const filter = {
2018-10-24 12:10:48 +00:00
where: {
2020-03-18 07:35:59 +00:00
clientFk: this.$params.id,
2018-10-24 12:10:48 +00:00
companyFk: this.receipt.companyFk
}
};
2020-03-30 15:30:03 +00:00
this.$http.get(`ClientRisks`, {filter}).then(res => {
2018-10-24 12:10:48 +00:00
this.receipt.amountPaid = (res.data.length && res.data[0].amount) || null;
});
}
2020-03-30 15:30:03 +00:00
responseHandler(response) {
if (response !== 'accept')
return super.responseHandler(response);
2018-10-24 12:10:48 +00:00
2020-03-30 15:30:03 +00:00
return this.$http.post(`Receipts`, this.receipt)
2020-03-31 08:19:01 +00:00
.then(() => super.responseHandler(response))
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
2018-10-24 12:10:48 +00:00
}
}
2020-03-30 15:30:03 +00:00
ngModule.vnComponent('vnClientBalanceCreate', {
2019-02-05 15:46:02 +00:00
controller: Controller,
2020-03-30 15:30:03 +00:00
transclude: true,
2019-02-05 15:46:02 +00:00
bindings: {
payed: '<?',
bankFk: '<?',
amountPaid: '<?',
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
});