<?
header("Content-Type: application/xhtml+xml; charset=utf8");
use_helper('UrlFunctions');
$o_ObjectBean = new PrestamoBean();

  
$tamanioPag = 180;
//COLOCAR CAMPOS DE LA CABECERA DEL LISTADO  

if($cboMercado     	!=""){ $o_ObjectBean->setIdMercado($cboMercado);}
if($cboColaborador     	!=""){ 
	$o_ObjectBean->setIdColaboradorPrestamo($cboColaborador);
}else{
	if(myUser::getUser()->getRoleId() == "sys.gen" || myUser::getUser()->getRoleId() == "sys.res" || myUser::getUser()->getRoleId() == "sys.sup"|| myUser::getUser()->getRoleId() == "sys.view"){
		
	}else{
		$o_ObjectBean->setIdColaboradorPrestamo(myUser::getUser()->getIdColaborador());
	}
}

//print_r($_GET);

if($cboSucursal){
	
	//Obtener el Administrador
	$o_SucursalBean = new SucursalBean();
	$o_SucursalBean->setIdSucursal($cboSucursal);
	$o_SucursalBL = new SucursalBL();
	$a_o_sucursal = $o_SucursalBL->busquedaSucursal($o_SucursalBean);

	if(is_array($a_o_sucursal)){
		foreach ($a_o_sucursal as $key => $o_sucursal){
			$IdAdministrador = $o_sucursal->getIdAdministrador();
		}
	}
		
	$o_ColaboradorBean = new ColaboradorBean();
	$o_ColaboradorBean->setIdPadre($IdAdministrador);
	$o_ColaboradorBL = new ColaboradorBL();	
	$a_o_Colaborador = $o_ColaboradorBL->busquedaColaborador($o_ColaboradorBean);
	if(is_array($a_o_Colaborador)){
		foreach ($a_o_Colaborador as $key => $o_colaborador){
			$a_Colaborador[] = $o_colaborador->getIdColaborador();
		}
	}
	//print_r($a_Colaborador);
	$o_ObjectBean->setFiltroSucursal($a_Colaborador);	
	
}

if($TipoMoroso==1) $o_ObjectBean->setFlagReporte('1');
if($TipoMoroso==2){
	$o_ObjectBean->setVencido(1); 
	$o_ObjectBean->setFlagReporte('2');
}

$o_ObjectBean->setEstado('P');

if($cboMercado     	!= ""){
	 $o_ObjectBean->setIdMercado($cboMercado);	 
}

 $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);




