private function createCommission($commissionGroupId, $commissionTypeId, $tier, $type, $value) {
        $c = new Pap_Db_Commission();

        $c->set("tier", $tier);
        $c->set("subtype", 'N');
        $c->set("commissiontype", $type);
        $c->set("commissionvalue", $value);
        $c->set("commtypeid", $commissionTypeId);
        $c->set("commissiongroupid", $commissionGroupId);

        $c->insert();
        return $c->get("commissionid");
    }
    private function saveCommissionRecord($tier, $subtype, $commissionType, $commissionValue) {
        $commission = new Pap_Db_Commission();
        $commission->setTier($tier);
        $commission->setSubtype($subtype);
        $commission->setGroupId($this->commissionGroupId);
        $commission->setTypeId($this->commissionTypeId);
        if ($commissionValue == null) {
            $commissionValue = 0;
        }

        try {
            $commission->loadFromData();
            // loaded, change commission value and save
            $commission->setCommType($commissionType);
            $commission->setCommission($commissionValue);
            $commission->save();
        } catch(Gpf_DbEngine_NoRowException $e) {
            // doesn't exist, insert new record
            $commission->setCommType($commissionType);
            $commission->setCommission($commissionValue);
            $commission->insert();
        } catch(Gpf_DbEngine_TooManyRowsException $e) {
            // there are multiple rows, it is a mistake
            $commission->deleteUnusedCommissions($tier, $subtype, $this->commissionGroupId, $this->commissionTypeId, 'exact');
            $commission->setCommType($commissionType);
            $commission->setCommission($commissionValue);
            $commission->insert();
        }
    }