示例#1
0
	/**
	 * @return Pap_Common_User or null
	 */
	public function getParent(Pap_Common_User $child) {
        $parentUserId = $child->getParentUserId();
        if (!isset($this->parentUserCache[$parentUserId])) {
            if (is_array($this->affiliatesInDownline)) {
                $this->affiliatesInDownline[] = $child->getId();
                if (in_array($parentUserId, $this->affiliatesInDownline) || $child->getId() == $parentUserId) {
                    $child->setParentUserId('');
                    $child->save();
                    $this->parentUserCache[$parentUserId] = null;
                    return null;
                }
            }
            $this->parentUserCache[$parentUserId] = $child->getParentUser();
        }
        return $this->parentUserCache[$parentUserId];
    }
	/**
	 * @return Gpf_SqlBuilder_SelectBuilder
	 */
	private function createTransactionsSelect($from, $to){
		$selectBuilder = new Gpf_SqlBuilder_SelectBuilder();
		$selectBuilder->select->add("c.".Pap_Db_Table_Campaigns::NAME,'campaign_name');
		$selectBuilder->select->add("t.".Pap_Db_Table_Transactions::DATE_INSERTED,'created');
		$selectBuilder->select->add("t.".Pap_Db_Table_Transactions::COMMISSION);
		$selectBuilder->select->add("t.".Pap_Db_Table_Transactions::PRODUCT_ID);
		$selectBuilder->select->add("t.".Pap_Db_Table_Transactions::ORDER_ID);
		$selectBuilder->select->add("t.".Pap_Db_Table_Transactions::R_STATUS);
		if($this->isAffiliate()){
			$selectBuilder->where->add("t.".Pap_Db_Table_Transactions::USERID,'=',$this->user->getId());
		}
		$selectBuilder->from->add(Pap_Db_Table_Transactions::getName(), "t");
		$onCondition = "t.".Pap_Db_Table_Transactions::CAMPAIGN_ID." = c.".Pap_Db_Table_Campaigns::ID;
		$selectBuilder->from->addLeftJoin(Pap_Db_Table_Campaigns::getName(), 'c', $onCondition);
		if($this->isMerchant()){
			$selectBuilder->select->add("au.".Gpf_Db_Table_AuthUsers::FIRSTNAME,'affname');
			$selectBuilder->select->add("au.".Gpf_Db_Table_AuthUsers::LASTNAME,'affsurname');
			$selectBuilder->from->addInnerJoin(Pap_Db_Table_Users::getName(), "pu", "t.userid = pu.userid");
			$selectBuilder->from->addInnerJoin(Gpf_Db_Table_Users::getName(), "gu", "pu.accountuserid = gu.accountuserid");
			$selectBuilder->from->addInnerJoin(Gpf_Db_Table_AuthUsers::getName(), "au", "gu.authid = au.authid");
		}
		$selectBuilder->orderBy->add("t.".Pap_Db_Table_Transactions::DATE_INSERTED, false);
		$selectBuilder->limit->set($from, $to - $from);
		return $selectBuilder;
	}
	protected function addFillBonus(Pap_Common_User $user, $fillCount, $commission) {
		$transaction = new Pap_Common_Transaction();
		$transaction->setCommission($commission);
		$transaction->setType(Pap_Db_Transaction::TYPE_EXTRA_BONUS);
		$transaction->setDateInserted(Gpf_Common_DateUtils::now());
		$transaction->setStatus(Pap_Common_Constants::STATUS_APPROVED);
		$transaction->setPayoutStatus(Pap_Common_Constants::PSTATUS_UNPAID);
		$transaction->setUserId($user->getId());
		$transaction->setSystemNote($this->_('Matrix %sx fill bonus', $fillCount));
		$transaction->insert();
	}
示例#4
0
 private function getBaseCode(Pap_Common_User $user, $fileName = 'hover.php', $flags = '') {
     $url = Gpf_Paths::getInstance()->getFullBaseServerUrl() . "include/Pap/Features/HoverBanner/LyteBox/";
     $code = '<script type="text/javascript" src="'.
     $url . 'lytebox.js"></script>
             <link rel="stylesheet" href="'.
     $url . 'lytebox.css" type="text/css" media="screen" />
             <div id="' . $this->getId() . '" rel="lyteframe" rev="width: {$width}px; height: {$height}px; scrolling: no;" href="'.
     Gpf_Paths::getInstance()->getFullScriptsUrl() . $fileName .
             '?'.Gpf_Settings::get(Pap_Settings::PARAM_NAME_USER_ID).'='.$user->getId().
             '&amp;'.Gpf_Settings::get(Pap_Settings::PARAM_NAME_BANNER_ID).'='.$this->getId() . '"></div>';
     return $this->replaceWidthHeightConstants($code, $flags);
 }
