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

$o_ObjectBean = new ArArqueoDetalleDepositoFN();
  
//$tamanioPag = 180;
//COLOCAR CAMPOS DE LA CABECERA DEL LISTADO  

if($cboSucursal  !=""){ $o_ObjectBean->setIdsucursal($cboSucursal);}
if($cboMercado   !=""){ $o_ObjectBean->setIdmercado($cboMercado);}
if($txtEstado    !=""){ $o_ObjectBean->setEstado($txtEstado);}
if($txtFechaIni  !="")  { $o_ObjectBean->addCondition( ArArqueoDetalleDepositoFN::Fecha , ">=", "'".$txtFechaIni."'",false ); }
if($txtFechaFin  !="")  { $o_ObjectBean->addCondition( ArArqueoDetalleDepositoFN::Fecha , "<=", "'".$txtFechaFin."'",false ); }
$o_ObjectBean->addOrderBy( ArArqueoDetalleDepositoFN::Fecharegistro, false ); 

//print_r($_GET);

if( !isset( $sortCampos ) ){ $sortCampos = ""; }
if( !isset( $sortType ) ){ $sortType     = ""; }

$valuesSort = array('sortCampos'=>$sortCampos, 'sortType'=>$sortType);

/* if( $sortCampos != "" )
{
    $a_Campos = explode( ";", $sortCampos );
    $a_Tipos = explode( ";", $sortType );
    foreach ( $a_Campos as $i_Key => $s_Values )
    {
        switch ( $s_Values )
        {
            case "NumeroDocumento": if( $a_Tipos[$i_Key] == "1" ){ $o_class->addOrderBy( Wf_trx_documento_cabFN::NumeroDocumento, true ); } else { $o_class->addOrderBy( Wf_trx_documento_cabFN::NumeroDocumento, false ); } break;
            case "DescripcionIdentificacion": if( $a_Tipos[$i_Key] == "1" ){ $o_class->addOrderBy( Wf_trx_documento_cabFN::DescripcionIdentificacion, true ); } else { $o_class->addOrderBy( Wf_trx_documento_cabFN::DescripcionIdentificacion, false ); } break;
            case "FechaEmision": if( $a_Tipos[$i_Key] == "1" ){ $o_class->addOrderBy( Wf_trx_documento_cabFN::FechaEmision, true ); } else { $o_class->addOrderBy( Wf_trx_documento_cabFN::FechaEmision, false ); } break;
            case "MontoTotal": if( $a_Tipos[$i_Key] == "1" ){ $o_class->addOrderBy( Wf_trx_documento_cabFN::MontoTotal, true ); } else { $o_class->addOrderBy( Wf_trx_documento_cabFN::MontoTotal, false ); } break;
        }
    }
}
else 
{
    $o_class->addOrderBy( Cr_pedido_prestamoFN::Idpedido, true );
} */


$tamanioPag = 15;
if( !isset( $page ) ) $page = 1;
$limitInf = ( $page - 1 ) * $tamanioPag;

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

	 
$a_ObjectBean = $o_ObjectBean->select( $limitInf, $tamanioPag );
//print_r($a_ObjectBean);
$i_NumReg     = $o_ObjectBean->selectNumRows();
//$a_f_suma     = $o_ObjectBean->selectSuma();

/* $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($i_NumReg);


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%" >Fecha</th>
				<th width="4%" >Cod. Cliente</th>
			    <th width="20%" align="left">Nombre Cliente&nbsp;&nbsp;&nbsp;</th>
				<th width="4%" >Cod. Prestamo</th>
				<th width="4%" >F. Operacion</th>
				<th width="4%" >Estado</th>
				<th width="4%" >Monto</th>
				<th width="8%" >Fecha Registro</th>
				<th width="4%" >Opciones</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;?>" align="center"><?=$n;?></td>
              	<td  align="center"><?=$o_objBean->getFecha();?></td>
                <td style="background:#ffffff;color:<?php echo $color_v;?>" align="center"><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></td>
                <td  align="left"><?=$o_objBean->getNombrecliente()?></td>
                <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:920,height:520})"><?=$o_objBean->getIdPrestamo()?></a></td>
                <td  align="center"><?=$o_objBean->getFechadeposito();?></td>
				<td  align="center"><?=ArArqueoDetalleDepositoFN::getDescripcionEstado($o_objBean->getEstado()) ;?></td>				
				<td  align="right"><?=$o_objBean->getSubtotal() ;?></td>
				<td  align="center"><?=$o_objBean->getFecharegistro();?></td>
				<td align="center" valign="top">
				<img src="/images/common/buttons/eye.png" title="Mostrar Deposito" style="cursor:pointer;" onclick="parent.objMainTab.modalDialog('<?=buildUrl('vdeposito/show/id/'.$o_objBean->getIdPrestamo(),"block=001&i_IdClase=".$o_objBean->getIdclase()."&i_IdSuc=".$o_objBean->getIdsucursal()."&i_IdMer=".$o_objBean->getIdmercado()."&i_IdCol=".$o_objBean->getIdcolaborador()."&i_Fec=".$o_objBean->getFecha()."&i_IdCli=".$o_objBean->getIdcliente()."&i_IdPre=".$o_objBean->getIdprestamo()."&i_NumVou=".$o_objBean->getNumeroboucher());?>',{title:'Mostrar Deposito',width:600,height:480})">&nbsp;
				<a target="_blank" href="<?php echo substr($o_objBean->getNombrearchivo(),2);?>"><img src="/images/common/buttons/btnReview.gif" title="Mostrar"></a>&nbsp;
				<?php if($o_objBean->getEstado()== 'P'){ ?>
					<img src="/images/common/buttons/btnKey.gif" style="cursor:pointer;" onclick="objMainTab.modalDialog('<?=buildUrl('vdeposito/verificar', "block=001&i_IdClase=".$o_objBean->getIdclase()."&i_IdSuc=".$o_objBean->getIdsucursal()."&i_IdMer=".$o_objBean->getIdmercado()."&i_IdCol=".$o_objBean->getIdcolaborador()."&i_Fec=".$o_objBean->getFecha()."&i_IdCli=".$o_objBean->getIdcliente()."&i_IdPre=".$o_objBean->getIdprestamo()."&i_NumVou=".$o_objBean->getNumeroboucher());?>',{title:'Validar Deposito',width:600,height:450})"/>	
				<?php }?>
				<?php 
				//echo $o_objBean->getIdsucursal()."*-*-*-";
            	$o_BalanceDia = new BalanceDiaBean();
				$o_BalanceDia->setIdSucursal($o_objBean->getIdsucursal());
				$o_BalanceDia->setFechaBalance($o_objBean->getFecha());
				$o_BalanceDia->setFechaBalanceFinal($o_objBean->getFecha());
				$o_BalanceDiaDP = new BalanceDiaDP($o_BalanceDia);
				$a_o_balance = $o_BalanceDiaDP->select();
				//print_r($a_o_balance);
				?>	            	
				<? if(!is_array($a_o_balance) && $o_objBean->getEstado()=="C"){?>
					
						<!--<input type="image" name="Revertir" title="Revertir" src="/images/common/buttons/wrench.png" onClick="location.href='<?php echo buildUrl('vdeposito/revertir', "") ?>'">&nbsp-->;
					
				<?php }?>
				</td>
				</tr>
              <? $n++;
              } ?>
              <? }else{ ?>
              <tr>
                <td colspan="8" align="center">No se produjo resultado</td>
              </tr>
              <? } ?>
			  <!--<tr>
				<td colspan="4" 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>