diff --git a/public/include/classes/base.class.php b/public/include/classes/base.class.php index aea25d60..6dc88b02 100644 --- a/public/include/classes/base.class.php +++ b/public/include/classes/base.class.php @@ -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(); diff --git a/public/include/classes/transaction.class.php b/public/include/classes/transaction.class.php index 3bb3e2a0..b706f7e4 100644 --- a/public/include/classes/transaction.class.php +++ b/public/include/classes/transaction.class.php @@ -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 diff --git a/public/include/pages/account/transactions.inc.php b/public/include/pages/account/transactions.inc.php index bd8f2aa4..a06eae61 100644 --- a/public/include/pages/account/transactions.inc.php +++ b/public/include/pages/account/transactions.inc.php @@ -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); diff --git a/public/include/pages/admin/transactions.inc.php b/public/include/pages/admin/transactions.inc.php index 505f25ab..92cdd2d8 100644 --- a/public/include/pages/admin/transactions.inc.php +++ b/public/include/pages/admin/transactions.inc.php @@ -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); diff --git a/public/templates/mmcFE/account/transactions/default.tpl b/public/templates/mmcFE/account/transactions/default.tpl index 5563aee4..62a32a17 100644 --- a/public/templates/mmcFE/account/transactions/default.tpl +++ b/public/templates/mmcFE/account/transactions/default.tpl @@ -1,3 +1,22 @@ +{include file="global/block_header.tpl" BLOCK_HEADER="Transaction Summary"} + + + + {foreach $SUMMARY as $type=>$total} + + {/foreach} + + + + + {foreach $SUMMARY as $type=>$total} + + {/foreach} + + +
{$type}
{$total}
+{include file="global/block_footer.tpl"} + {include file="global/block_header.tpl" ALIGN="left" BLOCK_STYLE="width: 23%" BLOCK_HEADER="Transaction Filter"}
diff --git a/public/templates/mmcFE/admin/transactions/default.tpl b/public/templates/mmcFE/admin/transactions/default.tpl index cbbc7e86..cc2693d9 100644 --- a/public/templates/mmcFE/admin/transactions/default.tpl +++ b/public/templates/mmcFE/admin/transactions/default.tpl @@ -1,3 +1,22 @@ +{include file="global/block_header.tpl" BLOCK_HEADER="Transaction Summary"} + + + + {foreach $SUMMARY as $type=>$total} + + {/foreach} + + + + + {foreach $SUMMARY as $type=>$total} + + {/foreach} + + +
{$type}
{$total}
+{include file="global/block_footer.tpl"} + {include file="global/block_header.tpl" ALIGN="left" BLOCK_STYLE="width: 23%" BLOCK_HEADER="Transaction Filter"}