function details($_POST, $errata = "<br>") { # Get vars foreach ($_POST as $key => $value) { ${$key} = $value; } # validate input require_lib("validate"); $v = new validate(); $v->isOk($budname, "string", 1, 255, "Invalid Budget Name."); $v->isOk($budfor, "string", 1, 20, "Invalid Budget for option."); $v->isOk($budtype, "string", 1, 20, "Invalid Budget type."); $v->isOk($fromprd, "string", 1, 20, "Invalid Budget period."); $v->isOk($toprd, "string", 1, 20, "Invalid Budget period."); # display errors, if any if ($v->isError()) { $confirm = ""; $errors = $v->getErrors(); foreach ($errors as $e) { $confirm .= "<li class=err>{$e['msg']}</li>"; } return slctOpt($confirm); } global $BUDFOR, $TYPES, $PERIODS; $vbudfor = $BUDFOR[$budfor]; $vbudtype = $TYPES[$budtype]; $vfromprd = $PERIODS[$fromprd]; $vtoprd = $PERIODS[$toprd]; /* budget headings */ if ($budfor == 'cost') { $head = "\n\t\t<tr>\n\t\t\t<th>Select Cost Centers</th>"; } else { $head = "\n\t\t<tr>\n\t\t\t<th>Select Accounts</th>"; } if ($fromprd < $toprd) { for ($i = $fromprd; $i <= $toprd; $i++) { $head .= "<th>{$PERIODS[$i]}</th>"; } } elseif ($fromprd > $toprd) { for ($i = $fromprd; $i <= 12; $i++) { $head .= "<th>{$PERIODS[$i]}</th>"; } for ($i = 1; $i <= $toprd; $i++) { $head .= "<th>{$PERIODS[$i]}</th>"; } } else { $head .= "<th>{$PERIODS[$toprd]}</th>"; } $head .= "<th>Annual Total</th>"; $head .= "</tr>"; /* Toggle Options */ $list = ""; $rowcnt = 0; $cellcnt = 0; # budget for $js_funcs_mon = "var tot_annual = new Array();"; $js_funcs_tot = ""; if ($budfor == 'cost') { # cost centers db_connect(); $sql = "SELECT * FROM costcenters WHERE div = '" . USER_DIV . "' ORDER BY centername ASC"; $ccRslt = db_exec($sql); if (pg_numrows($ccRslt) < 1) { return "<li>There are No cost centers in Cubit."; } $numacc = pg_num_rows($ccRslt); $cellcnt = $numacc * 3; while ($cc = pg_fetch_array($ccRslt)) { if ($rowcnt++ % 9 == 0) { $list .= $head; } $ccid = $cc["ccid"]; if (isset($all) || isset($ccids[$ccid])) { $ch = "checked"; } else { $ch = ""; } $ci = $numacc + $rowcnt + 1; // extra one added so submit button is after annuals $list .= "\n\t\t\t<tr class='bg-odd'>\n\t\t\t\t<td><input tabindex='{$ci}' id='cb{$ccid}' type=checkbox name='ccids[{$ccid}]' value='{$cc['ccid']}' {$ch}>{$cc['centercode']} - {$cc['centername']}</td>"; # Budget prd $tot_annual = 0; $js_totannuals = array(); if ($fromprd <= $toprd) { for ($i = $fromprd; $i <= $toprd; $i++) { if (!isset($amts[$ccid][$i])) { $amts[$ccid][$i] = 0; } $tot_annual += $amts[$ccid][$i]; $js_totannuals[] = "amts_{$ccid}_{$i}"; ++$cellcnt; $list .= "<td nowrap>" . CUR . " <input tabindex='{$cellcnt}' type=text size=7 id='amts_{$ccid}_{$i}' onChange='changedVal{$ccid}();' name=amts[{$ccid}][{$i}] value='" . $amts[$ccid][$i] . "'></td>"; } } elseif ($fromprd > $toprd) { for ($i = $fromprd; $i <= 12; $i++) { if (!isset($amts[$ccid][$i])) { $amts[$ccid][$i] = 0; } $tot_annual += $amts[$ccid][$i]; $js_totannuals[] = "amts_{$ccid}_{$i}"; ++$cellcnt; $list .= "<td nowrap>" . CUR . " <input tabindex='{$cellcnt}' type=text size=7 id='amts_{$ccid}_{$i}' onChange='changedVal{$ccid}();' name=amts[{$ccid}][{$i}] value='" . $amts[$ccid][$i] . "'></td>"; } for ($i = 1; $i <= $toprd; $i++) { if (!isset($amts[$ccid][$i])) { $amts[$ccid][$i] = 0; } $tot_annual += $amts[$ccid][$i]; $js_totannuals[] = "amts_{$ccid}_{$i}"; ++$cellcnt; $list .= "<td nowrap>" . CUR . " <input tabindex='{$cellcnt}' type=text size=7 id='amts_{$ccid}_{$i}' name=amts[{$ccid}][{$i}] value='" . $amts[$ccid][$i] . "'></td>"; } //}else{ // if (!isset($amts[$cc["ccid"]][$i])) $amts[$cc["ccid"]][$i] = 0; // $list .= "<td nowrap>".CUR." <input type=text size=7 onChange='changedVal$ccid();' name=amts[$cc[ccid]][$toprd] value='".$amts[$cc["ccid"]][$toprd]."'></td>"; } $js_funcs_mon .= "\n\t\t\tfunction changedVal{$ccid}() {\n\t\t\t\tgetObject('cb{$ccid}').checked = true;\n\n\t\t\t\ttot_annual[{$ccid}] = 0;"; $months_cnt = count($js_totannuals); $js_funcs_tot .= "\n\t\t\tfunction changedTot{$ccid}(totobj) {\n\t\t\t\tmthval = parseFloat(totobj.value) / {$months_cnt};\n\n\t\t\t\tsf = 0;"; $last = 0; foreach ($js_totannuals as $fid) { ++$last; $js_funcs_mon .= "\n\t\t\t\t\tobj = getObject('{$fid}');\n\t\t\t\t\tval = parseFloat(obj.value);\n\t\t\t\t\tobj.value = val.toFixed(2)\n\t\t\t\t\ttot_annual[{$ccid}] += val;"; $js_funcs_tot .= "\n\t\t\t\t\tobj = getObject('{$fid}');"; if ($last != $months_cnt) { $js_funcs_tot .= "\n\t\t\t\t\t\tobj.value = (Math.round(100*mthval)/100).toFixed(2);\n\t\t\t\t\t\tsf += Math.round(100*mthval)/100;"; } else { $js_funcs_tot .= "\n\t\t\t\t\t\tobj.value = (parseFloat(totobj.value) - sf).toFixed(2);"; } } $js_funcs_mon .= "\n\t\t\t\t//getObject('annual{$ccid}').innerHTML = '" . CUR . " ' + tot_annual[{$ccid}].toFixed(2);\n\t\t\t\tgetObject('annual_{$ccid}').value = tot_annual[{$ccid}].toFixed(2);\n\t\t\t}\n\n\t\t\ttot_annual[{$ccid}] = {$tot_annual};\n"; $js_funcs_tot .= "\n\t\t\t}\n"; $tot_annual = sprint($tot_annual); //$list .= "<td nowrap><div id='annual$ccid'>".CUR." $tot_annual</div></td>"; $list .= "\n\t\t\t<td nowrap>" . CUR . "\n\t\t\t\t<input tabindex='{$rowcnt}' type=text size=7 onchange='changedTot{$ccid}(this);' id='annual_{$accid}' name='annual[{$ccid}]' value='" . $tot_annual . "' />\n\t\t\t</td>"; } } elseif ($budfor == 'acc') { # budget type if ($budtype == 'exp') { $acctype = "E"; } elseif ($budtype == 'inc') { $acctype = "I"; } else { $acctype = "B"; } # accounts core_connect(); $sql = "SELECT * FROM accounts WHERE acctype = '{$acctype}' AND div = '" . USER_DIV . "' ORDER BY accname ASC"; $accRslt = db_exec($sql); if (pg_numrows($accRslt) < 1) { return "<li>There are No accounts in Cubit."; } $tbval = new dbSelect("trial_bal_actual", PYR_DB, grp(m("cols", "acctype, debit, credit"))); $numacc = pg_num_rows($accRslt); $cellcnt += $numacc * 3; while ($acc = pg_fetch_array($accRslt)) { if ($acc["accname"] == "Retained Income / Accumulated Loss") { continue; } if ($rowcnt++ % 9 == 0) { $list .= $head; } $accid = $acc["accid"]; /* create default values */ for ($i = 1; $i <= 12; ++$i) { if (!isset($amts[$accid][$i])) { if (isset($import)) { $tbval->setOpt(grp(m("where", "accid='{$accid}' AND month='{$i}'"))); $tbval->run(); $tbd = $tbval->fetch_array(); switch ($tbd["acctype"]) { case "I": $bal = $tbval->d["credit"] - $tbval->d["debit"]; break; case "E": case "B": $bal = $tbval->d["debit"] - $tbval->d["credit"]; break; } $amts[$accid][$i] = sprint($bal + $bal * $incperc / 100); } else { $amts[$accid][$i] = 0; } } } if (isset($all) || isset($accids[$accid]) || isset($import)) { $ch = "checked"; } else { $ch = ""; } $ci = $numacc + $rowcnt + 1; // extra one added so submit button is after annuals $list .= "\n\t\t\t<tr class='bg-odd'>\n\t\t\t\t<td><input tabindex='{$ci}' id='cb{$accid}' type='checkbox' name='accids[{$accid}]' value='{$accid}' {$ch}>{$acc['topacc']}/{$acc['accnum']} - {$acc['accname']}</td>"; # Budget prd $tot_annual = 0; $js_totannuals = array(); if ($fromprd <= $toprd) { for ($i = $fromprd; $i <= $toprd; $i++) { $tot_annual += $amts[$accid][$i]; $js_totannuals[] = "amts_{$accid}_{$i}"; ++$cellcnt; $list .= "<td nowrap>" . CUR . " <input tabindex='{$cellcnt}' type=text size=7 onChange='changedVal{$accid}();' id='amts_{$accid}_{$i}' name=amts[{$accid}][{$i}] value='" . $amts[$accid][$i] . "'></td>"; } } elseif ($fromprd > $toprd) { for ($i = $fromprd; $i <= 12; $i++) { $tot_annual += $amts[$accid][$i]; $js_totannuals[] = "amts_{$accid}_{$i}"; ++$cellcnt; $list .= "<td nowrap>" . CUR . " <input tabindex='{$cellcnt}' type=text size=7 onChange='changedVal{$accid}();' id='amts_{$accid}_{$i}' name=amts[{$accid}][{$i}] value='" . $amts[$accid][$i] . "' /></td>"; } for ($i = 1; $i <= $toprd; $i++) { $tot_annual += $amts[$accid][$i]; $js_totannuals[] = "amts_{$accid}_{$i}"; ++$cellcnt; $list .= "<td nowrap>" . CUR . " <input tabindex='{$cellcnt}' type=text size=7 onChange='changedVal{$accid}();' id='amts_{$accid}_{$i}' name=amts[{$accid}][{$i}] value='" . $amts[$accid][$i] . "' /></td>"; } } /* JAVA SCRIPT: BEGIN */ $js_funcs_mon .= "\n\t\t\tfunction changedVal{$accid}() {\n\t\t\t\tgetObject('cb{$accid}').checked = true;\n\n\t\t\t\ttot_annual[{$accid}] = 0;"; $months_cnt = count($js_totannuals); $js_funcs_tot .= "\n\t\t\tfunction changedTot{$accid}(totobj) {\n\t\t\t\tgetObject('cb{$accid}').checked = true;\n\t\t\t\tmthval = parseFloat(totobj.value) / {$months_cnt};\n\n\t\t\t\tsf = 0;"; $last = 0; foreach ($js_totannuals as $fid) { ++$last; $js_funcs_mon .= "\n\t\t\t\t\tobj = getObject('{$fid}');\n\t\t\t\t\tval = parseFloat(obj.value);\n\t\t\t\t\tobj.value = val.toFixed(2);\n\t\t\t\t\ttot_annual[{$accid}] += val;"; $js_funcs_tot .= "\n\t\t\t\t\tobj = getObject('{$fid}');"; if ($last != $months_cnt) { $js_funcs_tot .= "\n\t\t\t\t\t\tobj.value = (Math.round(100*mthval)/100).toFixed(2);\n\t\t\t\t\t\tsf += Math.round(100*mthval)/100;"; } else { $js_funcs_tot .= "\n\t\t\t\t\t\tobj.value = (parseFloat(totobj.value) - sf).toFixed(2);"; } } $js_funcs_mon .= "\n\t\t\t\tgetObject('annual_{$accid}').value = tot_annual[{$accid}].toFixed(2);\n\t\t\t}\n\n\t\t\ttot_annual[{$accid}] = {$tot_annual};\n"; $js_funcs_tot .= "\n\t\t\t}\n"; /* JAVA SCRIPT: END */ $tot_annual = sprint($tot_annual); //$list .= "<td nowrap><div id='annual$accid'>".CUR." $tot_annual</div></td>"; $list .= "\n\t\t\t<td nowrap='t'>" . CUR . "\n\t\t\t\t<input tabindex='{$rowcnt}' type=text size=7 onchange='changedTot{$accid}(this);' id='annual_{$accid}' name='annual[{$accid}]' value='" . $tot_annual . "' />\n\t\t\t</td>\n\t\t\t<td>{$acc['topacc']}/{$acc['accnum']} - {$acc['accname']}</td>"; } } /* End Toggle Options */ $OUT = "\n\t<script>\n\t{$js_funcs_mon}\n\t{$js_funcs_tot}\n\t</script>\n\t<div>\n\t<center><h3>New Monthly Budget</h3>\n\t<form action='" . SELF . "' method=post name=form>\n\t<input type=hidden name=key value=confirm>\n\t<input type=hidden name=budname value='{$budname}'>\n\t<input type=hidden name=budfor value='{$budfor}'>\n\t<input type=hidden name=budtype value='{$budtype}'>\n\t<input type=hidden name=fromprd value='{$fromprd}'>\n\t<input type=hidden name=toprd value='{$toprd}'>\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' align=center>\n\t\t<tr>\n\t\t\t<th colspan=2>Details</th>\n\t\t</tr>\n\t\t<tr class='bg-odd'>\n\t\t\t<td>Budget Name</td>\n\t\t\t<td>{$budname}</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td><br></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<th colspan=2>Options</th>\n\t\t</tr>\n\t\t<tr class='bg-odd'>\n\t\t\t<td>Budget For</td>\n\t\t\t<td>{$vbudfor}</td>\n\t\t</tr>\n\t\t<tr class='bg-even'>\n\t\t\t<td>Budget Type</td>\n\t\t\t<td>{$vbudtype}</td>\n\t\t</tr>\n\t\t<tr class='bg-odd'>\n\t\t\t<td>Budget Period</td>\n\t\t\t<td>{$vfromprd} to {$vtoprd}</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td colspan=2>{$errata}</td>\n\t\t</tr>\n\t</table>\n\t</div>\n\t<div>\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' align=center>\n\t\t{$list}\n\t</table>\n\t</div>\n\n\t<table border=0 cellpadding='" . TMPL_tblCellPadding . "' cellspacing='" . TMPL_tblCellSpacing . "' align=center>\n\t<tr>\n\t\t<td align='right'><input tabindex='" . ($rowcnt + 1) . "' type=submit value='Continue »'></td>\n\t</tr>\n\t</table>\n\t</form>\n\t<p>\n\t<table border=0 cellpadding='2' cellspacing='1' width=15%>\n\t\t<tr><th>Quick Links</th></tr>\n\t\t<tr class='bg-odd'><td align=center><a href='budget-view.php'>View Budgets</td></tr>\n\t\t<tr class='bg-odd'><td align=center><a href='../main.php'>Main Menu</td></tr>\n\t</table>"; return $OUT; }
if (isset($_POST["key"])) { switch ($_POST["key"]) { default: case "details": $OUTPUT = details($_POST); break; case "confirm": $OUTPUT = confirm($_POST); break; case "write": $OUTPUT = write($_POST); break; } } else { # Display default output $OUTPUT = slctOpt(); } # get templete require "../template.php"; # Select Accounts function slctOpt() { global $TYPES, $YEARS; $typesel = extlib_mksel("budtype", $TYPES); $fromyrsel = extlib_cpsel("fromyr", $YEARS, YR_DB); $toyrsel = extlib_cpsel("toyr", $YEARS, YR_DB); // Options Layout $Opts = "<center>\n\t<h3> New Yearly Budget </h3>\n\t<form action='" . SELF . "' method=post name=form>\n\t<input type=hidden name=key value=details>\n\t<table " . TMPL_tblDflts . " align=center>\n\t\t<tr>\n\t\t\t<th colspan=3>Details</th>\n\t\t</tr>\n\t\t<tr class='bg-odd'>\n\t\t\t<td>Budget Name</td>\n\t\t\t<td><input type=text size=30 name=budname></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td> </td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<th colspan=3>Options</th>\n\t\t</tr>\n\t\t<tr class='bg-odd'>\n\t\t\t<td>Budget For</td>\n\t\t\t<td>\n\t\t\t\t<input type=radio name=budfor value=cost checked=yes>Cost Centers \n\t\t\t\t<input type=radio name=budfor value=acc>Accounts\n\t\t\t</td>\n\t\t<tr class='bg-even'>\n\t\t\t<td>Budget Type</td>\n\t\t\t<td>{$typesel}</td>\n\t\t</tr>\n\t\t<tr class='bg-odd'>\n\t\t\t<td>Budget Year</td>\n\t\t\t<td>{$fromyrsel} to {$toyrsel}</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td> </td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td align=right>\n\t\t\t\t<input type=submit value='Continue »'>\n\t\t\t</td>\n\t\t</tr>\n\t</table></form>\n\t<p>\n\t<table border=0 cellpadding='2' cellspacing='1' width=15%>\n\t\t<tr><th>Quick Links</th></tr>\n\t\t<tr class='bg-odd'><td align=center><a href='budget-view.php'>View Budgets</td></tr>\n\t\t<tr class='bg-odd'><td align=center><a href='../main.php'>Main Menu</td></tr>\n\t</table>"; return $Opts; } # Error Handler