2021-05-11 07:43:15 +00:00
|
|
|
import ngModule from '../../module';
|
|
|
|
import Section from 'salix/components/section';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
export default class Controller extends Section {
|
|
|
|
constructor($element, $) {
|
|
|
|
super($element, $);
|
|
|
|
|
2021-09-24 10:51:20 +00:00
|
|
|
this.filterParams = this.fetchParams();
|
2021-11-11 16:18:44 +00:00
|
|
|
this.smartTableOptions = {
|
|
|
|
activeButtons: {
|
|
|
|
search: true,
|
|
|
|
shownColumns: true,
|
|
|
|
},
|
|
|
|
columns: [
|
|
|
|
{
|
2021-11-15 07:45:21 +00:00
|
|
|
field: 'totalProblems',
|
|
|
|
searchable: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: 'salesPersonFk',
|
2021-11-11 16:18:44 +00:00
|
|
|
autocomplete: {
|
2021-11-15 07:45:21 +00:00
|
|
|
url: 'Workers/activeWithInheritedRole',
|
|
|
|
where: `{role: 'salesPerson'}`,
|
|
|
|
searchFunction: '{firstName: $search}',
|
|
|
|
showField: 'nickname',
|
|
|
|
valueField: 'id',
|
2021-11-11 16:18:44 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2021-11-15 07:45:21 +00:00
|
|
|
field: 'provinceFk',
|
2021-11-11 16:18:44 +00:00
|
|
|
autocomplete: {
|
2021-11-15 07:45:21 +00:00
|
|
|
url: 'Provinces',
|
2021-11-11 16:18:44 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2021-11-15 07:45:21 +00:00
|
|
|
field: 'stateFk',
|
2021-11-11 16:18:44 +00:00
|
|
|
autocomplete: {
|
2021-11-15 07:45:21 +00:00
|
|
|
url: 'States',
|
2021-11-11 16:18:44 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2021-11-15 07:45:21 +00:00
|
|
|
field: 'zoneFk',
|
2021-11-11 16:18:44 +00:00
|
|
|
autocomplete: {
|
2021-11-15 07:45:21 +00:00
|
|
|
url: 'Zones',
|
2021-11-11 16:18:44 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2021-11-15 07:45:21 +00:00
|
|
|
field: 'warehouseFk',
|
2021-11-11 16:18:44 +00:00
|
|
|
autocomplete: {
|
2021-11-15 07:45:21 +00:00
|
|
|
url: 'Warehouses',
|
2021-11-11 16:18:44 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2021-11-15 07:45:21 +00:00
|
|
|
field: 'shipped',
|
2021-11-11 16:18:44 +00:00
|
|
|
searchable: false
|
|
|
|
},
|
|
|
|
{
|
2021-11-15 07:45:21 +00:00
|
|
|
field: 'theoreticalHour',
|
2021-11-11 16:18:44 +00:00
|
|
|
searchable: false
|
|
|
|
},
|
2021-11-15 07:45:21 +00:00
|
|
|
{
|
|
|
|
field: 'preparationHour',
|
|
|
|
searchable: false
|
|
|
|
}
|
2021-11-11 16:18:44 +00:00
|
|
|
]
|
|
|
|
};
|
2021-09-24 10:51:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$onInit() {
|
|
|
|
if (!this.$params.q) {
|
|
|
|
this.$.$applyAsync(
|
|
|
|
() => this.$.model.applyFilter(null, this.filterParams));
|
|
|
|
}
|
2021-05-11 07:43:15 +00:00
|
|
|
}
|
|
|
|
|
2021-09-24 10:51:20 +00:00
|
|
|
fetchParams($params = {}) {
|
|
|
|
const excludedParams = [
|
|
|
|
'search',
|
|
|
|
'clientFk',
|
|
|
|
'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
|
|
|
});
|
|
|
|
const hasParams = Object.entries($params).length;
|
|
|
|
if (!hasParams || !hasExcludedParams)
|
2021-05-11 07:43:15 +00:00
|
|
|
$params.scopeDays = 1;
|
|
|
|
|
|
|
|
if (typeof $params.scopeDays === 'number') {
|
|
|
|
const from = new Date();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
compareDate(date) {
|
|
|
|
let today = new Date();
|
|
|
|
today.setHours(0, 0, 0, 0);
|
|
|
|
let timeTicket = new Date(date);
|
|
|
|
timeTicket.setHours(0, 0, 0, 0);
|
|
|
|
|
|
|
|
let comparation = today - timeTicket;
|
|
|
|
|
|
|
|
if (comparation == 0)
|
|
|
|
return 'warning';
|
|
|
|
if (comparation < 0)
|
|
|
|
return 'success';
|
|
|
|
}
|
|
|
|
|
|
|
|
totalPriceColor(ticket) {
|
|
|
|
const total = parseInt(ticket.totalWithVat);
|
|
|
|
if (total > 0 && total < 50)
|
|
|
|
return 'warning';
|
|
|
|
}
|
|
|
|
|
|
|
|
exprBuilder(param, value) {
|
|
|
|
switch (param) {
|
|
|
|
case 'stateFk':
|
|
|
|
return {'ts.stateFk': value};
|
|
|
|
case 'salesPersonFk':
|
|
|
|
return {'c.salesPersonFk': value};
|
|
|
|
case 'provinceFk':
|
|
|
|
return {'a.provinceFk': value};
|
2021-10-13 12:17:45 +00:00
|
|
|
case 'theoreticalHour':
|
2021-05-11 07:43:15 +00:00
|
|
|
return {'z.hour': value};
|
2021-10-13 12:17:45 +00:00
|
|
|
case 'practicalHour':
|
|
|
|
return {'zed.etc': value};
|
2021-05-11 07:43:15 +00:00
|
|
|
case 'shipped':
|
|
|
|
return {'t.shipped': {
|
|
|
|
between: this.dateRange(value)}
|
|
|
|
};
|
|
|
|
case 'nickname':
|
2021-11-15 07:45:21 +00:00
|
|
|
return {[`t.nickname`]: {like: `%${value}%`}};
|
|
|
|
case 'zoneFk':
|
|
|
|
case 'totalWithVat':
|
2021-05-11 07:43:15 +00:00
|
|
|
return {[`t.${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];
|
|
|
|
}
|
|
|
|
|
|
|
|
preview(ticket) {
|
|
|
|
this.selectedTicket = ticket;
|
|
|
|
this.$.summary.show();
|
|
|
|
}
|
2021-10-20 12:40:08 +00:00
|
|
|
|
|
|
|
autoRefresh(value) {
|
|
|
|
if (value)
|
|
|
|
this.refreshTimer = setInterval(() => this.$.model.refresh(), 120000);
|
|
|
|
else {
|
|
|
|
clearInterval(this.refreshTimer);
|
|
|
|
this.refreshTimer = null;
|
|
|
|
}
|
|
|
|
}
|
2021-05-11 07:43:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngModule.vnComponent('vnMonitorSalesTickets', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller
|
|
|
|
});
|