2018-06-04 07:48:32 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
class Controller {
|
2018-07-04 06:50:34 +00:00
|
|
|
constructor($scope, $http, $state, $window) {
|
|
|
|
this.$scope = $scope;
|
2018-06-04 07:48:32 +00:00
|
|
|
this.$http = $http;
|
2018-07-04 06:50:34 +00:00
|
|
|
this.$state = $state;
|
|
|
|
this.$window = $window;
|
2018-06-04 07:48:32 +00:00
|
|
|
}
|
|
|
|
|
2018-07-04 06:50:34 +00:00
|
|
|
$postLink() {
|
|
|
|
if (this.item)
|
|
|
|
this.filterBuilder();
|
2018-06-04 07:48:32 +00:00
|
|
|
}
|
|
|
|
|
2018-07-04 06:50:34 +00:00
|
|
|
set item(value) {
|
|
|
|
this._item = value;
|
|
|
|
|
|
|
|
if (value && this.$scope.model)
|
|
|
|
this.filterBuilder();
|
|
|
|
}
|
|
|
|
|
|
|
|
get item() {
|
|
|
|
return this._item;
|
|
|
|
}
|
|
|
|
|
|
|
|
onChange(value) {
|
|
|
|
if (!value) return;
|
|
|
|
|
|
|
|
this.filter.where.warehouseFk = value;
|
|
|
|
this.$scope.model.refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds a filter with default values
|
|
|
|
* and aplies query params.
|
|
|
|
*/
|
|
|
|
filterBuilder() {
|
|
|
|
this.filter = {
|
|
|
|
where: {
|
|
|
|
itemFk: this.item.id,
|
|
|
|
warehouseFk: this.item.itemType.warehouseFk
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
let where = this.filter.where;
|
|
|
|
|
|
|
|
if (this.$state.params.q) {
|
|
|
|
let queryFilter = JSON.parse(this.$state.params.q);
|
|
|
|
where.warehouseFk = queryFilter.warehouseFk;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 10:12:41 +00:00
|
|
|
get freeLineIndex() {
|
|
|
|
let lines = this.$scope.model.data;
|
|
|
|
for (let i = 0; i < lines.length; i++) {
|
|
|
|
let isFutureDate = new Date(lines[i].date) > new Date();
|
|
|
|
let isGenreOut = lines[i].alertLevel != 0;
|
|
|
|
|
|
|
|
if (!isFutureDate && !isGenreOut)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get onPreparationLineIndex() {
|
|
|
|
let lines = this.$scope.model.data;
|
|
|
|
|
|
|
|
for (let i = this.freeLineIndex; i > 0; i--) {
|
|
|
|
let line = lines[i];
|
|
|
|
|
|
|
|
if (line.alertLevel == 1 && line.isPicked || line.alertLevel > 1) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-04 06:50:34 +00:00
|
|
|
scrollToActive() {
|
|
|
|
let body = this.$window.document.body;
|
2018-07-30 10:12:41 +00:00
|
|
|
let lineIndex = this.onPreparationLineIndex;
|
2018-07-04 06:50:34 +00:00
|
|
|
let lines = body.querySelector('vn-tbody').children;
|
|
|
|
|
|
|
|
if (!lineIndex || !lines.length) return;
|
|
|
|
|
2018-07-30 10:12:41 +00:00
|
|
|
let onPreparationLine = lines[lineIndex];
|
|
|
|
|
|
|
|
let balance = onPreparationLine.querySelector('.balance');
|
|
|
|
balance.classList.add('counter');
|
|
|
|
balance.title = 'Visible quantity';
|
|
|
|
|
|
|
|
let headerOffset = body.querySelector('header').getBoundingClientRect();
|
|
|
|
let headerHeight = headerOffset.height;
|
|
|
|
let offsetTop = onPreparationLine.offsetTop - headerHeight;
|
|
|
|
|
|
|
|
body.querySelector('ui-view').scrollTop = offsetTop;
|
2018-07-04 06:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compares a date with the current one
|
|
|
|
* @param {Object} date - Date to compare
|
|
|
|
* @return {Boolean} - Returns true if the two dates equals
|
|
|
|
*/
|
|
|
|
isToday(date) {
|
|
|
|
let today = new Date();
|
|
|
|
today.setHours(0, 0, 0, 0);
|
|
|
|
|
|
|
|
let comparedDate = new Date(date);
|
|
|
|
comparedDate.setHours(0, 0, 0, 0);
|
|
|
|
|
|
|
|
if (!(today - comparedDate))
|
|
|
|
return true;
|
2018-06-04 07:48:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-04 06:50:34 +00:00
|
|
|
Controller.$inject = ['$scope', '$http', '$state', '$window'];
|
2018-06-04 07:48:32 +00:00
|
|
|
|
|
|
|
ngModule.component('vnItemDiary', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
item: '<'
|
|
|
|
}
|
|
|
|
});
|