<?php


abstract class BaseComisionadosObjs extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $nitocc;


	
	protected $codobj;


	
	protected $id_comision;


	
	protected $valor;


	
	protected $estado = 1;


	
	protected $vigencia;


	
	protected $observa;

        protected $viaticos;
        
        protected $taxis;

	protected $tarifa;


	protected $id_clase_presup;

	protected $id_rubro;

	protected $id_elementos_gasto;

	protected $id_obj_gasto;
	
	protected $aTerceros;

	
	protected $aObjetosGasto;

	
	protected $aComisiones;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getNitocc()
	{

		return $this->nitocc;
	}

	
	public function getCodobj()
	{

		return $this->codobj;
	}

	
	public function getIdComision()
	{

		return $this->id_comision;
	}

	
	public function getValor()
	{

		return $this->valor;
	}

	
	public function getEstado()
	{

		return $this->estado;
	}

	
	public function getVigencia()
	{

		return $this->vigencia;
	}

	
	public function getObserva()
	{

		return $this->observa;
	}
        
        public function getViaticos()
	{

		return $this->viaticos;
	}
        
        public function getTaxis()
	{

		return $this->taxis;
	}
	public function getTarifa()
	{

		return $this->tarifa;
	}

	public function getIdClasePresup()
	{

		return $this->id_clase_presup;
	}

	public function getIdRubro()
	{

		return $this->id_rubro;
	}

	public function getIdElementosGasto()
	{

		return $this->id_elementos_gasto;
	}

	public function getIdObjGasto()
	{

		return $this->id_obj_gasto;
	}

	
	public function setNitocc($v)
	{

		if ($this->nitocc !== $v) {
			$this->nitocc = $v;
			$this->modifiedColumns[] = ComisionadosObjsPeer::NITOCC;
		}

		if ($this->aTerceros !== null && $this->aTerceros->getNitocc() !== $v) {
			$this->aTerceros = null;
		}

	} 
	
	public function setCodobj($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->codobj !== $v) {
			$this->codobj = $v;
			$this->modifiedColumns[] = ComisionadosObjsPeer::CODOBJ;
		}

		if ($this->aObjetosGasto !== null && $this->aObjetosGasto->getCodobj() !== $v) {
			$this->aObjetosGasto = null;
		}

	} 
	
	public function setIdComision($v)
	{

		if ($this->id_comision !== $v) {
			$this->id_comision = $v;
			$this->modifiedColumns[] = ComisionadosObjsPeer::ID_COMISION;
		}

		if ($this->aComisiones !== null && $this->aComisiones->getVigencia() !== $v) {
			$this->aComisiones = null;
		}

	} 
	
	public function setValor($v)
	{

		if ($this->valor !== $v) {
			$this->valor = $v;
			$this->modifiedColumns[] = ComisionadosObjsPeer::VALOR;
		}

	} 
	
	public function setEstado($v)
	{

		if ($this->estado !== $v || $v === 1) {
			$this->estado = $v;
			$this->modifiedColumns[] = ComisionadosObjsPeer::ESTADO;
		}

	} 
	
	public function setVigencia($v)
	{

		if ($this->vigencia !== $v) {
			$this->vigencia = $v;
			$this->modifiedColumns[] = ComisionadosObjsPeer::VIGENCIA;
		}

		if ($this->aComisiones !== null && $this->aComisiones->getVigencia() !== $v) {
			$this->aComisiones = null;
		}

	} 
	
	public function setObserva($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->observa !== $v) {
			$this->observa = $v;
			$this->modifiedColumns[] = ComisionadosObjsPeer::OBSERVA;
		}

	} 
        
        public function setViaticos($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->viaticos !== $v) {
			$this->viaticos = $v;
			$this->modifiedColumns[] = ComisionadosObjsPeer::VIATICOS;
		}

	} 
        
        public function setTaxis($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->taxis !== $v) {
			$this->taxis = $v;
			$this->modifiedColumns[] = ComisionadosObjsPeer::TAXIS;
		}

	}
	public function setTarifa($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->tarifa !== $v) {
			$this->tarifa = $v;
			$this->modifiedColumns[] = ComisionadosObjsPeer::TARIFA;
		}

	} 

	public function setIdClasePresup($v)
	{

		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->id_clase_presup !== $v) {
			$this->id_clase_presup = $v;
			$this->modifiedColumns[] = ComisionadosObjsPeer::ID_CLASE_PRESUP;
		}

	} 
	public function setIdRubro($v)
	{

		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->id_rubro !== $v) {
			$this->id_rubro = $v;
			$this->modifiedColumns[] = ComisionadosObjsPeer::ID_RUBRO;
		}

	} 
	public function setIdElementosGasto($v)
	{

		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->id_elementos_gasto !== $v) {
			$this->id_elementos_gasto = $v;
			$this->modifiedColumns[] = ComisionadosObjsPeer::ID_ELEMENTOS_GASTO;
		}

	} 
	public function setIdObjGasto($v)
	{

		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->id_obj_gasto !== $v) {
			$this->id_obj_gasto = $v;
			$this->modifiedColumns[] = ComisionadosObjsPeer::ID_OBJ_GASTO;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->nitocc = $rs->getFloat($startcol + 0);

			$this->codobj = $rs->getString($startcol + 1);

			$this->id_comision = $rs->getFloat($startcol + 2);

			$this->valor = $rs->getFloat($startcol + 3);

			$this->estado = $rs->getFloat($startcol + 4);

			$this->vigencia = $rs->getFloat($startcol + 5);

			$this->observa = $rs->getString($startcol + 6);
                        
			$this->viaticos = $rs->getString($startcol + 7);
                        
			$this->taxis = $rs->getString($startcol + 8);                        

			$this->tarifa = $rs->getString($startcol + 9);  

			$this->id_clase_presup = $rs->getString($startcol + 10);

			$this->id_rubro = $rs->getString($startcol + 11);

			$this->id_elementos_gasto = $rs->getString($startcol + 12);

			$this->id_obj_gasto = $rs->getString($startcol + 13);                      
		
			$this->resetModified();

			$this->setNew(false);

						return $startcol + 14; 
		} catch (Exception $e) {
			throw new PropelException("Error populating ComisionadosObjs object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(ComisionadosObjsPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			ComisionadosObjsPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(ComisionadosObjsPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


												
			if ($this->aTerceros !== null) {
				if ($this->aTerceros->isModified()) {
					$affectedRows += $this->aTerceros->save($con);
				}
				$this->setTerceros($this->aTerceros);
			}

			if ($this->aObjetosGasto !== null) {
				if ($this->aObjetosGasto->isModified()) {
					$affectedRows += $this->aObjetosGasto->save($con);
				}
				$this->setObjetosGasto($this->aObjetosGasto);
			}

			if ($this->aComisiones !== null) {
				if ($this->aComisiones->isModified()) {
					$affectedRows += $this->aComisiones->save($con);
				}
				$this->setComisiones($this->aComisiones);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = ComisionadosObjsPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setNew(false);
				} else {
					$affectedRows += ComisionadosObjsPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->aTerceros !== null) {
				if (!$this->aTerceros->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aTerceros->getValidationFailures());
				}
			}

			if ($this->aObjetosGasto !== null) {
				if (!$this->aObjetosGasto->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aObjetosGasto->getValidationFailures());
				}
			}

			if ($this->aComisiones !== null) {
				if (!$this->aComisiones->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aComisiones->getValidationFailures());
				}
			}


			if (($retval = ComisionadosObjsPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = ComisionadosObjsPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getNitocc();
				break;
			case 1:
				return $this->getCodobj();
				break;
			case 2:
				return $this->getIdComision();
				break;
			case 3:
				return $this->getValor();
				break;
			case 4:
				return $this->getEstado();
				break;
			case 5:
				return $this->getVigencia();
				break;
			case 6:
				return $this->getObserva();
				break;
			case 7:
				return $this->getViaticos();
				break;
			case 8:
				return $this->getTaxis();
				break;
			case 9:
				return $this->getTarifa();
				break;
			case 10:
				return $this->getIdClasePresup();
				break;
			case 11:
				return $this->getIdRubro();
				break;
			case 12:
				return $this->getIdElementosGasto();
				break;
			case 13:
				return $this->getIdObjGasto();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = ComisionadosObjsPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getNitocc(),
			$keys[1] => $this->getCodobj(),
			$keys[2] => $this->getIdComision(),
			$keys[3] => $this->getValor(),
			$keys[4] => $this->getEstado(),
			$keys[5] => $this->getVigencia(),
			$keys[6] => $this->getObserva(),
            $keys[7] => $this->getViaticos(),
            $keys[8] => $this->getTaxis(),
			$keys[9] => $this->getTarifa(),
			$keys[10] => $this->getIdClasePresup(),
			$keys[11] => $this->getIdRubro(),
			$keys[12] => $this->getIdElementosGasto(),
			$keys[13] => $this->getIdObjGasto(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = ComisionadosObjsPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setNitocc($value);
				break;
			case 1:
				$this->setCodobj($value);
				break;
			case 2:
				$this->setIdComision($value);
				break;
			case 3:
				$this->setValor($value);
				break;
			case 4:
				$this->setEstado($value);
				break;
			case 5:
				$this->setVigencia($value);
				break;
			case 6:
				$this->setObserva($value);
				break;
                        case 7:
				$this->setViaticos($value);
				break;
                        case 8:
				$this->setTaxis($value);
				break;    
			case 9:
				$this->setTarifa($value);
				break;
			case 10:
				$this->setIdClasePresup($value);
				break;
			case 11:
				$this->setIdRubro($value);
				break;
			case 12:
				$this->setIdElementosGasto($value);
				break;
			case 13:
				$this->setIdObjGasto($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = ComisionadosObjsPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setNitocc($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setCodobj($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setIdComision($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setValor($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setEstado($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setVigencia($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setObserva($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setViaticos($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setTaxis($arr[$keys[8]]); 
		if (array_key_exists($keys[9], $arr)) $this->setTarifa($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setIdClasePresup($arr[$keys[10]]);
		if (array_key_exists($keys[11], $arr)) $this->setIdRubro($arr[$keys[11]]);
		if (array_key_exists($keys[12], $arr)) $this->setIdElementosGasto($arr[$keys[12]]);
		if (array_key_exists($keys[13], $arr)) $this->setIdObjGasto($arr[$keys[13]]);                 
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(ComisionadosObjsPeer::DATABASE_NAME);

		if ($this->isColumnModified(ComisionadosObjsPeer::NITOCC)) $criteria->add(ComisionadosObjsPeer::NITOCC, $this->nitocc);
		if ($this->isColumnModified(ComisionadosObjsPeer::CODOBJ)) $criteria->add(ComisionadosObjsPeer::CODOBJ, $this->codobj);
		if ($this->isColumnModified(ComisionadosObjsPeer::ID_COMISION)) $criteria->add(ComisionadosObjsPeer::ID_COMISION, $this->id_comision);
		if ($this->isColumnModified(ComisionadosObjsPeer::VALOR)) $criteria->add(ComisionadosObjsPeer::VALOR, $this->valor);
		if ($this->isColumnModified(ComisionadosObjsPeer::ESTADO)) $criteria->add(ComisionadosObjsPeer::ESTADO, $this->estado);
		if ($this->isColumnModified(ComisionadosObjsPeer::VIGENCIA)) $criteria->add(ComisionadosObjsPeer::VIGENCIA, $this->vigencia);
		if ($this->isColumnModified(ComisionadosObjsPeer::OBSERVA)) $criteria->add(ComisionadosObjsPeer::OBSERVA, $this->observa);
                if ($this->isColumnModified(ComisionadosObjsPeer::VIATICOS)) $criteria->add(ComisionadosObjsPeer::VIATICOS, $this->viaticos);
                if ($this->isColumnModified(ComisionadosObjsPeer::TAXIS)) $criteria->add(ComisionadosObjsPeer::TAXIS, $this->taxis);
		if ($this->isColumnModified(ComisionadosObjsPeer::TARIFA)) $criteria->add(ComisionadosObjsPeer::TARIFA, $this->tarifa);
		if ($this->isColumnModified(ComisionadosObjsPeer::ID_CLASE_PRESUP)) $criteria->add(ComisionadosObjsPeer::ID_CLASE_PRESUP, $this->id_clase_presup);
		if ($this->isColumnModified(ComisionadosObjsPeer::ID_RUBRO)) $criteria->add(ComisionadosObjsPeer::ID_RUBRO, $this->id_rubro);
		if ($this->isColumnModified(ComisionadosObjsPeer::ID_ELEMENTOS_GASTO)) $criteria->add(ComisionadosObjsPeer::ID_ELEMENTOS_GASTO, $this->id_elementos_gasto);
		if ($this->isColumnModified(ComisionadosObjsPeer::ID_OBJ_GASTO)) $criteria->add(ComisionadosObjsPeer::ID_OBJ_GASTO, $this->id_obj_gasto);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(ComisionadosObjsPeer::DATABASE_NAME);

		$criteria->add(ComisionadosObjsPeer::NITOCC, $this->nitocc);
		$criteria->add(ComisionadosObjsPeer::CODOBJ, $this->codobj);
		$criteria->add(ComisionadosObjsPeer::ID_COMISION, $this->id_comision);
		$criteria->add(ComisionadosObjsPeer::VIGENCIA, $this->vigencia);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		$pks = array();

		$pks[0] = $this->getNitocc();

		$pks[1] = $this->getCodobj();

		$pks[2] = $this->getIdComision();

		$pks[3] = $this->getVigencia();

		return $pks;
	}

	
	public function setPrimaryKey($keys)
	{

		$this->setNitocc($keys[0]);

		$this->setCodobj($keys[1]);

		$this->setIdComision($keys[2]);

		$this->setVigencia($keys[3]);

	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setValor($this->valor);

		$copyObj->setEstado($this->estado);

		$copyObj->setObserva($this->observa);

                $copyObj->setViaticos($this->viaticos);

                $copyObj->setTaxis($this->taxis);
		
		$copyObj->setTarifa($this->taxis);


		$copyObj->setNew(true);

		$copyObj->setNitocc(NULL); 
		$copyObj->setCodobj(NULL); 
		$copyObj->setIdComision(NULL); 
		$copyObj->setVigencia(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new ComisionadosObjsPeer();
		}
		return self::$peer;
	}

	
	public function setTerceros($v)
	{


		if ($v === null) {
			$this->setNitocc(NULL);
		} else {
			$this->setNitocc($v->getNitocc());
		}


		$this->aTerceros = $v;
	}


	
	public function getTerceros($con = null)
	{
		if ($this->aTerceros === null && ($this->nitocc > 0)) {
						$this->aTerceros = TercerosPeer::retrieveByPK($this->nitocc, $con);

			
		}
		return $this->aTerceros;
	}

	
	public function setObjetosGasto($v)
	{


		if ($v === null) {
			$this->setCodobj(NULL);
		} else {
			$this->setCodobj($v->getCodigo());
		}


		$this->aObjetosGasto = $v;
	}


	
	public function getObjetosGasto($con = null)
	{
		if ($this->aObjetosGasto === null && (($this->codobj !== "" && $this->codobj !== null))) {
                                                $c=new Criteria();
                                                $c->add(ObjetosGastoPeer::CODIGO,$this->codobj);
                                                $objeto=  ObjetosGastoPeer::doSelectOne($c);
                                                
						$this->aObjetosGasto = ObjetosGastoPeer::retrieveByPK($objeto->getId(), $con);
                                                //echo $this->aObjetosGasto->getDescripcion();
			
		}
		return $this->aObjetosGasto;
	}

	
	public function setComisiones($v)
	{


		if ($v === null) {
			$this->setIdComision(NULL);
		} else {
			$this->setIdComision($v->getVigencia());
		}


		if ($v === null) {
			$this->setIdComision(NULL);
		} else {
			$this->setIdComision($v->getVigencia());
		}


		if ($v === null) {
			$this->setVigencia(NULL);
		} else {
			$this->setVigencia($v->getVigencia());
		}


		if ($v === null) {
			$this->setVigencia(NULL);
		} else {
			$this->setVigencia($v->getVigencia());
		}


		$this->aComisiones = $v;
	}


	
	public function getComisiones($con = null)
	{
		if ($this->aComisiones === null && ($this->id_comision > 0 && $this->id_comision > 0 && $this->vigencia > 0 && $this->vigencia > 0)) {
						$this->aComisiones = ComisionesPeer::retrieveByPK($this->id_comision, $this->id_comision, $this->vigencia, $this->vigencia, $con);

			
		}
		return $this->aComisiones;
	}

} 
