<?php 
session_start();

/*if(!isset($_SESSION['tipo']) or $_SESSION['tipo'] != 2){ header("Location:index.php"); }*/
	
include("../conexion_bd.php");
include("../funciones.php");

?>
<table width="100%" border="0" cellspacing="0" cellpadding="1" class="stdtable" id="dyntable">

<thead>
                        <tr>
                            <th class="head1">N</th>

                            <th class="head1">Folio + Serie</th>
                            <th class="head1">Razón Social</th>
                            <th class="head1">Importe</th>
                            <th class="head1">Descuento</th>
                            <th class="head1">Impuesto</th>
                            
                            <th class="head1">Total</th>
                            <th class="head1">Opciones</th>
                           
                          
                        </tr>
                    </thead>
       <tbody>
	
 
 <?php 
 
  $fecha_inicial = substr($_GET['fecha_inicial'],3,2)."/".substr($_GET['fecha_inicial'],0,2)."/".substr($_GET['fecha_inicial'],6,4); 
  $fecha_final = substr($_GET['fecha_final'],3,2)."/".substr($_GET['fecha_final'],0,2)."/".substr($_GET['fecha_final'],6,4); 
  $id_cliente = get_id_cliente($_GET['codigo']);

    $x=1;
	$conn = new COM("ADODB.Connection") or die ("Cannot start"); 
    $rs = New COM("ADODB.Recordset");
    $conn->Open(PATH); 
	$rs = $conn->Execute('select * from MGW10008 WHERE CIDDOCUM02 = 4 AND CCANCELADO = 0 AND  CFECHA >= ctod("'.$fecha_inicial.'") AND CFECHA <= ctod("'.$fecha_final.'") AND CIDCLIEN01 = '.$id_cliente.' ' );  

    while (!$rs->EOF)
     {
  
  ?>
  <tr>
    <td class="con0" align="center"><?php echo $x++; ?></td>
     
    <td class="con0"><?php echo $rs->fields['CFOLIO']->value(); echo $rs->fields['CSERIEDO01']->value(); ?></td>
    <td class="con0" align="left"><?php echo utf8_encode($rs->fields['CRAZONSO01']->value());  ?></td>
    <td class="con0" align="right"><?php echo formato($rs->fields['CNETO']->value());  @$total += $rs->fields['CNETO']->value(); ?></td>
     <td class="con0" align="right"><?php echo formato($rs->fields['CDESCUEN01']->value());  @$total2 += $rs->fields['CDESCUEN01']->value(); ?></td>
      <td class="con0" align="right"><?php echo formato($rs->fields['CIMPUESTO1']->value());  @$total3 += $rs->fields['CIMPUESTO1']->value(); ?></td>
    <td class="con0" align="right" style="background:#FF9;"><?php echo formato($rs->fields['CTOTAL']->value());  @$total4 += $rs->fields['CTOTAL']->value(); ?></td>
     <td class="con0" align="right">&nbsp;</td>
    
  </tr>
  <?php 
  $rs->MoveNext();
  }
  
  $rs->Close();
  $conn->Close();
  
   ?>
  <thead>
  <tr>
    <td class="head1" colspan="2" align="center">Total</td>
    <td class="head1" style="text-align:right;">&nbsp;</td>
    <td class="head1" style="text-align:right; background:#FF9;"><?php echo @formato($total); ?></td>
    <td class="head1" style="text-align:right; background:#FF9;"><?php echo @formato($total2); ?></td>
     <td class="head1" style="text-align:right; background:#FF9;"><?php echo @formato($total3); ?></td>
      <td class="head1" style="text-align:right; background:#FF9;"><?php echo @formato($total4); ?></td>
       <td class="head1" align="center"><img src="../images/icons/glass.png" width="16" height="16" /> </td>
    
  </tr> 
  </thead>
  </tbody>
  
 </table>