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

OfferUtils refactoring

parent 16cc7008
No related branches found
No related tags found
No related merge requests found
Showing
with 266 additions and 285 deletions
......@@ -4,15 +4,13 @@ import("Util_lib");
import("Neon_lib");
import("OfferOrder_lib");
var offUtils = new OfferUtils();
var InputMapping = {
"OFFER": {
condition: "OFFERID = '" + vars.get("$field.OFFERID") + "'"
, ValueMapping: {
"OFFER_ID": ""
, "OFFERCODE": offUtils.getNextOfferNumber()
, "OFFERCODE": OfferUtils.getNextOfferNumber()
, "VERSNR": "1"
}
, SubModules:{
......
......@@ -4,8 +4,6 @@ import("Util_lib");
import("Neon_lib");
import("OfferOrder_lib");
var offUtils = new OfferUtils();
var InputMapping = {
"OFFER": {
......@@ -13,7 +11,7 @@ var InputMapping = {
, ValueMapping: {
"OFFER_ID": vars.get("$field.OFFERID")
, "OFFERCODE": vars.get("$field.OFFERCODE")
, "VERSNR": offUtils.getNextOfferVersionNumber(vars.get("$field.OFFERCODE"))
, "VERSNR": OfferUtils.getNextOfferVersionNumber(vars.get("$field.OFFERCODE"))
}
, SubModules:{
"OFFERITEM": {
......
......@@ -5,8 +5,6 @@ import("OfferOrder_lib");
import("Util_lib");
import("Entity_lib");
var OfferUtils = new OfferUtils();
if( vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_NEW
&& !OfferUtils.validateOfferNumber(ProcessHandlingUtils.getOnValidationValue(vars.get("$field.OFFERCODE"))) )
{
......
......@@ -4,8 +4,6 @@ import("system.neon");
import("OfferOrder_lib");
if(vars.get("$sys.operatingstate") == neon.OPERATINGSTATE_NEW)
{
var OfferUtils = new OfferUtils();
{
result.string( OfferUtils.getNextOfferNumber() );
}
\ No newline at end of file
......@@ -2,5 +2,4 @@ import("system.vars");
import("system.result");
import("OfferOrder_lib");
var oUtils = new OfferUtils();
result.string(oUtils.isEditable(vars.get("$field.STATUS")));
\ No newline at end of file
result.string(OfferUtils.isEditable(vars.get("$field.STATUS")));
\ No newline at end of file
......@@ -2,5 +2,4 @@ import("system.vars");
import("system.result");
import("OfferOrder_lib");
var oUtils = new OfferUtils();
result.string(oUtils.isEditable(vars.get("$field.STATUS")));
\ No newline at end of file
result.string(OfferUtils.isEditable(vars.get("$field.STATUS")));
\ No newline at end of file
......@@ -2,5 +2,4 @@ import("system.vars");
import("system.result");
import("OfferOrder_lib");
var oUtils = new OfferUtils();
result.string(oUtils.isEditable(vars.get("$param.OfferStatus_param")));
\ No newline at end of file
result.string(OfferUtils.isEditable(vars.get("$param.OfferStatus_param")));
\ No newline at end of file
......@@ -2,5 +2,4 @@ import("system.vars");
import("system.result");
import("OfferOrder_lib");
var oUtils = new OfferUtils();
result.string(oUtils.isEditable(vars.get("$param.OfferStatus_param")));
\ No newline at end of file
result.string(OfferUtils.isEditable(vars.get("$param.OfferStatus_param")));
\ No newline at end of file
......@@ -2,5 +2,4 @@ import("system.vars");
import("system.result");
import("OfferOrder_lib");
var oUtils = new OfferUtils();
result.string(oUtils.isEditable(vars.get("$param.OfferStatus_param")));
\ No newline at end of file
result.string(OfferUtils.isEditable(vars.get("$param.OfferStatus_param")));
\ No newline at end of file
......@@ -14,8 +14,7 @@ if(oid != "")
deletedIds.push(oiid);
var cols = ["NET", "VAT"];
var colTypes = db.getColumnTypes("OFFER", cols);
var oUtils = new OfferUtils();
var vals = oUtils.getOfferNetAndVAT(oid, deletedIds);
var vals = OfferUtils.getOfferNetAndVAT(oid, deletedIds);
db.updateData("OFFER", cols, colTypes, vals, "OFFERID = '" + oid + "'");
......
......@@ -19,8 +19,7 @@ if(oid != "")
//update offer price
var cols = ["NET", "VAT"];
var colTypes = db.getColumnTypes("OFFER", cols);
var oUtils = new OfferUtils();
var vals = oUtils.getOfferNetAndVAT(oid);
var vals = OfferUtils.getOfferNetAndVAT(oid);
db.updateData("OFFER", cols, colTypes, vals, "OFFERID = '" + oid + "'");
......
......@@ -8,8 +8,7 @@ if(oid != "")
{
var cols = ["NET", "VAT"];
var colTypes = db.getColumnTypes("OFFER", cols);
var oUtils = new OfferUtils();
var vals = oUtils.getOfferNetAndVAT(oid);
var vals = OfferUtils.getOfferNetAndVAT(oid);
db.updateData("OFFER", cols, colTypes, vals, "OFFERID = '" + oid + "'");
......
......@@ -5,88 +5,93 @@ import("system.tools");
import("Util_lib");
import("Product_lib");
function OfferUtils()
{
var that = this;
/**
* Delivers the next valid offer number (has to be unique)
*
* @return {String} next valid offer number
*/
this.getNextOfferNumber = function()
{
return NumberSequencingUtils.getNextUniqueNumber("OFFERCODE", "OFFER");
}
/**
* Methods used by Offer.
*
* Do not create an instance of this!
* @class
*/
function OfferUtils() {}
/**
* Delivers the next valid offer number (has to be unique)
*
* @return {String} next valid offer number
*/
OfferUtils.getNextProjectNumber = function() {
return NumberSequencingUtils.getNextUniqueNumber("OFFERCODE", "OFFER");
}
/**
* Delivers the next valid offer version number
*
* @return {String} next valid offer version number
*/
this.getNextOfferVersionNumber = function(pOfferCode)
{
return NumberSequencingUtils.getNextUniqueNumber("VERSNR", "OFFER", 1, "OFFERCODE = " + pOfferCode);
}
/**
* Delivers the next valid offer version number
*
* @return {String} offerCode next valid offer version number
*/
OfferUtils.getNextOfferVersionNumber = function(offerCode) {
return NumberSequencingUtils.getNextUniqueNumber("VERSNR", "OFFER", 1, "OFFERCODE = " + offerCode);
}
/**
* Checks if the passed offer number is valid (has to be unique)
*
* @param {String} pOfferNumber offer number to check
*
* @return {boolean} passed number is valid
*/
this.validateOfferNumber = function(pOfferNumber)
{
return NumberSequencingUtils.validateUniqueNumber(pOfferNumber, "OFFERCODE", "OFFER");
}
/**
* Checks if the passed offer number is valid (has to be unique)
*
* @param {String} offerNumber offer number to check
*
* @return {boolean} passed number is valid
*/
OfferUtils.validateOfferNumber = function(offerNumber)
{
return NumberSequencingUtils.validateUniqueNumber(offerNumber, "OFFERCODE", "OFFER");
}
this.getOfferNumberValidationFailString = function()
{
return translate.text("The offer number already exists!");
}
OfferUtils.getOfferNumberValidationFailString = function()
{
return translate.text("The offer number already exists!");
}
this.getOfferNetAndVAT = function(pOfferId, pOfferitemIdsToDel)
OfferUtils.getOfferNetAndVAT = function(offerId, offeritemIdsToDel)
{
// TODO: Bessere Möglichkeit als per SQL die zugehörigen Posten aus der DB zu holen?
var sum = 0;
var vat = 0;
var oiUtils = new OfferItemUtils(offerId);
var condition = "where OFFER_ID = '" + offerId + "'";
if(offeritemIdsToDel != undefined)
condition += " and OFFERITEMID not in ('" + offeritemIdsToDel.join("','") + "')";
var offerItems = db.table("select QUANTITY, PRICE, DISCOUNT, VAT, OPTIONAL "
+ "from OFFERITEM " + condition);
for(var i = 0; i < offerItems.length; i++)
{
//TODO: Bessere Möglichkeit als per SQL die zugehörigen Posten aus der DB zu holen?
var sum = 0;
var vat = 0;
var oiUtils = new OfferItemUtils(pOfferId);
var condition = "where OFFER_ID = '" + pOfferId + "'";
if(pOfferitemIdsToDel != undefined)
condition += " and OFFERITEMID not in ('" + pOfferitemIdsToDel.join("','") + "')";
var offerItems = db.table("select QUANTITY, PRICE, DISCOUNT, VAT, OPTIONAL "
+ "from OFFERITEM " + condition);
for(var i = 0; i < offerItems.length; i++)
{
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]);
}
return [sum, vat];
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]);
}
return [sum, vat];
}
this.isEditable = function(pStatus)
{
//TODO: Administrator darf immer ändern, warten auf neue Berechtigungslogik?
//Offer should be editable if offer state not equals "Sent", "Won" or "Lost"
return pStatus != "2" && pStatus != "3" && pStatus != "4";
}
OfferUtils.isEditable = function(status)
{
// TODO: Administrator darf immer ändern, warten auf neue Berechtigungslogik?
// Offer should be editable if offer state not equals "Sent", "Won" or "Lost"
return status != "2" && status != "3" && status != "4";
}
/**OfferItemUtils
*
* Instance class that provides methods for dealing with offer / order items.
/******************************************************************************/
/**
* Provides methods for dealing with offer / order items.
* Inherits methods from abstract class ItemUtils.
* For documentation, see class ItemUtils.
*
******************************************************************************/
function OfferItemUtils(pOfferId) //constructor
*
* @class
*/
function OfferItemUtils(pOfferId)
{
// extends ItemUtils
ItemUtils.apply(this, [pOfferId]);
OfferItemUtils.prototype = Object.create(ItemUtils.prototype);
OfferItemUtils.prototype.constructor = OfferItemUtils;
......@@ -165,19 +170,14 @@ OfferItemUtils.prototype.reOrgItems = function()
ItemUtils.prototype.reOrgItems.apply(this, ["OFFERITEM"]);
}
/*
* OfferItemUtils **************************************************************
*/
/******************************************************************************/
/**ItemUtils
*
/**
* @abstract
*
* Abstract class that provides methods for dealing with offer / order items.
* Do not instantiate!
* Create a subclass like OfferItemUtils above to use methods of this class.
*
*******************************************************************************
*/
function ItemUtils(pOfferOrderId)
{
......@@ -186,8 +186,8 @@ function ItemUtils(pOfferOrderId)
this.offerOrderId = pOfferOrderId;
this.ItemTree = undefined;//object for dealing with hierarchical structure of Items, item position and item order
this.ItemIds = undefined;//contains all ItemIDs to save the order
this.ItemTree = undefined; // object for dealing with hierarchical structure of Items, item position and item order
this.ItemIds = undefined; // contains all ItemIDs to save the order
this._getItemTreeNodeObject = function(pAssignedTo, pPos, pItemSort)
{
......@@ -200,107 +200,107 @@ function ItemUtils(pOfferOrderId)
}
/**
*Adds a node to an ItemTree Object. <br>
*If no ItemTree Object is passed, the class variable this.ItemTree will be used.
* Adds a node to an ItemTree Object. <br>
* If no ItemTree Object is passed, the class variable this.ItemTree will be used.
*
*@param {String} pItemId req UID of item
*@param {String} pAssignedTo opt Parent UID of item
*@param {Object} pTree opt ItemTree Object to append
*@param {[]} pIds opt pIds Array for all ItemIDs to save order
* @param {String} itemId req UID of item
* @param {String} assignedTo opt Parent UID of item
* @param {Object} tree opt ItemTree Object to append
* @param {[]} ids opt ids Array for all ItemIDs to save order
*
*/
this._appendNode = function(pItemId, pAssignedTo, pTree, pIds)
this._appendNode = function(itemId, assignedTo, tree, ids)
{
if(pTree == undefined)
pTree = this.ItemTree;
if(pIds == undefined)
pIds = this.ItemIds;
if(tree == undefined)
tree = this.ItemTree;
if(ids == undefined)
ids = this.ItemIds;
pTree[pItemId] = this._getItemTreeNodeObject(pAssignedTo
, this.getNextItemPosition(pAssignedTo, pTree, pIds)
, this.getNextItemSort(pIds));
pIds.push(pItemId);
tree[itemId] = this._getItemTreeNodeObject(assignedTo
, this.getNextItemPosition(assignedTo, tree, ids)
, this.getNextItemSort(ids));
ids.push(itemId);
if(pAssignedTo != "")
if(assignedTo != "")
{
pTree[pAssignedTo].ids.push(pItemId);
tree[assignedTo].ids.push(itemId);
}
}
/**
*Deletes a node from an ItemTree Object within its subnodes. <br>
*If no ItemTree Object is passed, the class variable this.ItemTree will be used.
* Deletes a node from an ItemTree Object within its subnodes. <br>
* If no ItemTree Object is passed, the class variable this.ItemTree will be used.
*
*@param {String} pItemId req UID of item
*@param {Object} pTree opt ItemTree Object to delete from
*@param {[]} pIds opt pIds Array for all ItemIDs to save order
* @param {String} itemId req UID of item
* @param {Object} tree opt ItemTree Object to delete from
* @param {[]} ids opt ids Array for all ItemIDs to save order
*
*/
this._deleteNodes = function(pItemId, pTree, pIds)
this._deleteNodes = function(itemId, tree, ids)
{
if(pTree == undefined)
pTree = this.ItemTree;
if(pIds == undefined)
pIds = this.ItemIds;
if(tree == undefined)
tree = this.ItemTree;
if(ids == undefined)
ids = this.ItemIds;
__delete(pTree[pItemId]);
__delete(tree[itemId]);
_deleteNode(pItemId);
_deleteNode(itemId);
function __delete(pNode)
{
for(var i = 0; i < pNode.ids.length; i++)
{
__delete(pTree[pNode.ids[i]]);
__delete(tree[pNode.ids[i]]);
_deleteNode(pNode.ids[i]);
}
}
function _deleteNode(pItemId)
function _deleteNode(itemId)
{
//delete Object property
delete pTree[pItemId];
delete tree[itemId];
//delete id in global Array "ItemIds"
var idx = pIds.indexOf(pItemId);
var idx = ids.indexOf(itemId);
if(idx > -1)
pIds.splice(idx, 1);
ids.splice(idx, 1);
//delete id in Array from property "ids" of Tree
for(var oiid in pTree)
for(var oiid in tree)
{
idx = pTree[oiid].ids.indexOf(pItemId);
idx = tree[oiid].ids.indexOf(itemId);
if(idx > -1)
pTree[oiid].ids.splice(idx, 1);
tree[oiid].ids.splice(idx, 1);
}
}
}
/**
*Compares Positions & Sort of the passed ItemTree Object with the class variable this.ItemTree <br>
*and updates differences in database.
* Compares Positions & Sort of the passed ItemTree Object with the class variable this.ItemTree <br>
* and updates differences in database.
*
*
*@param {String} pTable req DB-Table of Items
*@param {Object} pCompTree req ItemTree Object to compare with this.ItemTree
* @param {String} table req DB-Table of Items
* @param {Object} compTree req ItemTree Object to compare with this.ItemTree
*
*/
this._updateReOrgItemChangesInDB = function(pTable, pCompTree)
this._updateReOrgItemChangesInDB = function(table, compTree)
{
var statements = [];
var cols = ["ITEMSORT", "ITEMPOSITION"];
var colTypes = db.getColumnTypes(pTable, cols);
var colTypes = db.getColumnTypes(table, cols);
var oiTree = this.ItemTree;
for(var oiid in pCompTree)
for(var oiid in compTree)
{
if(oiTree[oiid] != undefined)
{
//check if itemsort/pos has been changed
if(oiTree[oiid].itemsort != pCompTree[oiid].itemsort || oiTree[oiid].pos != pCompTree[oiid].pos)
if(oiTree[oiid].itemsort != compTree[oiid].itemsort || oiTree[oiid].pos != compTree[oiid].pos)
{
var vals = [pCompTree[oiid].itemsort, pCompTree[oiid].pos];
statements.push([pTable, cols, colTypes, vals, pTable + "ID = '" + oiid + "'"]);
var vals = [compTree[oiid].itemsort, compTree[oiid].pos];
statements.push([table, cols, colTypes, vals, table + "ID = '" + oiid + "'"]);
}
}
}
......@@ -311,24 +311,24 @@ function ItemUtils(pOfferOrderId)
}
/**
*Initializes ItemTree Object for class variable this.ItemTree <br>
*with items already stored in database.
* Initializes ItemTree Object for class variable this.ItemTree <br>
* with items already stored in database.
*
*@abstract
* @abstract
*
*@param {String} pTable req DB-Table of Items
*@param {String} pForeignKeyColumn req DB-Column that contains foreign key Items belong to
* @param {String} table req DB-Table of Items
* @param {String} foreignKeyColumn req DB-Column that contains foreign key Items belong to
*
*/
ItemUtils.prototype.initItemTree = function(pTable, pForeignKeyColumn)
ItemUtils.prototype.initItemTree = function(table, foreignKeyColumn)
{
if(this.ItemTree == undefined)
{
this.ItemTree = {};
this.ItemIds = [];
var data = db.table("select " + pTable + "ID, ASSIGNEDTO, ITEMPOSITION, ITEMSORT from " + pTable
+ " where " + pForeignKeyColumn + " = '" + this.offerOrderId + "' order by ITEMSORT");
var data = db.table("select " + table + "ID, ASSIGNEDTO, ITEMPOSITION, ITEMSORT from " + table
+ " where " + foreignKeyColumn + " = '" + this.offerOrderId + "' order by ITEMSORT");
for(var i = 0; i < data.length; i++)
{
......@@ -344,59 +344,59 @@ ItemUtils.prototype.initItemTree = function(pTable, pForeignKeyColumn)
}
}
ItemUtils.prototype.getItemSum = function(pQuantity, pPrice, pDiscount, pOptional)
ItemUtils.prototype.getItemSum = function(quantity, price, discount, optional)
{
pQuantity = pQuantity || 0;
pPrice = pPrice || 0;
pDiscount = pDiscount || 0;
quantity = quantity || 0;
price = price || 0;
discount = discount || 0;
return Number(pOptional) * parseFloat(pQuantity) * parseFloat(pPrice) * ((100 - parseFloat(pDiscount)) / 100);
return Number(optional) * parseFloat(quantity) * parseFloat(price) * ((100 - parseFloat(discount)) / 100);
}
ItemUtils.prototype.getItemVAT = function(pQuantity, pPrice, pDiscount, pVAT, pOptional)
ItemUtils.prototype.getItemVAT = function(quantity, price, discount, vat, optional)
{
pQuantity = pQuantity || 0;
pPrice = pPrice || 0;
pDiscount = pDiscount || 0;
pVAT = pVAT || 0;
quantity = quantity || 0;
price = price || 0;
discount = discount || 0;
vat = vat || 0;
return Number(pOptional) * parseFloat(pQuantity) * parseFloat(pPrice) * ((100 - parseFloat(pDiscount)) / 100) * (parseFloat(pVAT) / 100);
return Number(optional) * parseFloat(quantity) * parseFloat(price) * ((100 - parseFloat(discount)) / 100) * (parseFloat(vat) / 100);
}
ItemUtils.prototype.roundPrice = function(pPrice)
ItemUtils.prototype.roundPrice = function(price)
{
return eMath.roundDec(pPrice, 2, eMath.ROUND_HALF_UP);
return eMath.roundDec(price, 2, eMath.ROUND_HALF_UP);
}
/**
* Inserts parts list of the passed product into database.
*
* @abstract
*
* @param {[]} pColumns req Array of Item DB Columns
* @param {String} pTable req DB Table of Items
* @param {String} pProductId req UID of root product (selected product)
* @param {String} pAssignedTo opt UID of parent item
* @param {String} pCurrency opt currency for price list to use
* @param {String} pRelationId opt relationid for price list to use (custom price list)
*
* @return {[]} Array of inserted ItemIDs
*/
ItemUtils.prototype.insertPartsList = function(pColumns, pTable, pProductId, pAssignedTo, pCurrency, pRelationId)
* Inserts parts list of the passed product into database.
*
* @abstract
*
* @param {[]} columns req Array of Item DB Columns
* @param {String} table req DB Table of Items
* @param {String} productId req UID of root product (selected product)
* @param {String} assignedTo opt UID of parent item
* @param {String} currency opt currency for price list to use
* @param {String} relationId opt relationid for price list to use (custom price list)
*
* @return {[]} Array of inserted ItemIDs
*/
ItemUtils.prototype.insertPartsList = function(columns, table, productId, assignedTo, currency, relationId)
{
var insertedItemIds = [];
//save address for this here to call methods in recursive sub function __itemInsertStatement
var self = this;
if(pAssignedTo == undefined)
pAssignedTo = "";
if(pCurrency == undefined)
pCurrency = "";
if(pRelationId == undefined)
pRelationId = "";
if(assignedTo == undefined)
assignedTo = "";
if(currency == undefined)
currency = "";
if(relationId == undefined)
relationId = "";
var rootProdId = pProductId;
var rootProdId = productId;
if(rootProdId != "")
{
var pUtils = new ProductUtils();
......@@ -405,9 +405,9 @@ ItemUtils.prototype.insertPartsList = function(pColumns, pTable, pProductId, pAs
var partsList = p2pUtils.getPartsListObject();
var statements = [];
var colTypes = db.getColumnTypes(pTable, pColumns);
var colTypes = db.getColumnTypes(table, columns);
__itemInsertStatement(partsList.root, pAssignedTo, pCurrency, pRelationId);
__itemInsertStatement(partsList.root, assignedTo, currency, relationId);
if(statements.length > 0)
db.inserts(statements);
......@@ -416,19 +416,19 @@ ItemUtils.prototype.insertPartsList = function(pColumns, pTable, pProductId, pAs
return insertedItemIds;
//recursive function for building item insert statements
function __itemInsertStatement(pPartsListObj, pAssignedTo, pCurrency, pRelationId)
function __itemInsertStatement(partsListObj, assignedTo, currency, relationId)
{
for(var i = 0; i < pPartsListObj.ids.length; i++)
for(var i = 0; i < partsListObj.ids.length; i++)
{
var newid = util.getNewUUID();
self._appendNode(newid, pAssignedTo);
self._appendNode(newid, assignedTo);
var pos = self.ItemTree[newid].pos;
var itemsort = self.ItemTree[newid].itemsort;
var p2pid = pPartsListObj.ids[i];
var p2pid = partsListObj.ids[i];
var P2pObject = partsList[p2pid];
var prodid = partsList[p2pid].sourceid;
var ProductDetails = pUtils.getProductDetails(prodid, { currency: pCurrency, quantity: P2pObject.quantity, relationId: pRelationId } )
var ProductDetails = pUtils.getProductDetails(prodid, { currency: currency, quantity: P2pObject.quantity, relationId: relationId } )
var price = "";
var vat = "";
......@@ -442,7 +442,7 @@ ItemUtils.prototype.insertPartsList = function(pColumns, pTable, pProductId, pAs
, self.offerOrderId
, prodid
, ProductDetails.groupCode
, pAssignedTo
, assignedTo
, ProductDetails.productName
, ProductDetails.unit
, price
......@@ -454,7 +454,7 @@ ItemUtils.prototype.insertPartsList = function(pColumns, pTable, pProductId, pAs
, datetime.date()
, vars.get("$sys.user")];
statements.push([pTable, pColumns, colTypes, vals]);
statements.push([table, columns, colTypes, vals]);
insertedItemIds.push(newid);
__itemInsertStatement(partsList[p2pid], newid);
......@@ -463,16 +463,16 @@ ItemUtils.prototype.insertPartsList = function(pColumns, pTable, pProductId, pAs
}
/**
* Deletes parts list of the passed item from database.
*
* @abstract
*
* @param {String} pItemId req UID of item that will be deleted
* @param {String} pTable req DB Table of Items
*
* @return {[]} Array of deleted ItemIDs
*/
ItemUtils.prototype.deletePartsList = function(pItemId, pTable)
* Deletes parts list of the passed item from database.
*
* @abstract
*
* @param {String} itemId req UID of item that will be deleted
* @param {String} table req DB Table of Items
*
* @return {[]} Array of deleted ItemIDs
*/
ItemUtils.prototype.deletePartsList = function(itemId, table)
{
var deletedItemIds = [];
......@@ -481,24 +481,24 @@ ItemUtils.prototype.deletePartsList = function(pItemId, pTable)
var statements = [];
__itemDeleteStatement(pItemId);
__itemDeleteStatement(itemId);
if(statements.length > 0)
db.deletes(statements);
self._deleteNodes(pItemId);
self._deleteNodes(itemId);
return deletedItemIds;
//recursive function for building item delete statements
function __itemDeleteStatement(pItemId)
function __itemDeleteStatement(itemId)
{
var itemsToDelete = self.ItemTree[pItemId].ids;
var itemsToDelete = self.ItemTree[itemId].ids;
for(var i = 0; i < itemsToDelete.length; i++)
{
//unshift due to foreign key constraints (Delete hierarchically starting at the bottom)
statements.unshift([pTable, pTable + "ID = '" + itemsToDelete[i] + "'"]);
statements.unshift([table, table + "ID = '" + itemsToDelete[i] + "'"]);
deletedItemIds.push(itemsToDelete[i]);
__itemDeleteStatement(itemsToDelete[i]);
}
......@@ -506,77 +506,77 @@ ItemUtils.prototype.deletePartsList = function(pItemId, pTable)
}
/**
* Delivers next item sort value by passed ItemID-Array. <br>
* If no parameter is passed the class variable this.ItemIds will be used.
*
* @abstract
*
* @param {[]} pIds opt Array for all ItemIDs to save order
*
* @return {String} Next item sort value
*/
ItemUtils.prototype.getNextItemSort = function(pIds)
* Delivers next item sort value by passed ItemID-Array. <br>
* If no parameter is passed the class variable this.ItemIds will be used.
*
* @abstract
*
* @param {[]} ids opt Array for all ItemIDs to save order
*
* @return {String} Next item sort value
*/
ItemUtils.prototype.getNextItemSort = function(ids)
{
if(pIds == undefined)
pIds = this.ItemIds;
if(ids == undefined)
ids = this.ItemIds;
return (pIds.length + 1).toString();
return (ids.length + 1).toString();
}
/**
* Delivers next item position value by passed ItemTree Object. <br>
* If no parameter is passed the class variable this.ItemTree will be used. <br>
* <br>
* Item position is generated according to the following pattern: <br>
* 1 (Parent ItemID (AssignedTo) is empty) <br>
* 1.1 (Parent ItemID (AssignedTo) = ItemID of Pos 1) <br>
* 1.2 <br>
* 1.2.1 (Parent ItemID (AssignedTo) = ItemID of Pos 1.2) <br>
* ... <br>
* 2 <br>
* 2.1 <br>
* 2.1.1 <br>
* ... <br>
* 3 <br>
* ... <br>
*
* @abstract
*
* @param {String} pAssignedTo Parent ItemID
* @param {Object} pTree opt ItemTree Object to get next position from
* @param {[]} pIds opt Array for all ItemIDs to save order
*
* @return {String} Next item position value
*/
ItemUtils.prototype.getNextItemPosition = function(pAssignedTo, pTree, pIds)
* Delivers next item position value by passed ItemTree Object. <br>
* If no parameter is passed the class variable this.ItemTree will be used. <br>
* <br>
* Item position is generated according to the following pattern: <br>
* 1 (Parent ItemID (AssignedTo) is empty) <br>
* 1.1 (Parent ItemID (AssignedTo) = ItemID of Pos 1) <br>
* 1.2 <br>
* 1.2.1 (Parent ItemID (AssignedTo) = ItemID of Pos 1.2) <br>
* ... <br>
* 2 <br>
* 2.1 <br>
* 2.1.1 <br>
* ... <br>
* 3 <br>
* ... <br>
*
* @abstract
*
* @param {String} assignedTo Parent ItemID
* @param {Object} tree opt ItemTree Object to get next position from
* @param {[]} ids opt Array for all ItemIDs to save order
*
* @return {String} Next item position value
*/
ItemUtils.prototype.getNextItemPosition = function(assignedTo, tree, ids)
{
if(pAssignedTo == undefined)
pAssignedTo = "";
if(pTree == undefined)
pTree = this.ItemTree;
if(pIds == undefined)
pIds = this.ItemIds;
if(assignedTo == undefined)
assignedTo = "";
if(tree == undefined)
tree = this.ItemTree;
if(ids == undefined)
ids = this.ItemIds;
var maxPos = ["0"];
if(pAssignedTo != "")
if(assignedTo != "")
{
if(pTree[pAssignedTo].ids.length < 1) //first item in this level
if(tree[assignedTo].ids.length < 1) //first item in this level
{
maxPos = pTree[pAssignedTo].pos.split(".");
maxPos = tree[assignedTo].pos.split(".");
maxPos = maxPos.concat(["0"]); //next level pos
}
else
{
var childIds = pTree[pAssignedTo].ids;
maxPos = pTree[childIds[childIds.length-1]].pos.split(".");
var childIds = tree[assignedTo].ids;
maxPos = tree[childIds[childIds.length-1]].pos.split(".");
}
}
else
{
if(pIds.length > 0)
if(ids.length > 0)
{
maxPos[0] = this.ItemTree[pIds[pIds.length-1]].pos;
maxPos[0] = this.ItemTree[ids[ids.length-1]].pos;
}
}
......@@ -586,16 +586,16 @@ ItemUtils.prototype.getNextItemPosition = function(pAssignedTo, pTree, pIds)
}
/**
* Reorganizes hierarchical structure of Items, item position and item order. <br>
* Changes will be updated in database. <br>
* This function has to be executed after items have been added or deleted. <br>
*
* @abstract
*
* @param {String} pTable req DB Table of Items
*
*/
ItemUtils.prototype.reOrgItems = function(pTable)
* Reorganizes hierarchical structure of Items, item position and item order. <br>
* Changes will be updated in database. <br>
* This function has to be executed after items have been added or deleted. <br>
*
* @abstract
*
* @param {String} table req DB Table of Items
*
*/
ItemUtils.prototype.reOrgItems = function(table)
{
//save address for this here to get methods in recursive sub function __reorg
var self = this;
......@@ -605,7 +605,7 @@ ItemUtils.prototype.reOrgItems = function(pTable)
__reorg(self.ItemIds, "");
self._updateReOrgItemChangesInDB(pTable, newTree);
self._updateReOrgItemChangesInDB(table, newTree);
//recursive function to build new ItemTree Structure
function __reorg(pIds, pAssignedTo)
......@@ -621,7 +621,4 @@ ItemUtils.prototype.reOrgItems = function(pTable)
}
}
}
}
/*
* ItemUtils *******************************************************************
*/
\ No newline at end of file
}
\ No newline at end of file
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