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

if($txtNuemroPrestamo   !=""){ $o_ObjectBean->setIdPrestamo($txtNuemroPrestamo); }
if($cboEstadoPrestamo  !=""){ $o_ObjectBean->setEstado($cboEstadoPrestamo); }
//if($cboMercado     	!=""){ $o_ObjectBean->setObjectCliente()->setIdMercado($cboMercado); }
if($nombre     		!="" && $cboTipoNombre == "AP"){ $o_ObjectBean->setApellidoPaterno($txtNombre); }
if($nombre     		!="" && $cboTipoNombre == "AM"){ $o_ObjectBean->setApellidoMaterno($txtNombre); }
if($nombre     		!="" && $cboTipoNombre == "NO"){ $o_ObjectBean->setNombres($txtNombre); }
if($cboOrigen  !=""){ $o_ObjectBean->setOrigen($cboOrigen); }


 $o_ObjectBean->page = $page;
 $o_ObjectBean->tamPag = $tamanioPag;
 $o_ObjectBean->sortCampos = $sortCampos;
 $o_ObjectBean->sortType   = $sortType;

	 
 
$o_class = new PrestamoBL();
$a_ObjectBean = $o_class->busquedaPrestamo($o_ObjectBean);

/*if(is_array($a_ObjectBean)){
  while(list($key,$o_ObjectBean) = each($a_ObjectBean)){
  	
  	$o_ClienteBean = new ClienteBean();
	$o_ClienteBean->setIdCliente($o_ObjectBean->getIdCliente());
	$o_class = new ClienteBL();
	$a_ObjectCliente = $o_class->busquedaCliente($o_ClienteBean);
	
	while(list($keyCli,$o_ObjectBeanCli) = each($a_ObjectCliente)){
		$Nombre = $o_ObjectBeanCli->getNombreCompleto();		
		$o_MercadoBean = new MercadoBean();
		$o_MercadoBean->setIdMercado($o_ObjectBeanCli->getIdMercado());
		$o_class = new MercadoBL();
		$ObjectBean = $o_class->busquedaMercado($o_MercadoBean);
		
		$NombreMercado = $ObjectBean[0]->getDescripcion();
	}
  }*/

//$o_ClienteSystemClass = new ClienteSystemClass(new MercadoBean());
//$a_Mercado = $o_ClienteSystemClass->getMercado();
  

