<?php


abstract class BaseTarifasDestino extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $nitocc;


	
	protected $id_comision;


	
	protected $vigencia;


	
	protected $id_tarifa;


	
	protected $num_viajes = 0;


	
	protected $total = 0;

	
	protected $aTerceros;

	
	protected $aTarifasTaxis;

	
	protected $aComisiones;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getNitocc()
	{

		return $this->nitocc;
	}

	
	public function getIdComision()
	{

		return $this->id_comision;
	}

	
	public function getVigencia()
	{

		return $this->vigencia;
	}

	
	public function getIdTarifa()
	{

		return $this->id_tarifa;
	}

	
	public function getNumViajes()
	{

		return $this->num_viajes;
	}

	
	public function getTotal()
	{

		return $this->total;
	}

	
	public function setNitocc($v)
	{

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

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

	} 
	
	public function setIdComision($v)
	{

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

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

	} 
	
	public function setVigencia($v)
	{

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

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

	} 
	
	public function setIdTarifa($v)
	{

		if ($this->id_tarifa !== $v) {
			$this->id_tarifa = $v;
			$this->modifiedColumns[] = TarifasDestinoPeer::ID_TARIFA;
		}

		if ($this->aTarifasTaxis !== null && $this->aTarifasTaxis->getId() !== $v) {
			$this->aTarifasTaxis = null;
		}

	} 
	
	public function setNumViajes($v)
	{

		if ($this->num_viajes !== $v || $v === 0) {
			$this->num_viajes = $v;
			$this->modifiedColumns[] = TarifasDestinoPeer::NUM_VIAJES;
		}

	} 
	
	public function setTotal($v)
	{

		if ($this->total !== $v || $v === 0) {
			$this->total = $v;
			$this->modifiedColumns[] = TarifasDestinoPeer::TOTAL;
		}

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

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

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

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

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

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

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

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 6; 
		} catch (Exception $e) {
			throw new PropelException("Error populating TarifasDestino 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(TarifasDestinoPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			TarifasDestinoPeer::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(TarifasDestinoPeer::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->aTarifasTaxis !== null) {
				if ($this->aTarifasTaxis->isModified()) {
					$affectedRows += $this->aTarifasTaxis->save($con);
				}
				$this->setTarifasTaxis($this->aTarifasTaxis);
			}

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


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = TarifasDestinoPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setNew(false);
				} else {
					$affectedRows += TarifasDestinoPeer::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->aTarifasTaxis !== null) {
				if (!$this->aTarifasTaxis->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aTarifasTaxis->getValidationFailures());
				}
			}

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


			if (($retval = TarifasDestinoPeer::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 = TarifasDestinoPeer::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->getIdComision();
				break;
			case 2:
				return $this->getVigencia();
				break;
			case 3:
				return $this->getIdTarifa();
				break;
			case 4:
				return $this->getNumViajes();
				break;
			case 5:
				return $this->getTotal();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = TarifasDestinoPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getNitocc(),
			$keys[1] => $this->getIdComision(),
			$keys[2] => $this->getVigencia(),
			$keys[3] => $this->getIdTarifa(),
			$keys[4] => $this->getNumViajes(),
			$keys[5] => $this->getTotal(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TarifasDestinoPeer::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->setIdComision($value);
				break;
			case 2:
				$this->setVigencia($value);
				break;
			case 3:
				$this->setIdTarifa($value);
				break;
			case 4:
				$this->setNumViajes($value);
				break;
			case 5:
				$this->setTotal($value);
				break;
		} 	}

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

		if (array_key_exists($keys[0], $arr)) $this->setNitocc($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setIdComision($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setVigencia($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setIdTarifa($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setNumViajes($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setTotal($arr[$keys[5]]);
	}

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

		if ($this->isColumnModified(TarifasDestinoPeer::NITOCC)) $criteria->add(TarifasDestinoPeer::NITOCC, $this->nitocc);
		if ($this->isColumnModified(TarifasDestinoPeer::ID_COMISION)) $criteria->add(TarifasDestinoPeer::ID_COMISION, $this->id_comision);
		if ($this->isColumnModified(TarifasDestinoPeer::VIGENCIA)) $criteria->add(TarifasDestinoPeer::VIGENCIA, $this->vigencia);
		if ($this->isColumnModified(TarifasDestinoPeer::ID_TARIFA)) $criteria->add(TarifasDestinoPeer::ID_TARIFA, $this->id_tarifa);
		if ($this->isColumnModified(TarifasDestinoPeer::NUM_VIAJES)) $criteria->add(TarifasDestinoPeer::NUM_VIAJES, $this->num_viajes);
		if ($this->isColumnModified(TarifasDestinoPeer::TOTAL)) $criteria->add(TarifasDestinoPeer::TOTAL, $this->total);

		return $criteria;
	}

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

		$criteria->add(TarifasDestinoPeer::NITOCC, $this->nitocc);
		$criteria->add(TarifasDestinoPeer::ID_COMISION, $this->id_comision);
		$criteria->add(TarifasDestinoPeer::VIGENCIA, $this->vigencia);
		$criteria->add(TarifasDestinoPeer::ID_TARIFA, $this->id_tarifa);

		return $criteria;
	}

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

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

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

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

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

		return $pks;
	}

	
	public function setPrimaryKey($keys)
	{

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

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

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

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

	}

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

		$copyObj->setNumViajes($this->num_viajes);

		$copyObj->setTotal($this->total);


		$copyObj->setNew(true);

		$copyObj->setNitocc(NULL); 
		$copyObj->setIdComision(NULL); 
		$copyObj->setVigencia(NULL); 
		$copyObj->setIdTarifa(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 TarifasDestinoPeer();
		}
		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 setTarifasTaxis($v)
	{


		if ($v === null) {
			$this->setIdTarifa(NULL);
		} else {
			$this->setIdTarifa($v->getId());
		}


		$this->aTarifasTaxis = $v;
	}


	
	public function getTarifasTaxis($con = null)
	{
		if ($this->aTarifasTaxis === null && ($this->id_tarifa > 0)) {
						$this->aTarifasTaxis = TarifasTaxisPeer::retrieveByPK($this->id_tarifa, $con);

			
		}
		return $this->aTarifasTaxis;
	}

	
	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;
	}

} 