<?php
/* Busqueda de registros de la tabla TR_Chofer redefinidos por el usuario. */
class TR_ChoferFN extends BaseTR_ChoferFN
{
    public static function recuperarId()
    {
        $s_Sql = "SELECT IF( MAX( IdChofer ) IS NULL, 1, MAX( IdChofer ) + 1 ) i_Id FROM TR_Chofer;";
        $o_ResultSet = Conexion::getConexion()->prepareStatement( $s_Sql )->executeQuery();
        $o_ResultSet->next();
        return $o_ResultSet->getInt( 'i_Id' );
    }

    public static function selectActivos()
    {
        $o_TR_ChoferFN = new TR_ChoferFN();
        $o_TR_ChoferFN->setEstado( "A" );
        return $o_TR_ChoferFN->select();
    }
    
    public static function selectActivosProg( $s_FechaProgramada, $i_Turno, $i_Vehiculo )
    {
        $s_Sql = "
                    SELECT
                        (
                            SELECT IdRuta 
                            FROM TR_Ruta 
                            WHERE 1=1
                                AND RutaFechaProgramada='$s_FechaProgramada' 
                                AND IdChofer=C.IdChofer  
                                AND IdTurno='$i_Turno' 
                                AND IdVehiculo='$i_Vehiculo' 
                                AND IdCompania='".myUser::getUser()->getIdBusiness()."' 
                                AND IdSucursal='".myUser::getUser()->getIdSucursal()."'
                        ) IdRuta,
                        C.*
                    FROM TR_Chofer C
                    WHERE 1=1
                    AND C.Estado='A'
                    ORDER BY C.ChoferNombre;";
        $o_ResultSet = Conexion::getConexion()->prepareStatement( $s_Sql )->executeQuery();
        $a_ObjectArrayBN = array();
        $o_ObjectFN = new TR_ChoferFN();
        while( $o_ResultSet->next() ) 
        {
            $o_SQLRow = $o_ResultSet->getRow();
            $o_DefaultBN = $o_ObjectFN->insertObjectBN( $o_SQLRow );
            if( $o_SQLRow['IdRuta'] )
            {
                $o_DefaultBN->setChoferNombre( $o_DefaultBN->getChoferNombre()." (PROG)" );
            }
            $a_ObjectArrayBN[] = $o_DefaultBN;
        }
        return $a_ObjectArrayBN;
    }
}
?>