2019-11-10 10:08:44 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
import ModuleMain from 'salix/components/module-main';
|
2023-05-19 08:30:36 +00:00
|
|
|
const UserError = require('vn-loopback/util/user-error');
|
2019-11-10 10:08:44 +00:00
|
|
|
|
2020-03-13 19:33:12 +00:00
|
|
|
export default class Ticket extends ModuleMain {
|
2023-05-18 12:11:29 +00:00
|
|
|
constructor($element, $) {
|
|
|
|
super($element, $);
|
|
|
|
|
|
|
|
if (!this.$state.q) {
|
|
|
|
const today = Date.vnNew();
|
|
|
|
today.setHours(0, 0, 0, 0);
|
|
|
|
|
|
|
|
const tomorrow = Date.vnNew();
|
|
|
|
tomorrow.setHours(23, 59, 59, 59);
|
|
|
|
tomorrow.setDate(tomorrow.getDate() + 1);
|
|
|
|
|
|
|
|
this.filterParams = {
|
|
|
|
from: today,
|
|
|
|
to: tomorrow
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-20 06:45:03 +00:00
|
|
|
fetchParams($params) {
|
2021-09-24 10:51:20 +00:00
|
|
|
const excludedParams = [
|
|
|
|
'from',
|
|
|
|
'to',
|
|
|
|
'search',
|
|
|
|
'clientFk',
|
2021-12-14 08:17:00 +00:00
|
|
|
'collectionFk',
|
2021-09-24 10:51:20 +00:00
|
|
|
'orderFk',
|
|
|
|
'refFk',
|
|
|
|
'scopeDays'
|
|
|
|
];
|
|
|
|
|
|
|
|
const hasExcludedParams = excludedParams.some(param => {
|
2021-11-16 12:43:30 +00:00
|
|
|
return $params && $params[param] != undefined;
|
2021-09-24 10:51:20 +00:00
|
|
|
});
|
2023-05-19 08:30:36 +00:00
|
|
|
|
|
|
|
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');
|
|
|
|
const hasScopeDays = seachPanelParams.some(subarray => subarray.length > 0 && subarray[0] === 'scopeDays');
|
|
|
|
|
|
|
|
if (!hasFromParam)
|
|
|
|
delete this.filterParams.from;
|
|
|
|
|
|
|
|
if (!hasToParam)
|
|
|
|
delete this.filterParams.to;
|
|
|
|
|
|
|
|
if (!hasScopeDays)
|
|
|
|
delete this.filterParams.scopeDays;
|
|
|
|
|
|
|
|
if ((!hasFromParam || !hasToParam) && !hasScopeDays)
|
|
|
|
throw new UserError(`The filter 'From' and 'To' or 'Days onward' must be filled in`);
|
2023-05-18 12:11:29 +00:00
|
|
|
|
2021-09-24 10:51:20 +00:00
|
|
|
const hasParams = Object.entries($params).length;
|
|
|
|
if (!hasParams || !hasExcludedParams)
|
2020-08-20 07:50:22 +00:00
|
|
|
$params.scopeDays = 1;
|
|
|
|
|
2020-03-13 19:33:12 +00:00
|
|
|
if (typeof $params.scopeDays === 'number') {
|
2023-01-16 14:18:24 +00:00
|
|
|
const from = Date.vnNew();
|
2020-03-13 19:33:12 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2019-11-10 10:08:44 +00:00
|
|
|
|
|
|
|
ngModule.vnComponent('vnTicket', {
|
|
|
|
controller: Ticket,
|
|
|
|
template: require('./index.html')
|
|
|
|
});
|