hedera-web/reports/shelves-report/shelves-report.js

367 lines
9.2 KiB
JavaScript
Raw Normal View History

2015-09-22 07:20:47 +00:00
2019-05-21 14:16:27 +00:00
Hedera.ShelvesReport = new Class({
2016-09-26 09:28:47 +00:00
Extends: Hedera.Report
2015-11-19 13:57:23 +00:00
,nItem: -1
,nColors: 5
2016-10-04 15:27:49 +00:00
,trayThickness: 2
,trayMargin: 5
2015-11-19 13:57:23 +00:00
2019-05-21 14:16:27 +00:00
,open: function(batch) {
2015-11-19 13:57:23 +00:00
this.batch = batch;
2019-05-21 14:16:27 +00:00
this.title = batch.getValue('reportTitle');
this.maxAmount = batch.getValue('maxAmount');
this.showPacking = batch.getValue('showPacking');
this.stack = batch.getValue('stack');
this.useIds = batch.getValue('useIds');
2015-11-19 13:57:23 +00:00
var query =
2016-10-04 15:27:49 +00:00
'SELECT id, name, nTrays, topTrayHeight, trayHeight, width, depth '+
2015-11-19 13:57:23 +00:00
'FROM shelf WHERE id = #shelf; '+
2019-05-21 14:16:27 +00:00
'CALL item_listAllocation(#warehouse, #date, #family, #namePrefix, #useIds)';
2015-11-19 13:57:23 +00:00
2019-05-21 14:16:27 +00:00
this.conn.execQuery(query, this.onQueryExec.bind(this), this.batch);
2015-11-19 13:57:23 +00:00
}
2019-05-21 14:16:27 +00:00
,onQueryExec: function(resultSet) {
2015-11-19 13:57:23 +00:00
// Fetch query data
2022-05-28 15:49:46 +00:00
const row = resultSet.fetchObject();
2015-11-19 13:57:23 +00:00
2016-09-19 06:40:18 +00:00
// Calculates the scale
2016-10-04 15:27:49 +00:00
var maxWidth = 160;
var maxHeight = 160;
2015-11-19 13:57:23 +00:00
2022-05-28 15:49:46 +00:00
var shelfWidth = row.width;
var shelfHeight = row.trayHeight * (row.nTrays - 1) + row.topTrayHeight;
2015-11-19 13:57:23 +00:00
2016-10-04 15:27:49 +00:00
var scale = maxWidth / shelfWidth;
if (shelfHeight * scale > maxHeight)
scale = maxHeight / shelfHeight;
2016-09-19 06:40:18 +00:00
2016-10-04 15:27:49 +00:00
// Calculates the shelf dimensions
2015-11-19 13:57:23 +00:00
2022-05-28 15:49:46 +00:00
var shelf = this.shelf = {
nTrays: row.nTrays
,trayHeight: row.trayHeight * scale
,topTrayHeight: row.topTrayHeight * scale
,width: row.width * scale
,depth: row.depth * scale
2015-11-19 13:57:23 +00:00
};
2016-10-04 15:27:49 +00:00
2016-09-19 06:40:18 +00:00
// Gets the items
2015-11-19 13:57:23 +00:00
var items = this.items = [];
var remainings = this.remainings = [];
2022-05-28 15:49:46 +00:00
var res = resultSet.fetchData();
2015-11-19 13:57:23 +00:00
2022-05-28 15:49:46 +00:00
if (res.length == 0) {
2019-05-21 14:16:27 +00:00
Htk.Toast.showError(_('No items found, check that all fields are correct'));
2015-11-19 13:57:23 +00:00
return;
}
var boxScale = scale * 10;
2022-05-28 15:49:46 +00:00
for (const row of res) {
if (!this.maxAmount || row.etiquetas <= this.maxAmount) {
items.push({
id: row.Id_Article
,name: row.Article
,packing: row.packing
,amount: row.etiquetas
,boxHeight: row.height * boxScale
,boxWidth: row.width * boxScale
,boxDepth: row.depth * boxScale
});
} else {
remainings.push({
id: row.Id_Article
,name: row.Article
,packing: row.packing
,amount: row.etiquetas
});
}
2015-11-19 13:57:23 +00:00
}
// Intializes the allocator
2019-05-21 14:16:27 +00:00
alloc = this.alloc = new Vn.Allocator();
2015-11-19 13:57:23 +00:00
alloc.items = items;
2019-05-21 14:16:27 +00:00
alloc.shelfFunc = this.drawShelf.bind(this);
alloc.boxFunc = this.drawBox.bind(this);
2015-11-19 13:57:23 +00:00
alloc.stack = this.stack;
2016-10-04 15:27:49 +00:00
alloc.nTrays = shelf.nTrays;
alloc.width = shelf.width;
2015-11-19 13:57:23 +00:00
alloc.depth = shelf.depth;
2016-10-04 15:27:49 +00:00
alloc.trayHeight = shelf.trayHeight;
alloc.topTrayHeight = shelf.topTrayHeight;
2015-11-19 13:57:23 +00:00
// Opens the report
2019-05-21 14:16:27 +00:00
this.createWindow();
2015-11-19 13:57:23 +00:00
}
2019-05-21 14:16:27 +00:00
,onWindowCreate: function() {
2015-11-19 13:57:23 +00:00
// Remaining amount
var remainings = this.remainings;
2019-05-21 14:16:27 +00:00
if (remainings.length > 0) {
var sheet = this.doc.createElement('div');
2015-11-19 13:57:23 +00:00
sheet.className = 'sheet';
2019-05-21 14:16:27 +00:00
this.doc.body.appendChild(sheet);
2015-11-19 13:57:23 +00:00
2019-05-21 14:16:27 +00:00
var title = this.doc.createElement('h1');
2015-11-19 13:57:23 +00:00
title.className = 'title';
2019-05-21 14:16:27 +00:00
title.appendChild(this.doc.createTextNode(this.title));
sheet.appendChild(title);
2015-11-19 13:57:23 +00:00
2019-05-21 14:16:27 +00:00
var subtitle = this.doc.createElement('h2');
2015-11-19 13:57:23 +00:00
subtitle.className = 'subtitle';
2019-05-21 14:16:27 +00:00
subtitle.appendChild(this.doc.createTextNode(_('Pallets')));
sheet.appendChild(subtitle);
2015-11-19 13:57:23 +00:00
2019-05-21 14:16:27 +00:00
var ul = this.doc.createElement('ul');
sheet.appendChild(ul);
2015-11-19 13:57:23 +00:00
2019-05-21 14:16:27 +00:00
for (var i = 0; i < remainings.length; i++) {
var li = this.doc.createElement('li');
ul.appendChild(li);
2015-11-19 13:57:23 +00:00
2019-05-21 14:16:27 +00:00
var span = this.doc.createElement('span');
2015-11-19 13:57:23 +00:00
span.className = 'item-id';
2019-05-21 14:16:27 +00:00
span.appendChild(this.doc.createTextNode(remainings[i].id.toLocaleString()));
li.appendChild(span);
2015-11-19 13:57:23 +00:00
2019-05-21 14:16:27 +00:00
var span = this.doc.createElement('span');
2015-11-19 13:57:23 +00:00
span.className = 'item';
2019-05-21 14:16:27 +00:00
span.appendChild(this.doc.createTextNode(remainings[i].name));
li.appendChild(span);
2015-11-19 13:57:23 +00:00
if (this.showPacking)
2019-05-21 14:16:27 +00:00
span.appendChild(this.doc.createTextNode(' '+ remainings[i].packing));
2015-11-19 13:57:23 +00:00
2019-05-21 14:16:27 +00:00
var span = this.doc.createElement('span');
2015-11-19 13:57:23 +00:00
span.className = 'amount';
2019-05-21 14:16:27 +00:00
span.appendChild(this.doc.createTextNode(remainings[i].amount));
li.appendChild(span);
2015-11-19 13:57:23 +00:00
}
}
// Draws the shelves
2019-05-21 14:16:27 +00:00
this.alloc.run();
this.drawShelfRange(this.lastItem, false);
2015-11-19 13:57:23 +00:00
}
2019-05-21 14:16:27 +00:00
,drawShelf: function(allocator, item) {
2015-11-19 13:57:23 +00:00
var shelf = this.shelf;
2019-05-21 14:16:27 +00:00
var sheet = this.doc.createElement('div');
2015-11-19 13:57:23 +00:00
sheet.className = 'sheet';
2019-05-21 14:16:27 +00:00
this.doc.body.appendChild(sheet);
2015-11-19 13:57:23 +00:00
// Draws the title
2019-05-21 14:16:27 +00:00
var pageNumber = this.doc.createElement('h1');
2015-11-19 13:57:23 +00:00
pageNumber.className = 'page-number';
2019-05-21 14:16:27 +00:00
pageNumber.appendChild(this.doc.createTextNode(allocator.currentShelf + 1));
sheet.appendChild(pageNumber);
2015-11-19 13:57:23 +00:00
2019-05-21 14:16:27 +00:00
var title = this.doc.createElement('h1');
2015-11-19 13:57:23 +00:00
title.className = 'title';
2019-05-21 14:16:27 +00:00
title.appendChild(this.doc.createTextNode(this.title));
sheet.appendChild(title);
2016-10-04 15:27:49 +00:00
if (this.subtitles)
2019-05-21 14:16:27 +00:00
this.drawShelfRange(this.lastItem, false);
2016-10-04 15:27:49 +00:00
2019-05-21 14:16:27 +00:00
this.subtitles = this.doc.createElement('div');
sheet.appendChild(this.subtitles);
2015-11-19 13:57:23 +00:00
2019-05-21 14:16:27 +00:00
this.drawShelfRange(item, true);
2016-10-04 15:27:49 +00:00
this.lastSubtitles = this.subtitles;
2015-11-19 13:57:23 +00:00
// Draws the shelf
2016-10-04 15:27:49 +00:00
var trayWidth = shelf.width + this.trayMargin * 2;
var shelfHeight = shelf.trayHeight * (shelf.nTrays - 1) + shelf.topTrayHeight
+ (this.trayThickness + this.trayMargin) * shelf.nTrays;
2019-05-21 14:16:27 +00:00
var shelfDiv = this.shelfDiv = this.doc.createElement('div');
2015-11-19 13:57:23 +00:00
shelfDiv.className = 'shelf';
2019-05-21 14:16:27 +00:00
shelfDiv.style.width = this.mm(trayWidth);
shelfDiv.style.height = this.mm(shelfHeight);
sheet.appendChild(shelfDiv);
2015-11-19 13:57:23 +00:00
// Draws trays
2019-05-21 14:16:27 +00:00
for (var i = 0; i < shelf.nTrays; i++) {
var tray = this.doc.createElement('div');
2015-11-19 13:57:23 +00:00
tray.className = 'tray';
2019-05-21 14:16:27 +00:00
tray.style.bottom = this.mm((shelf.trayHeight + this.trayThickness + this.trayMargin) * i);
tray.style.width = this.mm(trayWidth);
tray.style.height = this.mm(this.trayThickness);
shelfDiv.appendChild(tray);
2015-11-19 13:57:23 +00:00
}
}
2019-05-21 14:16:27 +00:00
,drawShelfRange: function(item, isFirst) {
2016-10-04 15:27:49 +00:00
var labelText = isFirst ? _('Start') : _('End');
2019-05-21 14:16:27 +00:00
var label = this.doc.createElement('label');
2016-10-04 15:27:49 +00:00
label.className = 'range-label';
2019-05-21 14:16:27 +00:00
label.appendChild(this.doc.createTextNode(labelText));
this.subtitles.appendChild(label);
2016-10-04 15:27:49 +00:00
2019-05-21 14:16:27 +00:00
var subtitle = this.doc.createElement('h2');
2016-10-04 15:27:49 +00:00
subtitle.className = 'subtitle';
2019-05-21 14:16:27 +00:00
subtitle.appendChild(this.doc.createTextNode(this.getItemLabel(item)));
this.subtitles.appendChild(subtitle);
2015-11-19 13:57:23 +00:00
}
2019-05-21 14:16:27 +00:00
,getItemLabel: function(item) {
if (!this.useIds) {
2016-10-04 15:27:49 +00:00
var packing = this.showPacking ? (' x'+ item.packing) : '';
return item.name + packing;
2019-05-21 14:16:27 +00:00
} else
return item.id.toLocaleString();
2016-09-19 06:40:18 +00:00
}
2019-05-21 14:16:27 +00:00
,mm: function(size) {
return size.toFixed(2) +'mm';
2015-11-19 13:57:23 +00:00
}
2019-05-21 14:16:27 +00:00
,drawBox: function(allocator, item, amount) {
2015-11-19 13:57:23 +00:00
if (item.boxWidth == 0 || item.boxHeight == 0)
return;
var shelf = this.shelf;
2016-10-04 15:27:49 +00:00
var x = allocator.trayX + this.trayMargin;
var y = allocator.trayY + this.trayThickness
+ this.trayMargin * allocator.currentTray
+ allocator.currentTray * (shelf.trayHeight + this.trayThickness);
2015-11-19 13:57:23 +00:00
2019-05-21 14:16:27 +00:00
var box = this.doc.createElement('div');
2015-11-19 13:57:23 +00:00
box.className = 'box';
2019-05-21 14:16:27 +00:00
this.shelfDiv.appendChild(box);
2015-11-19 13:57:23 +00:00
2019-05-21 14:16:27 +00:00
box.style.left = this.mm(x);
box.style.bottom = this.mm(y);
box.style.width = this.mm(item.boxWidth);
box.style.height = this.mm(item.boxHeight);
2015-11-19 13:57:23 +00:00
if (amount == 0)
this.nItem++;
var nColor = this.nItem % this.nColors;
2019-05-21 14:16:27 +00:00
Vn.Node.addClass(box, 'color'+ nColor);
2015-11-19 13:57:23 +00:00
2019-05-21 14:16:27 +00:00
if (amount == 0 || allocator.firstShelfBox) {
var boxLabel = this.doc.createElement('div');
2015-11-19 13:57:23 +00:00
2019-05-21 14:16:27 +00:00
if (this.useIds) {
2016-10-04 15:27:49 +00:00
var fontSize = item.boxWidth / 5.2;
if (fontSize > item.boxHeight - 1)
fontSize = item.boxHeight - 1;
2015-11-19 13:57:23 +00:00
2019-05-21 14:16:27 +00:00
boxLabel.style.fontSize = this.mm(fontSize);
2016-10-04 15:27:49 +00:00
var cssClass = 'id';
2019-05-21 14:16:27 +00:00
} else
2016-10-04 15:27:49 +00:00
var cssClass = 'name';
boxLabel.className = 'box-label '+ cssClass;
2019-05-21 14:16:27 +00:00
var labelText = this.doc.createTextNode(this.getItemLabel(item));
boxLabel.appendChild(labelText);
2016-10-04 15:27:49 +00:00
2019-05-21 14:16:27 +00:00
box.appendChild(boxLabel);
2015-11-19 13:57:23 +00:00
}
this.lastItem = item;
}
});
2019-05-21 14:16:27 +00:00
Vn.Allocator = new Class({
addShelf: function(item) {
2015-11-19 13:57:23 +00:00
this.currentShelf++;
this.firstShelfBox = true;
if (this.shelfFunc)
2019-05-21 14:16:27 +00:00
this.shelfFunc(this, item);
2015-11-19 13:57:23 +00:00
}
2019-05-21 14:16:27 +00:00
,addTray: function(item) {
if (this.currentTray <= 0) {
this.addShelf(item);
2015-11-19 13:57:23 +00:00
this.currentTray = this.nTrays - 1;
2019-05-21 14:16:27 +00:00
} else
2015-11-19 13:57:23 +00:00
this.currentTray--;
this.trayX = 0;
}
2019-05-21 14:16:27 +00:00
,addColumn: function(item) {
2015-11-19 13:57:23 +00:00
if (this.trayX + this.columnWidth + item.boxWidth > this.width
|| this.currentTray == -1)
2019-05-21 14:16:27 +00:00
this.addTray(item);
2015-11-19 13:57:23 +00:00
else
this.trayX += this.columnWidth;
this.trayY = 0;
this.columnWidth = item.boxWidth;
this.lastBoxWidth = item.boxWidth;
}
2019-05-21 14:16:27 +00:00
,addBox: function(item, amount) {
2015-11-19 13:57:23 +00:00
var trayHeight = this.trayHeight;
if (this.currentTray == this.nTrays - 1)
trayHeight = this.topTrayHeight;
if (this.trayY + item.boxHeight > trayHeight
|| item.boxWidth > this.lastBoxWidth
|| (!this.stack && amount == 0))
2019-05-21 14:16:27 +00:00
this.addColumn(item);
2015-11-19 13:57:23 +00:00
if (this.boxFunc)
2019-05-21 14:16:27 +00:00
this.boxFunc(this, item, amount);
2015-11-19 13:57:23 +00:00
this.trayY += item.boxHeight;
if (item.boxWidth < this.lastBoxWidth)
this.lastBoxWidth = item.boxWidth;
}
2019-05-21 14:16:27 +00:00
,run: function() {
2015-11-19 13:57:23 +00:00
this.firstShelfBox = false;
this.currentShelf = -1;
this.currentTray = -1;
this.columnWidth = 0;
this.lastBoxWidth = 0;
this.trayX = 0;
this.trayY = 0;
this.remaining = false;
2019-05-21 14:16:27 +00:00
for (var i = 0; i < this.items.length; i++) {
2015-11-19 13:57:23 +00:00
var item = this.items[i];
2019-05-21 14:16:27 +00:00
var boxIncrement = Math.floor(this.depth / item.boxDepth);
2015-11-19 13:57:23 +00:00
if (boxIncrement < 1)
boxIncrement = 1;
2019-05-21 14:16:27 +00:00
for (var amount = 0; amount < item.amount; amount += boxIncrement) {
this.addBox(item, amount);
2015-11-19 13:57:23 +00:00
this.firstShelfBox = false;
}
}
return this.currentShelf + 1;
}
2015-09-22 07:20:47 +00:00
});