private function getFixedCost($commTypeId) {
		$commType = new Pap_Db_CommissionType();
		$commType->setId($commTypeId);
		$commType->load();
        if (($commType->getFixedcostValue()==0) || ($commType->getFixedcostValue()=='null')) {
        	return "";
        }
        return $commType->getFixedcostType().$commType->getFixedcostValue();
	}
 private function getCommissionTypeByCommissionTypeId($commissionTypeId) {
     if ($commissionTypeId == null || $commissionTypeId == '') {
         return null;
     }
     $commissionType = new Pap_Db_CommissionType();
     $commissionType->setId($commissionTypeId);
     try {
         $commissionType->load();
     } catch (Gpf_DbEngine_NoRowException $e) {
         return null;
     }
     return $commissionType->getType();
 }
	/**
	 *
	 * @service commission write
	 * @param $fields
	 * @return Gpf_Rpc_Action
	 */
	public function deleteCommissionType(Gpf_Rpc_Params $params) {
		$action = new Gpf_Rpc_Action($params);
		$action->setErrorMessage($this->_('Failed to delete type, some transactions are connected to this type. Remove them first.'));
		$action->setInfoMessage($this->_('Commission type successfully removed'));

		$commTypeId = $action->getParam('commtypeid');

		$transaction = new Pap_Db_Transaction();
		$transaction->setCommissionTypeId($commTypeId);
		$collection = $transaction->loadCollection(array(Pap_Db_Table_Transactions::COMMISSIONTYPEID));
		if ($collection->getSize() > 0) {
			$action->addError();
			return $action;
		}

        $commissionType = new Pap_Db_CommissionType();
        $commissionType->setId($commTypeId);
        $commissionType->delete();

        $action->addOk();
        return $action;
	}
    private function getCommissionTypeAndValue($campaignId, $userId, $commissionTypeId, $tier = null) {
        if (is_null($tier) || $tier == '') {
            $tier = 1;
        }

        // getting user
        if($userId == '') {
            $this->errorMsg = $this->_("User is not valid!");
            return false;
        }
        $user = new Pap_Common_User();
        $user->setPrimaryKeyValue($userId);
        try {
            $user->load();
        } catch (Gpf_DbEngine_NoRowException $e) {
            $this->errorMsg = $this->_("User is not valid!");
            return false;
        }

        // getting campaign
        $campaign = new Pap_Common_Campaign();
        $campaign->setId($campaignId);
        try {
            $campaign->load();
        } catch (Gpf_DbEngine_NoRowException $e) {
            $this->errorMsg = $this->_("Campaign is not valid!");
            return false;
        }
        // getting commission type
        try {
            $commissionType = new Pap_Db_CommissionType();
            $commissionType->setId($commissionTypeId);
            $commissionType->setStatus(Pap_Db_CommissionType::STATUS_ENABLED);
            $commissionType->loadFromData();
        } catch (Gpf_DbEngine_NoRowException $e) {
            $this->errorMsg = $this->_("Transaction type is not valid or doesn't exist in this campaign!");
            return false;
        }
        $fixedcostType = $commissionType->getFixedcostType();
        $fixedcostValue = $commissionType->getFixedcostValue();
        // getting commission group
        $commGroupId = $campaign->getCommissionGroupForUser($userId);
        if($commGroupId == false) {
            $this->errorMsg = $this->_("Cannot recognize commission group for this user in campaign!");
            return false;
        }

        $rsCommissions = $campaign->getCommissionsCollection($commGroupId, $commissionType->getId());
        $commType = null;
        $commValue = null;
        foreach($rsCommissions as $record) {
            if($record->get('tier') == $tier && $record->get('subtype') == 'N') {
                $commType = $record->get('commissiontype');
                $commValue = $record->get('commissionvalue');
                break;
            }
        }

        if($commType == null) {
            $this->errorMsg = $this->_("Error getting commission settings!");
            return false;
        }

        return array('type' => $commType, 'value' => $commValue, 'fixedcostValue' => $fixedcostValue, 'fixedcostType' => $fixedcostType);
    }
    public function saveForm() {
        $this->checkSaveInput();
        $commissionType = new Pap_Db_CommissionType();
        $commissionType->setId($this->commissionTypeId);

        try {
            $commissionType->load();
            $this->fill($commissionType);
        } catch (Gpf_DbEngine_NoRow $e) {
            throw new Exception($this->_("Commission type does not exist"));
        }

        $commissionType->save();

        $this->saveCommissions();
    }
 protected function getActionName($type, $id) {
     if ($type != Pap_Common_Constants::TYPE_ACTION) {
         return $this->_('Sale');
     } else {
         $commType = new Pap_Db_CommissionType();
         $commType->setId($id);
         $commType->load();
         return $commType->getName();
     }
 }
 /**
  * @return Pap_Db_CommissionType
  */
 protected function getCommType($commType) {
     $commObj = new Pap_Db_CommissionType();
     $commObj->setId($commType);
     $commObj->load();
     return $commObj;
 }
 /**
  * @return Pap_Db_CommissionType
  */
 private function loadCommissionType($commTypeId) {
     if (!array_key_exists($commTypeId, self::$commissionTypesCache)) {
         $commissionType = new Pap_Db_CommissionType();
         $commissionType->setId($commTypeId);
         try {
             $commissionType->load();
         } catch (Gpf_Exception $e) {
             $commissionType->setName($this->_('Unknown'));
         }
         self::$commissionTypesCache[$commTypeId] = $commissionType;
     }
     return self::$commissionTypesCache[$commTypeId];
 }