// Some useful functions for reports // $Header: /home/appl/Denkh/src/rptgen/RCS/JSFunc.html,v 3.0 2003/06/25 07:12:41 sauge Exp $ //------------------------------------------------------------ // Date related // // d is mm/dd/yy - be sure to format your date varible as such. function WeekDay (d) { var dm = new String(d.substr(0,2) - 1); // Month var dd = d.substr(3,2); // Day var dy = new String("20" + d.substr(6,2)); // Year (Bug after 100 years) // document.writeln(d); // document.writeln(dy); // document.writeln(dm); // document.writeln(dd); var W = new Date(dy, dm, dd); return W.getDay(); } // d is mm/dd/yy - be sure to format your date varible as such. function AbbrWeekDay (d) { var A = new Array("Sun","Mon","Tues","Wed","Thurs","Fri","Sat"); document.writeln( A[WeekDay(d)]); } function HMDay(d) { var T = new date(d); return T.getHours() + ":" + T.getMinutes(); } //------------------------------------------------------------ var rGndTotal = new Array(); function GndTotal (i, v) { if (i > rGndTotal.length) rGndTotal[i] = v; else rGndTotal[i] += v; } // Report the Grand Total named i function RptGndTotal(i) { document.writeln(iGndTotal[i]); } //------------------------------------------------------------ // Counter // Different kinds of counters named by an integer var iCount = new Array(); function Count(i) { if (i > iCount.length) iCount[i] = 1; else iCount[i]++; } // Report the counter value function RptCount(i) { document.writeln(iCount[i]); } var iSigma = new Array(); function Sigma(i, v) { if (i > iCount.length) iSigmaCount[i] = v; else iSigma[i] += v; } // Report the counter value function RptSigma(i) { document.writeln(iSigma[i]); } //------------------------------------------------------------ // Track sub totals in an array with a label // Note how there are three global vars associated with this // Call with the break value to track // // Update: Allow up to five sub-totals per report var LastBreakValue = new Array("","","","",""); var RptLastBreakValue = new Array("","","","",""); var cValue = new Array(5); cValue[0] = new Array(); cValue[1] = new Array(); cValue[2] = new Array(); cValue[3] = new Array(); cValue[4] = new Array(); var cLabel = new Array(5); cLabel[0] = new Array(); cLabel[1] = new Array(); cLabel[2] = new Array(); cLabel[3] = new Array(); cLabel[4] = new Array(); function TrkSubTotal (BreakValue, v, id) { var t; // Here we subtotal the case types in the system. Since we do not know how many might // be in the report, we store the case type in cLabel, and the count of that type in // cValue. Each is an array with // If the case type has changed, then we need to start a new label and value if (BreakValue != LastBreakValue[id]) { // Remember LAST case type for when we change LastBreakValue[id] = BreakValue; // Push a new value into the label cLabel[id].push(BreakValue); // Push in a default count cValue[id].push(v); // document.writeln("Pushed a value" + "
"); } // Otherwise we just pop out the LAST value and add to it 1, and push it back in else { t = cValue[id].pop() + v; cValue[id].push(t); // document.writeln("Added a value" + "
"); } } function RptSubTotal (BreakValue, Column, NColumn, id) { // If the case type has changed, then we need to start a new label and value if (RptLastBreakValue[id] == "") RptLastBreakValue[id] = BreakValue; if (BreakValue != RptLastBreakValue[id] && cValue[id].length > 0) { RptLastBreakValue[id] = BreakValue; document.writeln(""); // Progress users accostomed to 1 to n, not 0 to n in lists for (i = 0; i < NColumn; i++) { if (i == Column) { document.writeln ("" + cValue[id][cValue[id].length - 1] + ""); } else document.writeln(" "); } document.writeln(""); } } function CurSubTotal(id) { if (cValue.length >= 1) document.writeln(cValue[id][cValue[id].length - 1]); else document.writeln(0); } // Summary SubCount function SumSubTotal(id) { document.writeln(""); var j = cLabel[id].length; // We stack it, so it is backwards from how we found it cLabel[id].reverse(); cValue[id].reverse(); // Knock em out! for (i = 0; i < j; i++) { document.writeln(""); document.writeln ('"); document.writeln (""); document.writeln (""); } document.writeln("
' + cLabel[id].pop() + "" + cValue[id].pop() + "
"); } // Debugging stuff function DumpAllSubTotal() { // We stack it, so it is backwards from how we found it // cLabel[id].reverse(); // cValue[id].reverse(); // Knock em out! document.writeln(""); for (i = 0; i < cLabel.length; i++) { // For each subtotal document.writeln(""); j = cLabel[i].length; for (id = 0; id < j; id++) { document.writeln ('"); } for (id = 0; id < j; id++) { document.writeln (""); } document.writeln (""); } document.writeln("
' + cLabel[i][id] + "" + cValue[i][id] + "
"); }