const app = require('../app') const moment = require('moment-immutable') const _ = require('lodash') const { previousWeekIcon, previousDayIcon, nextDayIcon, nextWeekIcon } = require('../assets') app.component('appDashboardPage', { template: html`
{{workday.short}}

{{$ctrl.date.format('LL')}}

{{::$ctrl.serviceCategories[serviceCategory.serviceCategory].name}}

Cartons

{{serviceCategory.lastMetrics[serviceCategory.serviceColumn]}}

Labor Cost

$\{{Math.floor(serviceCategory.lastMetrics.laborCost) || null}}

Cost per Carton

{{serviceCategory.lastMetrics.costPer | currency}}

{{::$ctrl.terminals[terminal.terminal].name}}

Cost per Carton
{{::$ctrl.laborCategories[laborCategory.laborCategory].name}} {{laborCategory.costPer | currency}}
All {{terminal.costPer | currency}}

Overall

{{::$ctrl.laborCategories[laborCategory.laborCategory].name}} {{laborCategory.costPer | currency}}
All {{serviceCategory.costPer | currency}}
Labor Costs
{{$ctrl.charts.laborCost.series[$index]}}
Cost per Carton
{{$ctrl.charts.costPerCarton.series[$index]}}
`, controller: function(api, statistics, $scope) { $scope.Math = Math const load = (date) => { api.statistics(date).then(stats => { this.statistics = stats this.charts = statistics.charts(stats.metricsOverTime) this.last = stats.last }) } api.terminals().then(terminals => { this.terminals = terminals }) api.laborCategories().then(laborCategories => { this.laborCategories = laborCategories }) api.serviceCategories().then(serviceCategories => { this.serviceCategories = serviceCategories }) api.get(`/api/workdays`).then(workdays => { const wds = {} workdays.dates.forEach(x => (wds[x] = true)) const getWorkdays = (offset) => { const dates = _.range(offset - 6, offset + 1) .map(x => { const date = moment().startOf('day').add(x, 'days') return { date, formatted: date.format('L'), short: date.format('M/DD'), hasData: wds[date.format('YYYY-MM-DD')] } }) return dates } this.setOffset = (offset) => { this.offset = offset this.workdays = getWorkdays(offset) } this.setDate = (date) => { this.date = date this.now = moment() load(date) } this.setOffset(0) this.setDate(moment( workdays.dates .map(x => moment(x).valueOf()) .sort() .pop() || moment.now() )) }) // statistics.costPerCarton().then(statistics => { // Object.assign(this, statistics) // }) } }) window.moment = moment