<?
//http://mixelaneo.blogspot.com/
header("Content-Type: application/xhtml+xml; charset=iso-8859-1");
use_helper('UrlFunctions');

$o_BalanceDiaNew = new BalanceDiaBean();

if($cboColaborador){
	$o_BalanceDiaNew->setIdColaborador($cboColaborador); 
}else{
	$o_BalanceDiaNew->setIdColaborador(myUser::getUser()->getIdColaborador()); 	
}
$o_BalanceDiaNew->setFechaBalance($txtFecha); 

$o_BalanceDiaDP = new BalanceDiaDP($o_BalanceDiaNew);
$a_resumen_detalle = $o_BalanceDiaDP->ObtenerResumenDetalleMercado();

$a_inicioOperacion = $a_resumen_detalle['InicioOperacion'];
$a_pagos = $a_resumen_detalle['Pagos'];
$a_sofa = $a_resumen_detalle['Sofa'];
$a_prestamos = $a_resumen_detalle['Prestamos'];

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>
<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>
            <table class="grid" width="100%" border="0" cellpadding="0" cellspacing="0">
            	
            	<tr>
            		<td colspan="8" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-weight:bold; color:#000000; font-size:12px; background: #E3E9E2">Caja</td>
				 </tr>
	              	<?php
	              	if(is_array($a_inicioOperacion)){?>
					<tr>
						<td colspan="8" align="right"><b><?php echo "S/.&nbsp;".number_format((float)$a_inicioOperacion['IO'],2);?></b></td>
	              	<?php	
	              	}
	              	?>
              	</tr>
              	<tr>
              		<td colspan="8" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-weight:bold; color:#000000; font-size:12px; background: #E3E9E2">Pagos</td>
              	</tr>
              	<?php
              	$SumatoriaTotalPagos = 0;
              	if(is_array($a_pagos)){
              	foreach ($a_pagos as $key => $a_pagosTemp){?>
              		<tr>
					    <td width="2%">&nbsp;</td>
	              		<td width="10%" style="font-family:Verdana, Arial, Helvetica, sans-serif; color:#000000; font-size:12px; background: #E3E9E2"><?php echo "Mercado&nbsp;".ucwords(strtolower($a_pagosTemp['NombreMercado']))?></td>
	              		<td colspan="6"  align="right"><?php 
	              		$SumatoriaTotalPagos += $a_pagosTemp['PA'];
	              		echo "S/.&nbsp;".number_format($a_pagosTemp['PA'],2);
	              		?></td>
	              	</tr>	
              	<?php 
              	}
              	}
              	?>
              	<tr>
              		<td width="10%" align="right">&nbsp;</td>
              		<td colspan="7" align="right"><B>T. Pagos&nbsp;= &nbsp;&nbsp; <?php echo "S/.&nbsp;".number_format((float)$SumatoriaTotalPagos,2)?></B></td>
              	</tr>
              	<tr>
              		<td colspan="8" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-weight:bold; color:#000000; font-size:12px; background: #E3E9E2">Prestamos</td>
              		
              	</tr>
              	<?php
			    $sumatoriatotalprestamo = 0;
				$sumatoriatotalgastos = 0;
				
              	if(is_array($a_prestamos)){
              	foreach ($a_prestamos as $key => $a_prestamosTemp){
              		
              		?>
              	     
              		<tr>
	              	    <td width="2%" >&nbsp;</td>
						<td  colspan="7" style="font-family:Verdana, Arial, Helvetica, sans-serif; color:#000000; font-size:12px; background: #E3E9E2"><?php echo "Mercado&nbsp;".$key?></td>
	              		<td></td>
	              	</tr>
	              	<?php foreach ($a_prestamosTemp as $keydet => $a_PrestamoDetalle){
		              		if($a_PrestamoDetalle['OR']=='R'){
		              		   $origen='N';
		              		}elseif($a_PrestamoDetalle['OR']=='F'){
		              			$origen='R';
		              		}
	              		?>	
		              <tr>
		              		<td width="2%">&nbsp;</td>
							<td width="2%">&nbsp;</td>
							<td style="font-family:Verdana, Arial, Helvetica, sans-serif; color:#000000; font-size:11px;"><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='.$a_PrestamoDetalle['Idcliente'].'&s_tipo=' )?>',{width:700,height:400})"><?php echo ucwords(strtolower($a_PrestamoDetalle['NombreCliente']))?></a></td>
		              		<td>&nbsp;&nbsp;<?php echo $a_PrestamoDetalle['ES']?></td>
		              		<td>&nbsp;&nbsp;<?php echo $origen?></td>
		              		<!--<td>&nbsp;&nbsp;<?php echo $a_PrestamoDetalle['PO']."%"?></td>-->
		              		<td>&nbsp;&nbsp;&nbsp;&nbsp;<?php $sumatoriatotalgastos += $a_PrestamoDetalle['GA']; echo "S/.&nbsp;".number_format((float)$a_PrestamoDetalle['GA'],2)?></td>
		              		<td>&nbsp;&nbsp;<?php echo $a_PrestamoDetalle['PO']."%"?></td>
		              		<td  align="right"><?php if ($a_PrestamoDetalle['OR']=='R') { $sumatoriatotalprestamo  +=  $a_PrestamoDetalle['PR'];}  echo "S/.&nbsp;".number_format((float)$a_PrestamoDetalle['PR'],2) ;?></td>
		              	</tr>
						
	              	<?php }?>
              	<?php 
              	}?><tr>
              		<td width="10%" align="right">&nbsp;</td>
              		<td colspan="7" align="right"><B>T. Gatos&nbsp;= &nbsp;&nbsp; <?php echo "S/.&nbsp;".number_format((float)$sumatoriatotalgastos,2)?>&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; <B>T. Prestamos&nbsp;= &nbsp;&nbsp; <?php echo "S/.&nbsp;".number_format((float)$sumatoriatotalprestamo,2)?></B></td>
              	</tr>
              	
				<?
              	 }
              	 if(is_array($a_sofa)){
              	 	if($a_sofa['s']){?>
              	 <tr>
	              	 <td width="10%" align="right">&nbsp;</td>
              		<td colspan="7" align="right"><B>T. Sobrantes&nbsp;= &nbsp;&nbsp; <?php echo "S/.&nbsp;".number_format((float)$a_sofa['s'],2)?></td>
              	 </tr>
              	 <?
              	 	}
              	 	
              	 	if($a_sofa['f']){?>
              	 <tr>
	              	 <td width="10%" align="right">&nbsp;</td>
              		<td colspan="7" align="right"><B>T. Faltante&nbsp;= &nbsp;&nbsp; <?php echo "S/.&nbsp;".number_format((float)$a_sofa['f'],2)?></td>
              	 </tr>
              	 <?
              	 	}
              	 }
				   $totalresumen = $a_inicioOperacion['IO'] + $SumatoriaTotalPagos + $sumatoriatotalgastos - $sumatoriatotalprestamo + $a_sofa['s'] - $a_sofa['f']; 
				?>
				<tr>
				  <td colspan="8">&nbsp;</td>
				</tr>
              	<tr>
				   <td colspan="8"  align="right" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-weight:bold; color:#000000; font-size:12px; background: #E3E9E2"><B>Totales&nbsp;= </B> &nbsp;&nbsp; <?php echo "S/.&nbsp;".number_format((float)$totalresumen,2);?> </td>
				</tr>
            </table>
          </td>
        </tr>
      </table>