<?php
class GridRutaExistAction extends wtActions
{
    public function execute()
    {
        //////////////////////////////////////////////////////////////////////////////////////
        $o_GridAction = new GridAction();
        $o_GridAction->setClassFind( new TR_RutaFN() );
        
        $o_GridAction->addMethodDefault( "IdCompania", myUser::getUser()->getIdBusiness() );
        
        //$o_GridAction->addAssignFilter( "RutaFechaProgramada" );
        $o_GridAction->addAssignFilter( "IdTurno" );
        $o_GridAction->addConditionFilter( "RutaFechaDesde", TR_RutaFN::RutaFechaProgramada,  ">=", '00:00:00' );
        $o_GridAction->addConditionFilter( "RutaFechaHasta", TR_RutaFN::RutaFechaProgramada,  "<=", '23:59:59' );
        //$o_GridAction->addConditionFilter( "RutaFechaHasta", TR_RutaFN::RutaFechaProgramada,  "<=", '23:59:59' );
        
        $o_GridAction->addMethodDefault( TR_RutaFN::Estado, array( 'Condition'=>'NOT IN', 'Value'=>"('A')" ) );
        
        /*ParameterWR::getInstance()->setVar( "TotalDetalle", '0' );
        $o_GridAction->addConditionFilter( "TotalDetalle", "( SELECT COUNT(*) FROM TR_RutaDetalle WHERE IdRuta=TR_Ruta.IdRuta )",  ">" );*/
        
        $o_GridAction->addOrderDefault( TR_RutaFN::IdTurno, true );
        
        $o_GridAction->setControlArray( false );
        
        $o_GridAction->setNumberRecordsShow( 9999 );
        
        $o_GridAction->initialize();
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        $a_ResultJson['page']    = $o_GridAction->getPage();
        $a_ResultJson['total']   = $o_GridAction->getTotalPage();
        $a_ResultJson['records'] = $o_GridAction->getTotalRecords();
        //$a_ResultJson['rows']    = $o_GridAction->getResultArray();
        $this->a_TR_Ruta = $o_GridAction->getResultSelect();
        
        //pr($this->a_TR_Ruta);
        ////////////////////////////////////////////////////////////////////////////////////
        
        //para resultados por ajax
        ViewResponse::getInstance()->setMethodAjax();
    }
}