calcNumericMultiple.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /****************************************************************
  2. ** Licensed Materials - Property of IBM
  3. **
  4. ** BI and PM: qs
  5. **
  6. ** (C) Copyright IBM Corp. 2001, 2015
  7. **
  8. ** US Government Users Restricted Rights - Use, duplication or
  9. ** disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  10. *****************************************************************/
  11. // Copyright (C) 2008 Cognos ULC, an IBM Company. All Rights Reserved.
  12. // Cognos and the Cognos logo are trademarks of Cognos ULC (formerly Cognos Incorporated) in the United States and/or other countries. IBM and the IBM logo are trademarks of International Business Machines Corporation in the United States, or other countries, or both. Other company, product, or service names may be trademarks or service marks of others.
  13. function execute()
  14. {
  15. var calc = document.f.calcList.options[document.f.calcList.selectedIndex].value;
  16. var before_col_id = cf.dlgGlobalGetParm('xxInsBeforeColid');
  17. var regularAgg = cf.dlgGlobalGetParm('xxRegularAgg');
  18. var detailAgg = cf.dlgGlobalGetParm('xxDetailAgg');
  19. var calcExpr = "";
  20. var calcOp = "none";
  21. var ii;
  22. var selCount = expression.length;
  23. var constantVal;
  24. var textBoxnumberDecs = -1;
  25. var cType = -1;
  26. var cUsage = -1;
  27. if (calcType == 'interval')
  28. {
  29. if (!document.f.inputValueRadio || (document.f.inputValueRadio[0].checked || (document.f.inputValueRadio[1].checked && substVarValue == null)))
  30. {
  31. if (intervalControlintervalFrom.isValid())
  32. constantVal = intervalControlintervalFrom.sGetValue();
  33. else
  34. return;
  35. }
  36. else
  37. constantVal = substVarValue;
  38. }
  39. else
  40. {
  41. if (document.getElementById("textBoxNumeric").style.display != "none")
  42. {
  43. if (textBoxnumberValue.isValid())
  44. {
  45. constantVal = textBoxnumberValue.sGetValue();
  46. if (document.f.numberCheck.checked)
  47. textBoxnumberDecs = textBoxnumberValue.getDecimalSize();
  48. }
  49. else
  50. return;
  51. }
  52. else if (document.getElementById("textBoxString").style.display != "none")
  53. {
  54. constantVal = substVarValue;
  55. }
  56. constantVal = constantVal.replace("\.", goDialogManager.getMiniQueryManager().getDecimalSeparator());
  57. }
  58. if (calc != "*" && constantVal == "")
  59. constantVal = 0;
  60. if (selCount > 1 || document.f.numberCheck.checked)
  61. {
  62. detailAgg = "calculated";
  63. switch (calc) {
  64. case "+":
  65. calcExpr = "(^^^0^^^)";
  66. for (ii=1; ii < selCount; ii++)
  67. {
  68. calcExpr += " + (^^^" + ii + "^^^)";
  69. }
  70. if (selectedColumnSupportsTotal())
  71. {
  72. regularAgg = setRegAgg("total");
  73. }
  74. else
  75. {
  76. regularAgg = setRegAgg("automatic");
  77. }
  78. if (document.f.numberCheck.checked)
  79. {
  80. regularAgg = setRegAgg(regularAgg);
  81. calcExpr += " + (" + constantVal + ")";
  82. }
  83. if (calcType == 'interval')
  84. calcOp = "sumInterval";
  85. else
  86. calcOp = "sum";
  87. break;
  88. case "*":
  89. calcExpr = "(^^^0^^^)";
  90. if (constantVal == "")
  91. {
  92. constantVal = 1;
  93. }
  94. for (ii=1; ii < selCount; ii++)
  95. {
  96. calcExpr += " * (^^^" + ii + "^^^)";
  97. }
  98. if (selectedColumnSupportsTotal())
  99. {
  100. regularAgg = setRegAgg("total");
  101. }
  102. else
  103. {
  104. regularAgg = setRegAgg("automatic");
  105. }
  106. if (document.f.numberCheck.checked)
  107. {
  108. regularAgg = setRegAgg(regularAgg);
  109. calcExpr += " * (" + constantVal + ")";
  110. }
  111. calcOp = "product";
  112. break;
  113. case "maximum":
  114. calcExpr = minmax(">", constantVal);
  115. if (document.f.numberCheck.checked)
  116. regularAgg = setRegAgg(regularAgg);
  117. calcOp = "maximum";
  118. regularAgg = setRegAgg("calculated");
  119. break;
  120. case "minimum":
  121. calcExpr = minmax("<", constantVal);
  122. if (document.f.numberCheck.checked)
  123. regularAgg = setRegAgg(regularAgg);
  124. calcOp = "minimum";
  125. regularAgg = setRegAgg("calculated");
  126. break;
  127. case "average":
  128. calcExpr = "(^^^0^^^)";
  129. for (ii=1; ii < selCount; ii++)
  130. calcExpr += " + (^^^" + ii + "^^^)";
  131. if (document.f.numberCheck.checked)
  132. {
  133. regularAgg = setRegAgg(regularAgg);
  134. calcExpr += " + (" + constantVal + ")";
  135. ++selCount;
  136. }
  137. calcExpr = "(" + calcExpr + ")/" + selCount;
  138. calcOp = "average";
  139. regularAgg = setRegAgg("calculated");
  140. break;
  141. default:
  142. break;
  143. }
  144. }
  145. if (calcExpr != "")
  146. {
  147. var calculationExpression = calcExpr;
  148. var summarizationExpression = calcExpr;
  149. for (var counter = 0; counter < selCount; counter++)
  150. {
  151. calculationExpression = stringReplace (calculationExpression, "\\^\\^\\^" + counter + "\\^\\^\\^", expression[counter]);
  152. summarizationExpression = stringReplace (summarizationExpression, "\\^\\^\\^" + counter + "\\^\\^\\^", calculatedExpression[counter]);
  153. }
  154. var calcName = getCalcName();
  155. if (cf.dlgGlobalGetParm('xxIsMeasureOutput') == "false")
  156. {
  157. if (calcType == 'interval')
  158. cType = 53;
  159. else
  160. cType = 21;
  161. cUsage = 2;
  162. detailAgg = "none";
  163. regularAgg = "none";
  164. }
  165. getConfigFrame().addCalcColumn(before_col_id, calculationExpression, summarizationExpression, calcName, "none", calcOp, "none", textBoxnumberDecs, cType, cUsage, regularAgg, -1, detailAgg, calcParentIds);
  166. }
  167. };
  168. function setRegAgg(regAgg)
  169. {
  170. var selCount = detailAggs.length;
  171. var detailAgg = "";
  172. var isFirst = true;
  173. if (detailAggs[0] != "total")
  174. {
  175. return regAgg;
  176. }
  177. for (var ii = 0; ii < selCount; ii++)
  178. {
  179. if (detailAggs[0] != detailAggs[ii])
  180. return regAgg;
  181. }
  182. return "total";
  183. };
  184. function selectedColumnSupportsTotal()
  185. {
  186. var cf = (typeof getConfigFrame == "function" ? getConfigFrame() : this);
  187. if (typeof cf === "undefined" ||
  188. typeof selectionIsNumeric === "undefined"
  189. )
  190. {
  191. return true;
  192. }
  193. var bIsOLAP = (! cf.checkCalcFunctionAgainstDB("FLEXIBLE_FILTERS"));
  194. if (bIsOLAP && selectionIsNumeric() && ! selectionIsMeasure())
  195. {
  196. return false;
  197. }
  198. return true;
  199. };