<?php

    require_once("../dompdf/dompdf_config.inc.php");
	include ("../conectar.php");
    


$codigoHTML='
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Lista</title>
<link href="../estilos/estilos.css" type="text/css" rel="stylesheet">

</head>


   <script type="text/php">

        if ( isset($pdf) ) {

          $font = Font_Metrics::get_font("helvetica", "bold");
          $pdf->page_text(72, 18, "Header: {PAGE_NUM} of {PAGE_COUNT}", $font, 6, array(0,0,0));

        }
  

</script>

	    <style type="text/css">      
		tabla {
  border-collapse: separate;
  border-spacing:  3px;
}
 </style>
<body>
<div align="center">
  <p>&nbsp;</p>';
  
$query="SELECT * FROM web_0000";
$rs_query=mysql_query($query);
$NombreComercial=mysql_result($rs_query,0,"NOMCOM");
$Cedula=mysql_result($rs_query,0,"CEDJUR");
$Direccion=mysql_result($rs_query,0,"DIREMP");
$Telefono=mysql_result($rs_query,0,"NUMTEL");

	 $fecini=$_GET[fechainicio];
	 $fecfin=$_GET[fechafin];
	// $cdgtipven=$_GET[combotipoventa];
	 $cdgcaj=$_GET[cdgcaj];
	 $cdgtipven=$_GET[combotipoventa];
	 
if ($cdgcaj <> "") { $where.=" AND cdgcaj='$cdgcaj'"; }
//if ($cdgtipven <> "") { $where.=" AND cdgtipven='$cdgtipven'"; }


	 
	
	 
 $fechainicio= implode("-", array_reverse(explode("-", $fecini))); 
 $fechafin= implode("-", array_reverse(explode("-", $fecfin))); 

      $consulta=mysql_query("SELECT * FROM facturas WHERE cdgtipven='2' AND fecha  between '$fechainicio' AND '$fechafin' ".$where );
        while($dato=mysql_fetch_array($consulta)){
				$codfactura =$dato['codfactura'];
				$numfactura =$dato['numfactura'];
				$fecha = $dato['fecha'];
 				$fecha= implode("-", array_reverse(explode("-", $fecha))); 		
				$cdgcli = $dato['cdgcli'];
				$cdgcli=sprintf('%04d',$cdgcli) ;
				$dsccli = $dato['dsccli'];
				$dsccli = substr($dsccli, 0, 40);
				$pladia = $dato['pladia'];
				$totalfactura = $dato['totalfactura'];
				$subtot = $dato['subtot'];
				$impven =$dato['impven'];
				$destot =$dato['destot'];
	
$subtotcre= $subtotcre + $subtot;
$destotcre= $destotcre + $destot;
$impvencre= $impvencre + $impven;
$totalcre= $totalcre + $totalfactura;
	
}

      $consulta=mysql_query("SELECT * FROM facturas WHERE cdgtipven='1' AND  fecha  between '$fechainicio' AND '$fechafin'  ".$where );
        while($dato=mysql_fetch_array($consulta)){
				$codfactura =$dato['codfactura'];
				$numfactura =$dato['numfactura'];
				$fecha = $dato['fecha'];
 				$fecha= implode("-", array_reverse(explode("-", $fecha))); 		
				$cdgcli = $dato['cdgcli'];
				$cdgcli=sprintf('%04d',$cdgcli) ;
				$dsccli = $dato['dsccli'];
				$dsccli = substr($dsccli, 0, 40);
				$pladia = $dato['pladia'];
				$totalfactura = $dato['totalfactura'];
				$subtot = $dato['subtot'];
				$impven =$dato['impven'];
				$destot =$dato['destot'];
	
$subtotcon= $subtotcon + $subtot;
$destotcon= $destotcon + $destot;
$impvencon= $impvencon + $impven;
$totalcon= $totalcon + $totalfactura;
	
	
}

$estrec="1";
$borrado="0";


$sel_Recibo="SELECT  numrec, fecrec, cdgcli, estrec, cdgcaj, Sum(montot) AS totalRec, Sum(monint) AS totalint ,Sum(monabo) AS totalabo FROM pagos_clientes WHERE
 estrec = '$estrec'  AND  fecrec  between '$fechainicio' AND '$fechafin'".$where;
$rs_Recibos=mysql_query($sel_Recibo);
$totalrec=mysql_result($rs_Recibos,0,"totalRec");
$totalint=mysql_result($rs_Recibos,0,"totalint");
$totalabo=mysql_result($rs_Recibos,0,"totalabo");

