From 31de069533811ebb478079de708088ffc2aafd4e Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Mon, 10 Jun 2013 11:28:20 +0200 Subject: [PATCH] Changed getLockedBalance and added SQL * New SQL file for upgrade includes next changes * Properly calculate getLockedBalance based on shares Further addresses #70 --- public/include/classes/transaction.class.php | 16 +++++++++++----- sql/issue_70_transactions_upgrade.sql | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 sql/issue_70_transactions_upgrade.sql diff --git a/public/include/classes/transaction.class.php b/public/include/classes/transaction.class.php index 939684c4..4b304797 100644 --- a/public/include/classes/transaction.class.php +++ b/public/include/classes/transaction.class.php @@ -143,8 +143,11 @@ class Transaction { SELECT sum(t.amount) AS credit FROM $this->table AS t LEFT JOIN " . $this->block->getTableName() . " AS b ON t.block_id = b.id - WHERE t.type IN ('Credit', 'Credit_PPS') - AND b.confirmations >= " . $this->config['confirmations'] . " + WHERE + ( + ( t.type = 'Credit' AND b.confirmations >= ? ) OR + ( t.type = 'Credit_PPS' ) + ) ) AS t1, ( SELECT sum(t.amount) AS debit @@ -155,10 +158,13 @@ class Transaction { SELECT sum(t.amount) AS other FROM " . $this->table . " AS t LEFT JOIN " . $this->block->getTableName() . " AS b ON t.block_id = b.id - WHERE t.type IN ('Donation','Fee','Donation_PPS','Fee_PPS') - AND b.confirmations >= " . $this->config['confirmations'] . " + WHERE + ( + ( t.type IN ('Donation','Fee') AND b.confirmations >= ? ) OR + ( t.type IN ('Donation_PPS', 'Fee_PPS') ) + ) ) AS t3"); - if ($this->checkStmt($stmt) && $stmt->execute() && $stmt->bind_result($dBalance) && $stmt->fetch()) + if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $this->config['confirmations'], $this->config['confirmations']) && $stmt->execute() && $stmt->bind_result($dBalance) && $stmt->fetch()) return $dBalance; // Catchall $this->setErrorMessage('Unable to find locked credits for all users'); diff --git a/sql/issue_70_transactions_upgrade.sql b/sql/issue_70_transactions_upgrade.sql new file mode 100644 index 00000000..90561397 --- /dev/null +++ b/sql/issue_70_transactions_upgrade.sql @@ -0,0 +1 @@ +ALTER TABLE `transactions` CHANGE `type` `type` ENUM( 'Credit', 'Debit_MP', 'Debit_AP', 'Donation', 'Fee', 'Orphan_Credit', 'Orphan_Fee', 'Orphan_Donation', 'Bonus', 'Orphan_Bonus', 'Credit_PPS', 'Debit_PPS', 'Donation_PPS' ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL;