<?
header("Content-Type: application/xhtml+xml; charset=iso-8859-1");
use_helper('UrlFunctions');
//COLOCAR CAMPOS DE LA CABECERA DEL LISTADO 


$o_class = new Cr_cliente_fileFN();
$o_class->setIdtipofile(9);
if( isset( $txtNuemroCliente ) && $txtNuemroCliente != "" ){$o_class->setIdCliente( $txtNuemroCliente );};
$o_class->setEliminado( -1 );

if($txtNombre      	!="" && $cboTipoNombre == "AP"){ $o_class->setApellidoPaterno($txtNombre); }
if($txtNombre     	!="" && $cboTipoNombre == "AM"){ $o_class->setApellidoMaterno($txtNombre); }
if($txtNombre     	!="" && $cboTipoNombre == "NO"){ $o_class->setNombres($txtNombre); }

if( isset( $Estado ) && $Estado != "" ){ $o_class->setEstado( $Estado ); }
if( isset( $cboSucursal ) && $cboSucursal != "" ){ $o_class->setIdSucursal( $cboSucursal ); }
if( isset( $cboMercado ) && $cboMercado != "" ){ $o_class->setIdMercado( $cboMercado ); }
if( isset( $Tipo ) && $Tipo != "" ){ $o_class->setIdtipofile( $Tipo ); }
if( isset( $txtFechaInicial ) && $txtFechaInicial != "" ){ $o_class->addCondition( Cr_cliente_fileFN::FechaRegistro, ">=", $txtFechaInicial ); }
if( isset( $txtFechaFinal ) && $txtFechaFinal != "" ){ $o_class->addCondition( Cr_cliente_fileFN::FechaRegistro, "<=", $txtFechaFinal." 23:59:59" ); }
$o_class->addOrderBy(Cr_cliente_fileFN::IdClienteFile,false);
$tamanioPag = 10;
if( !isset( $page ) ) $page = 1;
$limitInf = ( $page - 1 ) * $tamanioPag;

$a_ObjectBean = $o_class->selectRep( $limitInf, $tamanioPag );
$i_NumReg     = $o_class->selectNumRowsRep();

$o_navigation = new navigation();
$o_navigation->setPaginaActual( $page );
$o_navigation->setTamanioPagina( $tamanioPag );
$o_navigation->setTotalRegistros( $i_NumReg );





 


if(!$page) $page = 1;



ViewResponse::getInstance()->setMethodAjax();

?>
<script>
functionSort = function(campo, type){
  var typeSort      = "";
  var elmSortCampos = $('sortCampos');
  var elmSortType   = $('sortType');
  var a_sortCampos  = elmSortCampos.value!=""?elmSortCampos.value.split(";"):[];
  var a_sortType    = elmSortType.value!=""?elmSortType.value.split(";"):[];
  var pos           = a_sortCampos.indexOf(campo);
  switch (type){
     case 'A' :
       a_sortType[pos]    = "2";
     break;
     case 'D' :
       a_sortCampos = sliceByPos(a_sortCampos, pos);
       a_sortType   = sliceByPos(a_sortType, pos);
     break;
     default :
       a_sortCampos[a_sortCampos.length] = campo;
       a_sortType[a_sortType.length]     = "1";
     break;
  }
  var strSortCampos = a_sortCampos.join(";");
  var strSortType   = a_sortType.join(";");
  concatValueStr('sortCampos='+strSortCampos+'&sortType='+strSortType+"&page=<?=$page?>");
}
</script>

<?php

$strConcat = "sortCampos=".$valuesSort['sortCampos']."&sortType=".$valuesSort['sortType'];

function showImgOrder($valuesSort, $campo, $nameCampos){
  $a_valCampos = explode(";", $valuesSort['sortCampos']);
  $a_valtype   = explode(";", $valuesSort['sortType']);
  $sImg = "
            <a href=\"JavaScript:functionSort('".$campo."', '');\">".$nameCampos."</a>
            <img src=\"/images/common/buttons/arrow.gif\" alt=\"Ordenado Ascendente\" width=\"8\" height=\"10\" align=\"absmiddle\" />
          ";
  foreach ($a_valCampos as $key => $val){
    if($val == $campo){
      switch ($a_valtype[$key]){
        case 1:
          $sImg = "
                    <a href=\"JavaScript:functionSort('".$campo."', 'A');\">".$nameCampos."</a>
                    <img src=\"/images/common/buttons/arrow_up.gif\" alt=\"Ordenado Ascendente\" width=\"8\" height=\"10\" align=\"absmiddle\" />
                  ";
        break;
        case 2:
          $sImg = "
                    <a href=\"JavaScript:functionSort('".$campo."', 'D');\">".$nameCampos."</a>
                    <img src=\"/images/common/buttons/arrow_down.gif\" alt=\"Ordenado Ascendente\" width=\"8\" height=\"10\" align=\"absmiddle\" />
                  ";
        break;
      }
    }
  };
  return $sImg;
}
?>

