168 lines
4.4 KiB
JavaScript
168 lines
4.4 KiB
JavaScript
import ngModule from '../module';
|
|
import './style.scss';
|
|
|
|
class Controller {
|
|
constructor($scope, $http, $state, $window, $translate, $stateParams) {
|
|
this.$scope = $scope;
|
|
this.$http = $http;
|
|
this.$state = $state;
|
|
this.$stateParams = $stateParams;
|
|
this.$window = $window;
|
|
this.$translate = $translate;
|
|
}
|
|
|
|
get item() {
|
|
return this._item;
|
|
}
|
|
|
|
set item(value) {
|
|
this._item = value;
|
|
|
|
this.filter = {
|
|
where: {itemFk: this.$stateParams.id}
|
|
};
|
|
|
|
this.$scope.$$postDigest(() => {
|
|
if (this.$stateParams.warehouseFk)
|
|
this.warehouseFk = this.$stateParams.warehouseFk;
|
|
else if (value)
|
|
this.warehouseFk = value.itemType.warehouseFk;
|
|
|
|
if (this.$stateParams.ticketFk)
|
|
this.ticketFk = this.$stateParams.ticketFk;
|
|
});
|
|
}
|
|
|
|
set warehouseFk(value) {
|
|
this._warehouseFk = value;
|
|
|
|
this.$state.go(this.$state.current.name, {
|
|
warehouseFk: value
|
|
});
|
|
|
|
this.filter.where.warehouseFk = value;
|
|
this.$scope.model.refresh();
|
|
}
|
|
|
|
get warehouseFk() {
|
|
return this._warehouseFk;
|
|
}
|
|
|
|
get freeLineIndex() {
|
|
let lines = this.$scope.model.data;
|
|
let currentDate = new Date();
|
|
currentDate.setHours(0, 0, 0);
|
|
|
|
for (let i = 0; i < lines.length; i++) {
|
|
let isFutureDate = new Date(lines[i].date) >= currentDate;
|
|
|
|
if (isFutureDate)
|
|
return i;
|
|
}
|
|
}
|
|
|
|
get onPreparationLineIndex() {
|
|
let lines = this.$scope.model.data;
|
|
|
|
for (let i = this.freeLineIndex; i > 0; i--) {
|
|
let line = lines[i];
|
|
let currentDate = new Date();
|
|
currentDate.setHours(0, 0, 0);
|
|
|
|
let isPastDate = new Date(lines[i].date) < currentDate;
|
|
let isPicked = line.alertLevel == 1 && line.isPicked;
|
|
|
|
if ((isPicked) || line.alertLevel > 1 || isPastDate)
|
|
return i;
|
|
}
|
|
}
|
|
|
|
get givenTicketIndex() {
|
|
let lines = this.$scope.model.data;
|
|
|
|
for (let i = lines.length - 1; i > 0; i--) {
|
|
let line = lines[i];
|
|
|
|
if (line.origin == this.ticketFk)
|
|
return i;
|
|
}
|
|
}
|
|
|
|
scrollToLine() {
|
|
let body = this.$window.document.body;
|
|
|
|
let lineIndex;
|
|
if (this.ticketFk)
|
|
lineIndex = this.givenTicketIndex;
|
|
else
|
|
lineIndex = this.onPreparationLineIndex;
|
|
|
|
let lines = body.querySelector('vn-tbody').children;
|
|
|
|
if (!lineIndex || !lines.length) return;
|
|
|
|
let onPreparationLine = lines[lineIndex];
|
|
|
|
let balance = onPreparationLine.querySelector('.balanceSpan');
|
|
balance.classList.add('counter');
|
|
balance.title = this.$translate.instant('Visible quantity');
|
|
|
|
let headerOffset = body.querySelector('header').getBoundingClientRect();
|
|
let headerHeight = headerOffset.height;
|
|
let offsetTop = onPreparationLine.offsetTop - headerHeight;
|
|
|
|
body.querySelector('ui-view').scrollTop = offsetTop;
|
|
this.ticketFk = null;
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
|
|
showDescriptor(event, sale) {
|
|
if (!sale.isTicket) return;
|
|
|
|
this.$scope.descriptor.ticketFk = sale.origin;
|
|
this.$scope.descriptor.parent = event.target;
|
|
this.$scope.descriptor.show();
|
|
event.preventDefault();
|
|
event.stopImmediatePropagation();
|
|
}
|
|
|
|
showClientDescriptor(event, sale) {
|
|
if (!sale.isTicket) return;
|
|
|
|
this.$scope.clientDescriptor.clientFk = sale.clientFk;
|
|
this.$scope.clientDescriptor.parent = event.target;
|
|
this.$scope.clientDescriptor.show();
|
|
event.preventDefault();
|
|
event.stopImmediatePropagation();
|
|
}
|
|
|
|
onDescriptorLoad() {
|
|
this.$scope.popover.relocate();
|
|
}
|
|
}
|
|
|
|
Controller.$inject = ['$scope', '$http', '$state', '$window', '$translate', '$stateParams'];
|
|
|
|
ngModule.component('vnItemDiary', {
|
|
template: require('./index.html'),
|
|
controller: Controller,
|
|
bindings: {
|
|
item: '<'
|
|
}
|
|
});
|