<? include('includes/main.php'); ?>
<?
echo texttitle("Activity Report for ".$companyname);
if ($beginyear&&$beginmonth&&$endyear&&$endmonth) {
$begindate=$beginyear.'-'.$beginmonth;
$enddate=$endyear.'-'.$endmonth;
if ($begindate!=$enddate) {
echo texttitle('(Period: '.$beginyear."/".$beginmonth." - ".$endyear."/".$endmonth.')');
} else {
echo texttitle('(Period: '.$beginyear."/".$beginmonth.')');
};
$timestamp=mktime(0, 0, 0, $endmonth+1, 1, $endyear);
$enddate=date("Y", $timestamp).'-'.date("m",$timestamp);
if (!$show) $showstr=" and status='1'";
if ($id>0) $showacct=' and gltransaction.glaccountid='.sqlprep($id);
$recordSet = &$conn->Execute("select gltransaction.amount, gltransaction.glaccountid, glaccount.name, glaccount.description, accounttype.description, gltransaction.voucherid, gltransvoucher.wherefrom, gltransvoucher.entrydate, gltransvoucher.post2date, gltransvoucher.description from gltransaction, gltransvoucher, glaccount, accounttype where gltransvoucher.cancel='0' and gltransvoucher.post2date >= ".sqlprep($begindate."-01")." and gltransvoucher.post2date < ".sqlprep($enddate."-01")." and gltransaction.voucherid=gltransvoucher.id and glaccount.id=gltransaction.glaccountid and accounttype.id=glaccount.accounttypeid".$showstr.$showacct." and gltransvoucher.companyid=".$active_company." order by glaccount.name, gltransvoucher.posteddate, gltransvoucher.voucher");
if (!$recordSet->EOF) {
$amount=0;
$recordSet2 = &$conn->Execute("select sum(gltransaction.amount) from gltransaction where gltransaction.accountid='".$recordSet->fields[1]."' and gltransvoucher.cancel='0' and gltransaction.voucherid=gltransvoucher.voucher and gltransvoucher.post2date > ".sqlprep($begindate."-01"));
if (!$recordSet2->EOF) $amount=$recordSet2->fields[0];
echo '<table border="1" width="90%">';
echo '<tr><th><b>From</b><th><b>Date</b></th><th align="center"><b>Description</b></th><th><b>Posted To</b></th><th><b>Debit</b></th><th><b>Credit</b></th></tr>';
echo '<tr><th colspan="6">'.$recordSet->fields[2].' - '.$recordSet->fields[3].' - '.$recordSet->fields[4]."</th></tr>";
$oldglaccountid=$recordSet->fields[1];
$oldglaccountname=$recordSet->fields[2];
$debit="";
$credit="";
if ($amount<0) {
$credit=checkdec((0-$amount),PREFERRED_DECIMAL_PLACES);
} else {
$debit=checkdec($amount,PREFERRED_DECIMAL_PLACES);
};
echo '<tr><td colspan="4" width="80%">Beginning Balance:</td><td width="10%" align="right"><nobr>'.$debit.'</nobr></td><td width="10%" align="right">'.$credit.'</nobr></td></tr>';
} else {
die(texterror('No entries match the specified criteria to report.'));
};
while (!$recordSet->EOF) {
$debit="";
$credit="";
if ($recordSet->fields[1]!=$oldglaccountid) {
if ($amount<0) {
$credit=checkdec((0-$amount),PREFERRED_DECIMAL_PLACES);
} else {
$debit=checkdec($amount,PREFERRED_DECIMAL_PLACES);
};
echo '<tr><td colspan="4">Ending Balance Account '.$oldglaccountname.':</td><td align="right"><nobr>'.$debit.'</nobr></td><td align="right"><nobr>'.$credit.'</nobr></td></tr>';
$oldglaccountid=$recordSet->fields[1];
$oldglaccountname=$recordSet->fields[2];
$debit="";
$credit="";
$recordSet2 = &$conn->Execute("select sum(gltransaction.amount) from gltransaction where gltransaction.accountid='".$recordSet->fields[1]."' and gltransvoucher.cancel='0' and gltransaction.voucherid=gltransvoucher.voucher and gltransvoucher.post2date > ".sqlprep($begindate."-01"));
if (!$recordSet2->EOF) $amount=$recordSet2->fields[0];
echo '</table><br><table border="1" width="90%">';
echo '<tr><th colspan="6">'.$recordSet->fields[2].' - '.$recordSet->fields[3].' - '.$recordSet->fields[4]."</th></tr>";
$oldglaccountid=$recordSet->fields[1];
$oldglaccountname=$recordSet->fields[2];
if ($amount<0) {
$credit=checkdec((0-$amount),PREFERRED_DECIMAL_PLACES);
} else {
$debit=checkdec($amount,PREFERRED_DECIMAL_PLACES);
};
echo '<tr><td colspan="4" width="80%">Beginning Balance:</td><td width="10%" align="right"><nobr>'.$debit.'</nobr></td><td width="10%" align="right"><nobr>'.$credit.'</nobr></td></tr>';
};
$oldglaccountid=$recordSet->fields[1];
$oldglaccountname=$recordSet->fields[2];
$debit="";
$credit="";
if ($recordSet->fields[0]<0) {
$credit=checkdec((0-$recordSet->fields[0]),PREFERRED_DECIMAL_PLACES);
} else {
$debit=checkdec($recordSet->fields[0],PREFERRED_DECIMAL_PLACES);
};
echo '<tr><td>'.strtoupper(modulenameshort($recordSet->fields[6])).'</td><td>'.substr($recordSet->fields[7],0,10).'</td><td>'.$recordSet->fields[9].'</td><td>'.substr($recordSet->fields[8],0,7).'</td><td align="right">'.$debit.'</td><td align="right">'.$credit.'</td></tr>';
$amount=$amount+$recordSet->fields[0];
$recordSet->MoveNext();
};
$debit="";
$credit="";
if ($amount<0) {
$credit=checkdec((0-$amount),PREFERRED_DECIMAL_PLACES);
} else {
$debit=checkdec($amount,PREFERRED_DECIMAL_PLACES);
};
echo '<tr><td colspan="4">Ending Balance Account '.$oldglaccountname.':</td><td align="right">'.$debit.'</td><td align="right">'.$credit.'</td></tr>';
} else {
$timestamp = time();
$date_time_array = getdate($timestamp);
$hours = $date_time_array["hours"];
$minutes = $date_time_array["minutes"];
$seconds = $date_time_array["seconds"];
$month = $date_time_array["mon"];
$day = $date_time_array["mday"];
$year = $date_time_array["year"];
$timestamp = mktime($hour, $minute, $second, $month-1, 1, $year);
$bgdateyear=date("Y", $timestamp);
$bgdatemonth=date("m", $timestamp);
$eddateyear=date("Y", $timestamp);
$eddatemonth=date("m", $timestamp);
echo '<form action="glrepactivity.php" method="post"><table>';
echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Begin Period:</td><td><input type="text" name="beginyear" onchange="validateint(this)" value="'.$bgdateyear.'" size="14" maxlength="4"'.INC_TEXTBOX.'><input type="text" name="beginmonth" onchange="validateint(this)" value="'.$bgdatemonth.'" size="14" maxlength="4"'.INC_TEXTBOX.'></td></tr>';
echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">End Period:</td><td><input type="text" name="endyear" onchange="validateint(this)" value="'.$eddateyear.'" size="14" maxlength="4"'.INC_TEXTBOX.'><input type="text" onchange="validateint(this)" name="endmonth" value="'.$eddatemonth.'" size="14" maxlength="4"'.INC_TEXTBOX.'></td></tr>';
echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Show Unposted Entries Only:</td><td><input type="radio" name="show" value="0" checked'.INC_TEXTBOX.'></td></tr>';
echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Show All Entries:</td><td><input type="radio" name="show" value="1"'.INC_TEXTBOX.'></td></tr>';
echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Specific General Ledger Account:</td><td><select name="id"'.INC_TEXTBOX.'>';
$recordSet = &$conn->Execute('select id,name,description from glaccount where (companyid=0 or companyid='.sqlprep($active_company).') order by id');
echo '<option value="0">0=All Accounts';
while (!$recordSet->EOF) {
echo '<option value="'.$recordSet->fields[0].'">'.$recordSet->fields[1]." - ".$recordSet->fields[2]."\n";
$recordSet->MoveNext();
};
echo '</select></td></tr></table><input type="submit" value="Continue"></form>';
};
?>
<? include('includes/footer.php'); ?>