Ejemplo n.º 1
0
 public function modifyCommission(Pap_Common_SaveCommissionCompoundContext $compoundContext) {
     $context = $compoundContext->getContext();
     if (!($context instanceof Pap_Contexts_Action)) {
         $context->debug($this->getPluginName().' plugin not applied as Action/Sale is not saved');
         return;
     }
     $context->debug($this->getPluginName().' plugin begin');
     $user = $compoundContext->getUser();
     $tier = $compoundContext->getTier();
     if ($user->getParentUserId() == '') {
         if (($transaction = $context->getTransaction($tier)) != null) {
             $newCommission = $this->computeCommission($context, $transaction, $user, $tier);
             if ($newCommission === null) {
                 $context->debug('Top Level Commission is not applicated');
                 return;
             }
             $transaction->setCommission($newCommission);
             $transaction->save();
         } else {
             $context->debug('Commission does not exist.');
             $commission = $this->getCommission($tier, $context, $user, $tier);
             if ($commission === null) {
                 $context->debug('Top Level Commission is not applicated');
                 return;
             }
             $commission->setStatusFromType($context->getCommissionTypeObject());
             $compoundContext->getSaveObject()->saveCommission($context, $user, $commission);
         }
         $context->debug($this->getPluginName().' commision saved to'. $user->getId());
     }
     $context->debug($this->getPluginName().' plugin end');
 }
Ejemplo n.º 2
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');
 }