<?php
/* Autor...: William L. Taype Perez */
/* Esquema.: TR_Vehiculo.xml */
/* Generado: 2021-09-09 16:56:52 */

/* Mantenimiento de los registros de la tabla TR_Vehiculo */
abstract class BaseTR_VehiculoDP extends TR_VehiculoBV
{
    /* Constructor ( Establece los valores desde un objeto TR_VehiculoBN ) */
    public function __construct( TR_VehiculoBN $o_TR_VehiculoBN = null )
    {
        parent::__construct();
        if ( !is_null( $o_TR_VehiculoBN ) )
        {
            $this->setByBN( $o_TR_VehiculoBN );
        }
    }

    public $b_Debug = false;

    public function getDebug()
    {
        if( SF_DEBUG )
        {
            $this->b_Debug = true;
        }
        return $this->b_Debug;
    }

    public function setDebug( $v )
    {
        $this->b_Debug = $v;
    }

    /* Establece los valores desde un objeto TR_VehiculoBN */
    public function setByBN( TR_VehiculoBN $o_TR_VehiculoBN )
    {
        if ( !is_null( $o_TR_VehiculoBN->getIdVehiculo() ) )
        {
            $this->setIdVehiculo( $o_TR_VehiculoBN->getIdVehiculo() );
        }
        if ( !is_null( $o_TR_VehiculoBN->getIdCompania() ) )
        {
            $this->setIdCompania( $o_TR_VehiculoBN->getIdCompania() );
        }
        if ( !is_null( $o_TR_VehiculoBN->getIdSucursal() ) )
        {
            $this->setIdSucursal( $o_TR_VehiculoBN->getIdSucursal() );
        }
        if ( !is_null( $o_TR_VehiculoBN->getVehiculoPlaca() ) )
        {
            $this->setVehiculoPlaca( $o_TR_VehiculoBN->getVehiculoPlaca() );
        }
        if ( !is_null( $o_TR_VehiculoBN->getVehiculoPlaca2() ) )
        {
            $this->setVehiculoPlaca2( $o_TR_VehiculoBN->getVehiculoPlaca2() );
        }
        if ( !is_null( $o_TR_VehiculoBN->getVehiculoMarca() ) )
        {
            $this->setVehiculoMarca( $o_TR_VehiculoBN->getVehiculoMarca() );
        }
        if ( !is_null( $o_TR_VehiculoBN->getVehiculoMdelo() ) )
        {
            $this->setVehiculoMdelo( $o_TR_VehiculoBN->getVehiculoMdelo() );
        }
        if ( !is_null( $o_TR_VehiculoBN->getNroMotor() ) )
        {
            $this->setNroMotor( $o_TR_VehiculoBN->getNroMotor() );
        }
        if ( !is_null( $o_TR_VehiculoBN->getAltura() ) )
        {
            $this->setAltura( $o_TR_VehiculoBN->getAltura() );
        }
        if ( !is_null( $o_TR_VehiculoBN->getVolumen() ) )
        {
            $this->setVolumen( $o_TR_VehiculoBN->getVolumen() );
        }
        if ( !is_null( $o_TR_VehiculoBN->getNroSOAT() ) )
        {
            $this->setNroSOAT( $o_TR_VehiculoBN->getNroSOAT() );
        }
        if ( !is_null( $o_TR_VehiculoBN->getVencSOAT() ) )
        {
            $this->setVencSOAT( $o_TR_VehiculoBN->getVencSOAT() );
        }
        if ( !is_null( $o_TR_VehiculoBN->getNroMTC() ) )
        {
            $this->setNroMTC( $o_TR_VehiculoBN->getNroMTC() );
        }
        if ( !is_null( $o_TR_VehiculoBN->getRUCtransportista() ) )
        {
            $this->setRUCtransportista( $o_TR_VehiculoBN->getRUCtransportista() );
        }
        if ( !is_null( $o_TR_VehiculoBN->getEstado() ) )
        {
            $this->setEstado( $o_TR_VehiculoBN->getEstado() );
        }
        if ( !is_null( $o_TR_VehiculoBN->getFechaCreacion() ) )
        {
            $this->setFechaCreacion( $o_TR_VehiculoBN->getFechaCreacion() );
        }
        if ( !is_null( $o_TR_VehiculoBN->getUsuarioCreacion() ) )
        {
            $this->setUsuarioCreacion( $o_TR_VehiculoBN->getUsuarioCreacion() );
        }
        if ( !is_null( $o_TR_VehiculoBN->getFechaModificacion() ) )
        {
            $this->setFechaModificacion( $o_TR_VehiculoBN->getFechaModificacion() );
        }
        if ( !is_null( $o_TR_VehiculoBN->getUsuarioModificacion() ) )
        {
            $this->setUsuarioModificacion( $o_TR_VehiculoBN->getUsuarioModificacion() );
        }
    }

