<?php

session_start();
include("DMMYSQLG.php");
require_once("DF80000.php");
if ($_SESSION['butimp']==0){
  $_REQUEST['bot']=$_SESSION['folioimp'];
	$_REQUEST['but']=$_SESSION['butimp'];
}	

//Consulta Datos Empresa
$dt_empres = mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM dxempres where cla_emp = '".$_SESSION['empresa']."'"));		
$cvdm = intval($dt_empres['cve_delmun']);
$cves = intval($dt_empres['cve_estado']);
//Consulta Datos Del/Mun
$sqld_encabezado = mysqli_query($con ,"SELECT * FROM dxdelmun where cve_delmun ='$cvdm'");
@$rowd_encabezado = mysqli_fetch_array($sqld_encabezado);
//Consulta Datos Estado 
$sqle_encabezado = mysqli_query($con ,"SELECT * FROM dxestado where cve_estado = '$cves'");
@$rowe_encabezado = mysqli_fetch_array($sqle_encabezado);
@$resu1=mysqli_query($con ,"select * from dgpemema where fol_ven = '".$_REQUEST['bot']."'");
@$rego1=mysqli_fetch_array($resu1);
$dt_ger_cajerosj=mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM dgger_cajerosj where pedido='".$rego1['fol_ven']."'"));
?>
<html>
<head>
<title><?php echo "PROPINAS POR PAGAR";?></title>

<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	font-family:Arial, Helvetica, sans-serif;
	font-size:10px;
}
.tit{
font-family:Arial, Helvetica, sans-serif;
font-size:10px;
}
.tot{
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
font-weight:bold;
}

