<?
header("Content-Type: application/xhtml+xml; charset=utf-8");
use_helper('UrlFunctions');
$o_ObjectBean = new CrCreditoPagoFN();
  
$tamanioPag = 50;
$o_ObjectBean->setEliminado('-1');

if($cboMercado    !=""){ $o_ObjectBean->setIdMercado($cboMercado); }
if($IdHipoteca    !=""){ $o_ObjectBean->setIdcreditocrono($IdHipoteca); }
if($IdCliente    !=""){ $o_ObjectBean->setIdCliente($IdCliente); }
if($txtNombre      !=""){ $o_ObjectBean->setDeudor($txtNombre); } 
if($cboEstado        !=""){ $o_ObjectBean->setEstado($cboEstado); }
if($cboMoneda        !=""){ $o_ObjectBean->setMoneda($cboMoneda); }
if($txtFechaInicial   !=""){ $o_ObjectBean->setFechatrxInicio($txtFechaInicial); }
if($txtFechaFinal   !=""){ $o_ObjectBean->setFechatrxFinal($txtFechaFinal); }


if(!isset($sortCampos))$sortCampos= "Tipopago";
if(!isset($sortType))  $sortType ="1";

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


$a_ObjectBean = $o_ObjectBean->select();

$o_navigation = new navigation();
$o_navigation->setPaginaActual($page);
$o_navigation->setTamanioPagina($tamanioPag);
$o_navigation->setTotalRegistros($o_ObjectBean->selectNumRows());
$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="4%" align="left" >N.Credito</th>
                <th width="4%" align="left" >C.Cliente</th>
                 <th width="13%" align="left">Nombre</th>
                 <th width="3%" >F.Trx.</th>
			    <th width="10%" align="left">M.Total Credito</th>
			    <th width="10%" align="left">Saldo Credito</th>
			    
			   
			    <th width="3%" align="left" >Tipo</th>
			    <th width="8%" align="center" >Banco/Recibo</th>
			    <th width="3%" >Moneda</th>
			    
			    <th width="8%" align="right" >M.Pagado</th>
				
                <th width="8%" id="col01" onMouseOver="sort_col(this);" >Usr.Crea.</th>
                <th width="12%" id="col01" onMouseOver="sort_col(this);" >Fec.Crea.</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->getIdcreditocrono()?></td>
                <td align="center"><?=$o_objBean->getIdcliente()?></td>
                <td align="left"><?
                
                echo $o_objBean->getNombreCompleto()?></td>
                <td align="right"><?=$o_objBean->getFechaTrx()?>&nbsp;</td>
                <td align="left"><?=$o_objBean->getMontotalCredito()?></td>
                <td align="left"><?=$o_objBean->getMontotalCredito()?></td>
                <td align="left"><?
                if($o_objBean->getTipopago() == "M") echo "Mora";
                if($o_objBean->getTipopago() == "C") echo "Cuota";
                ?></td>
                <td align="center">
                 <?
                 if($o_objBean->getBanco()){
	                if(strtolower($o_objBean->getBanco()) == "bcp") echo "BCP - Banco de Credito";
	                if(strtolower($o_objBean->getBanco()) == "int") echo "Interbank";
	                if(strtolower($o_objBean->getBanco()) == "bbva") echo "BBVA - Banco Continental.";
	                if(strtolower($o_objBean->getBanco()) == "bco") echo "Banco Comercio";
	                if(strtolower($o_objBean->getBanco()) == "bna") echo "Banco de la Naci&oacute;n";
	                echo " | ".$o_objBean->getNumerooperacion();
                 }else{
                 	echo $o_objBean->getNumerorecibo();
                 }
                ?></td>
                
                <td align="center"><?
                if($o_objBean->getMoneda() == "S") echo "S/.";
                if($o_objBean->getMoneda() == "D") echo "$";
                ?>
                </td>
                
                <td align="right"><?=number_format($o_objBean->getMontoPago(),2)?>&nbsp;</td>
                
                <td align="center"><?=$o_objBean->getUsaurioCreacion()?></td>
                <td align="center"><?=$o_objBean->getFechaCreacion()?></td>
                
              </tr>
              <? } ?>
              <? }else{ ?>
              <tr>
                <td colspan="8" align="center">No se produjo resultado</td>
              </tr>
              <? } ?>
            </table>
          </td>
        </tr>
        <tr>
          <td>Total Registros: <?=count($a_ObjectBean)?>&nbsp; <b>Monto Total de Pagos: <?=number_format($o_ObjectBean->selectTotalPagos(),2);?></b></td>
        </tr>
      </table>