<?
/*
Scryed Labs Financial Manager
Copyright (c) 2005-2007, Scryed Labs
http://www.scryedlabs.com
Financial Manager is copyrighted free software by Waheed Ayubi <hide@address.com>.
You can redistribute it and/or modify it under either the terms of the GPL
(see COPYING.txt), or the terms of the Artistic License (see README.txt).
http://sourceforge.net/projects/financemonitor/
*/
?>
<div class="ns_parent_title"><a name="inid_anchor" href="<?=$_SERVER['PHP_SELF']?>?month=<?=$month?>&year=<?=$year?>#inid_anchor">Income</a></div>
<div class="ns_parent"><table cellspacing="0" border="1">
<tr class="head">
<td class="account">Account</td>
<td class="amount">Amount</td>
</tr>
<?
# IncomeTotal will track sum of income items for use by various functions.
$IncomeTotal = 0;
# IncomeCategoryTotal will track the amount of a transaction.
$IncomeCategoryTotal = 0;
# RowSelectID is a counter that is used to identify the rows for the javascript hover/click functions.
$RowSelectID = 0;
# SELECT SUM (AMOUNT) FROM EACH CATEGORY IN DATE RANGE
$sql = "
select catid, sum(amount) as amount
from income_items
where userid = '" . $_COOKIE['UserID'] . "'
and date like '" . substr( $date, 0, 7 ) . "%'
group by catid
";
$rx = $conn->Execute($sql);
$sum_amount = null;
while (!$rx->EOF) {
$sum_amount[$rx->fields['catid']] = $rx->fields['amount'];
$rx->MoveNext();
}
$rx->Close();
# SELECT * CATEGORIES IN DATE RANGE
$sql = "
select * from income_categories
where userid = '" . $_COOKIE['UserID'] . "'
and (
close > '" . $eom . "'
or close = '0000-00-00'
)
and (
open <= '" . $date . "'
)
order by name asc
";
$r1 = $conn->Execute( $sql );
while ( !$r1->EOF )
{
$IncomeCategoryTotal = $sum_amount[$r1->fields['id']];
$IncomeTotal += $sum_amount[$r1->fields['id']];
# PROCESSING "PARENT" NODES
if ( $r1->fields['id'] != $_GET['inid'] )
{
?>
<tr class="content" id="categories_income_<?=$RowSelectID?>" onclick="categoryClick('index.php?month=<?=$month?>&year=<?=$year?>&inid=<?=$r1->fields['id']?>#inid_anchor');">
<td class="account"><?=$r1->fields['name']?></td>
<td class="amount"><?=number_format($IncomeCategoryTotal, 2, '.', '')?></td>
</tr>
<?
}
# OPENING "CHILD" NODES
else
{
?>
</table></div>
<div class="ns_child_title">
<a href="<?=$_SERVER['PHP_SELF']?>?month=<?=$month?>&year=<?=$year?>&inid=<?=$_GET['inid']?>#inid_anchor"><?=$r1->fields['name']?></a>
<span><a href="javascript:closeAccount('income', '<?=$_GET['inid']?>')">(Close Account)</a></span>
</div>
<div class="ns_child"><table cellspacing="0" border=1>
<tr class="head">
<td class="date">Date</td>
<td class="description">Description</td>
<td class="amount">Amount</td>
</tr>
<?
# SELECT * FROM INCOME_ITEMS IN CATEGORY BY DATE
$sql = "
select * from income_items
where userid = '" . $_COOKIE['UserID'] . "'
and catid = " . $r1->fields['id'] . "
and date like '" . substr( $date, 0, 7 ) . "%'
";
$r2 = $conn->Execute( $sql );
while ( !$r2->EOF )
{
# PROCESSING "CHILD" NODES
if ( $_GET['id'] != $r2->fields['id'] )
{
?>
<tr class="content" id="categories_income_<?=$RowSelectID?>" onclick="categoryClick('<?=$_SERVER['PHP_SELF']?>?month=<?=$month?>&year=<?=$year?>&inid=<?=$_GET['inid']?>&id=<?=$r2->fields['id']?>#inid_anchor');">
<td class="date"><?=$r2->fields['date']?></td>
<td class="description"><?=$r2->fields['comment']?></td>
<td class="amount"><?=number_format($r2->fields['amount'], 2, '.', '')?></td>
</tr>
<?
}
# PROCESSING "EDIT" NODES
else
{
?>
</table></div>
<div class="ns_edit"><table cellspacing="0" border=1>
<tr class="fields">
<td class="date"><a name="anchor_inid_old" id="anchor_inid_old"></a><input id="olddate" name="olddate" type="text" value="<?=$r2->fields['date']?>" onclick="cal.select(document.getElementById('olddate'),'anchor_inid_old','yyyy-MM-dd'); return false;" /></td>
<td class="description"><input id="oldname" name="oldname" type="text" value="<?=$r2->fields['comment']?>" /></td>
<td class="amount"><input id="oldamount" name="oldamount" type="text" value="<?=number_format($r2->fields['amount'], 2, '.', '')?>" /></td>
</tr>
<tr class="buttons">
<td colspan="3">
<input type="button" value="Apply" onclick="editIncomeItem(<?=$r2->fields['id']?>, document.getElementById('olddate').value, document.getElementById('oldname').value, document.getElementById('oldamount').value, <?=$r1->fields['id']?>)" /><input type="button" value="Delete" onclick="deleteIncomeItem(<?=$r2->fields['id']?>, <?=$r1->fields['id']?>);" /><input type="button" value="Close" onclick="browseTo('<?=$_SERVER['PHP_SELF']?>?month=<?=$month?>&year=<?=$year?>&inid=<?=$_GET['inid']?>#inid_anchor')" />
</td>
</tr>
</table></div>
<div class="ns_child"><table cellspacing="0" border=1>
<?
}
$r2->MoveNext();
$RowSelectID++;
}
$r2->Close();
# 'Add transaction item' fields are only available when no editing is taking place
if ( !$_GET['id'] )
{
?>
<tr class="fields">
<td><a name="anchor_inid_new" id="anchor_inid_new"></a><input id="newdate" name="newdate" type="text" onclick="cal.select(document.getElementById('newdate'),'anchor_inid_new','yyyy-MM-dd'); return false;" /></td>
<td><input id="newname" name="newname" type="text" /></td>
<td><input id="newamount" name="newamount" class="txtwidth" type="text" /></td>
</tr>
<tr class="buttons">
<td colspan="3">
<input type="button" value="Add Income Item" onclick="addIncomeItem(document.getElementById('newdate').value, document.getElementById('newname').value, document.getElementById('newamount').value, <?=$r1->fields['id']?>)" /><input type="button" value="Close" onclick="browseTo('<?=$_SERVER['PHP_SELF']?>?month=<?=$month?>&year=<?=$year?>#inid_anchor')">
</td>
</tr>
<?
}
?>
</table></div>
<div class="ns_parent"><table cellspacing="0" border="1">
<?
}
$r1->MoveNext();
$RowSelectID++;
}
$r1->Close();
?>
<tr class="buttons">
<td colspan="2">
<input type="text" name="addincomename" id="addincomename" />
<input type="button" onClick="addIncome(document.getElementById('addincomename').value)" id="addincome" value="Add Income" />
</td>
</tr>
<tr class="foot">
<td class="account">Total</td>
<td class="amount"><?=number_format($IncomeTotal, 2, '.', '')?></td>
</tr>
</table></div>