diff --git a/public/include/classes/transaction.class.php b/public/include/classes/transaction.class.php index 005eb430..6903299d 100644 --- a/public/include/classes/transaction.class.php +++ b/public/include/classes/transaction.class.php @@ -106,22 +106,51 @@ class Transaction extends Base { * @param account_id int Account ID, NULL for all * @return data array type and total **/ - public function getTransactionTypebyTime($account_id=NULL, $type=NULL) { + public function getTransactionTypebyTime($account_id=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 + IFNULL(SUM(IF(t.type = 'Credit' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 SECOND), t.amount, 0)), 0) AS 1HourCredit, + IFNULL(SUM(IF(t.type = 'Debit_MP' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 SECOND), t.amount, 0)), 0) AS 1HourDebitMP, + IFNULL(SUM(IF(t.type = 'Debit_AP' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 SECOND), t.amount, 0)), 0) AS 1HourDebitAP, + IFNULL(SUM(IF(t.type = 'TXFee' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 SECOND), t.amount, 0)), 0) AS 1HourTXFee, + IFNULL(SUM(IF(t.type = 'Fee' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 SECOND), t.amount, 0)), 0) AS 1HourFee, + IFNULL(SUM(IF(t.type = 'Donation' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 SECOND), t.amount, 0)), 0) AS 1HourDonation, + + IFNULL(SUM(IF(t.type = 'Credit' AND timestamp >= DATE_SUB(now(), INTERVAL 86400 SECOND), t.amount, 0)), 0) AS 24HourCredit, + IFNULL(SUM(IF(t.type = 'Debit_MP' AND timestamp >= DATE_SUB(now(), INTERVAL 86400 SECOND), t.amount, 0)), 0) AS 24HourDebitMP, + IFNULL(SUM(IF(t.type = 'Debit_AP' AND timestamp >= DATE_SUB(now(), INTERVAL 86400 SECOND), t.amount, 0)), 0) AS 24HourDebitAP, + IFNULL(SUM(IF(t.type = 'TXFee' AND timestamp >= DATE_SUB(now(), INTERVAL 86400 SECOND), t.amount, 0)), 0) AS 24HourTXFee, + IFNULL(SUM(IF(t.type = 'Fee' AND timestamp >= DATE_SUB(now(), INTERVAL 86400 SECOND), t.amount, 0)), 0) AS 24HourFee, + IFNULL(SUM(IF(t.type = 'Donation' AND timestamp >= DATE_SUB(now(), INTERVAL 86400 SECOND), t.amount, 0)), 0) AS 24HourDonation, + + IFNULL(SUM(IF(t.type = 'Credit' AND timestamp >= DATE_SUB(now(), INTERVAL 604800 SECOND), t.amount, 0)), 0) AS 1WeekCredit, + IFNULL(SUM(IF(t.type = 'Debit_MP' AND timestamp >= DATE_SUB(now(), INTERVAL 604800 SECOND), t.amount, 0)), 0) AS 1WeekDebitMP, + IFNULL(SUM(IF(t.type = 'Debit_AP' AND timestamp >= DATE_SUB(now(), INTERVAL 604800 SECOND), t.amount, 0)), 0) AS 1WeekDebitAP, + IFNULL(SUM(IF(t.type = 'TXFee' AND timestamp >= DATE_SUB(now(), INTERVAL 604800 SECOND), t.amount, 0)), 0) AS 1WeekTXFee, + IFNULL(SUM(IF(t.type = 'Fee' AND timestamp >= DATE_SUB(now(), INTERVAL 604800 SECOND), t.amount, 0)), 0) AS 1WeekFee, + IFNULL(SUM(IF(t.type = 'Donation' AND timestamp >= DATE_SUB(now(), INTERVAL 604800 SECOND), t.amount, 0)), 0) AS 1WeekDonation, + + IFNULL(SUM(IF(t.type = 'Credit' AND timestamp >= DATE_SUB(now(), INTERVAL 2419200 SECOND), t.amount, 0)), 0) AS 1MonthCredit, + IFNULL(SUM(IF(t.type = 'Debit_MP' AND timestamp >= DATE_SUB(now(), INTERVAL 2419200 SECOND), t.amount, 0)), 0) AS 1MonthDebitMP, + IFNULL(SUM(IF(t.type = 'Debit_AP' AND timestamp >= DATE_SUB(now(), INTERVAL 2419200 SECOND), t.amount, 0)), 0) AS 1MonthDebitAP, + IFNULL(SUM(IF(t.type = 'TXFee' AND timestamp >= DATE_SUB(now(), INTERVAL 2419200 SECOND), t.amount, 0)), 0) AS 1MonthTXFee, + IFNULL(SUM(IF(t.type = 'Fee' AND timestamp >= DATE_SUB(now(), INTERVAL 2419200 SECOND), t.amount, 0)), 0) AS 1MonthFee, + IFNULL(SUM(IF(t.type = 'Donation' AND timestamp >= DATE_SUB(now(), INTERVAL 2419200 SECOND), t.amount, 0)), 0) AS 1MonthDonation, + + IFNULL(SUM(IF(t.type = 'Credit' AND timestamp >= DATE_SUB(now(), INTERVAL 31536000 SECOND), t.amount, 0)), 0) AS 1YearCredit, + IFNULL(SUM(IF(t.type = 'Debit_MP' AND timestamp >= DATE_SUB(now(), INTERVAL 31536000 SECOND), t.amount, 0)), 0) AS 1YearDebitMP, + IFNULL(SUM(IF(t.type = 'Debit_AP' AND timestamp >= DATE_SUB(now(), INTERVAL 31536000 SECOND), t.amount, 0)), 0) AS 1YearDebitAP, + IFNULL(SUM(IF(t.type = 'TXFee' AND timestamp >= DATE_SUB(now(), INTERVAL 31536000 SECOND), t.amount, 0)), 0) AS 1YearTXFee, + IFNULL(SUM(IF(t.type = 'Fee' AND timestamp >= DATE_SUB(now(), INTERVAL 31536000 SECOND), t.amount, 0)), 0) AS 1YearFee, + IFNULL(SUM(IF(t.type = 'Donation' AND timestamp >= DATE_SUB(now(), INTERVAL 31536000 SECOND), t.amount, 0)), 0) AS 1YearDonation FROM transactions AS t 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)"); + t.account_id = ? AND (b.confirmations > 0 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->memcache->setCache(__FUNCTION__ . $account_id, $result->fetch_assoc(), 60); return $this->sqlError(); } diff --git a/public/include/pages/account/earnings.inc.php b/public/include/pages/account/earnings.inc.php index 50b946c0..03e6e48f 100644 --- a/public/include/pages/account/earnings.inc.php +++ b/public/include/pages/account/earnings.inc.php @@ -12,21 +12,9 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) { $debug->append('No cached version available, fetching from backend', 3); if (!$setting->getValue('disable_transactionsummary')) { $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'); - + $aTransactionSummaryByTime = $transaction->getTransactionTypebyTime($_SESSION['USERDATA']['id']); $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); + $smarty->assign('BYTIME', $aTransactionSummaryByTime); } } 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 index f1ac9356..896fedec 100644 --- a/public/templates/bootstrap/account/earnings/default.tpl +++ b/public/templates/bootstrap/account/earnings/default.tpl @@ -48,68 +48,68 @@