.dom{
font-family:Arial, Helvetica, sans-serif;
font-size:10px;
}
td{
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
}
.titOrd{
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
font-weight:bolder;
}
.titPer{
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
font-weight:bolder;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><object id=factory style="display:none"
  classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
  codebase="archivos/smsx.caab#Version=6,1,400,50">
</object>
<script>
function printWindow() {
factory.printing.header = "";
factory.printing.footer = "";
factory.printing.portrait = true;
factory.printing.leftMargin = 0;
factory.printing.topMargin = 0;
factory.printing.rightMargin = 0;
factory.printing.bottomMargin = 0;
//factory.printing.copies = 2;
factory.printing.Print(false);
}
</script>
 </head> 
 <body onLoad="printWindow()">
<form name="form1" method="post" action="">
  <table  border="0" cellspacing="0">
    <tr>
      <td colspan="4" scope="col" align="center" class="titOrd">
	  <img align="middle" src="logos/imgtax.jpg"  />
	  </td>
    </tr>
	<tr>
      <td colspan="4" scope="col" align="center" class="titOrd"><?php echo $dt_empres['nom_emp'];
	  				$_REQUEST['bot'];
					$_GET['bot'];
					$_POST['bot'];
					$_REQUEST['control'];
					$_GET['control'];
					$_POST['control']; ?></td>
    </tr>
    <tr>
      <td colspan="4" class="dom" align="justify"><?php  echo 'CALLE: '.$dt_empres['calle']." ".$dt_empres['no_ext'];?></td>
    </tr>
    <tr>
      <td colspan="4" class="dom" align="justify"><?php echo 'COL. '.$dt_empres['des_col'].", ".$rowd_encabezado['des_delmun']." ".$rowe_encabezado['des_estado'];?></td>
    </tr>
    <tr>       
	<td colspan="4" class="dom" align="justify"><?php echo 'C.P.'.$dt_empres['cod_pos'].' TEL: '.$dt_empres['telefono01'];?></td>
    </tr>
    <tr>
      <td colspan="4"><div align="center"><?php echo 'RFC:'.$dt_empres['rfc'];?></div></td>
    </tr>
    <tr> <?php $varfech=isset($dt_empres['fec_alta'])?$dt_empres['fec_alta']:date('Y-m-d');?>
      <td colspan="4" class="titOrd"><?php echo 'FECHA:&nbsp;&nbsp;'.chfecha($varfech,'Y-m-d','d/m/Y').'&nbsp;&nbsp;&nbsp; HORA:&nbsp;'.date('H:i:s');?></td>
    </tr>
    <tr>
	<td colspan="4"  class="titOrd" align="center">PROPINAS POR PAGAR</td>
	</tr>
	<tr>
	<td colspan="4"  class="titPer" align="center">PERIODO DEL <?php echo $_GET['bot'];?> AL <?php echo $_GET['but'];?></td>
	</tr>
<?php
 
    
	//echo "--->".$_GET['bot']."";
	//echo "--->".$_GET['but']."";
	
    $fecIni=chfecha($_GET['bot'],'d/m/Y','Y-m-d');
	$fecFin=chfecha($_GET['but'],'d/m/Y','Y-m-d');
	$arrBus[]="(dgpemema.fec_ven between '$fecIni' and '$fecFin') AND dgpemema.cancelado=0 and dgpemema.cancela=0 and dgpemema.pagado='S' ";	
	
	if($_GET['ven']!='T') {
		 $arrBus[]='dgger_cajerosj.vendedor='.$_GET['ven'].'';		
	}
	
	if($_GET['pvent']!='T') 
	{
	 	$arrBus[]=' ptventa.nparte1='.$_GET['pvent'].' ';
	}	
	
	if($_GET['pven']!='T') {
  		$arrBus[]=' dgpemema.cod_ven='.$_GET['pven'].' ';
	}else {
		$arrBus[]=' dgpemema.cod_ven!=0 ';
    }
	
	//echo "------->".$_GET['ven']."--".$_GET['pvent']."--".$_GET['pven']."--".$fecIni."--".$fecFin."";
	
 	$WHERE="WHERE ".implode(" AND ",$arrBus);
	
	echo "<tr>
	<td class=\"titOrd\" align=\"center\">FOLIO</td>
	<td class=\"titOrd\" align=\"center\">TOTAL</td>
	<td class=\"titOrd\" align=\"center\">PROPINA</td>
	<td class=\"titOrd\" align=\"center\">SERVICIO</td>
	</tr>";
	
	$asdf="SELECT distinct(cod_ven) FROM dgpemema
	LEFT JOIN ctmeser ON ctmeser.nparte1=dgpemema.cod_ven
	 where fec_ven between '$fecIni' and '$fecFin'
	  order by np_desc1";
	  //echo $asdf;
	  $sqlMes=mysqli_query($con ,$asdf);
	while($mesero=mysqli_fetch_array($sqlMes)){
	
	@$result = mysqli_query($con ,"
		SELECT 
			dgpemema.fol_ven,
			dgpemema.con_ven,
			dgpemema.tip_ven,
			dgpemema.fec_ven,
			dgpemema.cod_ven,
			
			ctmeser.np_desc1 as nomVen,
			
			
			dgpemema.sub_ven,
			dgpemema.por_des as descuento,
			fpos.mesa as mesa,
			ctmesas.np_desc1 as dmesa,
			ctarea.np_desc1 as  darea,
			ptventa.tip_ven as dptvta,
			dgger_cajerosj.acc_hor as hora,
			fpropina.tip as propina,
			dgpemema.servicio as servicio,
			dgger_cajerosd.tip_pag as tipag,
			dgtippag.ini_pag as descpag,
			dgpemema.cancela as cancela
		FROM 
			dgpemema
			LEFT JOIN fpos ON fpos.fol_ven=dgpemema.fol_ven
			LEFT JOIN ctmesas ON ctmesas.nparte1=fpos.mesa
			LEFT JOIN ctarea ON ctarea.nparte1=ctmesas.area
			LEFT JOIN ctmeser  ON ctmeser.nparte1=dgpemema.cod_ven
			LEFT JOIN ptventa ON ptventa.nparte1=ctmesas.descripcion
			LEFT JOIN dgger_cajerosj ON dgger_cajerosj.pedido=dgpemema.fol_ven		
			LEFT JOIN  fpropina ON fpropina.fol_ven=dgpemema.fol_ven
			LEFT JOIN dgger_cajerosd ON dgger_cajerosd.n_rec=dgger_cajerosj.n_rec	
			LEFT JOIN  dgtippag ON dgtippag.tip_pag=dgger_cajerosd.tip_pag
			LEFT JOIN dgcatven ON dgpemema.cod_ven=dgcatven.cod_ven
			
		$WHERE and dgger_cajerosj.fol_unp=0 and dgpemema.cod_ven='".$mesero['cod_ven']."' 
		group by dgpemema.fol_ven
		ORDER BY 
			dgpemema.con_ven");
			
			$mesEr0=mysqli_fetch_array(mysqli_query($con ,"SELECT np_desc1 FROM ctmeser WHERE nparte1='".$mesero['cod_ven']."'"));
	echo "<tr><td align=\"LEFT\" class=\"mesero\" colspan=\"4\"><strong>".$mesEr0['np_desc1']."</strong></td></tr>";
	
	$totp=0;
	$tots=0;
	$totc=0;
	if(!$result)die(mysqli_error($con));
	while($reg = mysqli_fetch_array($result))
	{
	//------suma de productos
	@$s = mysqli_query($con ,"SELECT SUM(dgpememd.pre_bas*dgpememd.can_ref) as sumat FROM dgpememd, dgger_cajerosj, dgpemema WHERE dgpememd.cons_ven='".$reg['fol_ven']."' and dgger_cajerosj.pedido='".$reg['fol_ven']."' and dgpememd.cons_ven=dgpemema.fol_ven and dgpemema.cancelado!=1 and dgpemema.cancela=0 and dgger_cajerosj.cancelado=0 and dgpememd.cancela=0");
		echo mysqli_error($con);
		while($r = mysqli_fetch_array($s)){
		$suma=$r["sumat"];
		}
////---------------------------------	

$tip = $reg["fol_ven"];
	$iop = mysqli_query($con ,"select * from fpropina where fol_ven = '$tip'");
	$qwe = mysqli_fetch_array($iop); 
	if ($qwe['tip']>0 || $reg["servicio"]>0){
		
		
	$serv = $reg["servicio"]; 
	
	$reg['descuento'];  //porcentaje descuento
	$desc=$suma*($reg['descuento']/100);  //cantidad descuento descuento		
	$sumtot=(($suma-$desc)+$reg['propina']);			//saldo			
	
		
		echo "<tr>"	
		       ." <td align=\"center\" class=\"mesInd\"> ".$reg['con_ven']." </td>" 
		         ." <td align=\"center\" class=\"mesInd\"> $ " .number_format($sumtot,2,'.',','). " </td>"
				  ."  <td align=\"center\" class=\"mesInd\"> $ " . number_format($qwe["tip"],2,'.',',') . " </td>"
		         ."     <td align=\"center\" class=\"mesInd\"> $ " . number_format($serv,2,'.',',') . " </td>";
		
		$totv+=$sumtot;
		$totp+=$qwe['tip'];
		$tots+=$serv;
		$totc+=$sumtot;
		
        	}	
	
	}

echo "<tr>
        <td align=\"center\" class=\"totMes\">&nbsp;</td>	
          <td align=\"center\" class=\"totMes\"><strong> $ ".number_format($totc,2,'.',',')."</strong></td>	
		    <td align=\"center\" class=\"totMes\"><strong>$ $totp </strong></td>
		      <td align=\"center\" class=\"totMes\"><strong>$ $tots </strong></td>";
				  
						$totpr+=$totp;
						$totse+=$tots;
						$totve+=$totc;

}

echo "<tr> 
			<td class=\"estiloSubTotal\" align=\"left\"><strong> TOTALES <strong></td>  								
			<td class=\"estiloSubTotal\" align=\"right\"><strong> $".number_format(($totve),2,'.',',')."<strong></td>
			<td class=\"estiloSubTotal\" align=\"right\"><strong> $".number_format(($totpr),2,'.',',')."<strong></td> 
			<td class=\"estiloSubTotal\" align=\"right\"><strong> $".number_format(($totse),2,'.',',')."<strong></td> 												
		</tr>";
	
?>	
    </table>
</form>
</body>
</html>