diff --git a/public/include/classes/transaction.class.php b/public/include/classes/transaction.class.php index fab7cf57..272f488d 100644 --- a/public/include/classes/transaction.class.php +++ b/public/include/classes/transaction.class.php @@ -100,6 +100,47 @@ class Transaction extends Base { return $this->sqlError(); } + /** + * Fetch a transaction summary by user with total amounts + * @param account_id int Account ID, NULL for all + * @return data array type and total + **/ + public function getTransactionSummarybyTime($account_id=NULL) { + if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data; + $sql = " + SELECT + SUM(t.amount) AS total, + t.type AS type + FROM transactions AS t + LEFT OUTER JOIN blocks AS b + ON b.id = t.block_id + WHERE ( b.confirmations > 0 OR b.id IS NULL )"; + if (!empty($account_id)) { + $sql .= " AND 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']; + } + // Cache data for a while, query takes long on many rows + return $this->memcache->setCache(__FUNCTION__ . $account_id, $aData, 60); + } + return $this->sqlError(); + } + /** * Get all transactions from start for account_id * @param start int Starting point, id of transaction diff --git a/public/include/pages/account/earnings.inc.php b/public/include/pages/account/earnings.inc.php new file mode 100644 index 00000000..1e31c4f7 --- /dev/null +++ b/public/include/pages/account/earnings.inc.php @@ -0,0 +1,22 @@ +isAuthenticated() || !$user->isAdmin($_SESSION['USERDATA']['id'])) { + header("HTTP/1.1 404 Page not found"); + die("404 Page not found"); +} + +if (!$smarty->isCached('master.tpl', $smarty_cache_key)) { + $iLimit = 30; + $debug->append('No cached version available, fetching from backend', 3); + if (!$setting->getValue('disable_transactionsummary')) { + $aTransactionSummary = $transaction->getTransactionSummarybyTime($_SESSION['USERDATA']['id']); + $smarty->assign('SUMMARY', $aTransactionSummary); + } +} else { + $debug->append('Using cached page', 3); +} + +$smarty->assign('CONTENT', 'default.tpl'); +?> diff --git a/public/templates/bootstrap/account/earnings/default.tpl b/public/templates/bootstrap/account/earnings/default.tpl new file mode 100755 index 00000000..57bb5b0d --- /dev/null +++ b/public/templates/bootstrap/account/earnings/default.tpl @@ -0,0 +1,31 @@ +{if $DISABLE_TRANSACTIONSUMMARY|default:"0" != 1} +
+
+
+
+ Total Earning Stats +
+
+
+ + + + {foreach $SUMMARY as $type=>$total} + + {/foreach} + + + + + {foreach $SUMMARY as $type=>$total} + + {/foreach} + + +
{$type}
{$total|number_format:"8"}
+
+
+
+
+
+{/if} \ No newline at end of file diff --git a/public/templates/bootstrap/admin/dashboard/default.tpl b/public/templates/bootstrap/admin/dashboard/default.tpl index 7d55a7a1..beb617c1 100644 --- a/public/templates/bootstrap/admin/dashboard/default.tpl +++ b/public/templates/bootstrap/admin/dashboard/default.tpl @@ -1,9 +1,6 @@ {nocache} - {include file="admin/dashboard/mpos.tpl"} - {include file="admin/dashboard/user.tpl"} -
{include file="admin/dashboard/registrations.tpl"} {if $GLOBAL.config.disable_invitations|default:"0" == 0} diff --git a/public/templates/bootstrap/admin/registrations/default.tpl b/public/templates/bootstrap/admin/registrations/default.tpl index 75600ed7..1bbaba47 100644 --- a/public/templates/bootstrap/admin/registrations/default.tpl +++ b/public/templates/bootstrap/admin/registrations/default.tpl @@ -25,7 +25,7 @@ {$LASTREGISTEREDUSERS[user].mposuser} {$LASTREGISTEREDUSERS[user].email} {$LASTREGISTEREDUSERS[user].signup_timestamp|date_format:"%d/%m %H:%M:%S"} - {if !$LASTREGISTEREDUSERS[user].inviter}{else}{/if} + {if !$LASTREGISTEREDUSERS[user].inviter}{else}{/if} {$LASTREGISTEREDUSERS[user].inviter} {/section} diff --git a/public/templates/bootstrap/global/navigation.tpl b/public/templates/bootstrap/global/navigation.tpl index bcacfb60..f2fc7929 100644 --- a/public/templates/bootstrap/global/navigation.tpl +++ b/public/templates/bootstrap/global/navigation.tpl @@ -15,6 +15,7 @@
  • Edit Account
  • My Workers
  • Transactions
  • +
  • Earnings
  • {if !$GLOBAL.config.disable_notifications}
  • Notifications
  • {/if} {if !$GLOBAL.config.disable_invitations}
  • Invitations
  • {/if}
  • QR Codes