<?php


abstract class BaseComisionadosPlanta extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id_comision;


	
	protected $nitocc;


	
	protected $id_transporte;


	
	protected $sueldo;


	
	protected $cargo;


	
	protected $fecha_salida;


	
	protected $dias;


	
	protected $codreg;


	
	protected $total_comision;


	
	protected $estado = 1;


	
	protected $fecha_regreso;


	
	protected $vigencia;


	
	protected $gastos_taxis;


	
	protected $dias_manu = 0;

	
	protected $aTerceros;

	
	protected $aTransportes;

	
	protected $aRegionales;

	
	protected $aComisiones;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getIdComision()
	{

		return $this->id_comision;
	}

	
	public function getNitocc()
	{

		return $this->nitocc;
	}

	
	public function getIdTransporte()
	{

		return $this->id_transporte;
	}

	
	public function getSueldo()
	{

		return $this->sueldo;
	}

	
	public function getCargo()
	{

		return $this->cargo;
	}

	
	public function getFechaSalida($format = 'Y-m-d')
	{

		if ($this->fecha_salida === null || $this->fecha_salida === '') {
			return null;
		} elseif (!is_int($this->fecha_salida)) {
						$ts = strtotime($this->fecha_salida);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [fecha_salida] as date/time value: " . var_export($this->fecha_salida, true));
			}
		} else {
			$ts = $this->fecha_salida;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getDias()
	{

		return $this->dias;
	}

	
	public function getCodreg()
	{

		return $this->codreg;
	}

	
	public function getTotalComision()
	{

		return $this->total_comision;
	}

	
	public function getEstado()
	{

		return $this->estado;
	}

	
	public function getFechaRegreso($format = 'Y-m-d')
	{

		if ($this->fecha_regreso === null || $this->fecha_regreso === '') {
			return null;
		} elseif (!is_int($this->fecha_regreso)) {
						$ts = strtotime($this->fecha_regreso);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [fecha_regreso] as date/time value: " . var_export($this->fecha_regreso, true));
			}
		} else {
			$ts = $this->fecha_regreso;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getVigencia()
	{

		return $this->vigencia;
	}

	
	public function getGastosTaxis()
	{

		return $this->gastos_taxis;
	}

	
	public function getDiasManu()
	{

		return $this->dias_manu;
	}

	
	public function setIdComision($v)
	{

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

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

	} 
	
	public function setNitocc($v)
	{

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

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

	} 
	
	public function setIdTransporte($v)
	{

		if ($this->id_transporte !== $v) {
			$this->id_transporte = $v;
			$this->modifiedColumns[] = ComisionadosPlantaPeer::ID_TRANSPORTE;
		}

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

	} 
	
	public function setSueldo($v)
	{

		if ($this->sueldo !== $v) {
			$this->sueldo = $v;
			$this->modifiedColumns[] = ComisionadosPlantaPeer::SUELDO;
		}

	} 
	
	public function setCargo($v)
	{

		if ($this->cargo !== $v) {
			$this->cargo = $v;
			$this->modifiedColumns[] = ComisionadosPlantaPeer::CARGO;
		}

	} 
	
	public function setFechaSalida($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [fecha_salida] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->fecha_salida !== $ts) {
			$this->fecha_salida = $ts;
			$this->modifiedColumns[] = ComisionadosPlantaPeer::FECHA_SALIDA;
		}

	} 
	
	public function setDias($v)
	{

		if ($this->dias !== $v) {
			$this->dias = $v;
			$this->modifiedColumns[] = ComisionadosPlantaPeer::DIAS;
		}

	} 
	
	public function setCodreg($v)
	{

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

		if ($this->codreg !== $v) {
			$this->codreg = $v;
			$this->modifiedColumns[] = ComisionadosPlantaPeer::CODREG;
		}

		if ($this->aRegionales !== null && $this->aRegionales->getCodreg() !== $v) {
			$this->aRegionales = null;
		}

	} 
	
	public function setTotalComision($v)
	{

		if ($this->total_comision !== $v) {
			$this->total_comision = $v;
			$this->modifiedColumns[] = ComisionadosPlantaPeer::TOTAL_COMISION;
		}

	} 
	
	public function setEstado($v)
	{

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

	} 
	
	public function setFechaRegreso($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [fecha_regreso] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->fecha_regreso !== $ts) {
			$this->fecha_regreso = $ts;
			$this->modifiedColumns[] = ComisionadosPlantaPeer::FECHA_REGRESO;
		}

	} 
	
	public function setVigencia($v)
	{

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

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

	} 
	
	public function setGastosTaxis($v)
	{

		if ($this->gastos_taxis !== $v) {
			$this->gastos_taxis = $v;
			$this->modifiedColumns[] = ComisionadosPlantaPeer::GASTOS_TAXIS;
		}

	} 
	
	public function setDiasManu($v)
	{

		if ($this->dias_manu !== $v || $v === 0) {
			$this->dias_manu = $v;
			$this->modifiedColumns[] = ComisionadosPlantaPeer::DIAS_MANU;
		}

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

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

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

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

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

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

			$this->fecha_salida = $rs->getDate($startcol + 5, null);

			$this->dias = $rs->getFloat($startcol + 6);

			$this->codreg = $rs->getString($startcol + 7);

			$this->total_comision = $rs->getFloat($startcol + 8);

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

			$this->fecha_regreso = $rs->getDate($startcol + 10, null);

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

			$this->gastos_taxis = $rs->getFloat($startcol + 12);

			$this->dias_manu = $rs->getFloat($startcol + 13);

			$this->resetModified();

			$this->setNew(false);

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

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

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

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


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

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

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


			if (($retval = ComisionadosPlantaPeer::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 = ComisionadosPlantaPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getIdComision();
				break;
			case 1:
				return $this->getNitocc();
				break;
			case 2:
				return $this->getIdTransporte();
				break;
			case 3:
				return $this->getSueldo();
				break;
			case 4:
				return $this->getCargo();
				break;
			case 5:
				return $this->getFechaSalida();
				break;
			case 6:
				return $this->getDias();
				break;
			case 7:
				return $this->getCodreg();
				break;
			case 8:
				return $this->getTotalComision();
				break;
			case 9:
				return $this->getEstado();
				break;
			case 10:
				return $this->getFechaRegreso();
				break;
			case 11:
				return $this->getVigencia();
				break;
			case 12:
				return $this->getGastosTaxis();
				break;
			case 13:
				return $this->getDiasManu();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = ComisionadosPlantaPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getIdComision(),
			$keys[1] => $this->getNitocc(),
			$keys[2] => $this->getIdTransporte(),
			$keys[3] => $this->getSueldo(),
			$keys[4] => $this->getCargo(),
			$keys[5] => $this->getFechaSalida(),
			$keys[6] => $this->getDias(),
			$keys[7] => $this->getCodreg(),
			$keys[8] => $this->getTotalComision(),
			$keys[9] => $this->getEstado(),
			$keys[10] => $this->getFechaRegreso(),
			$keys[11] => $this->getVigencia(),
			$keys[12] => $this->getGastosTaxis(),
			$keys[13] => $this->getDiasManu(),
		);
		return $result;
	}

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

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setIdComision($value);
				break;
			case 1:
				$this->setNitocc($value);
				break;
			case 2:
				$this->setIdTransporte($value);
				break;
			case 3:
				$this->setSueldo($value);
				break;
			case 4:
				$this->setCargo($value);
				break;
			case 5:
				$this->setFechaSalida($value);
				break;
			case 6:
				$this->setDias($value);
				break;
			case 7:
				$this->setCodreg($value);
				break;
			case 8:
				$this->setTotalComision($value);
				break;
			case 9:
				$this->setEstado($value);
				break;
			case 10:
				$this->setFechaRegreso($value);
				break;
			case 11:
				$this->setVigencia($value);
				break;
			case 12:
				$this->setGastosTaxis($value);
				break;
			case 13:
				$this->setDiasManu($value);
				break;
		} 	}

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

		if (array_key_exists($keys[0], $arr)) $this->setIdComision($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setNitocc($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setIdTransporte($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setSueldo($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setCargo($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setFechaSalida($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setDias($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setCodreg($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setTotalComision($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setEstado($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setFechaRegreso($arr[$keys[10]]);
		if (array_key_exists($keys[11], $arr)) $this->setVigencia($arr[$keys[11]]);
		if (array_key_exists($keys[12], $arr)) $this->setGastosTaxis($arr[$keys[12]]);
		if (array_key_exists($keys[13], $arr)) $this->setDiasManu($arr[$keys[13]]);
	}

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

		if ($this->isColumnModified(ComisionadosPlantaPeer::ID_COMISION)) $criteria->add(ComisionadosPlantaPeer::ID_COMISION, $this->id_comision);
		if ($this->isColumnModified(ComisionadosPlantaPeer::NITOCC)) $criteria->add(ComisionadosPlantaPeer::NITOCC, $this->nitocc);
		if ($this->isColumnModified(ComisionadosPlantaPeer::ID_TRANSPORTE)) $criteria->add(ComisionadosPlantaPeer::ID_TRANSPORTE, $this->id_transporte);
		if ($this->isColumnModified(ComisionadosPlantaPeer::SUELDO)) $criteria->add(ComisionadosPlantaPeer::SUELDO, $this->sueldo);
		if ($this->isColumnModified(ComisionadosPlantaPeer::CARGO)) $criteria->add(ComisionadosPlantaPeer::CARGO, $this->cargo);
		if ($this->isColumnModified(ComisionadosPlantaPeer::FECHA_SALIDA)) $criteria->add(ComisionadosPlantaPeer::FECHA_SALIDA, $this->fecha_salida);
		if ($this->isColumnModified(ComisionadosPlantaPeer::DIAS)) $criteria->add(ComisionadosPlantaPeer::DIAS, $this->dias);
		if ($this->isColumnModified(ComisionadosPlantaPeer::CODREG)) $criteria->add(ComisionadosPlantaPeer::CODREG, $this->codreg);
		if ($this->isColumnModified(ComisionadosPlantaPeer::TOTAL_COMISION)) $criteria->add(ComisionadosPlantaPeer::TOTAL_COMISION, $this->total_comision);
		if ($this->isColumnModified(ComisionadosPlantaPeer::ESTADO)) $criteria->add(ComisionadosPlantaPeer::ESTADO, $this->estado);
		if ($this->isColumnModified(ComisionadosPlantaPeer::FECHA_REGRESO)) $criteria->add(ComisionadosPlantaPeer::FECHA_REGRESO, $this->fecha_regreso);
		if ($this->isColumnModified(ComisionadosPlantaPeer::VIGENCIA)) $criteria->add(ComisionadosPlantaPeer::VIGENCIA, $this->vigencia);
		if ($this->isColumnModified(ComisionadosPlantaPeer::GASTOS_TAXIS)) $criteria->add(ComisionadosPlantaPeer::GASTOS_TAXIS, $this->gastos_taxis);
		if ($this->isColumnModified(ComisionadosPlantaPeer::DIAS_MANU)) $criteria->add(ComisionadosPlantaPeer::DIAS_MANU, $this->dias_manu);

		return $criteria;
	}

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

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

		return $criteria;
	}

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

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

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

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

		return $pks;
	}

	
	public function setPrimaryKey($keys)
	{

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

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

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

	}

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

		$copyObj->setIdTransporte($this->id_transporte);

		$copyObj->setSueldo($this->sueldo);

		$copyObj->setCargo($this->cargo);

		$copyObj->setFechaSalida($this->fecha_salida);

		$copyObj->setDias($this->dias);

		$copyObj->setCodreg($this->codreg);

		$copyObj->setTotalComision($this->total_comision);

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

		$copyObj->setFechaRegreso($this->fecha_regreso);

		$copyObj->setGastosTaxis($this->gastos_taxis);

		$copyObj->setDiasManu($this->dias_manu);


		$copyObj->setNew(true);

		$copyObj->setIdComision(NULL); 
		$copyObj->setNitocc(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 ComisionadosPlantaPeer();
		}
		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)) {
		if ($this->aTerceros === null) {
						$this->aTerceros = TercerosPeer::retrieveByPK($this->nitocc, $con);

			
		}
		return $this->aTerceros;
	}

	
	public function setTransportes($v)
	{


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


		$this->aTransportes = $v;
	}


	
	public function getTransportes($con = null)
	{
		if ($this->aTransportes === null && ($this->id_transporte > 0)) {
						$this->aTransportes = TransportesPeer::retrieveByPK($this->id_transporte, $con);

			
		}
		return $this->aTransportes;
	}

	
	public function setRegionales($v)
	{


		if ($v === null) {
			$this->setCodreg(NULL);
		} else {
			$this->setCodreg($v->getCodreg());
		}


		$this->aRegionales = $v;
	}


	
	public function getRegionales($con = null)
	{
		if ($this->aRegionales === null && (($this->codreg !== "" && $this->codreg !== null))) {
						$this->aRegionales = RegionalesPeer::retrieveByPK($this->codreg, $con);

			
		}
		return $this->aRegionales;
	}

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

} 