Skip to content
Snippets Groups Projects
Commit 583c5bd1 authored by Johannes Hörmann's avatar Johannes Hörmann
Browse files

refactor all libs

parent 67ac69b3
No related branches found
No related tags found
No related merge requests found
...@@ -54,13 +54,13 @@ OfferUtils.getOfferNetAndVAT = function(offerId, offeritemIdsToDel) { ...@@ -54,13 +54,13 @@ OfferUtils.getOfferNetAndVAT = function(offerId, offeritemIdsToDel) {
var oiUtils = new OfferItemUtils(offerId); var oiUtils = new OfferItemUtils(offerId);
var condition = "where OFFER_ID = '" + offerId + "'"; var condition = "where OFFER_ID = '" + offerId + "'";
if(offeritemIdsToDel != undefined) if (offeritemIdsToDel != undefined)
condition += " and OFFERITEMID not in ('" + offeritemIdsToDel.join("','") + "')"; condition += " and OFFERITEMID not in ('" + offeritemIdsToDel.join("','") + "')";
var offerItems = db.table("select QUANTITY, PRICE, DISCOUNT, VAT, OPTIONAL " var offerItems = db.table("select QUANTITY, PRICE, DISCOUNT, VAT, OPTIONAL "
+ "from OFFERITEM " + condition); + "from OFFERITEM " + condition);
for(var i = 0; i < offerItems.length; i++) for (var i = 0; i < offerItems.length; i++)
{ {
sum += oiUtils.getItemSum(offerItems[i][0], offerItems[i][1], offerItems[i][2], offerItems[i][4]); sum += oiUtils.getItemSum(offerItems[i][0], offerItems[i][1], offerItems[i][2], offerItems[i][4]);
vat += oiUtils.getItemVAT(offerItems[i][0], offerItems[i][1], offerItems[i][2], offerItems[i][3], offerItems[i][4]); vat += oiUtils.getItemVAT(offerItems[i][0], offerItems[i][1], offerItems[i][2], offerItems[i][3], offerItems[i][4]);
...@@ -166,7 +166,7 @@ OfferItemUtils.prototype.reOrgItems = function() { ...@@ -166,7 +166,7 @@ OfferItemUtils.prototype.reOrgItems = function() {
* @class * @class
*/ */
function ItemUtils(pOfferOrderId) { function ItemUtils(pOfferOrderId) {
if(this.constructor === ItemUtils) if (this.constructor === ItemUtils)
throw new Error("Can't instantiate abstract class ItemUtils!"); throw new Error("Can't instantiate abstract class ItemUtils!");
...@@ -195,9 +195,9 @@ function ItemUtils(pOfferOrderId) { ...@@ -195,9 +195,9 @@ function ItemUtils(pOfferOrderId) {
* @ignore * @ignore
*/ */
this._appendNode = function(itemId, assignedTo, tree, ids) { this._appendNode = function(itemId, assignedTo, tree, ids) {
if(tree == undefined) if (tree == undefined)
tree = this.ItemTree; tree = this.ItemTree;
if(ids == undefined) if (ids == undefined)
ids = this.ItemIds; ids = this.ItemIds;
tree[itemId] = this._getItemTreeNodeObject(assignedTo tree[itemId] = this._getItemTreeNodeObject(assignedTo
...@@ -205,7 +205,7 @@ function ItemUtils(pOfferOrderId) { ...@@ -205,7 +205,7 @@ function ItemUtils(pOfferOrderId) {
, this.getNextItemSort(ids)); , this.getNextItemSort(ids));
ids.push(itemId); ids.push(itemId);
if(assignedTo != "") if (assignedTo != "")
{ {
tree[assignedTo].ids.push(itemId); tree[assignedTo].ids.push(itemId);
} }
...@@ -222,9 +222,9 @@ function ItemUtils(pOfferOrderId) { ...@@ -222,9 +222,9 @@ function ItemUtils(pOfferOrderId) {
* @ignore * @ignore
*/ */
this._deleteNodes = function(itemId, tree, ids) { this._deleteNodes = function(itemId, tree, ids) {
if(tree == undefined) if (tree == undefined)
tree = this.ItemTree; tree = this.ItemTree;
if(ids == undefined) if (ids == undefined)
ids = this.ItemIds; ids = this.ItemIds;
__delete(tree[itemId]); __delete(tree[itemId]);
...@@ -232,7 +232,7 @@ function ItemUtils(pOfferOrderId) { ...@@ -232,7 +232,7 @@ function ItemUtils(pOfferOrderId) {
_deleteNode(itemId); _deleteNode(itemId);
function __delete(pNode) { function __delete(pNode) {
for(var i = 0; i < pNode.ids.length; i++) { for (var i = 0; i < pNode.ids.length; i++) {
__delete(tree[pNode.ids[i]]); __delete(tree[pNode.ids[i]]);
_deleteNode(pNode.ids[i]); _deleteNode(pNode.ids[i]);
} }
...@@ -244,13 +244,13 @@ function ItemUtils(pOfferOrderId) { ...@@ -244,13 +244,13 @@ function ItemUtils(pOfferOrderId) {
//delete id in global Array "ItemIds" //delete id in global Array "ItemIds"
var idx = ids.indexOf(itemId); var idx = ids.indexOf(itemId);
if(idx > -1) if (idx > -1)
ids.splice(idx, 1); ids.splice(idx, 1);
//delete id in Array from property "ids" of Tree //delete id in Array from property "ids" of Tree
for(var oiid in tree) { for (var oiid in tree) {
idx = tree[oiid].ids.indexOf(itemId); idx = tree[oiid].ids.indexOf(itemId);
if(idx > -1) if (idx > -1)
tree[oiid].ids.splice(idx, 1); tree[oiid].ids.splice(idx, 1);
} }
} }
...@@ -271,17 +271,17 @@ function ItemUtils(pOfferOrderId) { ...@@ -271,17 +271,17 @@ function ItemUtils(pOfferOrderId) {
var colTypes = db.getColumnTypes(table, cols); var colTypes = db.getColumnTypes(table, cols);
var oiTree = this.ItemTree; var oiTree = this.ItemTree;
for(var oiid in compTree) { for (var oiid in compTree) {
if(oiTree[oiid] != undefined) { if (oiTree[oiid] != undefined) {
//check if itemsort/pos has been changed //check if itemsort/pos has been changed
if(oiTree[oiid].itemsort != compTree[oiid].itemsort || oiTree[oiid].pos != compTree[oiid].pos) { if (oiTree[oiid].itemsort != compTree[oiid].itemsort || oiTree[oiid].pos != compTree[oiid].pos) {
var vals = [compTree[oiid].itemsort, compTree[oiid].pos]; var vals = [compTree[oiid].itemsort, compTree[oiid].pos];
statements.push([table, cols, colTypes, vals, table + "ID = '" + oiid + "'"]); statements.push([table, cols, colTypes, vals, table + "ID = '" + oiid + "'"]);
} }
} }
} }
if(statements.length > 0) if (statements.length > 0)
db.updates(statements); db.updates(statements);
} }
} }
...@@ -296,22 +296,22 @@ function ItemUtils(pOfferOrderId) { ...@@ -296,22 +296,22 @@ function ItemUtils(pOfferOrderId) {
* @abstract * @abstract
*/ */
ItemUtils.prototype.initItemTree = function(table, foreignKeyColumn) { ItemUtils.prototype.initItemTree = function(table, foreignKeyColumn) {
if(this.ItemTree == undefined) { if (this.ItemTree == undefined) {
this.ItemTree = {}; this.ItemTree = {};
this.ItemIds = []; this.ItemIds = [];
var data = db.table("select " + table + "ID, ASSIGNEDTO, ITEMPOSITION, ITEMSORT from " + table var data = db.table("select " + table + "ID, ASSIGNEDTO, ITEMPOSITION, ITEMSORT from " + table
+ " where " + foreignKeyColumn + " = '" + this.offerOrderId + "' order by ITEMSORT"); + " where " + foreignKeyColumn + " = '" + this.offerOrderId + "' order by ITEMSORT");
for(var i = 0; i < data.length; i++) for (var i = 0; i < data.length; i++)
{ {
this.ItemTree[data[i][0]] = this._getItemTreeNodeObject(data[i][1], data[i][2], data[i][3]); this.ItemTree[data[i][0]] = this._getItemTreeNodeObject(data[i][1], data[i][2], data[i][3]);
this.ItemIds.push(data[i][0]); this.ItemIds.push(data[i][0]);
} }
for(var oiid in this.ItemTree) for (var oiid in this.ItemTree)
{ {
if(this.ItemTree[oiid].assignedto != "") if (this.ItemTree[oiid].assignedto != "")
this.ItemTree[ this.ItemTree[oiid].assignedto ].ids.push(oiid); this.ItemTree[ this.ItemTree[oiid].assignedto ].ids.push(oiid);
} }
} }
...@@ -367,15 +367,15 @@ ItemUtils.prototype.insertPartsList = function(columns, table, productId, assign ...@@ -367,15 +367,15 @@ ItemUtils.prototype.insertPartsList = function(columns, table, productId, assign
//save address for this here to call methods in recursive sub function __itemInsertStatement //save address for this here to call methods in recursive sub function __itemInsertStatement
var self = this; var self = this;
if(assignedTo == undefined) if (assignedTo == undefined)
assignedTo = ""; assignedTo = "";
if(currency == undefined) if (currency == undefined)
currency = ""; currency = "";
if(relationId == undefined) if (relationId == undefined)
relationId = ""; relationId = "";
var rootProdId = productId; var rootProdId = productId;
if(rootProdId != "") { if (rootProdId != "") {
var p2pUtils = new Prod2ProdUtils(rootProdId); var p2pUtils = new Prod2ProdUtils(rootProdId);
var partsList = p2pUtils.getPartsListObject(); var partsList = p2pUtils.getPartsListObject();
...@@ -384,7 +384,7 @@ ItemUtils.prototype.insertPartsList = function(columns, table, productId, assign ...@@ -384,7 +384,7 @@ ItemUtils.prototype.insertPartsList = function(columns, table, productId, assign
__itemInsertStatement(partsList.root, assignedTo, currency, relationId); __itemInsertStatement(partsList.root, assignedTo, currency, relationId);
if(statements.length > 0) if (statements.length > 0)
db.inserts(statements); db.inserts(statements);
} }
...@@ -392,7 +392,7 @@ ItemUtils.prototype.insertPartsList = function(columns, table, productId, assign ...@@ -392,7 +392,7 @@ ItemUtils.prototype.insertPartsList = function(columns, table, productId, assign
//recursive function for building item insert statements //recursive function for building item insert statements
function __itemInsertStatement(partsListObj, assignedTo, currency, relationId) { function __itemInsertStatement(partsListObj, assignedTo, currency, relationId) {
for(var i = 0; i < partsListObj.ids.length; i++) { for (var i = 0; i < partsListObj.ids.length; i++) {
var newid = util.getNewUUID(); var newid = util.getNewUUID();
self._appendNode(newid, assignedTo); self._appendNode(newid, assignedTo);
var pos = self.ItemTree[newid].pos; var pos = self.ItemTree[newid].pos;
...@@ -405,7 +405,7 @@ ItemUtils.prototype.insertPartsList = function(columns, table, productId, assign ...@@ -405,7 +405,7 @@ ItemUtils.prototype.insertPartsList = function(columns, table, productId, assign
var price = ""; var price = "";
var vat = ""; var vat = "";
if(P2pObject.takeprice == "Y" && ProductDetails.productId && ProductDetails.PriceListToUse) { if (P2pObject.takeprice == "Y" && ProductDetails.productId && ProductDetails.PriceListToUse) {
price = ProductDetails.PriceListToUse.price; price = ProductDetails.PriceListToUse.price;
vat = ProductDetails.PriceListToUse.vat; vat = ProductDetails.PriceListToUse.vat;
} }
...@@ -454,7 +454,7 @@ ItemUtils.prototype.deletePartsList = function(itemId, table) { ...@@ -454,7 +454,7 @@ ItemUtils.prototype.deletePartsList = function(itemId, table) {
__itemDeleteStatement(itemId); __itemDeleteStatement(itemId);
if(statements.length > 0) if (statements.length > 0)
db.deletes(statements); db.deletes(statements);
self._deleteNodes(itemId); self._deleteNodes(itemId);
...@@ -465,7 +465,7 @@ ItemUtils.prototype.deletePartsList = function(itemId, table) { ...@@ -465,7 +465,7 @@ ItemUtils.prototype.deletePartsList = function(itemId, table) {
function __itemDeleteStatement(itemId) { function __itemDeleteStatement(itemId) {
var itemsToDelete = self.ItemTree[itemId].ids; var itemsToDelete = self.ItemTree[itemId].ids;
for(var i = 0; i < itemsToDelete.length; i++) { for (var i = 0; i < itemsToDelete.length; i++) {
//unshift due to foreign key constraints (Delete hierarchically starting at the bottom) //unshift due to foreign key constraints (Delete hierarchically starting at the bottom)
statements.unshift([table, table + "ID = '" + itemsToDelete[i] + "'"]); statements.unshift([table, table + "ID = '" + itemsToDelete[i] + "'"]);
deletedItemIds.push(itemsToDelete[i]); deletedItemIds.push(itemsToDelete[i]);
...@@ -485,7 +485,7 @@ ItemUtils.prototype.deletePartsList = function(itemId, table) { ...@@ -485,7 +485,7 @@ ItemUtils.prototype.deletePartsList = function(itemId, table) {
* @abstract * @abstract
*/ */
ItemUtils.prototype.getNextItemSort = function(ids) { ItemUtils.prototype.getNextItemSort = function(ids) {
if(ids == undefined) if (ids == undefined)
ids = this.ItemIds; ids = this.ItemIds;
return (ids.length + 1).toString(); return (ids.length + 1).toString();
...@@ -517,17 +517,17 @@ ItemUtils.prototype.getNextItemSort = function(ids) { ...@@ -517,17 +517,17 @@ ItemUtils.prototype.getNextItemSort = function(ids) {
* @abstract * @abstract
*/ */
ItemUtils.prototype.getNextItemPosition = function(assignedTo, tree, ids) { ItemUtils.prototype.getNextItemPosition = function(assignedTo, tree, ids) {
if(assignedTo == undefined) if (assignedTo == undefined)
assignedTo = ""; assignedTo = "";
if(tree == undefined) if (tree == undefined)
tree = this.ItemTree; tree = this.ItemTree;
if(ids == undefined) if (ids == undefined)
ids = this.ItemIds; ids = this.ItemIds;
var maxPos = ["0"]; var maxPos = ["0"];
if(assignedTo != "") { if (assignedTo != "") {
if(tree[assignedTo].ids.length < 1) { //first item in this level if (tree[assignedTo].ids.length < 1) { //first item in this level
maxPos = tree[assignedTo].pos.split("."); maxPos = tree[assignedTo].pos.split(".");
maxPos = maxPos.concat(["0"]); //next level pos maxPos = maxPos.concat(["0"]); //next level pos
} else { } else {
...@@ -535,7 +535,7 @@ ItemUtils.prototype.getNextItemPosition = function(assignedTo, tree, ids) { ...@@ -535,7 +535,7 @@ ItemUtils.prototype.getNextItemPosition = function(assignedTo, tree, ids) {
maxPos = tree[childIds[childIds.length-1]].pos.split("."); maxPos = tree[childIds[childIds.length-1]].pos.split(".");
} }
} else { } else {
if(ids.length > 0) { if (ids.length > 0) {
maxPos[0] = this.ItemTree[ids[ids.length-1]].pos; maxPos[0] = this.ItemTree[ids[ids.length-1]].pos;
} }
} }
...@@ -569,8 +569,8 @@ ItemUtils.prototype.reOrgItems = function(table) { ...@@ -569,8 +569,8 @@ ItemUtils.prototype.reOrgItems = function(table) {
//recursive function to build new ItemTree Structure //recursive function to build new ItemTree Structure
function __reorg(pIds, pAssignedTo) { function __reorg(pIds, pAssignedTo) {
for(var i = 0; i < pIds.length; i++) { for (var i = 0; i < pIds.length; i++) {
if(newTree[pIds[i]] == undefined) { if (newTree[pIds[i]] == undefined) {
//build new tree //build new tree
self._appendNode(pIds[i], pAssignedTo, newTree, newIds); self._appendNode(pIds[i], pAssignedTo, newTree, newIds);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment