예제 #1
0
 public function modifyCommission(Pap_Common_SaveCommissionCompoundContext $compoundContext) {
     $context = $compoundContext->getContext();
     if (!($context instanceof Pap_Contexts_Action)) {
         $context->debug('PartnerCommission plugin not applied as Action/Sale is not saved');
         return;
     }
     $context->debug('PartnerCommission plugin begin');
     $user = $compoundContext->getUser();
     $tier = $compoundContext->getTier();
     $saveAllCommissions = $compoundContext->getSaveObject();
     if ($user->getParentUserId() == '') {
         $firstTransaction = $context->getTransactionObject(1);
         $transaction = $context->getTransactionObject($tier);
         if ($transaction != null) {
             $transaction->setCommission($transaction->getTotalCost() - $transaction->getFixedCost() - $this->sumOfCommissions($context, $tier));
             $context->debug('  PartnerCommission changed commission to: ' . $transaction->getCommission());
             $transaction->save();
         } else {
             $context->debug('  Commission does not exist.');
             $commission = new Pap_Tracking_Common_Commission($tier, Pap_Db_CommissionType::COMMISSION_FIXED, $firstTransaction->getTotalCost() - $firstTransaction->getFixedCost() - $this->sumOfCommissions($context, $tier));
             $commission->setStatusFromType($context->getCommissionTypeObject());
             $saveAllCommissions->saveCommission($context, $user, $commission);
         }
     }
     $context->debug('PartnerCommission plugin end');
 }
	public function recognize(Pap_Contexts_Tracking $context, $customStatus = null) {
		$context->debug('Recognizing commission settings started');

		$campaign = $context->getCampaignObject();
		if($campaign == null) {
			$context->debug('    Error, campaign cannot be null!');
			return;
		}
			
		$commissionType = $context->getCommissionTypeObject();

		if ($commissionType == null) {
			$context->debug('    No commission type found for this action');
			return;
		}

		try {
			$commissionCollection = $this->getCommissionsCollection($context);
			foreach($commissionCollection as $dbCommission) {
				$commission = new Pap_Tracking_Common_Commission();
				$commission->loadFrom($dbCommission);
				$commission->setStatusFromType($commissionType);
				if ($customStatus != null) {
					$commission->setStatus($customStatus);
				}
				$context->addCommission($commission);
			}
			$context->debug('    Commission settings loaded, # of tiers: ' . $commissionCollection->getSize());
		} catch(Exception $e) {
			$context->debug('    EXCEPTION, STOPPING. Exception message: '.$e->getMessage());
			return;
		}
			
		$context->debug('Recognizing commission settings ended');
		$context->debug('');
	}
   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;
    }
예제 #4
0
 /**
  * add commission
  */
 public function addCommission(Pap_Tracking_Common_Commission $commission) {
     $this->commissions[$commission->getSubType()][$commission->getTier()] = $commission;
 }
    public function computeCustomCommissions(Pap_Contexts_Action $context) {
        $context->debug('Custom commission computing started');

        $commission = $context->getCustomCommissionFromRequest();
        if($commission != '') {
            $context->debug("        Found custom commission: ".$commission.", decoding");

            $type = $this->getParameterType($commission);
            $commission = $this->makeCorrections($commission);

            $value = '';
            if(is_numeric($commission) && $commission >= 0) {
                $value = $commission;
            }

            if($value != '') {
                $context->debug("        Custom commission is $type $value");
                $i = 1;
                while ($context->getCommission($i) != null) {
                    $context->removeCommission($i++);
                }
                $newCommission = new Pap_Tracking_Common_Commission(1, $type, $value);
                $newCommission->setStatus($this->recognizeStatus($context->getCommissionTypeObject()));
                $context->addCommission($newCommission);

                if ($type!='%'){
                    $this->recognizeCurrency->computeCustomCommission($context);
                }
            } else {
                $context->debug("        Custom commission has bad format");
            }
        } else {
        	$context->debug('No custom commission defined');
        }

        $context->debug('Checking for forced commissions ended');

        $context->debug('Custom commission computing ended');
        $context->debug("");
    }