protected function insertBonusTransaction($commissionValue) {
     $transaction = new Pap_Common_Transaction();
     $transaction->setCommission($commissionValue);
     $transaction->setType(Pap_Db_Transaction::TYPE_EXTRA_BONUS);
     $transaction->setDateInserted(Gpf_Common_DateUtils::now());
     $transaction->setStatus('A');
     $transaction->setPayoutStatus('U');
     $transaction->setUserId($this->getCurrentUserId());
     $transaction->setCampaignId($this->transaction->getCampaignId());
     $transaction->setSystemNote('Commission of rule: ' . $this->rule->getString());
     $transaction->setData1($this->rule->getId());
     $transaction->setData2($this->getToDateRange());
     $transaction->insert();
 }
    public function createCommissions() {
        $comissionEntry = new Pap_Db_RecurringCommissionEntry();
        $comissionEntry->setRecurringCommissionId($this->getId());
        try {
            $parentTransaction = $this->getTransaction();
        } catch (Gpf_Exception $e) {
            $parentTransaction = null;
        }
        foreach ($comissionEntry->loadCollection() as $comissionEntry) {
            if (!$this->isExistsUser($comissionEntry->getUserId())) {
                Gpf_log::error('Recurring commissions - createCommissions: user does not exist: ' . $comissionEntry->getUserId());
                if ($comissionEntry->getTier() == '1') {
                    return;
                } else {
                    continue;
                }
            }
            $transaction = new Pap_Common_Transaction();
            $transaction->setDateInserted(Gpf_Common_DateUtils::now());
            $transaction->setType(Pap_Common_Constants::TYPE_RECURRING);
            $transaction->setTier($comissionEntry->getTier());
            $transaction->setUserId($comissionEntry->getUserId());
            $transaction->setCommissionTypeId($this->getCommissionTypeId());
            $transaction->setParentTransactionId($this->getTransactionId());
            $transaction->setCommission($comissionEntry->getCommission());
            $transaction->setPayoutStatus(Pap_Common_Transaction::PAYOUT_UNPAID);
            $transaction->setStatus(Pap_Common_Constants::STATUS_APPROVED);
            $transaction->setOrderId($this->getOrderId());

            if ($parentTransaction != null) {
                if ($transaction->getOrderId() == '') {
                    $transaction->setOrderId($parentTransaction->getOrderId());
                }
                $transaction->setProductId($parentTransaction->getProductId());
                $transaction->setTotalCost($parentTransaction->getTotalCost());
                $transaction->setCampaignId($parentTransaction->getCampaignId());
                $transaction->setBannerId($parentTransaction->getBannerId());
                $transaction->setParentBannerId($parentTransaction->getParentBannerId());
                $transaction->setCountryCode($parentTransaction->getCountryCode());
                $transaction->setData1($parentTransaction->getData1());
                $transaction->setData2($parentTransaction->getData2());
                $transaction->setData3($parentTransaction->getData3());
                $transaction->setData4($parentTransaction->getData4());
                $transaction->setData5($parentTransaction->getData5());
            }

            $transaction->save();
        }
    }
    private function initTransactionObject(Pap_Contexts_Click $context) {
        $transaction = new Pap_Common_Transaction();

        $transaction->setTotalCost('');

        $transaction->generateNewTransactionId();
        $transaction->setData1($context->getExtraDataFromRequest(1));
        $transaction->setData2($context->getExtraDataFromRequest(2));
        $transaction->set(Pap_Db_Table_Transactions::REFERER_URL, $context->getReferrerUrl());
        $transaction->set(Pap_Db_Table_Transactions::IP, $context->getIp());
        $transaction->set(Pap_Db_Table_Transactions::BROWSER, $context->getUserAgent());
        $transaction->setType(Pap_Common_Constants::TYPE_CLICK);
        $transaction->setDateInserted($context->getVisitDateTime());
        if ($context->getVisit()!= null && $context->getVisit()->getCountryCode() != '') {
            $transaction->setCountryCode($context->getVisit()->getCountryCode());
        }
        $context->setTransactionObject($transaction);
        $context->debug("Transaction object set");
    }