<? include('includes/main.php'); ?>
<? include('includes/glfunctions.php'); ?>
<? //GLPIEADD.PHP - Copyright 2001 Noguska, Fostoria, OH 44830
// Select a pre-defined pie chart & edit or print
// Create a new pie chart definition
echo TextTitle("General Ledger Pie Chart");
if ($choice=="Save New Detail") {
$AddUpdate=0; //update flag
GLPieSliceDetailAddUpdate($AddUpdate,$id,$sliceid,0,$glaccountid,$companyid,$slicedetaillastchangedate);
$choice="Edit Slice Details"; // return to EDIT after save new
};
if ($choice) { //choice=false if no choice yet about select or add
//choice="Edit or Print" edit/print existing pie
//choice="Add New Pie" to create a new pie
//choice="Delete Pie" to delete existing pie
//choice="Save Pie" to save changes then go to edit slice details
//choice="Edit Slice Details" to edit a pie slice details
//choice="Add Slice Detail" to create a new pie slice detail
//choice="Pick New Slice" to pick a new slice for detail edit
if ($choice=="Edit or Print"||$choice=="Add New Pie") { //add or edit main pie info
//get main pie data now
echo '<form action="glpieadd.php" method="post"><input type="hidden" name="nonprintable" value="1"><table>';
if ($choice=="Add New Pie") $id="";
echo '<input type="hidden" name="id" value="'.$id.'">';
$AddUpdate=formglPie($id,$choice);
echo '</table><input type="submit" name="choice" value="Save Pie">';
if ($choice=="Edit or Print") {
echo '<input type="submit" name="choice" value="Delete Pie"></form><br>';
echo '<br><a href="glpie.php?printable=1&id='.$id.'">Create Pie Chart</a>';
};
} elseif ($choice=="Delete Pie"&&$id) {
//delete pie info in glpie, glpieslice, and glpieslicedetail
DeletePie($id);
DeletePieSlice($id,0); //0=no specific slice
DeletePieSliceDetail($id,0,0); //0=no specific slice or detail
} elseif ($choice=="Save Pie"||$choice=="Pick New Slice") {
if ($choice=="Save Pie") {
if ($id) {
$AddUpdate=1;
} else {
$AddUpdate=0;
};
glPieAddUpdate($AddUpdate,$id,$name,$description,$begindate,$findate,$lastchangedate);
if (!$id) {//if this was an add, need to read id
$recordSet=&$conn->Execute('select id from glpie where name='.sqlprep($name).' and description='.sqlprep($description));
if (!$recordSet->EOF) $id=$recordSet->fields[0];
};
for ($scount=1;$scount<13;$scount++) {
if (${"sliceid".$scount}) { //this slice exists already
if (${"slicedelete".$scount}) { //delete, do not update
DeletePieSlice($id,${"sliceid".$scount});
} else {//update slice data
glPieSliceAddUpdate(1,$id,${"sliceid".$scount},${"slicename".$scount},${"slicebegindate".$scount},${"slicefindate".$scount},${"slicelastchangedate".$scount});
};
} elseif (${"slicename".$scount}) { //add a new slice
if (!${"slicedelete".$scount}) glPieSliceAddUpdate(0,$id,${"sliceid".$scount},${"slicename".$scount},${"slicebegindate".$scount},${"slicefindate".$scount},${"slicelastchangedate".$scount});
};
};
};
//pick a slice to enter details for
echo '<form action="glpieadd.php" method="post">';
echo '<table><tr><th colspan="2">GENERAL LEDGER PIE SLICE DEFINITION </th></tr>';
echo '<input type="hidden" name="id" value="'.$id.'">';
echo '<input type="hidden" name="name" value="'.$name.'">';
echo '<tr><td>Slice to Edit:</td><td><select name="sliceid">';
$recordSet = &$conn->Execute('select id, name from glpieslice where glpieid='.$id.' order by name');
while (!$recordSet->EOF) {
echo '<option value="'.$recordSet->fields[0].'">'.$recordSet->fields[1]."\n";
$recordSet->MoveNext();
};
echo '</select></td></tr>';
echo '</table><input type="submit" name="choice" value="Edit Slice Details">';
echo '</form>';
} elseif ($choice=="Edit Slice Details") {
//display current slice details and allow edit.
//Also have ADD NEW and SAVE buttons
echo '<form action="glpieadd.php" method="post">';
echo '<table><tr><th colspan="2">GENERAL LEDGER PIE CHART DEFINITION </th></tr>';
echo '<input type="hidden" name="id" value="'.$id.'">';
echo '<input type="hidden" name="name" value="'.$name.'">';
echo '<input type="hidden" name="sliceid" value="'.$sliceid.'">';
$recordSet=&$conn->Execute('select name from glpieslice where id='.sqlprep($sliceid));
if (!$recordSet->EOF) {
$slicename=$recordSet->fields[0];
} else {
die(TextError("Invalid slice"));
};
echo '<tr><th colspan="3">Slice: '.$slicename.'</th></tr>';
echo '<tr><th>GL Account - Description</th>';
if ($multi_company) echo '<th>Company (0=All)</th>';
echo '<th>Delete Detail Line <input type="checkbox" checked></th></tr>';
$recordSet=&$conn->Execute('select glpieslicedetail.glaccountid,glpieslicedetail.companyid,glpieslicedetail.lastchangedate,glaccount.name,glaccount.description,glpieslicedetail.id from glpieslicedetail,glaccount where glpieslicedetail.glaccountid=glaccount.id and glpieslicedetail.glpiesliceid='.sqlprep($sliceid));
$dcount=0;
while (!$recordSet->EOF) {
$dcount=$dcount+1;
echo '<input type="hidden" name="slicedetaillastchangedate'.$dcount.'" value="'.$recordSet->fields[2].'">';
echo '<input type="hidden" name="slicedetailid'.$dcount.'" value="'.$recordSet->fields[5].'>"';
echo '<tr><td><select name="glaccountid'.$dcount.'"'.INC_TEXTBOX.'>';
$recordSet1=&$conn->Execute('select glaccount.id, glaccount.name, glaccount.description from glaccount where (companyid=0 or companyid='.sqlprep($active_company).') order by name');
while (!$recordSet1->EOF) {
$sel="";
if ($recordSet->fields[0]==$recordSet1->fields[0]) $sel=" selected ";
echo '<option value="'.$recordSet1->fields[0].'"'.$sel.'>'.$recordSet1->fields[1].' - '.$recordSet1->fields[2]."\n";
$recordSet1->MoveNext();
};
echo '</select></td>';
if ($multi_company) { //only ask company if companyid under account number is for ANY
echo '<td><select name="companyid'.$dcount.'"'.INC_TEXTBOX.'>';
echo '<option value="0"'.checkequal(0,$recordSet->fields[1]," selected").'>0 - all companies';
$recordSet2 = &$conn->Execute('select id, name from gencompany order by name');
while (!$recordSet2->EOF) {
echo '<option value="'.$recordSet2->fields[0].'"'.checkequal($recordSet2->fields[0],$recordSet->fields[1]," selected").'>'.$recordSet2->fields[1]."\n";
$recordSet2->MoveNext();
};
echo '</select></td>';
} else {
echo '<input type="hidden" name="companyid'.$dcount.'" value="0">';
};
echo '<td><input name="detaildelete'.$dcount.'" type="checkbox"></td></tr>';
$recordSet->MoveNext();
};
echo '<input type="hidden" name="dcount" value="'.$dcount.'">';
echo '</table><input type="submit" name="choice" value="Save Details">';
echo '<input type="submit" name="choice" value="Add New Detail"></form>';
} elseif ($choice=="Add New Detail"||$choice=="Save Details") { //save details first in either case
for ($dc=1;$dc<=$dcount;$dc++){
if (${"detaildelete".$dc}) {
DeletePieSliceDetail($id,$sliceid,${"slicedetailid".$dc});
} else {
GLPieSliceDetailAddUpdate(1,$id,$sliceid,${"slicedetailid".$dc},${"glaccountid".$dc},${"companyid".$dc},${"slicedetaillastchangedate".$dc});
};
};
if ($choice=="Save Details") {
//quit at this point if save only
//ask if edit another slice first
echo '<form action="glpieadd.php" method="post"><table>';
echo '<input type="hidden" name="id" value="'.$id.'">';
echo '<input type="hidden" name="name" value="'.$name.'">';
echo '<input type="hidden" name="sliceid" value="'.$sliceid.'">';
echo '</table><input type="submit" name="choice" value="Pick New Slice"></form>';
} else { // add new detail now
echo '<form action="glpieadd.php" method="post">';
echo '<table><tr><th colspan="2">GENERAL LEDGER PIE CHART DEFINITION </th></tr>';
echo '<input type="hidden" name="id" value="'.$id.'">';
echo '<input type="hidden" name="name" value="'.$name.'">';
echo '<input type="hidden" name="sliceid" value="'.$sliceid.'">';
$recordSet=&$conn->Execute('select name from glpieslice where id='.sqlprep($sliceid));
if (!$recordSet->EOF) {
$slicename=$recordSet->fields[0];
} else {
die(TextError("Invalid slice"));
};
echo '<tr><th colspan="3">Slice: '.$slicename.'</th></tr>';
echo '<tr><td>GL Account:</th><td><select name="glaccountid" >';
$recordSet1=&$conn->Execute('select id, name, description from glaccount where (companyid=0 or companyid='.sqlprep($active_company).') order by name');
while (!$recordSet1->EOF) {
echo '<option value="'.$recordSet1->fields[0].'"'.$sel.'>'.$recordSet1->fields[1].' - '.$recordSet1->fields[2]."\n";
$recordSet1->MoveNext();
};
if ($multi_company) {
echo '<td><select name="companyid" '.INC_TEXTBOX.'><option value="0">0 - all companies';
$recordSet2 = &$conn->Execute('select id, name from gencompany order by name');
while (!$recordSet2->EOF) {
$sel="";
if( $active_company==$recordSet2->fields[0]) $sel=" selected ";
echo '<option value="'.$recordSet2->fields[0].'"'.$sel.'>'.$recordSet2->fields[1]."\n";
$recordSet2->MoveNext();
};
};
echo '</select></td></tr>';
echo '</table><input type="submit" name="choice" value="Save New Detail">';
echo '</form>';
};
};
} else { // select an existing pie or press button to add a new one
// option button to delete selection instead of submit if want this
echo '<form action="glpieadd.php" method="post">';
$recordSet = &$conn->Execute('select id, name from glpie where cancel=0 order by name');
if (!$recordSet->EOF) {
echo '<table><tr><th colspan="2">GENERAL LEDGER PIE CHART DEFINITION </th></tr>';
echo '<td>Pie Chart To Edit/Print:</td><td><select name="id">';
while (!$recordSet->EOF) {
echo '<option value="'.$recordSet->fields[0].'">'.$recordSet->fields[1]."\n";
$recordSet->MoveNext();
};
echo '</select></td></tr></table><input type="submit" name="choice" value="Edit or Print">';
};
echo '<input type="submit" name="choice" value="Add New Pie">';
echo '</form>';
};
?>
<? include('includes/footer.php'); ?>