<?php

/**
 * notifica_levanta actions.
 *
 * @package    cobro_coactivo
 * @subpackage notifica_levanta
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class notifica_levantaActions 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_levanta_medida = $request['id_levanta_medida'];
            
                
            
            //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 levanta.id_tipo_notifica from cbr_notifica_medida levanta where levanta.id_tipo_notifica = ordenar.id_tipo_notifica and levanta.notificado = 0 and levanta.id_levanta_medida=$id_levanta_medida
    )

)
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 levanta.id_tipo_notifica from cbr_notifica_medida levanta where levanta.id_tipo_notifica = ordenar.id_tipo_notifica and levanta.notificado = 0 and levanta.id_levanta_medida=$id_levanta_medida
    )

)
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("[documento_modalidad] 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());
        }
        
        
    }
}
