diff --git a/cronjobs/pps_payout.php b/cronjobs/pps_payout.php index 329104c5..848b9d5c 100755 --- a/cronjobs/pps_payout.php +++ b/cronjobs/pps_payout.php @@ -58,14 +58,19 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { if (!$block->setShares($aBlock['id'], $iRoundShares)) $strStatus = "Shares Failed"; verbose("\t\t$strStatus\n\n"); - verbose("ID\tUsername\tValid\tInvalid\tPercentage\tPayout\t\tDonation\t\tStatus\n"); + verbose("ID\tUsername\tValid\tInvalid\tPercentage\tPayout\t\tDonation\tFee\t\tStatus\n"); foreach ($aAccountShares as $key => $aData) { // Payout based on shares, PPS system $aData['percentage'] = number_format(round(( 100 / $iRoundShares ) * $aData['valid'], 8), 8); $aData['payout'] = number_format(round(( $aData['percentage'] / 100 ) * $config['reward'], 8), 8); + // Defaults + $aData['fee' ] = 0; + $aData['donation'] = 0; - // Calculate donation amount for Donation transaction - $aData['donation'] = number_format(round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * $aData['payout'], 8), 8); + if ($config['fees'] > 0) + $aData['fee'] = number_format(round($config['fees'] / 100 * $aData['payout'], 8), 8); + // Calculate donation amount, fees not included + $aData['donation'] = number_format(round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8), 8); // Verbose output of this users calculations verbose($aData['id'] . "\t" . @@ -74,7 +79,8 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { $aData['invalid'] . "\t" . $aData['percentage'] . "\t" . $aData['payout'] . "\t" . - $aData['donation'] . "\t"); + $aData['donation'] . "\t" . + $aData['fee'] . "\t"); $strStatus = "OK"; // Update user share statistics @@ -84,11 +90,13 @@ foreach ($aAllBlocks as $iIndex => $aBlock) { if (!$transaction->addTransaction($aData['id'], $aData['payout'], 'Credit', $aBlock['id'])) $strStatus = "Transaction Failed"; // Add new donation debit - if ($aData['donation'] > 0) { + if ($aData['donation'] > 0) if (!$transaction->addTransaction($aData['id'], $aData['donation'], 'Donation', $aBlock['id'])) $strStatus = "Donation Failed"; - } - verbose("\t\t$strStatus\n"); + if ($aData['fee'] > 0 && $config['fees'] > 0) + if (!$transaction->addTransaction($aData['id'], $aData['fee'], 'Fee', $aBlock['id'])) + $strStatus = "Fee Failed"; + verbose("\t$strStatus\n"); } verbose("------------------------------------------------------------------------\n\n"); diff --git a/public/include/classes/transaction.class.php b/public/include/classes/transaction.class.php index 5fff814b..7f8cd76d 100644 --- a/public/include/classes/transaction.class.php +++ b/public/include/classes/transaction.class.php @@ -25,10 +25,10 @@ class Transaction { return $this->sError; } - public function addTransaction($account_id, $amount, $type='Credit', $block_id=NULL, $coin_address=NULL, $fee=0) { - $stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, amount, block_id, type, coin_address, fee_amount) VALUES (?, ?, ?, ?, ?, ?)"); + public function addTransaction($account_id, $amount, $type='Credit', $block_id=NULL, $coin_address=NULL) { + $stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, amount, block_id, type, coin_address) VALUES (?, ?, ?, ?, ?)"); if ($this->checkStmt($stmt)) { - $stmt->bind_param("idissd", $account_id, $amount, $block_id, $type, $coin_address, $fee); + $stmt->bind_param("idiss", $account_id, $amount, $block_id, $type, $coin_address); if ($stmt->execute()) { $this->setErrorMessage("Failed to store transaction"); $stmt->close(); @@ -96,7 +96,7 @@ 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') + WHERE t.type IN ('Donation','Fee') AND b.confirmations >= ? AND t.account_id = ? ) AS t3 diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index a6cbcb3e..4d55829e 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -20,6 +20,7 @@ $aGlobal = array( 'sharerate' => $iCurrentPoolShareRate, 'workers' => $iCurrentActiveWorkers, 'roundshares' => $aRoundShares, + 'fees' => $config['fees'], 'confirmations' => $config['confirmations'], 'reward' => $config['reward'] ); @@ -32,6 +33,12 @@ $aGlobal['userdata']['balance'] = $transaction->getBalance($_SESSION['USERDATA'] $aGlobal['userdata']['shares'] = $statistics->getUserShares($_SESSION['USERDATA']['id']); $aGlobal['userdata']['hashrate'] = $statistics->getUserHashrate($_SESSION['USERDATA']['id']); +// Some estimations +$aGlobal['userdata']['est_block'] = round(( (int)$aGlobal['userdata']['shares']['valid'] / (int)$aRoundShares['valid'] ) * (int)$config['reward'], 3); +$aGlobal['userdata']['est_donation'] = round((( $aGlobal['userdata']['donate_percent'] / 100) * $aGlobal['userdata']['est_block']), 3); +$aGlobal['userdata']['est_fee'] = round((($config['fees'] / 100) * ($aGlobal['userdata']['est_block'] - $aGlobal['userdata']['est_donation'])), 3); +$aGlobal['userdata']['est_payout'] = round($aGlobal['userdata']['est_block'] - $aGlobal['userdata']['est_donation'] - $aGlobal['userdata']['est_fee'], 3); + // Make it available in Smarty $smarty->assign('PATH', 'site_assets/' . THEME); $smarty->assign('GLOBAL', $aGlobal); diff --git a/public/templates/mmcFE/account/transactions/default.tpl b/public/templates/mmcFE/account/transactions/default.tpl index 4e490ad2..35ec2cc4 100644 --- a/public/templates/mmcFE/account/transactions/default.tpl +++ b/public/templates/mmcFE/account/transactions/default.tpl @@ -17,6 +17,7 @@ {if ( ($TRANSACTIONS[transaction].type == 'Credit' and $TRANSACTIONS[transaction].confirmations >= $GLOBAL.confirmations) or ($TRANSACTIONS[transaction].type == 'Donation' and $TRANSACTIONS[transaction].confirmations >= $GLOBAL.confirmations) + or ($TRANSACTIONS[transaction].type == 'Fee' and $TRANSACTIONS[transaction].confirmations >= $GLOBAL.confirmations) or $TRANSACTIONS[transaction].type == 'Debit_AP' or $TRANSACTIONS[transaction].type == 'Debit_MP' )} @@ -57,6 +58,7 @@ {if ( $TRANSACTIONS[transaction].type == 'Credit' && $TRANSACTIONS[transaction].confirmations < $GLOBAL.confirmations or ($TRANSACTIONS[transaction].type == 'Donation' and $TRANSACTIONS[transaction].confirmations < $GLOBAL.confirmations) + or ($TRANSACTIONS[transaction].type == 'Fee' and $TRANSACTIONS[transaction].confirmations < $GLOBAL.confirmations) )}