2015-09-22 07:20:47 +00:00
|
|
|
|
2016-09-26 09:28:47 +00:00
|
|
|
Hedera.ShelvesReport = new Class
|
2015-09-22 07:20:47 +00:00
|
|
|
({
|
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
|
|
|
|
2017-04-07 11:00:33 +00:00
|
|
|
,activate: function (lot)
|
2015-11-19 13:57:23 +00:00
|
|
|
{
|
2017-04-08 11:42:27 +00:00
|
|
|
var params = lot.params;
|
|
|
|
Object.assign (this, {
|
|
|
|
title: params.reportTitle,
|
|
|
|
maxAmount: params.maxAmount,
|
|
|
|
showPacking: params.showPacking,
|
|
|
|
stack: params.stack,
|
|
|
|
useIds: params.useIds
|
|
|
|
})
|
|
|
|
|
|
|
|
var params = {
|
|
|
|
warehouse: params.warehouse,
|
|
|
|
|
|
|
|
}
|
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; '+
|
2016-10-04 15:27:49 +00:00
|
|
|
'CALL itemAllocator (#warehouse, #date, #family, #namePrefix, #useIds)';
|
2015-11-19 13:57:23 +00:00
|
|
|
|
2017-04-07 11:00:33 +00:00
|
|
|
this.conn.execQuery (query,
|
|
|
|
this.onQueryExec.bind (this), lot);
|
2015-11-19 13:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,onQueryExec: function (resultSet)
|
|
|
|
{
|
|
|
|
// Fetch query data
|
|
|
|
|
2017-04-08 11:42:27 +00:00
|
|
|
var 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
|
|
|
|
2017-04-08 11:42:27 +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
|
|
|
|
|
|
|
var shelf = this.shelf =
|
|
|
|
{
|
2017-04-08 11:42:27 +00:00
|
|
|
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 = [];
|
|
|
|
var res = resultSet.fetchResult ();
|
|
|
|
|
|
|
|
if (res.data.length == 0)
|
|
|
|
{
|
|
|
|
Htk.Toast.showError (_('No items found, check that all fields are correct'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var boxScale = scale * 10;
|
|
|
|
|
2017-04-08 11:42:27 +00:00
|
|
|
while (row = res.fetchObject ())
|
|
|
|
if (!this.maxAmount || row.etiquetas <= this.maxAmount)
|
2015-11-19 13:57:23 +00:00
|
|
|
{
|
|
|
|
items.push ({
|
2017-04-08 11:42:27 +00:00
|
|
|
id: row.Id_Article
|
|
|
|
,name: row.Article
|
|
|
|
,packing: row.packing
|
|
|
|
,amount: row.etiquetas
|
|
|
|
,boxHeight: row.z * boxScale
|
|
|
|
,boxWidth: row.x * boxScale
|
|
|
|
,boxDepth: row.y * boxScale
|
2015-11-19 13:57:23 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
remainings.push ({
|
2017-04-08 11:42:27 +00:00
|
|
|
id: row.Id_Article
|
|
|
|
,name: row.Article
|
|
|
|
,packing: row.packing
|
|
|
|
,amount: row.etiquetas
|
2015-11-19 13:57:23 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Intializes the allocator
|
|
|
|
|
|
|
|
alloc = this.alloc = new Vn.Allocator ();
|
2017-04-08 11:42:27 +00:00
|
|
|
Object.assign (alloc, {
|
|
|
|
items: items,
|
|
|
|
shelfFunc: this.drawShelf.bind (this),
|
|
|
|
boxFunc: this.drawBox.bind (this),
|
|
|
|
stack: this.stack,
|
|
|
|
nTrays: shelf.nTrays,
|
|
|
|
width: shelf.width,
|
|
|
|
depth: shelf.depth,
|
|
|
|
trayHeight: shelf.trayHeight,
|
|
|
|
topTrayHeight: shelf.topTrayHeight,
|
|
|
|
});
|
2015-11-19 13:57:23 +00:00
|
|
|
|
|
|
|
// Opens the report
|
|
|
|
|
2017-03-30 11:44:53 +00:00
|
|
|
this.renderReport ();
|
2015-11-19 13:57:23 +00:00
|
|
|
}
|
|
|
|
|
2017-03-30 11:44:53 +00:00
|
|
|
,renderReport: function ()
|
|
|
|
{
|
2015-11-19 13:57:23 +00:00
|
|
|
// Remaining amount
|
|
|
|
|
|
|
|
var remainings = this.remainings;
|
|
|
|
|
|
|
|
if (remainings.length > 0)
|
|
|
|
{
|
|
|
|
var sheet = this.doc.createElement ('div');
|
2017-03-30 11:44:53 +00:00
|
|
|
sheet.className = 'sheet remaining';
|
|
|
|
this.body.appendChild (sheet);
|
2015-11-19 13:57:23 +00:00
|
|
|
|
|
|
|
var title = this.doc.createElement ('h1');
|
|
|
|
title.className = 'title';
|
|
|
|
title.appendChild (this.doc.createTextNode (this.title));
|
|
|
|
sheet.appendChild (title);
|
|
|
|
|
|
|
|
var subtitle = this.doc.createElement ('h2');
|
|
|
|
subtitle.className = 'subtitle';
|
|
|
|
subtitle.appendChild (this.doc.createTextNode (_('Pallets')));
|
|
|
|
sheet.appendChild (subtitle);
|
|
|
|
|
2017-03-30 11:44:53 +00:00
|
|
|
var ul = this.doc.createElement ('table');
|
2015-11-19 13:57:23 +00:00
|
|
|
sheet.appendChild (ul);
|
|
|
|
|
|
|
|
for (var i = 0; i < remainings.length; i++)
|
|
|
|
{
|
2017-03-30 11:44:53 +00:00
|
|
|
var li = this.doc.createElement ('tr');
|
2015-11-19 13:57:23 +00:00
|
|
|
ul.appendChild (li);
|
|
|
|
|
2017-03-30 11:44:53 +00:00
|
|
|
var span = this.doc.createElement ('td');
|
2015-11-19 13:57:23 +00:00
|
|
|
span.className = 'item-id';
|
|
|
|
span.appendChild (this.doc.createTextNode (remainings[i].id.toLocaleString ()));
|
|
|
|
li.appendChild (span);
|
|
|
|
|
2017-03-30 11:44:53 +00:00
|
|
|
var span = this.doc.createElement ('td');
|
2015-11-19 13:57:23 +00:00
|
|
|
span.className = 'item';
|
|
|
|
span.appendChild (this.doc.createTextNode (remainings[i].name));
|
|
|
|
li.appendChild (span);
|
|
|
|
|
|
|
|
if (this.showPacking)
|
|
|
|
span.appendChild (this.doc.createTextNode (' '+ remainings[i].packing));
|
|
|
|
|
2017-03-30 11:44:53 +00:00
|
|
|
var span = this.doc.createElement ('td');
|
2015-11-19 13:57:23 +00:00
|
|
|
span.className = 'amount';
|
|
|
|
span.appendChild (this.doc.createTextNode (remainings[i].amount));
|
|
|
|
li.appendChild (span);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draws the shelves
|
|
|
|
|
|
|
|
this.alloc.run ();
|
2016-10-04 15:27:49 +00:00
|
|
|
this.drawShelfRange (this.lastItem, false);
|
2015-11-19 13:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,drawShelf: function (allocator, item)
|
|
|
|
{
|
|
|
|
var shelf = this.shelf;
|
|
|
|
|
|
|
|
var sheet = this.doc.createElement ('div');
|
|
|
|
sheet.className = 'sheet';
|
2017-03-30 11:44:53 +00:00
|
|
|
this.body.appendChild (sheet);
|
2015-11-19 13:57:23 +00:00
|
|
|
|
|
|
|
// Draws the title
|
|
|
|
|
|
|
|
var pageNumber = this.doc.createElement ('h1');
|
|
|
|
pageNumber.className = 'page-number';
|
|
|
|
pageNumber.appendChild (this.doc.createTextNode (allocator.currentShelf + 1));
|
|
|
|
sheet.appendChild (pageNumber);
|
|
|
|
|
|
|
|
var title = this.doc.createElement ('h1');
|
|
|
|
title.className = 'title';
|
|
|
|
title.appendChild (this.doc.createTextNode (this.title));
|
|
|
|
sheet.appendChild (title);
|
2016-10-04 15:27:49 +00:00
|
|
|
|
|
|
|
if (this.subtitles)
|
|
|
|
this.drawShelfRange (this.lastItem, false);
|
|
|
|
|
|
|
|
this.subtitles = this.doc.createElement ('div');
|
|
|
|
sheet.appendChild (this.subtitles);
|
2015-11-19 13:57:23 +00:00
|
|
|
|
2016-10-04 15:27:49 +00:00
|
|
|
this.drawShelfRange (item, true);
|
|
|
|
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;
|
|
|
|
|
2015-11-19 13:57:23 +00:00
|
|
|
var shelfDiv = this.shelfDiv = this.doc.createElement ('div');
|
|
|
|
shelfDiv.className = 'shelf';
|
2016-10-04 15:27:49 +00:00
|
|
|
shelfDiv.style.width = this.mm (trayWidth);
|
|
|
|
shelfDiv.style.height = this.mm (shelfHeight);
|
2015-11-19 13:57:23 +00:00
|
|
|
sheet.appendChild (shelfDiv);
|
|
|
|
|
|
|
|
// Draws trays
|
|
|
|
|
2016-10-04 15:27:49 +00:00
|
|
|
for (var i = 0; i < shelf.nTrays; i++)
|
2015-11-19 13:57:23 +00:00
|
|
|
{
|
|
|
|
var tray = this.doc.createElement ('div');
|
|
|
|
tray.className = 'tray';
|
2016-10-04 15:27:49 +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);
|
2015-11-19 13:57:23 +00:00
|
|
|
shelfDiv.appendChild (tray);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-04 15:27:49 +00:00
|
|
|
,drawShelfRange: function (item, isFirst)
|
2015-11-19 13:57:23 +00:00
|
|
|
{
|
2016-10-04 15:27:49 +00:00
|
|
|
var labelText = isFirst ? _('Start') : _('End');
|
|
|
|
|
|
|
|
var label = this.doc.createElement ('label');
|
|
|
|
label.className = 'range-label';
|
|
|
|
label.appendChild (this.doc.createTextNode (labelText));
|
|
|
|
this.subtitles.appendChild (label);
|
|
|
|
|
|
|
|
var subtitle = this.doc.createElement ('h2');
|
|
|
|
subtitle.className = 'subtitle';
|
|
|
|
subtitle.appendChild (this.doc.createTextNode (this.getItemLabel (item)));
|
|
|
|
this.subtitles.appendChild (subtitle);
|
2015-11-19 13:57:23 +00:00
|
|
|
}
|
|
|
|
|
2016-10-04 15:27:49 +00:00
|
|
|
,getItemLabel: function (item)
|
2016-09-19 06:40:18 +00:00
|
|
|
{
|
2016-10-04 15:27:49 +00:00
|
|
|
if (!this.useIds)
|
|
|
|
{
|
|
|
|
var packing = this.showPacking ? (' x'+ item.packing) : '';
|
|
|
|
return item.name + packing;
|
|
|
|
}
|
2016-09-19 06:40:18 +00:00
|
|
|
else
|
2016-10-04 15:27:49 +00:00
|
|
|
return item.id.toLocaleString ();
|
2016-09-19 06:40:18 +00:00
|
|
|
}
|
|
|
|
|
2015-11-19 13:57:23 +00:00
|
|
|
,mm: function (size)
|
|
|
|
{
|
2017-03-30 11:44:53 +00:00
|
|
|
size *= 0.24;
|
|
|
|
return size.toFixed (2) +'em';
|
2015-11-19 13:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,drawBox: function (allocator, item, amount)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
var box = this.doc.createElement ('div');
|
|
|
|
box.className = 'box';
|
|
|
|
this.shelfDiv.appendChild (box);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (amount == 0)
|
|
|
|
this.nItem++;
|
|
|
|
|
|
|
|
var nColor = this.nItem % this.nColors;
|
|
|
|
Vn.Node.addClass (box, 'color'+ nColor);
|
|
|
|
|
|
|
|
if (amount == 0 || allocator.firstShelfBox)
|
2016-10-04 15:27:49 +00:00
|
|
|
{
|
|
|
|
var boxLabel = this.doc.createElement ('div');
|
2015-11-19 13:57:23 +00:00
|
|
|
|
2016-09-19 06:40:18 +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
|
|
|
|
2016-10-04 15:27:49 +00:00
|
|
|
boxLabel.style.fontSize = this.mm (fontSize);
|
|
|
|
|
|
|
|
var cssClass = 'id';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
var cssClass = 'name';
|
|
|
|
|
|
|
|
boxLabel.className = 'box-label '+ cssClass;
|
|
|
|
|
|
|
|
var labelText = this.doc.createTextNode (this.getItemLabel (item));
|
|
|
|
boxLabel.appendChild (labelText);
|
|
|
|
|
2015-11-19 13:57:23 +00:00
|
|
|
box.appendChild (boxLabel);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.lastItem = item;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Vn.Allocator = new Class
|
|
|
|
({
|
|
|
|
addShelf: function (item)
|
|
|
|
{
|
|
|
|
this.currentShelf++;
|
|
|
|
this.firstShelfBox = true;
|
|
|
|
|
|
|
|
if (this.shelfFunc)
|
|
|
|
this.shelfFunc (this, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
,addTray: function (item)
|
|
|
|
{
|
|
|
|
if (this.currentTray <= 0)
|
|
|
|
{
|
|
|
|
this.addShelf (item);
|
|
|
|
this.currentTray = this.nTrays - 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
this.currentTray--;
|
|
|
|
|
|
|
|
this.trayX = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
,addColumn: function (item)
|
|
|
|
{
|
|
|
|
if (this.trayX + this.columnWidth + item.boxWidth > this.width
|
|
|
|
|| this.currentTray == -1)
|
|
|
|
this.addTray (item);
|
|
|
|
else
|
|
|
|
this.trayX += this.columnWidth;
|
|
|
|
|
|
|
|
this.trayY = 0;
|
|
|
|
this.columnWidth = item.boxWidth;
|
|
|
|
this.lastBoxWidth = item.boxWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
,addBox: function (item, amount)
|
|
|
|
{
|
|
|
|
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))
|
|
|
|
this.addColumn (item);
|
|
|
|
|
|
|
|
if (this.boxFunc)
|
|
|
|
this.boxFunc (this, item, amount);
|
|
|
|
|
|
|
|
this.trayY += item.boxHeight;
|
|
|
|
|
|
|
|
if (item.boxWidth < this.lastBoxWidth)
|
|
|
|
this.lastBoxWidth = item.boxWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
,run: function ()
|
|
|
|
{
|
|
|
|
this.firstShelfBox = false;
|
|
|
|
this.currentShelf = -1;
|
|
|
|
this.currentTray = -1;
|
|
|
|
this.columnWidth = 0;
|
|
|
|
this.lastBoxWidth = 0;
|
|
|
|
this.trayX = 0;
|
|
|
|
this.trayY = 0;
|
|
|
|
this.remaining = false;
|
|
|
|
|
|
|
|
for (var i = 0; i < this.items.length; i++)
|
|
|
|
{
|
|
|
|
var item = this.items[i];
|
|
|
|
var boxIncrement = Math.floor (this.depth / item.boxDepth);
|
|
|
|
|
|
|
|
if (boxIncrement < 1)
|
|
|
|
boxIncrement = 1;
|
|
|
|
|
|
|
|
for (var amount = 0; amount < item.amount; amount += boxIncrement)
|
|
|
|
{
|
|
|
|
this.addBox (item, amount);
|
|
|
|
this.firstShelfBox = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.currentShelf + 1;
|
|
|
|
}
|
|
|
|
|
2015-09-22 07:20:47 +00:00
|
|
|
});
|