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

106 lines
2.5 KiB
JavaScript
Raw Normal View History

import ngModule from '../module';
2020-11-23 12:41:51 +00:00
import Summary from 'salix/components/summary';
2018-03-27 13:06:22 +00:00
import './style.scss';
2020-11-23 12:41:51 +00:00
class Controller extends Summary {
constructor($element, $) {
super($element, $);
this.ticketFilter = {
include: {
relation: 'ticketState',
scope: {
fields: ['stateFk', 'code', 'alertLevel'],
include: {
relation: 'state'
}
}
}
};
}
$onChanges() {
2018-03-27 13:06:22 +00:00
if (!this.client)
2018-03-05 09:56:51 +00:00
return;
this.$http.get(`Clients/${this.client.id}/summary`).then(res => {
if (res && res.data) {
2018-03-05 09:56:51 +00:00
this.summary = res.data;
if (res.data.classifications.length)
this.grade = res.data.classifications[0].insurances[0].grade;
2018-10-19 06:40:32 +00:00
this.summary.sumRisk = this.sumRisk();
}
2018-03-01 13:48:02 +00:00
});
}
get isEmployee() {
return this.aclService.hasAny(['employee']);
}
2018-10-19 06:40:32 +00:00
sumRisk() {
let total = 0;
this.summary.clientRisks.forEach(risk => {
total += risk.amount;
});
return total;
}
claimRate(priceIncreasing) {
if (priceIncreasing)
return priceIncreasing * 100;
}
claimingRate(rate) {
if (rate)
return rate * 100;
}
2021-06-16 07:43:07 +00:00
stateColor(ticket) {
const ticketState = ticket.ticketState;
if (ticketState.code === 'OK')
2021-06-16 07:43:07 +00:00
return 'success';
else if (ticketState.code === 'FREE')
2021-06-16 07:43:07 +00:00
return 'notice';
else if (ticketState.alertLevel === 1)
2021-06-16 07:43:07 +00:00
return 'warning';
else if (ticketState.alertLevel === 0)
2021-06-16 07:43:07 +00:00
return 'alert';
}
chipColor(date) {
const today = new Date();
today.setHours(0, 0, 0, 0);
const ticketShipped = new Date(date);
ticketShipped.setHours(0, 0, 0, 0);
const difference = today - ticketShipped;
if (difference == 0)
return 'warning';
if (difference < 0)
return 'success';
}
totalPriceColor(ticket) {
const total = parseInt(ticket.totalWithVat);
if (total > 0 && total < 50)
return 'warning';
}
preview(ticket) {
this.selectedTicket = ticket;
this.$.summary.show();
}
2018-03-01 13:48:02 +00:00
}
2018-03-27 13:06:22 +00:00
ngModule.vnComponent('vnClientSummary', {
2018-05-23 12:26:51 +00:00
template: require('./index.html'),
controller: Controller,
bindings: {
client: '<'
}
});