<?php

/**
 * notifica_etapa_arc actions.
 *
 * @package    cobro_coactivo
 * @subpackage notifica_etapa_arc
 * @author     Manuel Enrique Paredes Lopez
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class notifica_etapa_arcActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  
    
    public function executeList(sfWebRequest $request) {

        //Revisar que sea post
        //$this->forward404Unless($request->isMethod('post'));
        //Guardar los parametros del request en el log
        $this->logMessage("---BEGIN Logging request");
        foreach ($request->getPostParameters() as $key => $value) {
            $this->logMessage("request[$key] = $value");
        }
        $this->logMessage("--------------------------------------------------*  Ip: " . $_SERVER['REMOTE_ADDR']);
        foreach ($request->getGetParameters() as $key => $value) {
            $this->logMessage("request[$key] = $value");
        }
        $this->logMessage("---END Logging request");

        /*
         * Paginacion
         */
        if (isset($request['_startRow'])) {
            $rowStart = $request['_startRow'];
        } else {
            $rowStart = 0;
        }

        if (isset($request['_endRow'])) {
            $rowEnd = $request['_endRow'];
        } else {
            $rowEnd = 75;
        }

        //ordenar consulta
        if (isset($request['_sortBy'])) {
            $sortBy = 'order by tab0.orden';
        } else {
            $sortBy = 'order by tab0.orden';
        }
        
        try {
            
            $id_remision_titulo = $request['id_remision_titulo'];
            
                
            
            //sentencia sql
            $sql = <<<EOD
ALTER SESSION SET NLS_DATE_FORMAT = "YYYY-MM-DD"
EOD;
            //ejecuta y obtiene el resultado del sql
            CN_TABLE::executeSQL($sql);
            
            $sql = <<<EOD
                    select count(*) as count from (
select tab0.*

from cbr_tipo_notifica tab0

where tab0.orden = (select min(ordenar.orden) from cbr_tipo_notifica ordenar where not exists(
select etapa.id_tipo_notifica from cbr_notificacion_archivar etapa where etapa.id_tipo_notifica = ordenar.id_tipo_notifica and etapa.notificado = 0 and etapa.id_remision_titulo=$id_remision_titulo
    )

)
or tab0.opcional=1
                    )
EOD;
            
        $total_record_count = CN_TABLE::executeSQL($sql);
        $total_record_count = $total_record_count[0]["count"];
        
        
        $sql = <<<EOD
                SELECT * FROM ( SELECT row_.*, ROWNUM rownum_ FROM (
select tab0.*

from cbr_tipo_notifica tab0

where tab0.orden = (select min(ordenar.orden) from cbr_tipo_notifica ordenar where not exists(
select etapa.id_tipo_notifica from cbr_notificacion_archivar etapa where etapa.id_tipo_notifica = ordenar.id_tipo_notifica and etapa.notificado = 0 and etapa.id_remision_titulo=$id_remision_titulo
    )

)
or tab0.opcional=1
    $sortBy
          
) row_ WHERE ROWNUM <=  $rowEnd   ) where rownum_ >  $rowStart
EOD;
            
        $resultado = CN_TABLE::executeSQL($sql);
        


            $this->totalRows = $total_record_count;
            $this->startRow = $rowStart;
            $this->endRow = $rowStart + count($resultado);
            $this->list_data = $resultado;
            $this->logMessage("[notifica_etapa_arc] Consulta exitosa.");
            
            
        } catch (Exception $e) {

            $this->status = 1;
            $this->totalRows = 0;
            $this->startRow = 0;
            $this->endRow = 0;
            $this->list_data = array();
            $this->logMessage("ERROR!!!");
            $this->logMessage($e->getMessage());
        }
        
        
    }
}
