From 1960df0d9149de0e161fd18d0c1e450c50db3653 Mon Sep 17 00:00:00 2001 From: iAmShorty Date: Mon, 3 Mar 2014 16:59:06 +0100 Subject: [PATCH] [UPDATE] updated query and template --- public/include/classes/transaction.class.php | 45 +++++++++--- public/include/pages/account/earnings.inc.php | 16 +---- .../bootstrap/account/earnings/default.tpl | 69 +++++++++---------- 3 files changed, 72 insertions(+), 58 deletions(-) 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 @@ Credit Debit AP Debit MP - TXFee + Donation {if $GLOBAL.fees > 0} Fee {/if} - Donation + TXFee Last Hour - {$CREDIT.HourlyTrans|number_format:"8"} - {$DEBITAP.HourlyTrans|number_format:"8"} - {$DEBITMP.HourlyTrans|number_format:"8"} - {$TXFEE.HourlyTrans|number_format:"8"} + {$BYTIME.1HourCredit|number_format:"8"} + {$BYTIME.1HourDebitAP|number_format:"8"} + {$BYTIME.1HourDebitMP|number_format:"8"} + {$BYTIME.1HourDonation|number_format:"8"} {if $GLOBAL.fees|default:"0" > 0} - {$FEE.HourlyTrans|number_format:"8"} + {$BYTIME.1HourFee|number_format:"8"} {/if} - {$DONATION.HourlyTrans|number_format:"8"} + {$BYTIME.1HourTXFee|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"} + {$BYTIME.24HourCredit|number_format:"8"} + {$BYTIME.24HourDebitAP|number_format:"8"} + {$BYTIME.24HourDebitMP|number_format:"8"} + {$BYTIME.24HourDonation|number_format:"8"} {if $GLOBAL.fees|default:"0" > 0} - {$FEE.DailyTrans|number_format:"8"} + {$BYTIME.24HourFee|number_format:"8"} {/if} - {$DONATION.DailyTrans|number_format:"8"} + {$BYTIME.24HourTXFee|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"} + {$BYTIME.1WeekCredit|number_format:"8"} + {$BYTIME.1WeekDebitAP|number_format:"8"} + {$BYTIME.1WeekDebitMP|number_format:"8"} + {$BYTIME.1WeekDonation|number_format:"8"} {if $GLOBAL.fees|default:"0" > 0} - {$FEE.WeeklyTrans|number_format:"8"} + {$BYTIME.1WeekFee|number_format:"8"} {/if} - {$DONATION.WeeklyTrans|number_format:"8"} + {$BYTIME.1WeekTXFee|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"} + {$BYTIME.1MonthCredit|number_format:"8"} + {$BYTIME.1MonthDebitAP|number_format:"8"} + {$BYTIME.1MonthDebitMP|number_format:"8"} + {$BYTIME.1MonthDonation|number_format:"8"} {if $GLOBAL.fees|default:"0" > 0} - {$FEE.MonthlyTrans|number_format:"8"} + {$BYTIME.1MonthFee|number_format:"8"} {/if} - {$DONATION.MonthlyTrans|number_format:"8"} + {$BYTIME.1MonthTXFee|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"} + {$BYTIME.1YearCredit|number_format:"8"} + {$BYTIME.1YearDebitAP|number_format:"8"} + {$BYTIME.1YearDebitMP|number_format:"8"} + {$BYTIME.1YearDonation|number_format:"8"} {if $GLOBAL.fees|default:"0" > 0} - {$FEE.YearlyTrans|number_format:"8"} + {$BYTIME.1YearFee|number_format:"8"} {/if} - {$DONATION.YearlyTrans|number_format:"8"} + {$BYTIME.1YearTXFee|number_format:"8"} @@ -117,6 +117,7 @@ + @@ -124,7 +125,3 @@ {/if} - - - -