2022-01-25 13:27:30 +00:00
|
|
|
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 = {};
|
2022-02-21 14:11:39 +00:00
|
|
|
|
|
|
|
this.smartTableOptions = {
|
|
|
|
activeButtons: {
|
|
|
|
search: true
|
|
|
|
},
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
field: 'clientName',
|
|
|
|
autocomplete: {
|
|
|
|
url: 'Clients',
|
|
|
|
showField: 'name',
|
|
|
|
valueField: 'name'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'salesPersonFk',
|
|
|
|
autocomplete: {
|
|
|
|
url: 'Workers/activeWithInheritedRole',
|
|
|
|
where: `{role: 'salesPerson'}`,
|
|
|
|
searchFunction: '{firstName: $search}',
|
|
|
|
showField: 'nickname',
|
|
|
|
valueField: 'id',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'amount',
|
|
|
|
searchable: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'workerFk',
|
|
|
|
autocomplete: {
|
|
|
|
url: 'Workers/activeWithInheritedRole',
|
|
|
|
where: `{role: 'salesPerson'}`,
|
|
|
|
searchFunction: '{firstName: $search}',
|
|
|
|
showField: 'nickname',
|
|
|
|
valueField: 'id',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'observation',
|
|
|
|
autocomplete: {
|
|
|
|
url: 'Defaulters/filter',
|
|
|
|
showField: 'observation',
|
|
|
|
valueField: 'observation',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'creditInsurance',
|
|
|
|
searchable: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'defaulterSinced',
|
|
|
|
searchable: false
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2022-01-25 13:27:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get balanceDueTotal() {
|
|
|
|
let balanceDueTotal = 0;
|
2022-02-21 14:11:39 +00:00
|
|
|
const defaulters = this.$.model.data || [];
|
2022-01-25 13:27:30 +00:00
|
|
|
|
2022-02-21 14:11:39 +00:00
|
|
|
for (let defaulter of defaulters)
|
|
|
|
balanceDueTotal += defaulter.amount;
|
2022-01-25 13:27:30 +00:00
|
|
|
|
|
|
|
return balanceDueTotal;
|
|
|
|
}
|
|
|
|
|
|
|
|
get checked() {
|
|
|
|
const clients = this.$.model.data || [];
|
|
|
|
const checkedLines = [];
|
|
|
|
for (let defaulter of clients) {
|
|
|
|
if (defaulter.checked)
|
|
|
|
checkedLines.push(defaulter);
|
|
|
|
}
|
|
|
|
|
|
|
|
return checkedLines;
|
|
|
|
}
|
|
|
|
|
2022-02-21 14:11:39 +00:00
|
|
|
chipColor(date) {
|
|
|
|
const day = 24 * 60 * 60 * 1000;
|
|
|
|
const today = new Date();
|
|
|
|
today.setHours(0, 0, 0, 0);
|
|
|
|
|
|
|
|
const observationShipped = new Date(date);
|
|
|
|
observationShipped.setHours(0, 0, 0, 0);
|
|
|
|
|
|
|
|
const difference = today - observationShipped;
|
|
|
|
|
|
|
|
if (difference > (day * 20))
|
|
|
|
return 'alert';
|
|
|
|
if (difference > (day * 10))
|
|
|
|
return 'warning';
|
|
|
|
}
|
|
|
|
|
2022-01-25 13:27:30 +00:00
|
|
|
onResponse() {
|
|
|
|
if (!this.defaulter.observation)
|
|
|
|
throw new UserError(`The message can't be empty`);
|
|
|
|
|
2022-02-01 07:49:56 +00:00
|
|
|
const params = [];
|
2022-01-25 13:27:30 +00:00
|
|
|
for (let defaulter of this.checked) {
|
2022-02-01 07:49:56 +00:00
|
|
|
params.push({
|
2022-01-25 13:27:30 +00:00
|
|
|
text: this.defaulter.observation,
|
|
|
|
clientFk: defaulter.clientFk
|
2022-02-01 07:49:56 +00:00
|
|
|
});
|
2022-01-25 13:27:30 +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();
|
|
|
|
});
|
2022-01-25 13:27:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exprBuilder(param, value) {
|
|
|
|
switch (param) {
|
2022-02-21 14:11:39 +00:00
|
|
|
case 'observation':
|
|
|
|
return {[`observation`]: value};
|
2022-01-25 13:27:30 +00:00
|
|
|
case 'clientName':
|
2022-02-21 14:11:39 +00:00
|
|
|
case 'workerFk':
|
2022-01-25 13:27:30 +00:00
|
|
|
case 'salesPersonFk':
|
|
|
|
return {[`d.${param}`]: value};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ngModule.vnComponent('vnClientDefaulterIndex', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller
|
|
|
|
});
|