    /* Graba un nuevo registro */
    public function save()
    {
        $this->validateRecord();
        $o_TR_VehiculoFN = new TR_VehiculoFN();
        $o_TR_VehiculoBN = $o_TR_VehiculoFN->selectByPk( $this->getIdVehiculo() );
        if ( is_null( $o_TR_VehiculoBN ) )
        {
            $s_SQLQuery1 = "INSERT INTO TR_Vehiculo ( ";
            $s_SQLQuery2 = "VALUES ( ";
            $s_Separator = "";
            if ( !is_null( $this->getIdVehiculo() ) )
            {
                $s_SQLQuery1 .= $s_Separator."IdVehiculo";
                $s_SQLQuery2 .= $s_Separator."".$this->getIdVehiculo()."";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getIdCompania() ) )
            {
                $s_SQLQuery1 .= $s_Separator."IdCompania";
                $s_SQLQuery2 .= $s_Separator."".$this->getIdCompania()."";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getIdSucursal() ) )
            {
                $s_SQLQuery1 .= $s_Separator."IdSucursal";
                $s_SQLQuery2 .= $s_Separator."".$this->getIdSucursal()."";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getVehiculoPlaca() ) )
            {
                $s_SQLQuery1 .= $s_Separator."VehiculoPlaca";
                $s_SQLQuery2 .= $s_Separator."'".$this->getVehiculoPlaca()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getVehiculoPlaca2() ) )
            {
                $s_SQLQuery1 .= $s_Separator."VehiculoPlaca2";
                $s_SQLQuery2 .= $s_Separator."'".$this->getVehiculoPlaca2()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getVehiculoMarca() ) )
            {
                $s_SQLQuery1 .= $s_Separator."VehiculoMarca";
                $s_SQLQuery2 .= $s_Separator."'".$this->getVehiculoMarca()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getVehiculoMdelo() ) )
            {
                $s_SQLQuery1 .= $s_Separator."VehiculoMdelo";
                $s_SQLQuery2 .= $s_Separator."'".$this->getVehiculoMdelo()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getNroMotor() ) )
            {
                $s_SQLQuery1 .= $s_Separator."NroMotor";
                $s_SQLQuery2 .= $s_Separator."'".$this->getNroMotor()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getAltura() ) )
            {
                $s_SQLQuery1 .= $s_Separator."Altura";
                $s_SQLQuery2 .= $s_Separator."'".$this->getAltura()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getVolumen() ) )
            {
                $s_SQLQuery1 .= $s_Separator."Volumen";
                $s_SQLQuery2 .= $s_Separator."'".$this->getVolumen()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getNroSOAT() ) )
            {
                $s_SQLQuery1 .= $s_Separator."NroSOAT";
                $s_SQLQuery2 .= $s_Separator."'".$this->getNroSOAT()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getVencSOAT() ) )
            {
                $s_SQLQuery1 .= $s_Separator."VencSOAT";
                $s_SQLQuery2 .= $s_Separator."'".$this->getVencSOAT()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getNroMTC() ) )
            {
                $s_SQLQuery1 .= $s_Separator."NroMTC";
                $s_SQLQuery2 .= $s_Separator."'".$this->getNroMTC()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getRUCtransportista() ) )
            {
                $s_SQLQuery1 .= $s_Separator."RUCtransportista";
                $s_SQLQuery2 .= $s_Separator."'".$this->getRUCtransportista()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getEstado() ) )
            {
                $s_SQLQuery1 .= $s_Separator."Estado";
                $s_SQLQuery2 .= $s_Separator."'".$this->getEstado()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getFechaCreacion() ) )
            {
                $s_SQLQuery1 .= $s_Separator."FechaCreacion";
                $s_SQLQuery2 .= $s_Separator."'".$this->getFechaCreacion()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getUsuarioCreacion() ) )
            {
                $s_SQLQuery1 .= $s_Separator."UsuarioCreacion";
                $s_SQLQuery2 .= $s_Separator."'".$this->getUsuarioCreacion()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getFechaModificacion() ) )
            {
                $s_SQLQuery1 .= $s_Separator."FechaModificacion";
                $s_SQLQuery2 .= $s_Separator."'".$this->getFechaModificacion()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getUsuarioModificacion() ) )
            {
                $s_SQLQuery1 .= $s_Separator."UsuarioModificacion";
                $s_SQLQuery2 .= $s_Separator."'".$this->getUsuarioModificacion()."'";
                $s_Separator = ", ";
            }
            $s_SQLQuery = $s_SQLQuery1." ) ".$s_SQLQuery2." );";
            if( $this->getDebug() ){ pr( $s_SQLQuery ); }
            $o_Resource = Conexion::getConexion();
            $o_Statement = $o_Resource->createStatement();
            $o_Statement->executeQuery( $s_SQLQuery );
        }
        else
        {
            throw new Exception( "El id ya esta registrado." );
        }
        return true;
    }

    /* Actualiza los datos del registro */
    public function update()
    {
        $this->validateRecord();
        if ( true )
        {
            $s_SQLQuery = "UPDATE TR_Vehiculo SET ";
            $s_Separator = "";
            if ( !is_null( $this->getIdCompania() ) )
            {
                $s_SQLQuery .= $s_Separator."IdCompania = ".$this->getIdCompania()."";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getIdSucursal() ) )
            {
                $s_SQLQuery .= $s_Separator."IdSucursal = ".$this->getIdSucursal()."";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getVehiculoPlaca() ) )
            {
                $s_SQLQuery .= $s_Separator."VehiculoPlaca = '".$this->getVehiculoPlaca()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getVehiculoPlaca2() ) )
            {
                $s_SQLQuery .= $s_Separator."VehiculoPlaca2 = '".$this->getVehiculoPlaca2()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getVehiculoMarca() ) )
            {
                $s_SQLQuery .= $s_Separator."VehiculoMarca = '".$this->getVehiculoMarca()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getVehiculoMdelo() ) )
            {
                $s_SQLQuery .= $s_Separator."VehiculoMdelo = '".$this->getVehiculoMdelo()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getNroMotor() ) )
            {
                $s_SQLQuery .= $s_Separator."NroMotor = '".$this->getNroMotor()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getAltura() ) )
            {
                $s_SQLQuery .= $s_Separator."Altura = '".$this->getAltura()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getVolumen() ) )
            {
                $s_SQLQuery .= $s_Separator."Volumen = '".$this->getVolumen()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getNroSOAT() ) )
            {
                $s_SQLQuery .= $s_Separator."NroSOAT = '".$this->getNroSOAT()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getVencSOAT() ) )
            {
                $s_SQLQuery .= $s_Separator."VencSOAT = '".$this->getVencSOAT()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getNroMTC() ) )
            {
                $s_SQLQuery .= $s_Separator."NroMTC = '".$this->getNroMTC()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getRUCtransportista() ) )
            {
                $s_SQLQuery .= $s_Separator."RUCtransportista = '".$this->getRUCtransportista()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getEstado() ) )
            {
                $s_SQLQuery .= $s_Separator."Estado = '".$this->getEstado()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getFechaCreacion() ) )
            {
                $s_SQLQuery .= $s_Separator."FechaCreacion = '".$this->getFechaCreacion()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getUsuarioCreacion() ) )
            {
                $s_SQLQuery .= $s_Separator."UsuarioCreacion = '".$this->getUsuarioCreacion()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getFechaModificacion() ) )
            {
                $s_SQLQuery .= $s_Separator."FechaModificacion = '".$this->getFechaModificacion()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getUsuarioModificacion() ) )
            {
                $s_SQLQuery .= $s_Separator."UsuarioModificacion = '".$this->getUsuarioModificacion()."'";
                $s_Separator = ", ";
            }
            $s_SQLQuery .= " WHERE  IdVehiculo = ".$this->getIdVehiculo().";";
            if( $this->getDebug() ){ pr( $s_SQLQuery ); }

            $o_Resource = Conexion::getConexion();
            $o_Statement = $o_Resource->createStatement();
            $o_Statement->executeQuery( $s_SQLQuery );
        }
        else
        {
            throw new Exception( "El id no esta registrado." );
        }
        return true;
    }

    /* Elimina el registro */
    public function delete()
    {
        $s_SQLQuery = "DELETE FROM TR_Vehiculo WHERE  IdVehiculo = ".$this->getIdVehiculo().";";
        if( $this->getDebug() ){ pr( $s_SQLQuery ); }
        $o_Resource = Conexion::getConexion();
        $o_Statement = $o_Resource->createStatement();
        $o_Statement->executeQuery( $s_SQLQuery );
        return true;
    }

}
?>