136 lines
3.2 KiB
JavaScript
136 lines
3.2 KiB
JavaScript
import ngModule from '../module';
|
|
import Summary from 'salix/components/summary';
|
|
import './style.scss';
|
|
|
|
class Controller extends Summary {
|
|
constructor($element, $) {
|
|
super($element, $);
|
|
|
|
this.ticketFilter = {
|
|
include: [
|
|
{
|
|
relation: 'ticketState',
|
|
scope: {
|
|
fields: ['stateFk', 'code', 'alertLevel'],
|
|
include: {
|
|
relation: 'state'
|
|
}
|
|
}
|
|
},
|
|
{
|
|
relation: 'invoiceOut',
|
|
scope: {
|
|
fields: ['id']
|
|
}
|
|
},
|
|
{
|
|
relation: 'agencyMode',
|
|
scope: {
|
|
fields: ['name']
|
|
}
|
|
},
|
|
]
|
|
};
|
|
}
|
|
|
|
get client() {
|
|
return this._client;
|
|
}
|
|
|
|
set client(value) {
|
|
this._client = value;
|
|
if (value) {
|
|
this.loadData();
|
|
this.loadTickets();
|
|
}
|
|
}
|
|
|
|
loadData() {
|
|
this.$http.get(`Clients/${this.client.id}/summary`).then(res => {
|
|
if (res && res.data) {
|
|
this.summary = res.data;
|
|
|
|
if (res.data.classifications.length)
|
|
this.grade = res.data.classifications[0].insurances[0].grade;
|
|
|
|
this.summary.sumRisk = this.sumRisk();
|
|
}
|
|
});
|
|
}
|
|
|
|
loadTickets() {
|
|
this.$.$applyAsync(() => this.$.ticketsModel.refresh());
|
|
}
|
|
|
|
get isEmployee() {
|
|
return this.aclService.hasAny(['employee']);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
stateColor(ticket) {
|
|
const ticketState = ticket.ticketState;
|
|
|
|
if (!ticketState) return;
|
|
|
|
if (ticketState.code === 'OK')
|
|
return 'success';
|
|
else if (ticketState.code === 'FREE')
|
|
return 'notice';
|
|
else if (ticketState.alertLevel === 1)
|
|
return 'warning';
|
|
else if (ticketState.alertLevel === 0)
|
|
return 'alert';
|
|
}
|
|
|
|
chipColor(date) {
|
|
const today = Date.vnNew();
|
|
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();
|
|
}
|
|
}
|
|
|
|
ngModule.vnComponent('vnClientSummary', {
|
|
template: require('./index.html'),
|
|
controller: Controller,
|
|
bindings: {
|
|
client: '<'
|
|
}
|
|
});
|