$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="1" cellpadding="0" cellspacing="0">
              <tr height="35">
               <th width="3%" >Nro</th>
               <th width="4%" >N.Pre.</th>
               
    
			    <th width="20%" align="left">Nro Cliente - Nombre&nbsp;&nbsp;&nbsp;</th>
				<th width="4%" >Documento</th>
				<th width="4%" >Celular</th>
			    <th width="8%" >Estado</th>
			    <th width="3%" >F.Inicio</th>
				<th width="3%" >F.Vencim.</th>
				<th width="3%" >%</th>
                 <th width="5%" >M.Total</th>
                 <th width="5%" >Saldo</th>
                 <th width="5%" >Mora</th>
                 
                 <th width="5%" >Tipo</th>
                 
                 <th width="4%" >Cuota&nbsp;&nbsp;&nbsp;</th>
                 
              
              </tr>
              <? if(count($a_ObjectBean)>0){ 
              	$n=1;
				$color_v = "";
				foreach ($a_ObjectBean as $iKey => $o_objBean){ 
              	
              		?>

              <tr onClick="TR_click(this);">
              		<td style="background:<?=$color;?>"><?=$n;?></td>
              	<?php if(myUser::getUser()->getRoleId() != 'sys.ope'){?>
	                <td  align="center"><a style="cursor:pointer;text-decoration:underline;color:#00f;" href="#" onclick="parent.objMainTab.modalDialog('<?=buildUrlComplet('mnt.php/pre/estado_cuenta/id/'.$o_objBean->getIdPrestamo());?>',{title:'',width:710,height:520})"><?=$o_objBean->getIdPrestamo()?></a></td>
	                
	                <?php if(myUser::getUser()->getRoleId() == 'sys.gen' || myUser::getUser()->getRoleId() == 'sys.view'){?>
	                	<td  align="left"><a style="cursor:pointer;text-decoration:underline;color:#00f;" href="#" onclick="objMainTab.modalDialog('<?php echo buildUrlComplet( 'op.php/ajax/requestPdo', 's_TypeRequest=infopopupprestamo&i_idcliente='.$o_objBean->getIdCliente().'&s_tipo=' )?>',{width:900,height:420})"><?php echo $o_objBean->getIdCliente()?></a>&nbsp;<a style="cursor:pointer;text-decoration:underline;color:#00f;" href="#" onclick="parent.objMainTab.modalDialog('<?=buildUrlComplet('mnt.php/cli/edit/id/'.$o_objBean->getIdCliente());?>',{width:1200,height:420})"><?=$o_objBean->getObjectCliente()->getNombreCompleto()?></a></td>
	                <?php }else{?>
	                	<td  align="left"><a style="cursor:pointer;text-decoration:underline;color:#00f;" href="#" onclick="objMainTab.modalDialog('<?php echo buildUrlComplet( 'op.php/ajax/requestPdo', 's_TypeRequest=infopopupprestamo&i_idcliente='.$o_objBean->getIdCliente().'&s_tipo=' )?>',{width:900,height:420})"><?php echo $o_objBean->getIdCliente()?></a>&nbsp;<a style="cursor:pointer;text-decoration:underline;color:#00f;" href="#" onclick="parent.objMainTab.modalDialog('<?=buildUrlComplet('mnt.php/cli/show/id/'.$o_objBean->getIdCliente());?>','block=001')"><?=$o_objBean->getObjectCliente()->getNombreCompleto()?></a> <a style="cursor:pointer;text-decoration:underline;color:#00f;" href="#" onclick="parent.objMainTab.modalDialog('<?=buildUrlComplet('mnt.php/cli/fotos/id/'.$o_objBean->getIdCliente());?>',{width:900,height:420})"><img src="/images/common/iconos/photos.png"></a></td>
	                <?php }?>
                <?php }else{?>
                	<td  align="center"><?=$o_objBean->getIdPrestamo()?></td>
	                
	                <td  align="left"><?=$o_objBean->getObjectCliente()->getNombreCompleto()?></td>
					<td align="center"><?php echo $o_objBean->getIdCliente()?></td>	
                <?php }?>
                <td  align="left"><?php echo $o_objBean->getObjectCliente()->getDni()?></td>
                <td  align="center"> 
                
					<?=$o_objBean->getObjectCliente()->getCelular()?>
				<?php 
				$color_t = "#000000;font-size:16px;";
				if($o_objBean->getOrigen()=='F'){
						$color_t = "#ff0000;font-weight:bold;font-size:16px";
				}
					?>
               </td>
                <td style="background:#ffffff;color:<?php echo $color_v;?>" align="center"><?=$o_objBean->getEstado()?></td>
                <td  align="center"><?=$o_objBean->getFechaInicio()?></td>
                <td  ><?=$o_objBean->getFechaVencimiento()?></td>  
                <td  align="center"><?=$o_objBean->getInteresPorcentaje();?></td>  
				<td  align="right"><?=$o_objBean->getMontoTotal() ; $total_monto +=$o_objBean->getMontoTotal();?></td>
				<td  align="right"><?=$o_objBean->getSaldoPrestamo() ;?></td>
				<td  align="right" <?php if($o_objBean->getSaldoMora()>0){ echo "style='color:#ff0000'";} ?>><?php $total_saldo+=$o_objBean->getSaldoPrestamo();echo $o_objBean->getSaldoMora() ;?></td>
				<td style="background:#ffffff;color:<?php echo $color_t;?>" align="center"><?php if($o_objBean->getOrigen()=='R') echo N; elseif($o_objBean->getOrigen()=='F') echo R;?></td>
				
				<td  align="center"><?=$o_objBean->getCuotaPago()?></td>
				<?php
				 
				?>
				

				</tr>
              <? $n++;
              } ?>
              <? }else{ ?>
              <tr>
                <td colspan="8" align="center">No se produjo resultado</td>
              </tr>
              <? } ?>
			  <tr>
				<td colspan="9" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size:11px; font-weight:bold; color:#000000">T Registros: <?=count($a_ObjectBean)?></td>
				
				<td style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size:11px; font-weight:bold; color:#000000" align="right"><b><?=number_format($total_monto,2)?></b></td>
			
				<td style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size:11px; font-weight:bold; color:#000000" align="right"><b><?=number_format($total_saldo,2)?></b></td>
				<td style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size:11px; font-weight:bold; color:#000000"><b>&nbsp;</b></td>
				
<!--	          		<td><?=count($a_ObjectBean)?></td>-->
			</tr>
            </table>
          </td>
        </tr>
        
	           
	         
        <!--<tr>
          <td>Total Registros: <?=count($a_ObjectBean)?></td>
        </tr>-->
      </table>