protected function recomputeCommissions() {
        $transactions = $this->getTransactionsSelect();
        $this->rule->setTransactionsWhere($transactions->where, 't');

        foreach ($transactions->getAllRowsIterator() as $record) {       	
            $newCommission = new Pap_Db_Commission();
            $newCommission->setTypeId($record->get(Pap_Db_Table_Transactions::COMMISSIONTYPEID));
            $newCommission->setTier($record->get(Pap_Db_Table_Transactions::TIER));
            $newCommission->setGroupId($this->rule->getCommissionGroupId());          
            if ($record->get(Pap_Db_Table_Transactions::R_TYPE) == Pap_Common_Constants::TYPE_RECURRING) { 
            	$newCommission->setSubtype(Pap_Db_Table_Commissions::SUBTYPE_RECURRING);
            } else {
            	$newCommission->setSubtype(Pap_Db_Table_Commissions::SUBTYPE_NORMAL);
            }
            try {
            	$newCommission->loadFromData();
            } catch (Exception $e) {
            	$this->logMessage(sprintf("Error loading commission (%s)", $e->getMessage()));
            	return;
            }            
            $transaction = new Pap_Db_Transaction();
            $transaction->fillFromRecord($record);
            $transaction->recompute($newCommission);            
            $transaction->update();         
            $refundTransaction = $transaction->getRefundOrChargebackTransaction();
            if (!is_null($refundTransaction) &&
                    $refundTransaction->getStatus() != Pap_Common_Constants::STATUS_DECLINED &&
                    $refundTransaction->getPayoutStatus() == Pap_Common_Constants::PSTATUS_UNPAID) {
                $refundTransaction->recompute($newCommission);
                $refundTransaction->update();
            }
        }
        $this->logMessage(sprintf("Transactions were updated based on new commission group %s", $this->rule->getCommissionGroupId()));
    }
 /**
  * @return Pap_Db_Transaction
  */
 public function getRefundOrChargebackTransaction() {
     $select = new Gpf_SqlBuilder_SelectBuilder();
     $select->select->addAll(Pap_Db_Table_Transactions::getInstance());
     $select->from->add(Pap_Db_Table_Transactions::getName());
     $select->where->add(Pap_Db_Table_Transactions::PARRENT_TRANSACTION_ID, '=', $this->getId());
     $select->where->add(Pap_Db_Table_Transactions::R_TYPE, 'IN', array(Pap_Db_Transaction::TYPE_REFUND, Pap_Db_Transaction::TYPE_CHARGE_BACK));
     try {
         $record = $select->getOneRow();
         $transaction = new Pap_Db_Transaction();
         $transaction->fillFromRecord($record);
         return $transaction;
     } catch (Gpf_Exception $e) {
         return null;
     }
 }