import ngModule from '../module'; import Section from 'salix/components/section'; export default class Controller extends Section { preview(travel) { this.travelSelected = travel; this.$.summary.show(); } onCloneAccept(travel) { const params = JSON.stringify({ ref: travel.ref, agencyModeFk: travel.agencyModeFk, shipped: travel.shipped, landed: travel.landed, warehouseInFk: travel.warehouseInFk, warehouseOutFk: travel.warehouseOutFk }); this.$state.go('travel.create', {q: params}); } compareDate(date) { let today = new Date(); today.setHours(0, 0, 0, 0); date = new Date(date); date.setHours(0, 0, 0, 0); const timeDifference = today - date; if (timeDifference == 0) return 'warning'; if (timeDifference < 0) return 'success'; } exprBuilder(param, value) { switch (param) { case 'search': return /^\d+$/.test(value) ? {'t.id': value} : {'t.ref': {like: `%${value}%`}}; case 'ref': return {'t.ref': {like: `%${value}%`}}; case 'shipped': return {'t.shipped': {between: this.dateRange(value)}}; case 'landed': return {'t.landed': {between: this.dateRange(value)}}; case 'id': case 'agencyModeFk': case 'warehouseOutFk': case 'warehouseInFk': case 'totalEntries': param = `t.${param}`; return {[param]: value}; } } dateRange(value) { const minHour = new Date(value); minHour.setHours(0, 0, 0, 0); const maxHour = new Date(value); maxHour.setHours(23, 59, 59, 59); return [minHour, maxHour]; } } ngModule.vnComponent('vnTravelIndex', { template: require('./index.html'), controller: Controller });