salix/modules/item/front/last-entries/index.js

86 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-06-20 09:39:29 +00:00
import ngModule from '../module';
2020-03-17 13:43:46 +00:00
import Section from 'salix/components/section';
2018-06-20 09:39:29 +00:00
import './style.scss';
2020-03-17 13:43:46 +00:00
class Controller extends Section {
constructor($element, $) {
super($element, $);
2018-06-20 09:39:29 +00:00
2020-08-31 13:03:00 +00:00
const from = new Date();
from.setDate(from.getDate() - 75);
from.setHours(0, 0, 0, 0);
const to = new Date();
to.setDate(to.getDate() + 60);
2020-08-31 13:03:00 +00:00
to.setHours(23, 59, 59, 59);
2018-06-20 09:39:29 +00:00
2018-07-16 07:28:32 +00:00
this.filter = {
where: {
2020-03-17 13:43:46 +00:00
itemFk: this.$params.id,
2020-08-31 13:03:00 +00:00
shipped: {
between: [from, to]
}
2018-07-16 07:28:32 +00:00
}
};
2020-08-31 13:03:00 +00:00
this._date = from;
2018-06-20 09:39:29 +00:00
}
2018-07-16 07:28:32 +00:00
set date(value) {
this._date = value;
2018-06-20 10:30:59 +00:00
2018-07-16 07:28:32 +00:00
if (!value) return;
2018-06-20 10:30:59 +00:00
2020-10-06 06:52:11 +00:00
const from = new Date(value);
from.setHours(0, 0, 0, 0);
const to = new Date();
to.setDate(to.getDate() + 60);
2020-10-06 06:52:11 +00:00
to.setHours(23, 59, 59, 59);
this.filter.where.shipped = {
between: [from, to]
};
2020-03-17 13:43:46 +00:00
this.$.model.refresh();
2018-06-20 09:39:29 +00:00
}
2018-07-16 07:28:32 +00:00
get date() {
return this._date;
2018-06-20 09:39:29 +00:00
}
2020-08-31 13:03:00 +00:00
exprBuilder(param, value) {
switch (param) {
case 'id':
case 'quantity':
case 'packageFk':
return {[`b.${param}`]: value};
case 'supplierFk':
return {[`s.id`]: value};
case 'warehouseFk':
return {'tr.warehouseInFk': value};
case 'landed':
return {'tr.landed': {
between: this.dateRange(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];
}
2018-06-20 09:39:29 +00:00
}
2020-03-17 13:43:46 +00:00
Controller.$inject = ['$element', '$scope'];
2018-06-20 09:39:29 +00:00
ngModule.vnComponent('vnItemLastEntries', {
2018-06-20 09:39:29 +00:00
template: require('./index.html'),
controller: Controller,
bindings: {
item: '<'
}
});