import ngModule from '../module'; import ModuleMain from 'salix/components/module-main'; import UserError from 'core/lib/user-error'; export default class Ticket extends ModuleMain { fetchParams($params) { const excludedParams = [ 'from', 'to', 'search', 'clientFk', 'collectionFk', 'orderFk', 'refFk', 'scopeDays' ]; const seachPanelParams = Object.entries($params); const hasFromParam = seachPanelParams.some(subarray => subarray.length > 0 && subarray[0] === 'from'); const hasToParam = seachPanelParams.some(subarray => subarray.length > 0 && subarray[0] === 'to'); if ((hasFromParam && !hasToParam) || (!hasFromParam && hasToParam)) throw new UserError(`Date range must have 'from' and 'to'`); const hasExcludedParams = excludedParams.some(param => { return $params && $params[param] != undefined; }); const hasParams = Object.entries($params).length; if (!hasParams || !hasExcludedParams) $params.scopeDays = 1; if (typeof $params.scopeDays === 'number') { const from = Date.vnNew(); from.setHours(0, 0, 0, 0); const to = new Date(from.getTime()); to.setDate(to.getDate() + $params.scopeDays); to.setHours(23, 59, 59, 999); Object.assign($params, {from, to}); } return $params; } } ngModule.vnComponent('vnTicket', { controller: Ticket, template: require('./index.html') });