<?php

session_cache_limiter('private');
session_start();
$com = "I";
include("DMMYSQLG.php");
include("DSA3000.php");
include("DMMYSQLG.php");
 include('DF80000.php');
$name="Notas de Credito.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 border="0">
    <tr>
      <th colspan="7" >
        <div align="left">
          <input name="bo_imp" type="button" id="bo_imp" value="Imprimir"  onClick="openpage('DV46000_IM.php','_self')">
          <input name="toExcel" type="button" id="toExcel" value="Exportar Excel" onClick="openpage('DV46000_IME.php','_self')">
        </div>     </th>
    </tr>
    <tr>
      <td nowrap class="tdagre1">Fecha </td>
      <td nowrap class="tdagre1">Codigo </td>
      <td nowrap class="tdagre1">Nombre</td>
      <td nowrap class="tdagre1">Num. Nota </td>
      <td nowrap class="tdagre1">Subtotal</td>
      <td nowrap class="tdagre1">IVA</td>
      <td nowrap class="tdagre1">Total  </td>
      </tr>
	<?php
 

		$z=-1;
		$totales=NULL;
		$totgeneral=NULL;
		$sq_redocl=mysqli_query($con ,$_POST['busqueda']);
		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']."'"));
			llenaTotales($totgeneral,$dt_redocl);
			echo '<tr>';
			echo '<td class="regFacL" nowrap colspan="1">'.chfecha($dt_redocl['fec_not'],'Y-m-d','d/m/Y').'&nbsp;</td>';
			echo '<td class="regFacL" nowrap colspan="1">'.$dt_redocl['codigo'].'&nbsp;</td>';
			echo '<td class="regFacL" nowrap colspan="1">'.$dt_bascps['ap_paterno'].' '.$dt_bascps['ap_materno'].' '.$dt_bascps['nombre'].'&nbsp;</td>';
			echo '<td class="regFacL" nowrap colspan="1">'.$dt_redocl['tip_not'].$dt_redocl['num_not'].'&nbsp;</td>';
			echo '<td class="regFacR" nowrap colspan="1">'.number_format($dt_redocl['sub_not']*$tipcambio,2,'.',',').'</td>';
			echo '<td class="regFacR" nowrap colspan="1">'.number_format($dt_redocl['iva_not']*$tipcambio,2,'.',',').'</td>';
			echo '<td class="regFacR" nowrap colspan="1">'.number_format($dt_redocl['tot_not']*$tipcambio,2,'.',',').'</td>';
			echo '</tr>';
		}
		
		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["sub_not"]*$tipcambio;
		$totales[1]+=$dat["iva_not"]*$tipcambio;
		$totales[2]+=$dat["tot_not"]*$tipcambio;
	}
	
	function imptotales($leyenda,$totales){
		echo '<tr>';
		echo '<td class="granTotal" colspan="4"><div align="right">'.$leyenda.'&nbsp;</div></td>';
		echo '<td class="granTotal" colspan="1">'.number_format($totales[0],2,'.',',').'</td>';
		echo '<td class="granTotal" colspan="1">'.number_format($totales[1],2,'.',',').'</td>';
		echo '<td class="granTotal" colspan="1">'.number_format($totales[2],2,'.',',').'</td>';
		echo '</tr>';
	}
	?>
  </table>
