Adding transaction summary by types

Addresses #581
This commit is contained in:
Sebastian Grewe 2013-08-08 12:02:39 +02:00
parent 7e81336e7d
commit 1a459a7913
6 changed files with 77 additions and 0 deletions

View File

@ -103,6 +103,9 @@ class Base {
}
public function getParam() {
$array = array_merge(array($this->types), $this->values);
// Clear the data
$this->values = NULL;
$this->types = NULL;
// See here why we need this: http://stackoverflow.com/questions/16120822/mysqli-bind-param-expected-to-be-a-reference-value-given
if (strnatcmp(phpversion(),'5.3') >= 0) {
$refs = array();

View File

@ -47,6 +47,38 @@ class Transaction extends Base {
return false;
}
/**
* Fetch a transaction summary by type with total amounts
* @param account_id int Account ID, NULL for all
* @return data array type and total
**/
public function getTransactionSummary($account_id=NULL) {
$sql = "SELECT SUM(t.amount) AS total, t.type AS type FROM $this->table AS t";
if (!empty($account_id)) {
$sql .= " WHERE t.account_id = ? ";
$this->addParam('i', $account_id);
}
$sql .= " GROUP BY t.type";
$stmt = $this->mysqli->prepare($sql);
if (!empty($account_id)) {
if (!($this->checkStmt($stmt) && call_user_func_array( array($stmt, 'bind_param'), $this->getParam()) && $stmt->execute()))
return false;
$result = $stmt->get_result();
} else {
if (!($this->checkStmt($stmt) && $stmt->execute()))
return false;
$result = $stmt->get_result();
}
if ($result) {
$aData = NULL;
while ($row = $result->fetch_assoc()) {
$aData[$row['type']] = $row['total'];
}
return $aData;
}
return false;
}
/**
* Get all transactions from start for account_id
* @param start int Starting point, id of transaction

View File

@ -6,11 +6,13 @@ if ($user->isAuthenticated()) {
$iLimit = 30;
empty($_REQUEST['start']) ? $start = 0 : $start = $_REQUEST['start'];
$aTransactions = $transaction->getTransactions($start, @$_REQUEST['filter'], $iLimit, $_SESSION['USERDATA']['id']);
$aTransactionSummary = $transaction->getTransactionSummary($_SESSION['USERDATA']['id']);
$iCountTransactions = $transaction->num_rows;
$aTransactionTypes = $transaction->getTypes();
if (!$aTransactions) $_SESSION['POPUP'][] = array('CONTENT' => 'Could not find any transaction', 'TYPE' => 'errormsg');
$smarty->assign('LIMIT', $iLimit);
$smarty->assign('TRANSACTIONS', $aTransactions);
$smarty->assign('SUMMARY', $aTransactionSummary);
$smarty->assign('TRANSACTIONTYPES', $aTransactionTypes);
$smarty->assign('TXSTATUS', array('' => '', 'Confirmed' => 'Confirmed', 'Unconfirmed' => 'Unconfirmed', 'Orphan' => 'Orphan'));
$smarty->assign('COUNTTRANSACTIONS', $iCountTransactions);

View File

@ -14,11 +14,13 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) {
$debug->append('No cached version available, fetching from backend', 3);
empty($_REQUEST['start']) ? $start = 0 : $start = $_REQUEST['start'];
$aTransactions = $transaction->getTransactions($start, @$_REQUEST['filter'], $iLimit);
$aTransactionSummary = $transaction->getTransactionSummary($_SESSION['USERDATA']['id']);
$iCountTransactions = $transaction->num_rows;
$aTransactionTypes = $transaction->getTypes();
if (!$aTransactions) $_SESSION['POPUP'][] = array('CONTENT' => 'Could not find any transaction', 'TYPE' => 'errormsg');
$smarty->assign('LIMIT', $iLimit);
$smarty->assign('TRANSACTIONS', $aTransactions);
$smarty->assign('SUMMARY', $aTransactionSummary);
$smarty->assign('TRANSACTIONTYPES', $aTransactionTypes);
$smarty->assign('TXSTATUS', array('' => '', 'Confirmed' => 'Confirmed', 'Unconfirmed' => 'Unconfirmed', 'Orphan' => 'Orphan'));
$smarty->assign('COUNTTRANSACTIONS', $iCountTransactions);

View File

@ -1,3 +1,22 @@
{include file="global/block_header.tpl" BLOCK_HEADER="Transaction Summary"}
<table>
<thead>
<tr>
{foreach $SUMMARY as $type=>$total}
<th>{$type}</th>
{/foreach}
</tr>
</thead>
<tbody>
<tr>
{foreach $SUMMARY as $type=>$total}
<td class="right">{$total}</td>
{/foreach}
</tr>
</tbody>
</table>
{include file="global/block_footer.tpl"}
{include file="global/block_header.tpl" ALIGN="left" BLOCK_STYLE="width: 23%" BLOCK_HEADER="Transaction Filter"}
<form action="{$smarty.server.PHP_SELF}">
<input type="hidden" name="page" value="{$smarty.request.page}" />

View File

@ -1,3 +1,22 @@
{include file="global/block_header.tpl" BLOCK_HEADER="Transaction Summary"}
<table>
<thead>
<tr>
{foreach $SUMMARY as $type=>$total}
<th>{$type}</th>
{/foreach}
</tr>
</thead>
<tbody>
<tr>
{foreach $SUMMARY as $type=>$total}
<td class="right">{$total}</td>
{/foreach}
</tr>
</tbody>
</table>
{include file="global/block_footer.tpl"}
{include file="global/block_header.tpl" ALIGN="left" BLOCK_STYLE="width: 23%" BLOCK_HEADER="Transaction Filter"}
<form action="{$smarty.server.PHP_SELF}">
<input type="hidden" name="page" value="{$smarty.request.page}" />