salix/modules/client/front/defaulter/index.js

66 lines
1.6 KiB
JavaScript
Raw Normal View History

import ngModule from '../module';
import Section from 'salix/components/section';
import UserError from 'core/lib/user-error';
export default class Controller extends Section {
constructor($element, $) {
super($element, $);
this.defaulter = {};
}
get balanceDueTotal() {
let balanceDueTotal = 0;
if (this.checked.length > 0) {
for (let defaulter of this.checked)
balanceDueTotal += defaulter.amount;
return balanceDueTotal;
}
return balanceDueTotal;
}
get checked() {
const clients = this.$.model.data || [];
const checkedLines = [];
for (let defaulter of clients) {
if (defaulter.checked)
checkedLines.push(defaulter);
}
return checkedLines;
}
onResponse() {
if (!this.defaulter.observation)
throw new UserError(`The message can't be empty`);
2022-02-01 07:49:56 +00:00
const params = [];
for (let defaulter of this.checked) {
2022-02-01 07:49:56 +00:00
params.push({
text: this.defaulter.observation,
clientFk: defaulter.clientFk
2022-02-01 07:49:56 +00:00
});
}
2022-02-01 07:49:56 +00:00
this.$http.post(`ClientObservations`, params) .then(() => {
this.vnApp.showMessage(this.$t('Observation saved!'));
this.$state.reload();
});
}
exprBuilder(param, value) {
switch (param) {
case 'clientName':
case 'salesPersonFk':
return {[`d.${param}`]: value};
}
}
}
ngModule.vnComponent('vnClientDefaulterIndex', {
template: require('./index.html'),
controller: Controller
});