Você está na página 1de 5

function ReadAndersenIQData(xml) {

// Remove <CIP> and <Accessory> data. Its not needed and causes problems wit
h extracting data.
xml = RemoveAllInstancesOfTags(xml, "<CIP>", "</CIP>");
xml = RemoveAllInstancesOfTags(xml, "<Accessory", "</Accessory>");
var incrementalItemNumber = 1;
// Get all unit xml
var xmlCompositeUnits = GetAllPieces(xml, "<Composite>", "</Composite>");
xml = RemoveAllInstancesOfTags(xml, "<Composite>", "</Composite>");
var compositeUnits = [];
for (var i = 0; i < xmlCompositeUnits.length; i++) {
var unit = xmlCompositeUnits[i];
var unitPrice = "", quantity = "tmp", width = "", height = "", color = "
", unitSize = "", isWindow = "", shape = "", prodDescArray = [];
var allAttributes = GetAllPieces(unit.str, "<Attribute", "</Attribute>")
;
for (var k = 0; k < allAttributes.length; k++) {
var attrStr = allAttributes[k].str;
if (attrStr.indexOf("PRODTYPE") >= 0 || attrStr.indexOf("PRODSTYLE")
>= 0 || attrStr.indexOf("PRODSHAPE") >= 0) {
prodDescArray.push(GetTextBetweenTags(attrStr, ">", "<"));
}
}
var tmpStr = RemoveAllInstancesOfTags(unit.str, "<Group>", "</Group>");
tmpStr = RemoveAllInstancesOfTags(unit.str, "<Unit>", "</Unit>");
var compositeAttributes = GetAllPieces(tmpStr, "<Attribute", "</Attribut
e>");
for (var k = 0; k < compositeAttributes.length - 1; k++) {
var attrStr = compositeAttributes[k].str;
if (attrStr.indexOf("Order_Quantity") >= 0 || attrStr.indexOf("ORDER
_QUANTITY") >= 0) {
if (isNaN(quantity)) {
quantity = parseInt(GetTextBetweenTags(attrStr, ">", "<"));
}
}
if (attrStr.indexOf("RO_HIGH") >= 0) {
var tmpHeight = parseFloat(GetTextBetweenTags(attrStr, ">", "<")
);
if (height === "") {
height = GetTextBetweenTags(attrStr, ">", "<");
} else if (tmpHeight > height) {
height = GetTextBetweenTags(attrStr, ">", "<");
}
}
if (attrStr.indexOf("RO_WIDE") >= 0) {
var tmpWidth = parseFloat(GetTextBetweenTags(attrStr, ">", "<"))
;
if (width === "") {
width = GetTextBetweenTags(attrStr, ">", "<");
} else if (tmpHeight > width) {
width = GetTextBetweenTags(attrStr, ">", "<");
}
}

if (attrStr.indexOf("FS_WIDE") >= 0) {
var tmpWidth = parseFloat(GetTextBetweenTags(attrStr, ">", "<"))
;
if (width
width
} else if
width
}

=== "") {
= GetTextBetweenTags(attrStr, ">", "<");
(tmpHeight > width) {
= GetTextBetweenTags(attrStr, ">", "<");

}
if (attrStr.indexOf("FS_HIGH") >= 0) {
var tmpHeight = parseFloat(GetTextBetweenTags(attrStr, ">", "<")
);
if (height === "") {
height = GetTextBetweenTags(attrStr, ">", "<");
} else if (tmpHeight > height) {
height = GetTextBetweenTags(attrStr, ">", "<");
}
}
if (attrStr.indexOf('"UNIT_CODE"') >= 0) {
if (unitSize == "") {
unitSize = GetTextBetweenTags(attrStr, ">", "<");
}
}
if (attrStr.indexOf("PRODCAT") >= 0) {
var productCategory = GetTextBetweenTags(attrStr, ">", "<").toUp
perCase();
if (productCategory.indexOf("WINDOW") !== -1) {
isWindow = true;
} else {
isWindow = false;
}
}
if (attrStr.indexOf("EXTR_COLOR") >= 0) {
color = GetTextBetweenTags(attrStr, ">", "<");
}
if (attrStr.indexOf("Total_Price_in_USD") >= 0) {
unitPrice = parseFloat(GetTextBetweenTags(attrStr, ">", "<"));
}
}
for (var k = 0; k < quantity; k++) {
var tmpUnit = {};
tmpUnit.UnitSize = unitSize;
tmpUnit.ProductLineCode = "";
tmpUnit.ItemNumber = incrementalItemNumber;
incrementalItemNumber++;
tmpUnit.Width = ConvertFracToDec(width);
tmpUnit.Height = ConvertFracToDec(height);
tmpUnit.IsWindow = isWindow;
tmpUnit.Shape = DescriptionToShape(prodDescArray);;
tmpUnit.Color = color;
tmpUnit.UnitPrice = parseFloat(unitPrice);
compositeUnits.push(tmpUnit);
}
unitPrice = "", quantity = "tmp", width = "", height = "", color = "", u
nitSize = "", isWindow = "", shape = "", prodDescArray = [];
}

var xmlUnits = GetAllPieces(xml, "<Unit>", "</Unit>");


// For each unit, get all attribute xml and associate it with that unit xml.
for (var i = 0; i < xmlUnits.length; i++) {
// Get all the attritbutes for the current unit
xmlUnits[i].xmlAttributes = GetAllPieces(xmlUnits[i].str, "<Attribute",
"</Attribute>");
// Remove the last attribute, in some files it corrupts the data.
xmlUnits[i].xmlAttributes.splice(xmlUnits[i].xmlAttributes.length - 1, 1
);
}
var resultUnits = [];
for (var i = 0; i < xmlUnits.length; i++) {
var tmpAttributes = xmlUnits[i].xmlAttributes;
var tmpUnit = {};
tmpUnit.Width = "";
tmpUnit.Height = "";
tmpUnit.ProductLineCode = "";
var tmpProdDescArray = [];
var quantity = 0;
for (var k = 0; k < tmpAttributes.length; k++) {
if (tmpAttributes[k].str.indexOf("Order_Quantity") >= 0 || tmpAttrib
utes[k].str.indexOf("ORDER_QUANTITY") >= 0) {
quantity = parseInt(GetTextBetweenTags(tmpAttributes[k].str, ">"
, "<"));
}
if (tmpAttributes[k].str.indexOf("RO_HIGH") >= 0) {
var tmpHeight = parseFloat(GetTextBetweenTags(tmpAttributes[k].s
tr, ">", "<"));
if (tmpUnit.Height === "") {
tmpUnit.Height = tmpHeight;
} else if (tmpHeight > tmpUnit.Height){
tmpUnit.Height = tmpHeight;
}
}
if (tmpAttributes[k].str.indexOf("RO_WIDE") >= 0) {
var tmpWidth = parseFloat(GetTextBetweenTags(tmpAttributes[k].st
r, ">", "<"));
if (tmpUnit.Width === "") {
tmpUnit.Width = tmpWidth;
} else if (tmpHeight > tmpUnit.Width) {
tmpUnit.Width = tmpWidth;
}
}
if (tmpAttributes[k].str.indexOf("FS_WIDE") >= 0) {
var tmpWidth = parseFloat(GetTextBetweenTags(tmpAttributes[k].st
r, ">", "<"));
if (tmpUnit.Width === "") {
tmpUnit.Width = tmpWidth;
} else if (tmpHeight > tmpUnit.Width) {
tmpUnit.Width = tmpWidth;
}
}
if (tmpAttributes[k].str.indexOf("FS_HIGH") >= 0) {
var tmpHeight = parseFloat(GetTextBetweenTags(tmpAttributes[k].s
tr, ">", "<"));

if (tmpUnit.Height === "") {


tmpUnit.Height = tmpHeight;
} else if (tmpHeight > tmpUnit.Height) {
tmpUnit.Height = tmpHeight;
}
}
if (tmpAttributes[k].str.indexOf("UNIT_CODE") >= 0) {
tmpUnit.UnitSize = GetTextBetweenTags(tmpAttributes[k].str, ">",
"<");
}
if (tmpAttributes[k].str.indexOf("PRODCAT") >= 0) {
var productCategory = GetTextBetweenTags(tmpAttributes[k].str, "
>", "<").toUpperCase();
if (productCategory.indexOf("WINDOW") !== -1) {
tmpUnit.IsWindow = true;
} else {
tmpUnit.IsWindow = false;
}
}
if (tmpAttributes[k].str.indexOf("PRODTYPE") >= 0 || tmpAttributes[k
].str.indexOf("PRODSTYLE") >= 0 || tmpAttributes[k].str.indexOf("PRODSHAPE") >=
0) {
tmpProdDescArray.push(GetTextBetweenTags(tmpAttributes[k].str, "
>", "<"));
}
if (tmpAttributes[k].str.indexOf("EXTR_COLOR") >= 0) {
tmpUnit.Color = GetTextBetweenTags(tmpAttributes[k].str, ">", "<
");
}
if (tmpAttributes[k].str.indexOf("Total_Price_in_USD") >= 0) {
tmpUnit.UnitPrice = parseFloat(GetTextBetweenTags(tmpAttributes[
k].str, ">", "<"));
}
}
tmpUnit.Shape = DescriptionToShape(tmpProdDescArray);
for (var j = 0; j < quantity; j++) {
tmpUnit.ItemNumber = incrementalItemNumber;
resultUnits.push(clone(tmpUnit));
incrementalItemNumber++;
}
}
var path = $("#material-file-object").val() || $("#accessory-file-object").v
al();
var fileName = path.substr(path.lastIndexOf("\\") + 1);
fileName = fileName.split('.')[0];
if (fileName === "") {
fileName = "File#" + fileNumber;
fileNumber++;
}
// Check if this property exists. If it does, its a Silverline unit, otherwi
se it is an Andersen unit.
var companyName = (xml.indexOf("PRODSHAPE") >= 0 ? "Silverline" : "Andersen"
);
var result = {};

result.units = compositeUnits.concat(resultUnits);
result.fileName = fileName;
result.companyName = companyName;
return result;
}

Você também pode gostar