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

//print_r($_GET);
$o_ObjectBean = new PrestamoBean();
  
$tamanioPag = 180;
//COLOCAR CAMPOS DE LA CABECERA DEL LISTADO  
if(myUser::getUser()->getRoleId() == "sys.ope" && !$cboMercado) $cboMercado = 99999;
if($cboSucursal     !=""){ $o_ObjectBean->setFiltroSucursal($cboSucursal);}
if($cboMercado     	!=""){ $o_ObjectBean->setIdMercado($cboMercado);}
if($cboEstado    	!=""){ $o_ObjectBean->setEstado($cboEstado);}
if($cboTipo    	!=""){ $o_ObjectBean->setOrigen($cboTipo);}


$o_ObjectBean->setFechaInicio($txtFechaInicial); 
$o_ObjectBean->setFechaFinal($txtFechaFinal); 
$o_ObjectBean->setFlagReporte('2');

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

	 
 
$o_PrestamoDP = new PrestamoDP($o_ObjectBean);
$a_ObjectBean = $o_PrestamoDP->selectVentas();;




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

if(!$page) $page = 1;



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

?>
<script src="<?php echo Constantes::ROOT_DIR_APP?>/web/hc/code/highcharts.js"></script>
<script src="<?php echo Constantes::ROOT_DIR_APP?>/web/hc/code/highcharts-3d.js"></script>
<script src="<?php echo Constantes::ROOT_DIR_APP?>/web/hc/code/modules/data.js"></script>
<script src="<?php echo Constantes::ROOT_DIR_APP?>/web/hc/code/modules/exporting.js"></script>
<script src="<?php echo Constantes::ROOT_DIR_APP?>/web/hc/code/modules/export-data.js"></script>
<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="90%">
        
        <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>
              
               
				<th>Fecha</th>
			    <th align="left">Sucursal/Mercado</th>
				
			    <th>Monto</th>
			    <th>#. Prestamos</th>
				
              
              </tr>
              <?php
			  if(count($a_ObjectBean)>0){ 
              	foreach ($a_ObjectBean as $iKey => $o_objBean){ 
              	
              		?>

              <tr onClick="TR_click(this);" style="background:<? //=$bgcolor;?>">
              	<td align="center"><?=$o_objBean->getFechaInicio()?></td>
                <td align="left"><?php echo $o_objBean->getSucursal()?>&nbsp;/&nbsp;<?=$o_objBean->getMercado()?></td>
                
                
				<td align="right"><?=number_format($o_objBean->getMontoTotal(),2) ; $total_monto +=$o_objBean->getMontoTotal();?></td>
				<td align="right"><?php if($o_objBean->getObservacion()>0){?><label style="cursor:pointer;text-decoration:underline;color:#00f" onclick="objMainTab.modalDialog('<?php echo buildUrlComplet( 'op.php/ajax/requestPdo', 's_TypeRequest=infopopupprestamodet&cboMercado='.$o_objBean->getIdMercado().'&fecha='.$o_objBean->getFechaInicio().'&s_tipo=' )?>',{width:700,height:400})"><?php  echo  $o_objBean->getObservacion(); $total_cantidad +=$o_objBean->getObservacion();?></label><?php }else{?><label style="color:#f00">0</label><?php }?></td>
				
				
				
				
				</tr>
              <? } ?>
              <? }else{ ?>
              <tr>
                <td colspan="7" align="center">No se produjo resultado</td>
              </tr>
              <? } ?>
			  <tr>
				<td colspan="2" 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_cantidad,2)?></b></td>
			
				
<!--	          		<td><?=count($a_ObjectBean)?></td>-->
			</tr>
            </table>
          </td>
        </tr>
        
	           
	         
        <!--<tr>
          <td>Total Registros: <?=count($a_ObjectBean)?></td>
        </tr>-->
      </table>
	  <div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>	
	  