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' } } } }; } $onChanges() { if (!this.client) return; 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(); } }); } 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 = 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(); } } ngModule.vnComponent('vnClientSummary', { template: require('./index.html'), controller: Controller, bindings: { client: '<' } });