示例#5
0
	/**
	 * @return Pap_Stats_Params
	 */
	private function getStatsParams() {
		$todayDate = $this->getDateArray(new Gpf_SqlBuilder_Filter(array("", "DP", "T")));

		$statsParams = new Pap_Stats_Params();

		$statsParams->setDateFrom(new Gpf_DateTime($todayDate["dateFrom"]));
		$statsParams->setDateTo(new Gpf_DateTime($todayDate["dateTo"]));

		if ($this->user->getType() == Pap_Application::ROLETYPE_AFFILIATE) {
			$statsParams->setAffiliateId($this->user->getId());
		}

		return $statsParams;
	}
示例#6
0
 /**
  * @param Pap_Common_User $user
  * @return string
  */
 public function getDescription(Pap_Common_User $user) {
     if ($user->getType() == Pap_Application::ROLETYPE_MERCHANT) {
         $description = $this->get(Pap_Db_Table_Banners::DATA1);
     } else {
         $description = $this->get(Pap_Db_Table_Banners::DATA2);
     }
     
     $description = str_replace('$Affiliate_id', $user->getId(), $description);
     $description = str_replace('$Affiliate_refid', $user->getRefId(), $description);
     $description = str_replace('$Affiliate_name', $user->getName(), $description);
     $description = str_replace('$Affiliate_username', $user->getUserName(), $description);
     
     return $description;
 }
    public function getUserFieldsValues($mainFields = null) {
        if($this->user == null) {
            throw new Gpf_Exception("You have to set User before getting user fields value!");
        }

        if (array_key_exists($this->user->getId(), $this->cache)) {
            return $this->cache[$this->user->getId()];
        }

        $fields = $this->getUserFields(array('M', 'O', 'R', 'D'), $mainFields);
        $result = array();
        foreach($fields as $code => $name) {
            $result[$code] = $this->getUserFieldValue($code);
        }
        $this->cache[$this->user->getId()] = $result;
        return $result;
    }