<input type="hidden" id="sortCampos" size="100" value="<?=$valuesSort['sortCampos']?>">
<input type="hidden" id="sortType" size="100" value="<?=$valuesSort['sortType']?>">
<table class="marco" border="0" cellpadding="0" cellspacing="0" width="100%">
	    <tr>
	        <td height="17" align="right" class="pager">
	            <div id="contenedor">
	                <?php echo $o_navigation->ContruirHTMLNavigation( 'contenedor', $strConcat ); ?>
	            </div>
	        </td>
	    </tr>
	    <tr>
	        <td>
                    <table class="grid" width="100%" border="0" cellpadding="2" cellspacing="0">
                        <tr>
                            <th width="5%" nowrap="nowrap">Nro</th>
                            <th width="10%" nowrap="nowrap">Cod.Cli.</th>
                            <th width="10%" nowrap="nowrap">Cliente</th>
    						<th width="5%" nowrap="nowrap">Tipo</th>
    						<th width="5%" nowrap="nowrap">Estado</th>
    						<th width="10%" nowrap="nowrap">Fecha de Registro</th>
    						<th width="10%" nowrap="nowrap">Usr Registro</th>
                            <th width="10%" nowrap="nowrap">Opciones</th>
                        </tr>

                        <?php if( $a_ObjectBean ){ ?>
                            <?php foreach ( $a_ObjectBean as $i_Key => $o_Cr_cliente_fileBN ){ ?>
                                <?php
                                $i_IdClienteFile = $o_Cr_cliente_fileBN->getIdClienteFile();
                                $i_IdCliente = $o_Cr_cliente_fileBN->getIdCliente();
                                $i_IdTipoFile = $o_Cr_cliente_fileBN->getIdClienteFile();
                                $i_IdTipoFile2 = $o_Cr_cliente_fileBN->getIdTipoFile();
                                $o_Cr_tipo_fileFN = new Cr_tipo_fileFN();
                                $o_Cr_tipo_fileBN = $o_Cr_tipo_fileFN->selectByPK( $i_IdTipoFile2 );
                                if( $o_Cr_tipo_fileBN )
                                {
                                    $s_Descripcion = $o_Cr_tipo_fileBN->getDescripcion();
                                }
                                $s_EstadoDes = $o_Cr_cliente_fileBN->getEstado()=="A"?"Activo":"Anulado";
                                $o_ObjectBean = new ClienteBean();
                                $o_ObjectBean->setIdCliente($i_IdCliente);
                                $o_ObjectDP = new ClienteDP($o_ObjectBean);
                                $a_clientes = $o_ObjectDP->selectByPk();
                                if(is_array($a_clientes)){
                               		$nombreCliente = $a_clientes[0]->getNombreCompleto();
                                }
                                ?>
                            <tr>
                                <td style="text-align: center;"><?php echo $i_Key + 1 ?></td>
                                <td style="text-align: center;"><?php echo $i_IdCliente; ?></td>
                                <td style="text-align: center;"><?php echo $nombreCliente ?></td>
                                <td style="text-align: center;"><?php echo $s_Descripcion ?></td>
                                <td style="text-align: center;"><?php echo $s_EstadoDes ?></td>
                                <td style="text-align: center;"><?php echo $o_Cr_cliente_fileBN->getFechaRegistro() ?></td>
                                <td style="text-align: center;"><?php echo $o_Cr_cliente_fileBN->getUsuarioRegistro() ?></td>
                                <td style="text-align: center;">
                                    <input type="button" class="button" value="Ver" onclick="abrirVentanaVer( '<?php echo $i_IdClienteFile ?>', '1' );"/>&nbsp;
                                    
                                </td>
                            </tr>
                            <?php } ?>
                        <?php } ?>
                    </table>
	                                        
	            
	        </td>
	    </tr>
	    <tr>
	          <td style="background-color:#005ea8; color:#FFFFFF">Total registros: <?=count($a_ObjectBean)?></td>
	    </tr>
	    
	</table>