$o_navigation = new navigation();
$o_navigation->setPaginaActual($page);
$o_navigation->setTamanioPagina($tamanioPag);
$o_navigation->setTotalRegistros($o_class->getCountResult($o_ObjectBean));
$valuesSort = array('sortCampos'=>$sortCampos, 'sortType'=>$sortType);

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">
              <? $o_navigation->ContruirHTMLNavigation('contenedor', $strConcat); ?>
            </div>
          </td>
        </tr>
        <tr>
          <td>
            <table class="grid" width="100%" border="0" cellpadding="0" cellspacing="0">
              <tr height="23">
               <!--<th width="4%" >Nro</th>-->
               <th width="3%" >Nš Pre.</th>
                 <!--<th width="18%" id="col01" onMouseOver="sort_col(this);" ><?=showImgOrder($valuesSort, 'Nombres','Nombres')?>&nbsp;</th>
				         <th width="11%" >Ap. Paterno &nbsp;&nbsp;&nbsp;</th>
				        <th width="11%" >Ap. Materno &nbsp;&nbsp;&nbsp;</th> -->
			    <th width="22%" >Cliente&nbsp;&nbsp;&nbsp;</th>
			    <th width="4%" >F. Ini&nbsp;&nbsp;&nbsp;</th>
				<th width="4%" >F. Fin&nbsp;&nbsp;&nbsp;</th>
				<th width="5%" >Capital &nbsp;&nbsp;&nbsp;</th>
                <th width="2%" >(%) &nbsp;&nbsp;&nbsp;</th>
                 <th width="6%" >M. Total &nbsp;&nbsp;&nbsp;</th>
                 <th width="5%" >Saldo &nbsp;&nbsp;&nbsp;</th>
                 <th width="5%" >C. Pago &nbsp;&nbsp;&nbsp;</th>
                <th width="4%" >Estado &nbsp;&nbsp;&nbsp;</th>
                <th width="3%" id="col01" onMouseOver="sort_col(this);" >Usr.Act.</th>
                <th width="3%" id="col01" onMouseOver="sort_col(this);" >Fec.Act.</th>
              
                <th width="3%">Opciones</th>
              </tr>
              <? if(count($a_ObjectBean)>0){ ?>
              <? foreach ($a_ObjectBean as $iKey => $o_objBean){ ?>
              <tr onClick="TR_click(this);">
                <!--<td class="chk"><?=($tamanioPag)*($page-1)+($iKey+1)?></td>-->
                <td align="center"><?=$o_objBean->getIdPrestamo()?></td>
               <td align="left"><?=$o_objBean->getObjectCliente()->getNombreCompleto()?></td>
                <td><?=$o_objBean->getFechaInicio()?></td>
                <td><?=$o_objBean->getFechaVencimiento()?></td>  
				<td align="center"><?=$o_objBean->getMontoPrestado() ; $total_prestamo +=$o_objBean->getMontoPrestado();?></td>
				<td align="center"><?=$o_objBean->getInteresPorcentaje()?></td>
				<td align="center"><?=$o_objBean->getMontoTotal() ; $total_monto +=$o_objBean->getMontoTotal();?></td>
				<td align="center"><?=$o_objBean->getSaldoPrestamo() ; $total_saldo +=$o_objBean->getSaldoPrestamo();?></td>
				<td align="center"><?=$o_objBean->getCuotaPago(); $total_couta+=$o_objBean->getCuotaPago();?></td>
				<td align="center"><?=$o_objBean->getEstado()?></td>
                <td align="center"><?=$o_objBean->getUsuarioModificacion()?></td>
                <td align="center"><?=$o_objBean->getFechaModificacion(date("Y-m-d"))?></td>
                <td align="center" valign="top">
                   
                   <img name="add" title="Ingreso de Pagos" src="/images/common/buttons/btnMoney.gif" onClick="exportFindControl('addpays');" style="cursor:pointer">
					<!-- <input type="image" name="Editar" src="/images/common/buttons/btnMoney.gif" title="Editar Pagos" onclick="parent.objMainTab.reqBody('<?=buildUrl('pag/edit/id/'.$o_objBean->getIdPrestamo());?>','001')">&nbsp;-->
                   <!--<input type="image" name="Eliminar" src="/images/common/buttons/btnDelete.gif" title="Eliminar Prsetamo" onclick="deleteRegistro('<?=$o_objBean->getIdCliente()?>','<?=$o_objBean->getIdCliente()?>')">&nbsp;-->
                  
                </td>
              </tr>
              <? } ?>
              <? }else{ ?>
              <tr>
                <td colspan="7" align="center">No se produjo resultado</td>
              </tr>
              <? } ?>
            </table>
          </td>
        </tr>
         <tr>
          <td>
	          <table class="marco" border="0" cellpadding="0" cellspacing="0" width="100%">
	            <tr>
	          		<td width="46%">T Registros: <?=count($a_ObjectBean)?></td>
	          		<td width="10%"><?=number_format($total_prestamo,2)?></td>
	          		<td width="7%"><?=number_format($total_monto,2)?></td>
	          		<td width="7%"><?=number_format($total_saldo,2)?></td>
	          		<td><?=number_format($total_couta,2)?></td>
	          		<td>&nbsp;</td>
	          		<!--<td><?=count($a_ObjectBean)?></td>-->
	          	</tr>
	          </table>
          </td>
        </tr>
      </table>