2018-06-04 07:48:32 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
class Controller {
|
2018-09-06 13:08:02 +00:00
|
|
|
constructor($scope, $http, $state, $window, $translate, $stateParams) {
|
2018-07-04 06:50:34 +00:00
|
|
|
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;
|
2018-09-06 13:08:02 +00:00
|
|
|
this.$stateParams = $stateParams;
|
2018-07-04 06:50:34 +00:00
|
|
|
this.$window = $window;
|
2018-09-03 06:09:56 +00:00
|
|
|
this.$translate = $translate;
|
2018-06-04 07:48:32 +00:00
|
|
|
}
|
2018-09-18 11:34:11 +00:00
|
|
|
|
|
|
|
get item() {
|
|
|
|
return this._item;
|
2018-06-04 07:48:32 +00:00
|
|
|
}
|
2018-09-18 11:34:11 +00:00
|
|
|
|
2018-07-04 06:50:34 +00:00
|
|
|
set item(value) {
|
|
|
|
this._item = value;
|
|
|
|
|
2018-09-06 13:08:02 +00:00
|
|
|
this.filter = {
|
|
|
|
where: {itemFk: this.$stateParams.id}
|
|
|
|
};
|
|
|
|
|
2019-02-13 06:57:08 +00:00
|
|
|
this.$scope.$applyAsync(() => {
|
2018-09-18 11:34:11 +00:00
|
|
|
if (this.$stateParams.warehouseFk)
|
|
|
|
this.warehouseFk = this.$stateParams.warehouseFk;
|
|
|
|
else if (value)
|
|
|
|
this.warehouseFk = value.itemType.warehouseFk;
|
2018-10-05 13:53:31 +00:00
|
|
|
|
|
|
|
if (this.$stateParams.ticketFk)
|
|
|
|
this.ticketFk = this.$stateParams.ticketFk;
|
2018-09-18 11:34:11 +00:00
|
|
|
});
|
2018-07-04 06:50:34 +00:00
|
|
|
}
|
|
|
|
|
2018-09-06 13:08:02 +00:00
|
|
|
set warehouseFk(value) {
|
2018-11-14 10:17:33 +00:00
|
|
|
if (value && value != this._warehouseFk) {
|
|
|
|
this._warehouseFk = value;
|
2018-09-06 13:08:02 +00:00
|
|
|
|
2018-11-14 10:17:33 +00:00
|
|
|
this.$state.go(this.$state.current.name, {
|
|
|
|
warehouseFk: value
|
|
|
|
});
|
2018-07-04 06:50:34 +00:00
|
|
|
|
2018-11-14 10:17:33 +00:00
|
|
|
this.filter.where.warehouseFk = value;
|
|
|
|
this.$scope.model.refresh();
|
|
|
|
}
|
2018-07-04 06:50:34 +00:00
|
|
|
}
|
|
|
|
|
2018-09-06 13:08:02 +00:00
|
|
|
get warehouseFk() {
|
|
|
|
return this._warehouseFk;
|
2018-07-04 06:50:34 +00:00
|
|
|
}
|
|
|
|
|
2018-07-30 10:12:41 +00:00
|
|
|
get freeLineIndex() {
|
|
|
|
let lines = this.$scope.model.data;
|
2019-10-21 09:08:41 +00:00
|
|
|
let minDate = new Date();
|
|
|
|
minDate.setHours(0, 0, 0, 0);
|
|
|
|
|
|
|
|
let maxDate = new Date();
|
|
|
|
maxDate.setHours(23, 59, 59, 59);
|
|
|
|
|
2018-09-06 13:08:02 +00:00
|
|
|
|
2018-07-30 10:12:41 +00:00
|
|
|
for (let i = 0; i < lines.length; i++) {
|
2019-10-21 09:08:41 +00:00
|
|
|
const dated = new Date(lines[i].date);
|
2018-07-30 10:12:41 +00:00
|
|
|
|
2019-10-21 09:08:41 +00:00
|
|
|
let isForFuture = dated > maxDate;
|
|
|
|
let isForToday = (dated >= minDate && dated <= maxDate);
|
|
|
|
|
|
|
|
if (isForFuture || isForToday)
|
2018-07-30 10:12:41 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get onPreparationLineIndex() {
|
|
|
|
let lines = this.$scope.model.data;
|
2018-11-14 10:17:33 +00:00
|
|
|
for (let i = this.freeLineIndex; i >= 0; i--) {
|
2018-07-30 10:12:41 +00:00
|
|
|
let line = lines[i];
|
2019-10-21 09:08:41 +00:00
|
|
|
|
2018-09-03 06:09:56 +00:00
|
|
|
let currentDate = new Date();
|
2019-10-21 09:08:41 +00:00
|
|
|
currentDate.setHours(0, 0, 0, 0);
|
2018-07-30 10:12:41 +00:00
|
|
|
|
2018-09-03 06:09:56 +00:00
|
|
|
let isPastDate = new Date(lines[i].date) < currentDate;
|
|
|
|
let isPicked = line.alertLevel == 1 && line.isPicked;
|
|
|
|
|
|
|
|
if ((isPicked) || line.alertLevel > 1 || isPastDate)
|
2018-11-14 10:17:33 +00:00
|
|
|
return i + 1;
|
2018-07-30 10:12:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 13:53:31 +00:00
|
|
|
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() {
|
2018-07-04 06:50:34 +00:00
|
|
|
let body = this.$window.document.body;
|
2018-11-14 10:17:33 +00:00
|
|
|
let selectedTicketLineIndex = this.givenTicketIndex;
|
|
|
|
let lineIndex = this.onPreparationLineIndex;
|
2018-10-05 13:53:31 +00:00
|
|
|
|
2019-10-21 09:08:41 +00:00
|
|
|
|
2018-07-04 06:50:34 +00:00
|
|
|
let lines = body.querySelector('vn-tbody').children;
|
|
|
|
|
2018-11-14 10:17:33 +00:00
|
|
|
if (lineIndex == undefined || !lines.length) return;
|
|
|
|
|
2018-07-04 06:50:34 +00:00
|
|
|
|
2018-07-30 10:12:41 +00:00
|
|
|
let onPreparationLine = lines[lineIndex];
|
|
|
|
|
2018-11-14 10:17:33 +00:00
|
|
|
|
2018-10-05 13:53:31 +00:00
|
|
|
let balance = onPreparationLine.querySelector('.balanceSpan');
|
2019-09-12 09:47:56 +00:00
|
|
|
balance.classList.add('message');
|
2018-09-03 06:09:56 +00:00
|
|
|
balance.title = this.$translate.instant('Visible quantity');
|
2018-07-30 10:12:41 +00:00
|
|
|
|
2019-11-12 13:18:46 +00:00
|
|
|
let headerOffset = body.querySelector('vn-topbar').getBoundingClientRect();
|
2018-07-30 10:12:41 +00:00
|
|
|
let headerHeight = headerOffset.height;
|
2018-11-14 10:17:33 +00:00
|
|
|
|
|
|
|
let offsetTop;
|
|
|
|
if (this.ticketFk) {
|
|
|
|
let selectedTicketLine = lines[selectedTicketLineIndex];
|
2019-09-10 06:47:46 +00:00
|
|
|
let id = selectedTicketLine.querySelector('[name=origin]');
|
2019-09-12 09:47:56 +00:00
|
|
|
id.classList.add('message');
|
2018-11-14 10:17:33 +00:00
|
|
|
offsetTop = selectedTicketLine.offsetTop - headerHeight;
|
|
|
|
} else
|
|
|
|
offsetTop = onPreparationLine.offsetTop - headerHeight;
|
2018-07-30 10:12:41 +00:00
|
|
|
|
2019-02-18 08:50:09 +00:00
|
|
|
this.$window.scrollTo(0, offsetTop);
|
2018-10-05 13:53:31 +00:00
|
|
|
this.ticketFk = null;
|
2018-07-04 06:50:34 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 10:17:33 +00:00
|
|
|
/**
|
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-08-30 09:02:50 +00:00
|
|
|
|
|
|
|
showDescriptor(event, sale) {
|
|
|
|
if (!sale.isTicket) return;
|
|
|
|
|
|
|
|
this.$scope.descriptor.ticketFk = sale.origin;
|
|
|
|
this.$scope.descriptor.parent = event.target;
|
|
|
|
this.$scope.descriptor.show();
|
2019-02-04 09:10:57 +00:00
|
|
|
|
2018-08-30 09:02:50 +00:00
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
|
2018-09-04 09:49:00 +00:00
|
|
|
showClientDescriptor(event, sale) {
|
|
|
|
if (!sale.isTicket) return;
|
|
|
|
|
|
|
|
this.$scope.clientDescriptor.clientFk = sale.clientFk;
|
|
|
|
this.$scope.clientDescriptor.parent = event.target;
|
|
|
|
this.$scope.clientDescriptor.show();
|
2019-02-04 09:10:57 +00:00
|
|
|
|
2018-09-04 09:49:00 +00:00
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
|
2018-08-30 09:02:50 +00:00
|
|
|
onDescriptorLoad() {
|
|
|
|
this.$scope.popover.relocate();
|
|
|
|
}
|
2018-06-04 07:48:32 +00:00
|
|
|
}
|
|
|
|
|
2018-09-06 13:08:02 +00:00
|
|
|
Controller.$inject = ['$scope', '$http', '$state', '$window', '$translate', '$stateParams'];
|
2018-06-04 07:48:32 +00:00
|
|
|
|
|
|
|
ngModule.component('vnItemDiary', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
item: '<'
|
|
|
|
}
|
|
|
|
});
|