/**
     * @param Pap_Common_Transaction $transaction
     * @param $transactionHeader
     * @param $transactionData
     * @param $matchTransactionField
     * @return Pap_Common_Transaction
     */
    private function loadTransaction(Pap_Common_Transaction $transaction, $transactionHeader, $transactionData, $matchTransactionField) {
        Gpf_Log::info('Matching transaction by: ' . $matchTransactionField);
        $data = array_flip($transactionHeader);
        $orderId = $transactionData[$data[$matchTransactionField]];

        if(trim($orderId)!=''){
            $transaction->set($matchTransactionField, $orderId);
            try{
                $transaction->loadFromData(array($matchTransactionField));
            } catch (Gpf_DbEngine_NoRowException $e) {
                Gpf_Log::info('No transaction with '.$matchTransactionField.': '.$orderId.' found.');
            } catch (Gpf_DbEngine_TooManyRowsException $e) {
                Gpf_Log::info('Too many transactions with '.$matchTransactionField.': '.$orderId);
                throw new Gpf_Exception($this->_('Too many transactions with '.$matchTransactionField.': '.$orderId));
            }
        }
        return $transaction;
    }
    protected function insertSummarizedTransaction($record) {
    	$obj = new Pap_Common_Transaction();
    	
    	$obj->setUserId($record->get('affiliateid'));
    	$obj->setCampaignId($record->get('campaignid'));
		$obj->setDateInserted($record->get('dateinserted'));
		$obj->setType(Pap3Compatibility_Migration_Pap3Constants::translateTransType($record->get('transtype')));
		$obj->setAllowFirstClickData(GPF::YES);
        $obj->setAllowLastClickData(GPF::YES);
		$obj->setStatus(Pap3Compatibility_Migration_Pap3Constants::translateStatus($record->get('rstatus')));
		
		if($record->get('rstatus') == Pap3Compatibility_Migration_Pap3Constants::STATUS_APPROVED) {
			$obj->setDateApproved($record->get('dateinserted'));
		}
		
		$obj->setCommission($record->get('commission'));
		$obj->setSystemNote("Migrated from PAP3");
		if($record->get('payoutstatus') == 2) {
			$obj->setPayoutStatus('P');
		} else {
			$obj->setPayoutStatus('U');
		}
		$obj->setClickCount($record->get('count'));

		$transKind = $record->get('transkind');
		if($transKind > Pap3Compatibility_Migration_Pap3Constants::TRANSKIND_SECONDTIER) {
			$tier = $transKind - Pap3Compatibility_Migration_Pap3Constants::TRANSKIND_SECONDTIER;
		} else {
			$tier = 1;
		}
		$obj->setTier($tier);
		$obj->set('commtypeid', $record->get('campcategoryid'));
		
    	$obj->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");
    }