0
1
Fork 0
This commit is contained in:
Juan Ferrer Toribio 2017-04-10 17:17:56 +02:00
parent 403845bf2b
commit 22ee7e5020
16 changed files with 202 additions and 108 deletions

View File

@ -5,16 +5,17 @@ Hedera.Items = new Class
,activate: function () ,activate: function ()
{ {
var set = this.$('set'); this.$('lot').assign ({
set.set ('warehouse', 7); warehouse: 7,
set.set ('realm', null); realm: null
});
} }
,onShowClick: function () ,onShowClick: function ()
{ {
var set = this.$('set'); var lot = this.$('lot');
set.set ('rate', this.$('rate').value); lot.assign ({rate: this.$('rate').value});
this.gui.openReport ('items-report', set.params); this.gui.openReport ('items-report', lot.params);
} }
}); });

View File

@ -1,5 +1,5 @@
<vn> <vn>
<vn-basic-set id="set"/> <vn-basic-set id="lot"/>
<h1 id="title"> <h1 id="title">
<t>Item list</t> <t>Item list</t>
</h1> </h1>
@ -13,23 +13,19 @@
<div class="card form"> <div class="card form">
<div> <div>
<label><t>Store</t></label> <label><t>Store</t></label>
<htk-combo lot="set" name="warehouse"> <htk-combo lot="lot" name="warehouse">
<db-model property="model"> <db-model property="model">
<custom> SELECT id, name FROM vn2008.warehouse
SELECT id, name FROM vn2008.warehouse WHERE reserve ORDER BY name
WHERE reserve ORDER BY name
</custom>
</db-model> </db-model>
</htk-combo> </htk-combo>
</div> </div>
<div> <div>
<label><t>Realm</t></label> <label><t>Realm</t></label>
<htk-combo lot="set" name="realm" not-null="false"> <htk-combo lot="lot" name="realm" not-null="false">
<db-model property="model"> <db-model property="model">
<custom> SELECT id, reino FROM vn2008.reinos
SELECT id, reino FROM vn2008.reinos WHERE display != FALSE ORDER BY reino
WHERE display != FALSE ORDER BY reino
</custom>
</db-model> </db-model>
</htk-combo> </htk-combo>
</div> </div>

View File

@ -17,6 +17,8 @@
id="config" id="config"
placeholder="_Select config" placeholder="_Select config"
model="configs-model" model="configs-model"
lot="hash"
name="config"
on-changed="onConfigChange" on-changed="onConfigChange"
on-ready="onConfigChange"> on-ready="onConfigChange">
<db-model property="model" id="configs-model"> <db-model property="model" id="configs-model">
@ -43,7 +45,7 @@
<div> <div>
<label><t>Family</t></label> <label><t>Family</t></label>
<htk-combo lot="lot" name="family"> <htk-combo lot="lot" name="family">
<db-model property="model" lot="config"> <db-model property="model" lot="lot">
SELECT tipo_id, Tipo FROM vn2008.Tipos SELECT tipo_id, Tipo FROM vn2008.Tipos
WHERE reino_id = #realm ORDER BY Tipo WHERE reino_id = #realm ORDER BY Tipo
</db-model> </db-model>

View File

