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()));
    }
    /**
     * returns recordset with commission objects
     *
     * @param string $commissionGroupId
     * @param string $commissionTypeId
     * @return Gpf_DbEngine_Row_Collection <Pap_Db_Commission>
     */
    public function getCommissionsCollection($commissionGroupId, $commissionTypeId) {
        $commission = new Pap_Db_Commission();
        $commission->setGroupId($commissionGroupId);
        $commission->setTypeId($commissionTypeId);

        try {
            return $commission->loadCollection();
        } catch (Gpf_DbEngine_NoRowException $e) {
            throw new Gpf_Exception("Cannot load commission settings for comgroupid=".$commissionGroupId.", commtypeid=".$commissionTypeId);
        }
    }
    private function saveCommissionRecord($tier, $subtype, $commissionType, $commissionValue) {
        $commission = new Pap_Db_Commission();
        $commission->setTier($tier);
        $commission->setSubtype($subtype);
        $commission->setGroupId($this->commissionGroupId);
        $commission->setTypeId($this->commissionTypeId);
        if ($commissionValue == null) {
            $commissionValue = 0;
        }

        try {
            $commission->loadFromData();
            // loaded, change commission value and save
            $commission->setCommType($commissionType);
            $commission->setCommission($commissionValue);
            $commission->save();
        } catch(Gpf_DbEngine_NoRowException $e) {
            // doesn't exist, insert new record
            $commission->setCommType($commissionType);
            $commission->setCommission($commissionValue);
            $commission->insert();
        } catch(Gpf_DbEngine_TooManyRowsException $e) {
            // there are multiple rows, it is a mistake
            $commission->deleteUnusedCommissions($tier, $subtype, $this->commissionGroupId, $this->commissionTypeId, 'exact');
            $commission->setCommType($commissionType);
            $commission->setCommission($commissionValue);
            $commission->insert();
        }
    }