diff --git a/public/earnings.png b/public/earnings.png
new file mode 100644
index 00000000..3eb4cbbc
Binary files /dev/null and b/public/earnings.png differ
diff --git a/public/include/classes/transaction.class.php b/public/include/classes/transaction.class.php
index 272f488d..005eb430 100644
--- a/public/include/classes/transaction.class.php
+++ b/public/include/classes/transaction.class.php
@@ -100,44 +100,28 @@ 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
+ public function getTransactionTypebyTime($account_id=NULL, $type=NULL) {
+ $this->debug->append("STA " . __METHOD__, 4);
+ if ($data = $this->memcache->get(__FUNCTION__)) return $data;
+ $stmt = $this->mysqli->prepare("
+ SELECT
+ IFNULL(SUM(IF(t.type = '" . $type ."' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 SECOND), t.amount, 0)), 0) AS HourlyTrans,
+ IFNULL(SUM(IF(t.type = '" . $type ."' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 * 24 SECOND), t.amount, 0)), 0) AS DailyTrans,
+ IFNULL(SUM(IF(t.type = '" . $type ."' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 * 24 * 7 SECOND), t.amount, 0)), 0) AS WeeklyTrans,
+ IFNULL(SUM(IF(t.type = '" . $type ."' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 * 24 * 30 SECOND), t.amount, 0)), 0) AS MonthlyTrans,
+ IFNULL(SUM(IF(t.type = '" . $type ."' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 * 24 * 30 * 12 SECOND), t.amount, 0)), 0) AS YearlyTrans
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);
- }
+ LEFT OUTER JOIN blocks AS b ON b.id = t.block_id
+ WHERE
+ t.account_id = ? AND (b.confirmations > 120 OR b.id IS NULL)");
+ if ($this->checkStmt($stmt) && $stmt->bind_param("i", $account_id) && $stmt->execute() && $result = $stmt->get_result())
+ return $this->memcache->setCache(__FUNCTION__, $result->fetch_assoc());
return $this->sqlError();
}
diff --git a/public/include/pages/account/earnings.inc.php b/public/include/pages/account/earnings.inc.php
index 1e31c4f7..50b946c0 100644
--- a/public/include/pages/account/earnings.inc.php
+++ b/public/include/pages/account/earnings.inc.php
@@ -11,8 +11,22 @@ 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']);
+ $aTransactionSummary = $transaction->getTransactionSummary($_SESSION['USERDATA']['id']);
+
+ $aCredit = $transaction->getTransactionTypebyTime($_SESSION['USERDATA']['id'], 'CREDIT');
+ $aDebitAP = $transaction->getTransactionTypebyTime($_SESSION['USERDATA']['id'], 'DEBIT_AP');
+ $aDebitMP = $transaction->getTransactionTypebyTime($_SESSION['USERDATA']['id'], 'DEBIT_MP');
+ $aTXFee = $transaction->getTransactionTypebyTime($_SESSION['USERDATA']['id'], 'TXFee');
+ $aFee = $transaction->getTransactionTypebyTime($_SESSION['USERDATA']['id'], 'Fee');
+ $aDonation = $transaction->getTransactionTypebyTime($_SESSION['USERDATA']['id'], 'Donation');
+
$smarty->assign('SUMMARY', $aTransactionSummary);
+ $smarty->assign('CREDIT', $aCredit);
+ $smarty->assign('DEBITAP', $aDebitAP);
+ $smarty->assign('DEBITMP', $aDebitMP);
+ $smarty->assign('TXFEE', $aTXFee);
+ $smarty->assign('FEE', $aFee);
+ $smarty->assign('DONATION', $aDonation);
}
} else {
$debug->append('Using cached page', 3);
diff --git a/public/templates/bootstrap/account/earnings/default.tpl b/public/templates/bootstrap/account/earnings/default.tpl
old mode 100755
new mode 100644
index 57bb5b0d..f1ac9356
--- a/public/templates/bootstrap/account/earnings/default.tpl
+++ b/public/templates/bootstrap/account/earnings/default.tpl
@@ -3,29 +3,128 @@
- Total Earning Stats
+ Total {$GLOBAL.config.currency} Earning Reports
-
-
-
-
-
- {foreach $SUMMARY as $type=>$total}
- | {$type} |
- {/foreach}
-
-
-
-
- {foreach $SUMMARY as $type=>$total}
- | {$total|number_format:"8"} |
- {/foreach}
-
-
-
+
+
+
+
+
+ All Time
+
+
+
+
+
+ {foreach $SUMMARY as $type=>$total}
+ | {$type} |
+ {/foreach}
+
+
+
+
+ {foreach $SUMMARY as $type=>$total}
+ | {$total|number_format:"8"} |
+ {/foreach}
+
+
+
+
+
+
+
+
+
+
+
+
+ Sorted by Time
+
+
+
+
+
+ |
+ Credit |
+ Debit AP |
+ Debit MP |
+ TXFee |
+ {if $GLOBAL.fees > 0}
+ Fee |
+ {/if}
+ Donation |
+
+
+
+
+ | Last Hour
+ | {$CREDIT.HourlyTrans|number_format:"8"} |
+ {$DEBITAP.HourlyTrans|number_format:"8"} |
+ {$DEBITMP.HourlyTrans|number_format:"8"} |
+ {$TXFEE.HourlyTrans|number_format:"8"} |
+ {if $GLOBAL.fees|default:"0" > 0}
+ {$FEE.HourlyTrans|number_format:"8"} |
+ {/if}
+ {$DONATION.HourlyTrans|number_format:"8"} |
+
+
+ | Last Day
+ | {$CREDIT.DailyTrans|number_format:"8"} |
+ {$DEBITAP.DailyTrans|number_format:"8"} |
+ {$DEBITMP.DailyTrans|number_format:"8"} |
+ {$TXFEE.DailyTrans|number_format:"8"} |
+ {if $GLOBAL.fees|default:"0" > 0}
+ {$FEE.DailyTrans|number_format:"8"} |
+ {/if}
+ {$DONATION.DailyTrans|number_format:"8"} |
+
+
+ | Last Week
+ | {$CREDIT.WeeklyTrans|number_format:"8"} |
+ {$DEBITAP.WeeklyTrans|number_format:"8"} |
+ {$DEBITMP.WeeklyTrans|number_format:"8"} |
+ {$TXFEE.WeeklyTrans|number_format:"8"} |
+ {if $GLOBAL.fees|default:"0" > 0}
+ {$FEE.WeeklyTrans|number_format:"8"} |
+ {/if}
+ {$DONATION.WeeklyTrans|number_format:"8"} |
+
+
+ | Last Month
+ | {$CREDIT.MonthlyTrans|number_format:"8"} |
+ {$DEBITAP.MonthlyTrans|number_format:"8"} |
+ {$DEBITMP.MonthlyTrans|number_format:"8"} |
+ {$TXFEE.MonthlyTrans|number_format:"8"} |
+ {if $GLOBAL.fees|default:"0" > 0}
+ {$FEE.MonthlyTrans|number_format:"8"} |
+ {/if}
+ {$DONATION.MonthlyTrans|number_format:"8"} |
+
+
+ | Last Year
+ | {$CREDIT.YearlyTrans|number_format:"8"} |
+ {$DEBITAP.YearlyTrans|number_format:"8"} |
+ {$DEBITMP.YearlyTrans|number_format:"8"} |
+ {$TXFEE.YearlyTrans|number_format:"8"} |
+ {if $GLOBAL.fees|default:"0" > 0}
+ {$FEE.YearlyTrans|number_format:"8"} |
+ {/if}
+ {$DONATION.YearlyTrans|number_format:"8"} |
+
+
+
+
+
+
-{/if}
\ No newline at end of file
+{/if}
+
+
+
+
+
+
diff --git a/public/templates/bootstrap/account/earnings/default.tpl-b330233e-4d93-45b2-b7d4-8fcedc058927 b/public/templates/bootstrap/account/earnings/default.tpl-b330233e-4d93-45b2-b7d4-8fcedc058927
new file mode 100644
index 00000000..91e08685
--- /dev/null
+++ b/public/templates/bootstrap/account/earnings/default.tpl-b330233e-4d93-45b2-b7d4-8fcedc058927
@@ -0,0 +1,85 @@
+{if $DISABLE_TRANSACTIONSUMMARY|default:"0" != 1}
+
+
+
+
+ Total Earning Stats
+
+
+
+
+
+
+ |
+ {foreach $SUMMARY as $type=>$total}
+ {$type} |
+ {/foreach}
+
+
+
+
+ | All Time |
+ {foreach $SUMMARY as $type=>$total}
+ {$total|number_format:"8"} |
+ {/foreach}
+
+ 1 Hour |
+ {$DEBITAP_HOUR|number_format:"8" + $DEBITMP_HOUR|number_format:"8"} |
+ {$DEBITAP_HOUR|number_format:"8"} |
+ {$DEBITMP_HOUR|number_format:"8"} |
+ {$TXFEE_HOUR|number_format:"8"} |
+ {if $GLOBAL.fees|default:"0" > 0}
+ {$FEE_HOUR|number_format:"8"} |
+ {/if}
+ {$DONATION_HOUR|number_format:"8"} |
+
+
+ | 1 Day |
+ {$DEBITAP_DAY|number_format:"8" + $DEBITMP_DAY|number_format:"8"} |
+ {$DEBITAP_DAY|number_format:"8"} |
+ {$DEBITMP_DAY|number_format:"8"} |
+ {$TXFEE_DAY|number_format:"8"} |
+ {if $GLOBAL.fees|default:"0" > 0}
+ {$FEE_DAY|number_format:"8"} |
+ {/if}
+ {$DONATION_DAY|number_format:"8"} |
+
+
+ | 1 Week |
+ {$DEBITAP_WEEK|number_format:"8" + $DEBITMP_WEEK|number_format:"8"} |
+ {$DEBITAP_WEEK|number_format:"8"} |
+ {$DEBITMP_WEEK|number_format:"8"} |
+ {$TXFEE_WEEK|number_format:"8"} |
+ {if $GLOBAL.fees|default:"0" > 0}
+ {$FEE_WEEK|number_format:"8"} |
+ {/if}
+ {$DONATION_WEEK|number_format:"8"} |
+
+
+ | 1 Month |
+ {$DEBITAP_MONTH|number_format:"8" + $DEBITMP_MONTH|number_format:"8"} |
+ {$DEBITAP_MONTH|number_format:"8"} |
+ {$DEBITMP_MONTH|number_format:"8"} |
+ {$TXFEE_MONTH|number_format:"8"} |
+ {if $GLOBAL.fees|default:"0" > 0}
+ {$FEE_MONTH|number_format:"8"} |
+ {/if}
+ {$DONATION_MONTH|number_format:"8"} |
+
+
+ | 1 Year |
+ {$DEBITAP_YEAR + $DEBITMP_YEAR} |
+ {$DEBITAP_YEAR|number_format:"8"} |
+ {$DEBITMP_YEAR|number_format:"8"} |
+ {$TXFEE_YEAR|number_format:"8"} |
+ {if $GLOBAL.fees|default:"0" > 0}
+ {$FEE_YEAR|number_format:"8"} |
+ {/if}
+ {$DONATION_YEAR|number_format:"8"} |
+
+
+
+
+
+
+{/if}