2015-09-22 07:20:47 +00:00
|
|
|
|
|
|
|
Vn.Shelves = new Class
|
|
|
|
({
|
|
|
|
Extends: Vn.Module
|
|
|
|
|
|
|
|
,activate: function ()
|
|
|
|
{
|
|
|
|
this.$('report-title').value = 'Anthuriums';
|
2015-10-21 23:42:52 +00:00
|
|
|
this.$('warehouse').value = 44;
|
2015-09-22 07:20:47 +00:00
|
|
|
this.$('date').value = new Date ();
|
|
|
|
this.$('shelf').value = 1;
|
|
|
|
this.$('reign').value = 1;
|
|
|
|
this.$('family').value = 2;
|
|
|
|
this.$('filter').value = 'Ant %';
|
|
|
|
this.$('max-amount').value = 50;
|
|
|
|
}
|
|
|
|
|
|
|
|
,onPreviewClick: function ()
|
|
|
|
{
|
2015-10-21 23:42:52 +00:00
|
|
|
var report = new Vn.ShelvesReport ({conn: this.conn});
|
|
|
|
report.setParams (
|
|
|
|
this.$('report-title').value,
|
|
|
|
this.$('warehouse').value,
|
|
|
|
this.$('date').value,
|
|
|
|
this.$('family').value,
|
|
|
|
this.$('filter').value,
|
|
|
|
this.$('max-amount').value,
|
|
|
|
this.$('shelf').value
|
|
|
|
);
|
|
|
|
report.open ();
|
2015-09-22 07:20:47 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-10-21 23:42:52 +00:00
|
|
|
Vn.ShelvesReport = new Class
|
|
|
|
({
|
|
|
|
Extends: Vn.Report
|
|
|
|
|
|
|
|
,nItem: -1
|
|
|
|
,nColors: 4
|
|
|
|
|
|
|
|
,setParams: function (title, warehouse, date, type, filter, maxAmount, shelf)
|
|
|
|
{
|
|
|
|
this.title = title;
|
|
|
|
this.maxAmount = maxAmount;
|
|
|
|
|
|
|
|
var batch = new Sql.Batch ();
|
|
|
|
batch.addValue ('shelf', shelf);
|
|
|
|
batch.addValue ('wh', warehouse);
|
|
|
|
batch.addValue ('date', date);
|
|
|
|
batch.addValue ('type', type);
|
|
|
|
batch.addValue ('filter', filter);
|
|
|
|
this.batch = batch;
|
|
|
|
}
|
|
|
|
|
|
|
|
,open: function ()
|
|
|
|
{
|
|
|
|
var query =
|
|
|
|
'SELECT id, name, width, height, max_height, tray_height, '+
|
|
|
|
'first_tray_elevation, tray_density, vspacing, hspacing '+
|
|
|
|
'FROM vn2008.shelf WHERE id = #shelf; '+
|
|
|
|
'CALL item_organizer (#wh, #date, #type, #filter)';
|
|
|
|
|
|
|
|
this.conn.execQuery (query, this.onQueryExec.bind (this), this.batch);
|
|
|
|
}
|
|
|
|
|
|
|
|
,onQueryExec: function (resultSet)
|
|
|
|
{
|
|
|
|
// Fetch query data
|
|
|
|
|
|
|
|
var res = resultSet.fetchResult ();
|
|
|
|
res.next ();
|
|
|
|
|
2015-10-22 05:11:17 +00:00
|
|
|
var scale = 0.065;
|
2015-10-21 23:42:52 +00:00
|
|
|
|
|
|
|
var shelf = this.shelf =
|
|
|
|
{
|
|
|
|
width: res.get ('width') * scale
|
|
|
|
,height: res.get ('height') * scale
|
|
|
|
,maxHeight: res.get ('max_height') * scale
|
|
|
|
,trayHeight: res.get ('tray_height') * scale
|
|
|
|
,firstTrayElevation: res.get ('first_tray_elevation') * scale
|
|
|
|
,trayDensity: res.get ('tray_density') * scale
|
|
|
|
,vspacing: res.get ('vspacing') * scale
|
|
|
|
,hspacing: res.get ('hspacing') * scale
|
|
|
|
};
|
|
|
|
|
|
|
|
var items = [];
|
|
|
|
var res = resultSet.fetchResult ();
|
|
|
|
|
|
|
|
while (res.next ())
|
|
|
|
items.push ({
|
|
|
|
name: res.get ('Article') +' x'+ res.get ('Medida')
|
|
|
|
,boxHeight: res.get ('z') * 10 * scale
|
|
|
|
,boxWidth: res.get ('x') * 10 * scale
|
|
|
|
,amount: res.get ('etiquetas')
|
|
|
|
});
|
|
|
|
|
|
|
|
// Intializes the allocator
|
|
|
|
|
|
|
|
alloc = new Vn.Allocator ();
|
|
|
|
alloc.items = items;
|
|
|
|
alloc.maxAmount = this.maxAmount;
|
|
|
|
alloc.shelfFunc = this.drawShelf.bind (this);
|
|
|
|
alloc.boxFunc = this.drawBox.bind (this);
|
|
|
|
|
|
|
|
alloc.nTrays = Math.ceil (
|
|
|
|
(shelf.height - shelf.firstTrayElevation) /
|
|
|
|
(shelf.trayHeight + shelf.trayDensity)
|
|
|
|
);
|
|
|
|
alloc.trayWidth = shelf.width - shelf.hspacing * 2;
|
|
|
|
alloc.trayHeight = shelf.trayHeight - shelf.vspacing;
|
|
|
|
alloc.topTrayHeight = shelf.maxHeight - shelf.vspacing
|
|
|
|
- shelf.firstTrayElevation - (alloc.nTrays - 1) * shelf.trayHeight;
|
|
|
|
|
|
|
|
// Opens the report
|
|
|
|
|
|
|
|
this.createWindow ('shelves');
|
|
|
|
alloc.run ();
|
|
|
|
}
|
|
|
|
|
|
|
|
,drawShelf: function (allocator)
|
|
|
|
{
|
|
|
|
var shelf = this.shelf;
|
|
|
|
|
|
|
|
var sheet = this.doc.createElement ('div');
|
|
|
|
sheet.className = 'sheet';
|
|
|
|
/* sheet.style.top = (allocator.currentShelf * 297) +'mm';
|
|
|
|
*/ this.doc.body.appendChild (sheet);
|
|
|
|
|
|
|
|
// Draws the title
|
|
|
|
|
|
|
|
var title = this.doc.createElement ('h1');
|
|
|
|
title.className = 'title';
|
|
|
|
title.appendChild (this.doc.createTextNode (this.title));
|
|
|
|
sheet.appendChild (title);
|
|
|
|
|
|
|
|
var pageNumber = this.doc.createElement ('h1');
|
|
|
|
pageNumber.className = 'page-number';
|
|
|
|
pageNumber.appendChild (this.doc.createTextNode (allocator.currentShelf + 1));
|
|
|
|
sheet.appendChild (pageNumber);
|
|
|
|
|
|
|
|
// Draws the shelf
|
|
|
|
|
|
|
|
var shelfDiv = this.shelfDiv = this.doc.createElement ('div');
|
|
|
|
shelfDiv.className = 'shelf';
|
|
|
|
shelfDiv.style.width = this.shelf.width +'mm';
|
|
|
|
shelfDiv.style.height = this.shelf.maxHeight +'mm';
|
|
|
|
sheet.appendChild (shelfDiv);
|
|
|
|
|
|
|
|
this.drawEdge ().style.left = 0;
|
|
|
|
this.drawEdge ().style.right = 0;
|
|
|
|
|
|
|
|
// Draws trays
|
|
|
|
|
|
|
|
var lastTrayY = shelf.firstTrayElevation;
|
|
|
|
|
|
|
|
if (shelf.trayHeight > 0)
|
|
|
|
while (lastTrayY + shelf.trayDensity < shelf.height)
|
|
|
|
{
|
|
|
|
var tray = this.doc.createElement ('div');
|
|
|
|
tray.className = 'tray';
|
|
|
|
tray.style.width = this.shelf.width +'mm';
|
|
|
|
tray.style.height = '1mm';
|
|
|
|
tray.style.bottom = lastTrayY +'mm';
|
|
|
|
shelfDiv.appendChild (tray);
|
|
|
|
|
|
|
|
lastTrayY += shelf.trayHeight + shelf.trayDensity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
,drawEdge: function (shelfDiv)
|
|
|
|
{
|
|
|
|
var edge = this.doc.createElement ('div');
|
|
|
|
edge.className = 'edge';
|
|
|
|
edge.style.width = '1mm';
|
|
|
|
edge.style.height = this.shelf.height +'mm';
|
|
|
|
edge.style.bottom = 0;
|
|
|
|
this.shelfDiv.appendChild (edge);
|
|
|
|
return edge;
|
|
|
|
}
|
|
|
|
|
|
|
|
,drawBox: function (allocator, item, amount)
|
|
|
|
{
|
|
|
|
if (item.boxWidth == 0 || item.boxHeight == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var shelf = this.shelf;
|
|
|
|
|
|
|
|
var x = allocator.trayX + shelf.hspacing;
|
|
|
|
var y = allocator.trayY
|
|
|
|
+ shelf.firstTrayElevation + shelf.trayDensity
|
|
|
|
+ allocator.currentTray * (shelf.trayHeight + shelf.trayDensity);
|
|
|
|
|
|
|
|
var box = this.doc.createElement ('div');
|
|
|
|
box.className = 'box';
|
|
|
|
this.shelfDiv.appendChild (box);
|
|
|
|
|
|
|
|
box.style.left = x +'mm';
|
|
|
|
box.style.bottom = y +'mm';
|
|
|
|
box.style.width = item.boxWidth +'mm';
|
|
|
|
box.style.height = item.boxHeight +'mm';
|
|
|
|
|
|
|
|
if (amount == 0)
|
|
|
|
this.nItem++;
|
|
|
|
|
|
|
|
var nColor = this.nItem % this.nColors;
|
|
|
|
Vn.Node.addClass (box, 'color'+ nColor);
|
|
|
|
|
|
|
|
if (amount == 0 || allocator.firstShelfBox)
|
|
|
|
{
|
|
|
|
var boxLabel = this.doc.createElement ('span');
|
|
|
|
box.appendChild (boxLabel);
|
|
|
|
|
|
|
|
var text = this.doc.createTextNode (item.name);
|
|
|
|
boxLabel.appendChild (text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Vn.Allocator = new Class
|
|
|
|
({
|
|
|
|
addShelf: function ()
|
|
|
|
{
|
|
|
|
this.currentShelf++;
|
|
|
|
this.firstShelfBox = true;
|
|
|
|
|
|
|
|
if (this.shelfFunc)
|
|
|
|
this.shelfFunc (this);
|
|
|
|
}
|
|
|
|
|
|
|
|
,addTray: function ()
|
|
|
|
{
|
|
|
|
if (this.currentTray <= 0)
|
|
|
|
{
|
|
|
|
this.addShelf ();
|
|
|
|
this.currentTray = this.nTrays - 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
this.currentTray--;
|
|
|
|
|
|
|
|
this.trayX = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
,addColumn: function (width)
|
|
|
|
{
|
|
|
|
if (this.trayX + this.columnWidth + width > this.trayWidth
|
|
|
|
|| this.currentTray == -1)
|
|
|
|
this.addTray ();
|
|
|
|
else
|
|
|
|
this.trayX += this.columnWidth;
|
|
|
|
|
|
|
|
this.trayY = 0;
|
|
|
|
this.columnWidth = width;
|
|
|
|
this.lastBoxWidth = width;
|
|
|
|
}
|
|
|
|
|
|
|
|
,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.addColumn (item.boxWidth);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
for (var i = 0; i < this.items.length; i++)
|
|
|
|
{
|
|
|
|
var item = this.items[i];
|
|
|
|
|
|
|
|
for (var amount = 0; amount < item.amount; amount++)
|
|
|
|
{
|
|
|
|
if (amount == 0
|
|
|
|
&& this.maxAmount > 0
|
|
|
|
&& item.amount > this.maxAmount)
|
|
|
|
break;
|
|
|
|
|
|
|
|
this.addBox (item, amount);
|
|
|
|
this.firstShelfBox = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.currentShelf + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|