示例#8
0
    private function assignPayoutVariablesToTemplate(Gpf_Templates_Template $template) {
        $template->assignAttributes($this->user);
        $template->assign('vat_number', $this->vatNumber);
        $template->assign('reg_number', $this->regNumber);
        $template->assign('amount_of_reg_capital', $this->amountOfRegCapital);
        $template->assign('vat_percentage', $this->vatPercentage);
        $template->assign('payoutcurrency', $this->currency->getName());
        $template->assign('affiliate_note', $this->getAffiliateNote());
        $template->assign('payment', $this->getAmount());
        $template->assign('amount', str_replace('.', ',', $this->getAmount()));
        $template->assign('currency', $this->currency->getName());

        if ($this->payoutOption != null) {
            $template->assign('payoutmethod', $this->_localize($this->payoutOption->getName()));
        }
        $template->assign('payment_vat_part', $this->amountVatPart);
        $template->assign('payment_incl_vat', $this->amountWithVat);
        $template->assign('payment_excl_vat', $this->amountWithoutWat);

        $historyItem = $this->getPayoutHistoryItem();
        if ($historyItem === null) {
            
            $template->assign('date', Gpf_Common_DateUtils::getDateInLocaleFormat());
            $template->assign('time', Gpf_Common_DateUtils::getTimeInLocaleFormat());
        } else {
            $time = new Gpf_DateTime($historyItem->getDateInserted());
            $template->assign('date', Gpf_Common_DateUtils::getDateInLocaleFormat($time->toTimestamp()));
            $template->assign('time', Gpf_Common_DateUtils::getTimeInLocaleFormat($time->toTimestamp()));
        }
        $template->assign('invoicenumber',$this->getInvoiceNumber());

        if ($this->payoutOptionFields != null) {
            $userPayoutOptions = Pap_Db_Table_UserPayoutOptions::getInstance()->getValues(
            $this->payoutOption->getFormId(), $this->user->getId());
            foreach ($this->payoutOptionFields as $payoutOptionField) {
                $code = $payoutOptionField->get('code');
                if (array_key_exists($code, $userPayoutOptions)) {
                    $template->assign($code, $userPayoutOptions[$code]->getValue());
                }
            }
        }
    }
   public function saveCommission(Pap_Contexts_Tracking $context, Pap_Common_User $user, Pap_Tracking_Common_Commission $commission) {
        $context->debug('Saving '.$context->getActionType().' commission started');

        $transaction = $context->getTransaction($commission->getTier());
        if ($transaction == null) {
            $transaction = clone $context->getTransaction(1);
            $transaction->setPersistent(false);
            $transaction->generateNewTransactionId();
        }
        if (($parentTransaction = $context->getTransaction($commission->getTier() - 1)) != null) {
            $transaction->setParentTransactionId($parentTransaction->getId());
        }
        if (($channel = $context->getChannelObject()) != null) {
            $transaction->setChannel($channel->getId());
        }

        $transaction->setTier($commission->getTier());
        $transaction->setUserId($user->getId());
        $transaction->setCampaignId($context->getCampaignObject()->getId());
        $transaction->setAccountId($context->getAccountId());

        $banner = $context->getBannerObject();
        if (!is_null($banner)) {
            $transaction->setBannerId($banner->getId());
        }

        if ($user->getStatus() == 'P') {
        	$transaction->setStatus('P');
        	$context->debug('Commission is saved as pending because user state is in pending');
        } else {
            $transaction->setStatus($commission->getStatus());
        }
        $transaction->setPayoutStatus(Pap_Common_Transaction::PAYOUT_UNPAID);
        $transaction->setCommissionTypeId($context->getCommissionTypeObject()->getId());
        $transaction->setCountryCode(($context->getVisit()!=null)?$context->getVisit()->getCountryCode():'');
        $transaction->setType($context->getCommissionTypeObject()->getType());
        $transaction->setCommission($commission->getCommission($context->getRealTotalCost()-$context->getFixedCost()));
        $context->debug('  Computed commission is: '.$transaction->getCommission());
        $transaction->setClickCount(1);
        $transaction->setLogGroupId($context->getLoggerGroupId());

        if ($transaction->getTier() == 1) {
            $transaction->setSaleId($transaction->getId());
        } else {
            $transaction->setSaleId($context->getTransaction(1)->getSaleId());
        }

        //check if we can save zero commission
        if ($transaction->getCommission() == 0 &&
        $context->getCommissionTypeObject()->getSaveZeroCommissions() != Gpf::YES) {
            $context->debug('  Saving of commission transaction was STOPPED. Saving of zero commissions is disabled. Trans id: '.$transaction->getId());
            return Gpf_Plugins_Engine::PROCESS_CONTINUE;
        }


        $transactionCompoundContext = new Pap_Common_TransactionCompoundContext($transaction, $context);
        Gpf_Plugins_Engine::extensionPoint('Tracker.saveCommissions.beforeSaveTransaction', $transactionCompoundContext);
        if (!$transactionCompoundContext->getSaveTransaction()) {
            $context->debug('  Saving of commission transaction was STOPPED by plugin. Trans id: '.$transaction->getId());
            return Gpf_Plugins_Engine::PROCESS_CONTINUE;
        }

        $this->saveTransaction($transaction, $context->getVisitDateTime());
        $context->setTransactionObject($transaction, $commission->getTier());

        $context->debug('    Commission transaction was successfully saved with ID: '.$transaction->getId());
        $context->debug('Saving '.$context->getActionType().' commission ended');
        $context->debug('');

        return Gpf_Plugins_Engine::PROCESS_CONTINUE;
    }
示例#10
0
 function getAffiliateID(){
     return $this->user->getId();
 }
示例#11
0
 public function setUser(Pap_Common_User $user) {
     $this->statsParams->setAffiliateId($user->getId());
     $this->user = $user;
 }
示例#12
0
 /**
  * @return Pap_Db_AffiliateTrackingCode
  */
 private function loadAffiliateTrackingCode(Pap_Db_CommissionType $commissionType, Pap_Common_User $affiliate) {
     $code = new Pap_Db_AffiliateTrackingCode();
     $code->setAffiliateId($affiliate->getId());
     $code->setCommissionTypeId($commissionType->getId());
     $code->setStatus(Pap_Common_Constants::STATUS_APPROVED);
     $code->loadFromData();
     return $code;
 }