$sel_notas="SELECT codnota, fecha, cdgcli, borrado, cdgcaj, Sum(totalnota) AS totalNotas FROM facturas_notas WHERE 	
 borrado = '$borrado'  AND fecha  between '$fechainicio' AND '$fechafin' ".$where ;
$rs_notas=mysql_query($sel_notas);
	$totalNot=mysql_result($rs_notas,0,"totalNotas");
	

$totalventas=$totalcre+$totalcon-$totalNot;







 if ($cdgcaj=="") {
	 
	 $nomcomusu="TODOS LOS CAJEROS";
	 
	     } else {


  	$query_codcaj="SELECT * FROM usuarios  WHERE codusu=$cdgcaj ";
						$res_codcaj=mysql_query($query_codcaj);
						$contador=0;
						
	 $nomcomusu=mysql_result($res_codcaj,$contador,"nomcomusu");
     }
 
$codigoHTML='
  <table width="100%"  cellpadding="0" cellspacing="0"  border="0">
      <tr>
        <td width="22%" align="" rowspan="3"><img src="../img/logo.jpg" /></td>
        <td width="56%" align="center"><font color="blue" size=4><strong>'.$NombreComercial.'</strong></font></td>
        <td width="22%">&nbsp;</td>
      </tr>
      <tr>	 
        <td height="12" align="center"><font size=2 >Reporte Analitico de Ventas del '.$fecini.' Al '.$fecfin.'</font></td>
        <td height="12">&nbsp;</td>
      </tr>
      <tr>
        <td height="12" align="center"><font size=2 ></font><font size="3" ><strong>Cajero: '.$cdgcaj.' - '.$nomcomusu.'</strong></font></td>
        <td height="12">&nbsp;</td>
      </tr>
    </table>
    ';
  
   

	 

	 
	 $codigoHTML.='
  
  ';
	
	
    $codigoHTML.='</p>
    <hr  color="#000000"/>
    <table cellspacing="0" align="center" cellpadding="0" style=" border-width: 2px;"  width="55%" border="1" bordercolor="#000000">
      <tr>
        <td colspan="4"  align="center" bgcolor="#CCCCCC" class="titulo"><strong><em>Facturas de Credito</em></strong></td>
      </tr>
      <tr>
        <td width="4%"   style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td width="50%"   style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td width="41%"   style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td width="5%"   style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">Monto Subtotal</td>
        <td align="right"  style="padding-bottom: 1px; border:0px solid black;"><font size="3" > '.number_format($subtotcre,2).'</font></td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">Mto Descuento</td>
        <td align="right"  style="padding-bottom: 1px; border:0px solid black;"><font size="3" >'.number_format($destotcre,2).'</font></td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">Impuesto Ventas</td>
        <td  align="right" style="padding-bottom: 1px; border:0px solid black;"><font size="3" >'.number_format($impvencre,2).'</font></td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td colspan="2"  style="padding-bottom: 1px; border:0px solid black;">_________________________________________________________________</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;"><strong>Total Facturas de Credito</strong></td>
        <td  align="right" style="padding-bottom: 1px; border:0px solid black;"><strong><font size="3" >'.number_format($totalcre,2).'</font></strong></td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="4"  align="center" bgcolor="#CCCCCC" class="titulo"><strong><em>Facturas de Contado</em></strong></td>
      </tr>
      <tr>
        <td   style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td   style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td   style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td   style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">Monto Subtotal</td>
        <td align="right"  style="padding-bottom: 1px; border:0px solid black;"><font size="3" > '.number_format($subtotcon,2).'</font></td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">Mto Descuento</td>
        <td align="right"  style="padding-bottom: 1px; border:0px solid black;"><font size="3" >'.number_format($destotcon,2).'</font></td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">Impuesto Ventas</td>
        <td  align="right" style="padding-bottom: 1px; border:0px solid black;"><font size="3" >'.number_format($impvencon,2).'</font></td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td colspan="2"  style="padding-bottom: 1px; border:0px solid black;">_________________________________________________________________</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;"><strong>Total Facturas de Contado</strong></td>
        <td  align="right" style="padding-bottom: 1px; border:0px solid black;"><strong><font size="3" >'.number_format($totalcon,2).'</font></strong></td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td align="right"  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="4"  align="center" bgcolor="#CCCCCC" class="titulo"><strong><em>Recibos por Dinero</em></strong></td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">Monto Capital</td>
        <td  align="right" style="padding-bottom: 1px; border:0px solid black;"><font size="3" >'.number_format($totalabo,2).'</font></td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">Monto Interes</td>
        <td  align="right" style="padding-bottom: 1px; border:0px solid black;"><font size="3" >'.number_format($totalint,2).'</font></td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td colspan="2"  style="padding-bottom: 1px; border:0px solid black;">_________________________________________________________________</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;"><strong>Total Recibos</strong></td>
        <td  align="right" style="padding-bottom: 1px; border:0px solid black;"><strong><font size="3" >'.number_format($totalrec,2).'</font></strong></td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="4"  align="center" bgcolor="#CCCCCC" class="titulo"><em><strong>Notas de Credito</strong></em></td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td align="right"  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">Total Notas Credito</td>
        <td align="right"  style="padding-bottom: 1px; border:0px solid black;"><font size="3" >'.number_format($totalNot,2).'</font></td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td colspan="2"  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="4"  align="center" bgcolor="#CCCCCC" class="titulo"><em><strong>Totales</strong></em></td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  align="right" style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;"><strong>Total Facturas de Credito</strong></td>
        <td  align="right" style="padding-bottom: 1px; border:0px solid black;"><strong><font size="3" >'.number_format($totalcre,2).'</font></strong></td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;"><strong>Total Facturas de Contado</strong></td>
        <td  align="right" style="padding-bottom: 1px; border:0px solid black;"><strong><font size="3" >'.number_format($totalcon,2).'</font></strong></td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">Total Notas Credito (-)</td>
        <td align="right"  style="padding-bottom: 1px; border:0px solid black;"><font size="3" >'.number_format($totalNot,2).'</font></td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td colspan="2"  style="padding-bottom: 1px; border:0px solid black;">_________________________________________________________________</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;"><strong>Total Acumulado  Ventas</strong></td>
        <td  align="right" style="padding-bottom: 1px; border:0px solid black;"><strong><font size="3" >'.number_format($totalventas,2).'</font></strong></td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
      <tr>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  align="right" style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
        <td  style="padding-bottom: 1px; border:0px solid black;">&nbsp;</td>
      </tr>
    </table>
  <p>&nbsp;</p>
 ';
          

     //   $consulta=mysql_query("SELECT * FROM web_2101 WHERE CDGCLI=$Cdgcli");
     //   while($dato=mysql_fetch_array($consulta)){
		//		$MONTOS = number_format($dato['TOTNET'], 2);
		//		$SALDOS = number_format($dato['SALACT'], 2);
							