@ -9,7 +9,6 @@
.balance .balance
{ {
margin-top: 1.2em; margin-top: 1.2em;
margin-right: .5em;
} }
.balance > * .balance > *
{ {
@ -26,6 +25,7 @@
cursor: pointer; cursor: pointer;
height: 1.2em; height: 1.2em;
cursor: pointer; cursor: pointer;
margin: 0 .3em;
} }
.balance > .negative .balance > .negative
{ {

View File

@ -26,7 +26,11 @@
<t>Balance:</t> <t>Balance:</t>
</span> </span>
<span class="amount" id="balance"> <span class="amount" id="balance">
<htk-text lot="debt" name="debt" format="%.2d€"/> <htk-text
lot="debt"
name="debt"
format="%.2d€"
conditional-func="balanceConditionalFunc"/>
</span> </span>
<img <img
src="image/icon/dark/info.svg" src="image/icon/dark/info.svg"
@ -44,7 +48,7 @@
</div> </div>
<div class="card list"> <div class="card list">
<htk-repeater form-id="iter" renderer="repeaterFunc"> <htk-repeater form-id="iter" renderer="repeaterFunc">
<db-model property="model" id="tickets" lot="hash"> <db-model property="model" lot="hash">
CALL clientTicketList (#from, NULL) CALL clientTicketList (#from, NULL)
</db-model> </db-model>
<custom> <custom>

View File

@ -72,7 +72,12 @@ Connection.implement
*/ */
,execQuery: function (query, callback, params) ,execQuery: function (query, callback, params)
{ {
this.execStmt (new Sql.String ({query: query}), callback, params); this.execSql (this.renderQuery (query, params), callback);
}
,renderQuery: function (query, params)
{
return new Sql.String ({query: query}).render (params);
} }
/* /*

View File

@ -109,8 +109,8 @@ Model.implement
type: Vn.Lot type: Vn.Lot
,set: function (x) ,set: function (x)
{ {
this.link ({_lot: x}, {'change': this._autoLoad}); this.link ({_lot: x}, {'change': this._onLotChange});
this._autoLoad (); this._onLotChange ();
} }
,get: function () ,get: function ()
{ {
@ -242,6 +242,7 @@ Model.implement
,_conn: null ,_conn: null
,_resultIndex: 0 ,_resultIndex: 0
,_batch: null ,_batch: null
,_lot: null
,_stmt: null ,_stmt: null
,_status: Status.CLEAN ,_status: Status.CLEAN
,data: null ,data: null
@ -276,7 +277,34 @@ Model.implement
if (child.nodeType === Node.TEXT_NODE) if (child.nodeType === Node.TEXT_NODE)
this.query = child.textContent; this.query = child.textContent;
} }
,_getParams: function ()
{
if (!this._stmt)
return null;
var ids = this._stmt.findHolders ();
if (!ids)
return null;
var lotParams = this._lot ? this._lot.params : {};
var params = {};
for (var i = 0; i < ids.length; i++)
params[ids[i]] = lotParams[ids[i]];
return params;
}
,_onLotChange: function ()
{
var params = this._getParams ();
if (!Vn.Value.equals (params, this._lastParams))
this._autoLoad ();
}
,_autoLoad: function () ,_autoLoad: function ()
{ {
if (this.autoLoad) if (this.autoLoad)
@ -285,31 +313,15 @@ Model.implement
this.clean (); this.clean ();
} }
/** ,_isReady: function (params)
* Checks wether the model is ready to execute its query.
*
* @return {Boolean} %true if its ready, %false otherwise
*/
,isReady: function ()
{ {
if (!this._stmt || !this._conn) if (!this._stmt || !this._conn)
return false; return false;
if (!params)
var ids = this._stmt.findHolders ();
if (!ids)
return true; return true;
if (!this._lot) for (var key in params)
return false; if (params[key] === undefined)
var params = this._lot.params;
if (!params)
return false;
for (var i = 0; i < ids.length; i++)
if (params[ids[i]] === undefined)
return false; return false;
return true; return true;
@ -320,9 +332,11 @@ Model.implement
*/ */
,refresh: function () ,refresh: function ()
{ {
if (this.isReady ()) var params = this._getParams ();
if (this._isReady (params))
{ {
var params = this._lot ? this._lot.params : null; this._lastParams = params;
this._setStatus (Status.LOADING); this._setStatus (Status.LOADING);
this._conn.execStmt (this._stmt, this._selectDone.bind (this), params); this._conn.execStmt (this._stmt, this._selectDone.bind (this), params);
} }
@ -396,7 +410,7 @@ Model.implement
} }
} }
,_cleanData: function (error) ,_cleanData: function ()
{ {
this.data = null; this.data = null;
this.tables = null; this.tables = null;

View File

@ -237,8 +237,8 @@ module.exports = new Class
childData.set.unref (); childData.set.unref ();
childData.builder.unref (); childData.builder.unref ();
} }
,destroy: function () ,_destroy: function ()
{ {
this._freeChildsData (); this._freeChildsData ();
this.parent (); this.parent ();

View File

@ -19,18 +19,21 @@ module.exports = new Class
,render: function (params) ,render: function (params)
{ {
var object; if (params)
if (params && (object = params[this.id]))
{ {
if (!(object instanceof SqlObject)) var object = params[this.id];
if (object != null)
{ {
var sqlValue = new Value (); if (!(object instanceof SqlObject))
sqlValue.value = object; {
return sqlValue.render (); var sqlValue = new Value ();
sqlValue.value = object;
return sqlValue.render ();
}
else
return object.render (params);
} }
else
return object.render (params);
} }
return '#'+ this.id; return '#'+ this.id;

View File

@ -1,5 +1,5 @@
var Object = require ('./object'); var VnObject = require ('./object');
var Type = require ('./type'); var Type = require ('./type');
/** /**
@ -7,7 +7,7 @@ var Type = require ('./type');
*/ */
module.exports = new Class module.exports = new Class
({ ({
Extends: Object Extends: VnObject
,_addedMap: {} ,_addedMap: {}
,_contexts: null ,_contexts: null
@ -577,7 +577,7 @@ module.exports = new Class
var BuilderResult = new Class var BuilderResult = new Class
({ ({
Extends: Object Extends: VnObject
,initialize: function (builder, objects) ,initialize: function (builder, objects)
{ {
@ -615,7 +615,7 @@ var BuilderResult = new Class
var objects = this.objects; var objects = this.objects;
for (var i = 0; i < objects.length; i++) for (var i = 0; i < objects.length; i++)
if (objects[i] instanceof Object) if (objects[i] instanceof VnObject)
objects[i].unref (); objects[i].unref ();
this.parent (); this.parent ();

View File

@ -2,6 +2,7 @@
var VnObject = require ('./object'); var VnObject = require ('./object');
var VnDate = require ('./date'); var VnDate = require ('./date');
var Lot = require ('./lot'); var Lot = require ('./lot');
var Value = require ('./value');
/** /**
* Class to handle the URL. * Class to handle the URL.
@ -48,9 +49,9 @@ module.exports = new Class
this.parent (props); this.parent (props);
} }
,get: function (key, type) ,get: function (key)
{ {
return this.parseValue (this._hashMap[key], type); return this._hashMap[key];
} }
,set: function (key, value) ,set: function (key, value)
@ -67,8 +68,10 @@ module.exports = new Class
*/ */
,assign: function (object) ,assign: function (object)
{ {
var newObject = this._hashMap; var newObject = {};
for (var key in this._hashMap)
newObject[key] = this._hashMap[key];
for (var key in object) for (var key in object)
newObject[key] = object[key]; newObject[key] = object[key];
@ -92,7 +95,7 @@ module.exports = new Class
if (!object) if (!object)
object = {}; object = {};
if (newHash !== this._hash) if (!Value.equals (this._hashMap, object))
{ {
this._hashMap = object; this._hashMap = object;
this._hash = newHash; this._hash = newHash;
@ -135,8 +138,8 @@ module.exports = new Class
,_hashChanged: function () ,_hashChanged: function ()
{ {
var newHash = location.hash; var newHash = location.hash;
if (this._blockChanged || newHash === this._hash) if (this._blockChanged || this._hash == newHash)
return; return;
var newMap = hashMap = {}; var newMap = hashMap = {};
@ -147,12 +150,15 @@ module.exports = new Class
var kvPair = kvPairs[i].split ('=', 2); var kvPair = kvPairs[i].split ('=', 2);
if (kvPair[0]) if (kvPair[0])
newMap[decodeURIComponent (kvPair[0])] = decodeURIComponent (kvPair[1]); newMap[decodeURIComponent (kvPair[0])] = this.parseValue (kvPair[1]);
} }
this._hashMap = newMap; if (!Value.equals (this._hashMap, newMap))
this._hash = newHash; {
this.changed (); this._hashMap = newMap;
this._hash = newHash;
this.changed ();
}
} }
,renderValue: function (v) ,renderValue: function (v)
@ -160,36 +166,70 @@ module.exports = new Class
switch (typeof v) switch (typeof v)
{ {
case 'number': case 'number':
return v; return '(Number)'+ v;
case 'boolean': case 'boolean':
return (v) ? 'true' : 'false'; return '(Boolean)'+ (v ? 'true' : 'false');
case 'object': case 'object':
if (v instanceof Date) if (v instanceof Date)
return VnDate.strftime (v, '%Y-%m-%d'); return '(Date)'+ VnDate.strftime (v, '%Y-%m-%d');
else
return '(Object)'+ JSON.stringify (v)
}
switch (v.charAt (0))
{
case '(':
case '\\':
return '\\'+ v;
} }
return v; return v;
} }
,parseValue: function (v, type) ,parseValue: function (v)
{ {
if (v == null)
return v;
v = decodeURIComponent (v);
if (v === '')
return v;
var typeStr;
switch (v.charAt(0))
{
case '(':
var index = v.indexOf (')');
typeStr = v.substr (1, index - 1);
v = v.substr (index + 1);
break;
case '\\':
v = v.substr (1);
break;
}
if (v === '') if (v === '')
return null; return null;
if (!typeStr)
return v;
if (type && v !== undefined && v !== null) switch (typeStr)
switch (type)
{ {
case Boolean: case 'Boolean':
return (/^(true|1)$/i).test (v); return (/^(true|1)$/i).test (v);
case Number: case 'Number':
return 0 + new Number (v); return 0 + new Number (v);
case Date: case 'Date':
var date = new Date (v); var date = new Date (v);
date.setHours (0, 0, 0, 0); date.setHours (0, 0, 0, 0);
return date; return date;
case 'Object':
return JSON.parse (v);
default:
return v;
} }
return v;
} }
,_destroy: function () ,_destroy: function ()

View File

@ -156,8 +156,8 @@ module.exports = new Class
return; return;
for (var i = 0; i < callbacks.length; i++) for (var i = 0; i < callbacks.length; i++)
if (callbacks[i].callback == callback if (callbacks[i].callback === callback
&& callbacks[i].instance == instance) && callbacks[i].instance === instance)
callbacks.splice (i--, 1); callbacks.splice (i--, 1);
} }
@ -178,7 +178,7 @@ module.exports = new Class
var callbacks = signals[signalId]; var callbacks = signals[signalId];
for (var i = 0; i < callbacks.length; i++) for (var i = 0; i < callbacks.length; i++)
if (callbacks[i].instance == instance) if (callbacks[i].instance === instance)
callbacks.splice (i--, 1); callbacks.splice (i--, 1);
} }
} }
@ -195,10 +195,16 @@ module.exports = new Class
var links = this._signalData.links; var links = this._signalData.links;
for (var key in links) for (var key in links)
links[key].disconnectByInstance (this); this._unlink (links[key]);
this._signalData = null; this._signalData = null;
} }
,_unlink: function (object)
{
object.disconnectByInstance (this);
object.unref ();
}
/** /**
* Links the object with another object. * Links the object with another object.
@ -217,10 +223,7 @@ module.exports = new Class
var oldObject = this[key]; var oldObject = this[key];
if (oldObject) if (oldObject)
{ this._unlink (oldObject);
oldObject.disconnectByInstance (this);
oldObject.unref ();
}
this[key] = newObject; this[key] = newObject;

View File

@ -1,11 +1,43 @@
var VnDate = require ('./date'); var VnDate = require ('./date');
/**
* Checks if two values are equal, it also checks objects. Basic
* values are compared using the non-strict equality operator.
*
* @param {*} a Value to compare to
* @param {*} b Value to compare with
* @return {Boolean} %true if they are equal, %false otherwise
*/
function equals (a, b)
{
if (a == b)
return true;
if (a instanceof Date && b instanceof Date)
return a.getTime () === b.getTime ();
if (a && b && (typeof a === 'object') && (typeof b === 'object'))
{
for (var key in a)
if (!equals (a[key], b[key]))
return false;
for (var key in b)
if (a[key] === undefined && b[key] != null)
return false;
return true;
}
return false;
}
module.exports = module.exports =
{ {
regexpNumber: /%\.([0-9]+)d/g regexpNumber: /%\.([0-9]+)d/g
,regexpString: /%s/g ,regexpString: /%s/g
,equals: equals
,compare: function (a, b) ,compare: function (a, b)
{ {
if (a === b) if (a === b)

View File

@ -33,13 +33,13 @@
<db-model property="model" id="movements" conn="conn" lot="hash"> <db-model property="model" id="movements" conn="conn" lot="hash">
CALL clientTicketRowGet(#ticket) CALL clientTicketRowGet(#ticket)
</db-model> </db-model>
<htk-column-spin title="_Ref" name="item"/> <htk-column-spin title="_Ref" column="item"/>
<htk-column-spin title="_Amount" name="amount"/> <htk-column-spin title="_Amount" column="amount"/>
<htk-column-text title="_Item" name="concept"/> <htk-column-text title="_Item" column="concept"/>
<htk-column-text title="_S1" name="Medida"/> <htk-column-text title="_S1" column="Medida"/>
<htk-column-text title="_Cat" name="Categoria"/> <htk-column-text title="_Cat" column="Categoria"/>
<htk-column-text title="_Color" name="Color"/> <htk-column-text title="_Color" column="Color"/>
<htk-column-spin title="_Price" name="price" unit="€" digits="2"/> <htk-column-spin title="_Price" column="price" unit="€" digits="2"/>
<htk-column-spin title="_Import" unit="€" digits="2" renderer="subtotalRenderer"/> <htk-column-spin title="_Import" unit="€" digits="2" renderer="subtotalRenderer"/>
</htk-grid> </htk-grid>
<div class="footer"> <div class="footer">

View File

@ -17,20 +17,14 @@ Hedera.ShelvesReport = new Class
showPacking: params.showPacking, showPacking: params.showPacking,
stack: params.stack, stack: params.stack,
useIds: params.useIds useIds: params.useIds
}) });
var params = {
warehouse: params.warehouse,
}
var query = var query =
'SELECT id, name, nTrays, topTrayHeight, trayHeight, width, depth '+ 'SELECT id, name, nTrays, topTrayHeight, trayHeight, width, depth '+
'FROM shelf WHERE id = #shelf; '+ 'FROM shelf WHERE id = #shelf; '+
'CALL itemAllocator (#warehouse, #date, #family, #namePrefix, #useIds)'; 'CALL itemAllocator (#warehouse, #date, #family, #namePrefix, #useIds)';
this.conn.execQuery (query, this.conn.execQuery (query,
this.onQueryExec.bind (this), lot); this.onQueryExec.bind (this), params);
} }
,onQueryExec: function (resultSet) ,onQueryExec: function (resultSet)

View File

@ -60,7 +60,7 @@
} }
.report .box-label .report .box-label
{ {
font-size: .25em; font-size: .65em;
word-wrap: break-word; word-wrap: break-word;
box-sizing: border-box; box-sizing: border-box;
padding: 1% 2%; padding: 1% 2%;