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 = {};
|
2023-03-15 07:40:53 +00:00
|
|
|
this.checkedDefaulers = [];
|
2022-02-21 14:11:39 +00:00
|
|
|
|
|
|
|
this.smartTableOptions = {
|
|
|
|
activeButtons: {
|
|
|
|
search: true
|
|
|
|
},
|
|
|
|
columns: [
|
|
|
|
{
|
2022-04-08 06:52:21 +00:00
|
|
|
field: 'clientFk',
|
2022-02-21 14:11:39 +00:00
|
|
|
autocomplete: {
|
|
|
|
url: 'Clients',
|
2022-04-08 06:52:21 +00:00
|
|
|
showField: 'name',
|
|
|
|
valueField: 'id'
|
2022-02-21 14:11:39 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'salesPersonFk',
|
|
|
|
autocomplete: {
|
|
|
|
url: 'Workers/activeWithInheritedRole',
|
|
|
|
where: `{role: 'salesPerson'}`,
|
|
|
|
searchFunction: '{firstName: $search}',
|
2022-05-16 12:30:48 +00:00
|
|
|
showField: 'name',
|
2022-02-21 14:11:39 +00:00
|
|
|
valueField: 'id',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'workerFk',
|
|
|
|
autocomplete: {
|
|
|
|
url: 'Workers/activeWithInheritedRole',
|
|
|
|
searchFunction: '{firstName: $search}',
|
2022-05-16 12:30:48 +00:00
|
|
|
showField: 'name',
|
2022-02-21 14:11:39 +00:00
|
|
|
valueField: 'id',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'observation',
|
2022-03-01 10:43:35 +00:00
|
|
|
searchable: false
|
2022-02-21 14:11:39 +00:00
|
|
|
},
|
2022-02-23 08:52:45 +00:00
|
|
|
{
|
|
|
|
field: 'created',
|
|
|
|
searchable: false
|
|
|
|
},
|
2022-02-21 14:11:39 +00:00
|
|
|
{
|
|
|
|
field: 'defaulterSinced',
|
|
|
|
searchable: false
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2022-01-25 13:27:30 +00:00
|
|
|
|
2022-06-13 05:44:21 +00:00
|
|
|
this.getBalanceDueTotal();
|
2022-01-25 13:27:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get checked() {
|
|
|
|
const clients = this.$.model.data || [];
|
|
|
|
const checkedLines = [];
|
|
|
|
for (let defaulter of clients) {
|
|
|
|
if (defaulter.checked)
|
|
|
|
checkedLines.push(defaulter);
|
|
|
|
}
|
|
|
|
|
|
|
|
return checkedLines;
|
|
|
|
}
|
|
|
|
|
2023-03-15 07:40:53 +00:00
|
|
|
saveChecked(clientId) {
|
|
|
|
this.checkedDefaulers = this.checkedDefaulers.includes(clientId) ?
|
|
|
|
this.checkedDefaulers.filter(id => id !== clientId) : [...this.checkedDefaulers, clientId];
|
|
|
|
}
|
|
|
|
|
|
|
|
reCheck() {
|
|
|
|
if (!this.$.model.data || !this.checkedDefaulers.length) return;
|
|
|
|
|
|
|
|
this.$.model.data.forEach(defaulter => {
|
|
|
|
defaulter.checked = this.checkedDefaulers.includes(defaulter.clientFk);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-06-13 05:44:21 +00:00
|
|
|
getBalanceDueTotal() {
|
|
|
|
this.$http.get('Defaulters/filter')
|
|
|
|
.then(res => {
|
|
|
|
if (!res.data) return 0;
|
|
|
|
|
|
|
|
this.balanceDueTotal = res.data.reduce(
|
|
|
|
(accumulator, currentValue) => {
|
|
|
|
return accumulator + (currentValue['amount'] || 0);
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-02-21 14:11:39 +00:00
|
|
|
chipColor(date) {
|
|
|
|
const day = 24 * 60 * 60 * 1000;
|
2023-01-16 14:18:24 +00:00
|
|
|
const today = Date.vnNew();
|
2022-02-21 14:11:39 +00:00
|
|
|
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-23 07:53:25 +00:00
|
|
|
case 'creditInsurance':
|
|
|
|
case 'amount':
|
2022-04-08 06:52:21 +00:00
|
|
|
case 'clientFk':
|
2022-02-21 14:11:39 +00:00
|
|
|
case 'workerFk':
|
2022-01-25 13:27:30 +00:00
|
|
|
case 'salesPersonFk':
|
|
|
|
return {[`d.${param}`]: value};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-25 09:34:17 +00:00
|
|
|
ngModule.vnComponent('vnClientDefaulter', {
|
2022-01-25 13:27:30 +00:00
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller
|
|
|
|
});
|