<?php

session_cache_limiter('private');
session_start();
$com = "I";
include("DMMYSQLG.php");
include("DSA3000.php");
include("DMMYSQLG.php");
 include('DF80000.php');
$name="Pago X Dia.xls"; 
if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
	header('Content-Type: application/force-download');
else
	header('Content-Type: application/octet-stream');
header('Content-disposition: attachment; filename="'.$name.'"');
?> 
<table width="747"   align="center">
  <tr>
    <th colspan="6"> <div align="center"> PAGO X DIA 
  </tr>
  <tr>
    <td nowrap class="tdagre1">Folio Caja </td>
    <td nowrap class="tdagre1">Numero Docto. </td>
    <td nowrap class="tdagre1">Nombre Cliente </td>
    <td nowrap class="tdagre1">Subtotal</td>
    <td nowrap class="tdagre1">IVA</td>
    <td nowrap class="tdagre1">Total </td>
  </tr>
  <?php
 
		$sq_redocl=mysqli_query($con ,$_POST['busqueda']);
		$z=-1;
		$totales=NULL;
		$totgeneral=NULL;
		while(@$dt_redocl=mysqli_fetch_array($sq_redocl)){
		if ($dt_redocl['tip_cam'] > 0 && $dt_redocl['tip_mon']!='N') $tipcambio=$dt_redocl['tip_cam'];
		else $tipcambio=1;
			$dt_bascps=mysqli_fetch_array(mysqli_query($con ,"select * from dxbascps where codigo='".$dt_redocl['codigo']."'"));
			if($z==-1){
				echo '<tr><td colspan="6" class="typeagre"><div align="center"> Movimientos Del '.chfecha($dt_redocl['fec_cob'],'Y-m-d','d de M del Y').'&nbsp;</div></td></tr>';
				$z=$dt_redocl['fec_cob'];
			}elseif($z!=$dt_redocl['fec_cob']){
				imptotales("Total x dia: ",$totales);
				echo '<tr><td colspan="6" class="typeagre"><div align="center"> Movimientos Del '.chfecha($dt_redocl['fec_cob'],'Y-m-d','d de M del Y').'&nbsp;</div></td></tr>';
				$z=$dt_redocl['fec_cob'];
				$totales=NULL;
			}
			llenaTotales($totales,$dt_redocl);
			llenaTotales($totgeneral,$dt_redocl);
			echo '<tr>';
			echo '<td nowrap colspan="1">'.$dt_redocl['fol_cob'].'&nbsp;</td>';
			echo '<td nowrap colspan="1">'.$dt_redocl['num_doc'].'&nbsp;</td>';
			echo '<td nowrap colspan="1">'.$dt_bascps['ap_paterno'].' '.$dt_bascps['ap_materno'].' '.$dt_bascps['nombre'].'&nbsp;</td>';
			echo '<td nowrap colspan="1">'.number_format($dt_redocl['imp_cob']*$tipcambio,2,'.',',').'</td>';
			echo '<td nowrap colspan="1">'.number_format($dt_redocl['iva_cob']*$tipcambio,2,'.',',').'</td>';
			echo '<td nowrap colspan="1">'.number_format($dt_redocl['tot_cob']*$tipcambio,2,'.',',').'</td>';
			echo '</tr>';
		}
		imptotales("Total x dia: ",$totales);
		imptotales("Total General: ",$totgeneral);
		//imptotales("Saldo General Documentos: ",$totgeneral);
	
	
	function llenaTotales(&$totales, $dat){
		if ($dat['tip_cam'] > 0 && $dat['tip_mon']!='N') $tipcambio=$dat['tip_cam'];
		else $tipcambio=1;
		$totales[0]+=$dat["imp_cob"]*$tipcambio;
		$totales[1]+=$dat["iva_cob"]*$tipcambio;
		$totales[2]+=$dat["tot_cob"]*$tipcambio;
	}
	
	function imptotales($leyenda,$totales){
		echo '<tr>';
		echo '<td colspan="3"><div align="right">'.$leyenda.'&nbsp;</div></td>';
		echo '<td colspan="1">'.number_format($totales[0],2,'.',',').'</td>';
		echo '<td colspan="1">'.number_format($totales[1],2,'.',',').'</td>';
		echo '<td colspan="1">'.number_format($totales[2],2,'.',',').'</td>';
		echo '</tr>';
	}
	?>
</table>
