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

106 lines
2.3 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
2020-03-17 13:43:46 +00:00
class Controller extends Section {
constructor($element, $) {
super($element, $);
2018-06-20 09:39:29 +00:00
2023-01-16 14:18:24 +00:00
const from = Date.vnNew();
2021-11-10 11:34:56 +00:00
from.setDate(from.getDate() - 75);
2020-08-31 13:03:00 +00:00
from.setHours(0, 0, 0, 0);
2023-01-16 14:18:24 +00:00
const to = Date.vnNew();
to.setDate(to.getDate() + 10);
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
}
};
this._dateFrom = from;
this._dateTo = to;
2018-06-20 09:39:29 +00:00
}
set dateFrom(value) {
this._dateFrom = 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(this._dateTo);
to.setHours(23, 59, 59, 59);
this.filter.where.shipped = {
between: [from, to]
};
this.$.model.refresh();
}
set dateTo(value) {
this._dateTo = value;
if (!value) return;
const from = new Date(this._dateFrom);
from.setHours(0, 0, 0, 0);
const to = new Date(value);
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
}
get dateFrom() {
return this._dateFrom;
}
get dateTo() {
return this._dateTo;
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: '<'
}
});