$codigoHTML.='
   <table width="80%"  rules="none" border="0">
    
      <tr>
        <td width="21%">  <font size=2 >'.$dato['NUMFAC'].'</font></td>
        <td width="20%">  <font size=2 >'.$dato['FECFAC'].'</font></td>
        <td width="19%" align="center">  <font size=2 >'.$dato['PLADIA'].'</font></td>
   	    <td width="20%">  <font size=2 align="center">'.$dato['FECVEN'].'</font></td>
        <td width="20%" align="right">  <font size=2 >'.$MONTOS.'</font></td>
        <td width="20%" align="right">  <font size=2 >'.$SALDOS.'</font></td>
      </tr>

      
  </table>';
  
  	          
			  // $consulta=mysql_query("SELECT SUM(SALACT)AS ACTUAL, SUM(TOTNET) AS INICIAL FROM web_2101 WHERE CDGCLI=$Cdgcli");
     //   while($dato=mysql_fetch_array($consulta)){
			//	$INICIAL = number_format($dato['INICIAL'], 2);
			//	$ACTUAL  = number_format($dato['ACTUAL'], 2);
			
$codigoHTML.='
   
   <p>';
   
   //  } 
$codigoHTML.='

   </p>
   <p>&nbsp;</p>
   <p>&nbsp;</p>
  <table width="100%" border="0">
     <tr>
     </tr>
  </table>
   <p>&nbsp;</p>
</div>
</body>
</html>';

$codigoHTML=utf8_decode($codigoHTML);
$dompdf=new DOMPDF();
$dompdf->set_paper( "A4", "portrait" ); // a4,vertical
$dompdf->load_html($codigoHTML);
ini_set("memory_limit","256M");
$dompdf->render();
$dompdf->stream("Cierre de Caja.pdf", array("Attachment" => false));

?>
