<?php
 
session_start();

include("DMMYSQLG.php");
include("DSA1000.php");
include("DF30000.inc");
include("DF80000.php");
include('JQUERY.inc');
$totve=0;
$totpr=0;
$totse=0;
$totv=0;
$update=mysqli_query($con ,"UPDATE dgpemema as a JOIN fpropina as b ON a.fol_ven = b.fol_ven SET a.tip =b.tip");

$updbte=mysqli_query($con ,"SELECT cvmesero, fol_ven FROM fcomhues WHERE modify='1'");
while ($dt_date=mysqli_fetch_array($updbte)){
$insbrt=mysqli_query($con ,"update dgpemema set cod_ven='".$dt_date['cvmesero']."' where fol_ven='".$dt_date['fol_ven']."'");
}
?>
<html>
<HEAD> <meta name="tipo_contenido" content="text/html;" http-equiv="content-type" charset="utf-8">


<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>
<script language="javascript">
function abrir2popup(val1,val2) 
{

a= window.open("rep_propinas_IMK.php?bot=<?php
 echo $_POST['fecini']; ?>&but=<?php
 echo $_POST['fecfin']; ?>&ven=<?php
 echo $_POST['secodven']; ?>&pven=<?php
 echo $_POST['setipvent']; ?>&pvent=<?php
 echo $_POST['setipven']; ?>","",
"scrollbars=yes, resizable=no, width=300,height=700, top=85, left=140");
}
</script>
  <script language="javascript">
    $(document).ready(function() {
     $(".botonExcel").click(function(event) {
      $("#datos_a_enviar").val( $("<div>").append( $("#pcs").eq(0).clone()).html());
      $("#FormularioExportacion").submit();
     });
    });
    </script>
    
    
    </HEAD>
<body>
<?php
 
$sq_pvta = mysqli_query($con ,"select * from ctmeser");//Datos para combo punto de venta 
$sq_pv = mysqli_query($con ,"select * from ptventa");//Datos para combo punto de venta 
?>
<div align="center">
  <form name="frm1" id="frm1" method="post" action="">
    <table width="441" border="0">
	<tr> <th colspan="2"><span class="Estilo16">VENTAS POR MESERO</span> </th> 
	</tr>
		<tr>
     	  <td><div align="right" class="Estilo19 Estilo21">Punto de Venta:</div></td>
        	<td>
            	<div align="left">
            	  <select name="setipven" id="setipven">
            	    <option value="T">------ TODOS ------</option>
            	    <?php
 
						while ($dt_pv = mysqli_fetch_array($sq_pv)){
							if($dt_pv['nparte1'] == $_POST['setipven']) 
								echo '<option value="'.$dt_pv['nparte1'].'" selected>'.$dt_pv['np_desc1'].'</option>';
							else
								echo '<option value="'.$dt_pv['nparte1'].'">'.$dt_pv['np_desc1'].'</option>';
						}
					?>
          	    </select>
       	        </div></td>
      	</tr>
		<tr>
     	  <td><div align="right" class="Estilo22">Mesero:</div></td>
        	<td>
            	<div align="left">
            	  <select name="setipvent" id="setipvent">
            	    <option value="T">------ TODOS ------</option>
            	    <?php
 
						while ($dt_tippag = mysqli_fetch_array($sq_pvta)){
							if($dt_tippag['nparte1'] == $_POST['setipvent']) 
								echo '<option value="'.$dt_tippag['nparte1'].'" selected>'.$dt_tippag['np_desc1'].'</option>';
							else
								echo '<option value="'.$dt_tippag['nparte1'].'">'.$dt_tippag['np_desc1'].'</option>';
						}
					?>
          	    </select>
       	        </div></td>
      	</tr>		
		<tr>
      	  <td><div align="right" class="Estilo21"><span class="Estilo4"><strong><span class="Estilo19">Cajero:</span>:</strong></span></div></td>
      	  <td><span class="Estilo4">
      	    <select name="secodven" id="secodven">
      	      <option value="T">---- TODOS ----</option>
      	      <?php
 
			$sql = mysqli_query($con ,"SELECT * FROM dgcatven order by CONCAT(nom_ven,' ',ap_pat_ven,' ',ap_mat_ven) asc");
			while($reg=mysqli_fetch_array($sql)){
				if($reg['cod_ven'] == $_POST['secodven']){
					echo '<option value="' . $reg['cod_ven'] . '" selected>' . $reg['nom_ven'] . ' ' . $reg['ap_pat_ven'] . ' ' . $reg['ap_mat_ven'] .'</option>';
				}else{
					echo '<option value="' . $reg['cod_ven'] . '">' . $reg['nom_ven'] . ' ' . $reg['ap_pat_ven'] . ' ' . $reg['ap_mat_ven'] . '</option>';
				}
			
			}
			?>
   	        </select>
   	      &nbsp;</span></td>
   	  </tr>
	  	<tr>
     	  <td>Tipo Pago:</td>
        	<td>
            	<div align="left">
            	  <select name="setippag" id="setippag">
            	    <option value="T">------ TODOS ------</option>
            	    <?php
 $sq_tippag = mysqli_query($con ,"select * from dgtippag");
						while ($dt_tippag = mysqli_fetch_array($sq_tippag)){
							if($dt_tippag['tip_pag'] == $_POST['setippag']) 
								echo '<option value="'.$dt_tippag['tip_pag'].'" selected>'.$dt_tippag['desc_pag'].'</option>';
							else
								echo '<option value="'.$dt_tippag['tip_pag'].'">'.$dt_tippag['desc_pag'].'</option>';
						}
					?>
          	    </select>
       	        </div></td>
      	</tr>    
      <tr>
      
        <td width="67%" colspan="2"><div align="center" class="Estilo21">
            
            De:
           
            <input name="fecini" type="text" class="Estilo23 datefrom" id="fecini" size="9" maxlength="20" 
			<?php

				if(isset($_POST['fecini'])){ //este es el truco
					echo 'value="' . $_POST['fecini'] .  '"';
				}else{
					echo 'value="'.date("d/m/Y").'"';
				}
			?>onkeypress="return soloNumeros(event)" 
		/>
                    Al:
            <input name="fecfin" type="text" class="Estilo23 dateto" id="fecfin" size="9" maxlength="20" 
			<?php

				if(isset($_POST['fecfin'])){ //este es el truco
					echo 'value="' . $_POST['fecfin'] .  '"';
				}else{
					echo 'value="'.date("d/m/Y").'"';
				}
			?>onkeypress="return soloNumeros(event)"		/>
     
        </div></td>
      </tr>
      <tr>
        <td colspan="2">
          <div align="center"> 
            <input name="buscar" id="buscar" type="submit" class="original" onClick="openpage('rep_propinas_PR.php','_self')" value="Buscar"/>
			<input name="imp" id="imp" type="submit" class="bot_WsW" onClick="openpage('rep_propinas_IM.php','_self')" value="Propinas PDF"/>			
			<input name="imp" id="imp" type="submit" class="bot_WsW" onClick="openpage('rep_ventas_mesero_IM.php','_self')" value="Ventas PDF"/>			

			<input name="ex" id="ex" type="submit" class="bot_WsW" onClick="openpage('rep_ventas_mesero_EX.php','_self')" value="Ventas EXCEL"/>			
		  </div></td> 
      </tr>
    </table>
     
  </form>
</div>
<div align="center">
      <form action="../t2e.php" method="post" target="_blank" id="FormularioExportacion"> 
   <input type="hidden" id="datos_a_enviar" name="datos_a_enviar" />
   </form> 
       <img src="../export_to_excel.gif" class="botonExcel" />
  <form method="post" action="" >
  
   <table  width="69%" height="19" border="0" align="center" id="pcs"  cellpadding="0" cellspacing="1">
	<tr>
	   <th width="14%"><div align="center">FECHA</div></th>
	    <th width="14%"><div align="center">CHEQUE</div>
		<th><div align="center">TOTAL CTA.</div></th> 
		<th width="14%"><div align="center">PROPINA</div></th>
		<th width="14%"><div align="center">SERVICIO</div></th>
   <th width="16%"><div align="center">TOT s/IVA</div></th>
		<th width="16%"><div align="center">PORCENTAJE</div></th>
		<th width="11%"><div align="center">TIPO PAGO</div></th>
	  </tr>
	  
    <?php

 if ( isset($_POST["buscar"])){
 
    $fecIni=chfecha($_POST['fecini'],'d/m/Y','Y-m-d');
	$fecFin=chfecha($_POST['fecfin'],'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($_POST['secodven']!='T') {
		 $arrBus[]="dgger_cajerosj.vendedor='".$_POST['secodven']."'";		
	}
	
	if($_POST['setipven']!='T') 
	{
	 	$arrBus[]=' ptventa.nparte1='.$_POST['setipven'].' ';
	}	
	
	if($_POST['setipvent']!='T') {
  		$arrBus[]=' dgpemema.cod_ven='.$_POST['setipvent'].' ';
	}else {
		$arrBus[]=' dgpemema.cod_ven!=0 ';
    }
	
	if($_POST['setippag']!='T') {
  		$arrBus[]=' dgger_cajerosd.tip_pag='.$_POST['setippag'].' ';
	}else {
		$arrBus[]=' dgger_cajerosd.tip_pag!=0 ';
    }
	
 	$WHERE="WHERE ".implode(" AND ",$arrBus);
 

    $sqlMes=mysqli_query($con ,"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");
	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,			
			fpropina.tip as propina,
			dgpemema.servicio as servicio,			
			dgpemema.cancela as cancela,
			dgtippag.desc_pag as pagotip
		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 dgcatven ON dgpemema.cod_ven=dgcatven.cod_ven
			LEFT JOIN dgger_cajerosd ON dgger_cajerosj.n_rec=dgger_cajerosd.n_rec	
			LEFT JOIN dgtippag ON dgtippag.tip_pag=dgger_cajerosd.tip_pag
		$WHERE and dgger_cajerosj.fol_unp=0 and dgpemema.cod_ven='".$mesero['cod_ven']."' 
		group by dgpemema.fol_ven
		ORDER BY 
			dgpemema.con_ven");

	?>
   
	<?php

	$mesEr0=mysqli_fetch_array(mysqli_query($con ,"SELECT np_desc1 FROM ctmeser WHERE nparte1='".$mesero['cod_ven']."'"));
	echo "<tr><td align=\"center\" class=\"mesero\" colspan=\"3\"><strong>".$mesEr0['np_desc1']."</strong></td></tr>";
	
	$totp=0;
	$tots=0;
	$totc=0;
	
	while($reg = mysqli_fetch_array($result))
	{
	//------suma de productos
	@$s = mysqli_query($con ,"SELECT SUM(dgpememd.pre_bas*dgpememd.can_ref) as sumat, sum(dgpememd.imp_des) as desCuento 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"];
 $desCuento = $r['desCuento'];
		}
////---------------------------------	

	
	$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=$desCuento;  //cantidad descuento descuento		
	$sumtot=(($suma-$desc));			//saldo			
	
		
		echo "<tr><td align=\"center\" class=\"mesInd\"><strong>".chfecha($reg['fec_ven'],'Y-m-d','d/m/Y')."&nbsp;</strong></td>	
		        <td align=\"center\" class=\"mesInd\"> <strong>  ".$reg['con_ven']." &nbsp;</strong></td> 
		        
		            <td align=\"center\" class=\"mesInd\"> <strong>$" .number_format( $sumtot,2,'.',','). "&nbsp;</strong></td>
		              <td align=\"center\" class=\"mesInd\"> <strong>$" . number_format($qwe["tip"],2,'.',',') . " &nbsp;</strong></td>
		                <td align=\"center\" class=\"mesInd\"> <strong>$" . number_format($serv,2,'.',',') . " &nbsp;</strong></td>
						";
		
		$totv+=$sumtot;
		$totp+=$qwe['tip'];
		$tots+=$serv;
		$totc+=$sumtot;
		$porce = $sumtot;
		$taje = $qwe["tip"];
		$p = ($taje * 100);
		if ($porce==0)
		$o=0;
		else
		$o =$p / $porce;
	
	
	     $totsiva=$sumtot/1.16;
	      $totprop=$qwe['tip']+$reg["servicio"];
		  if ($totsiva==0)
		  {
			$por=0;
		  }else 
			$por=($totprop*100)/$totsiva;
	
		echo "<td align=\"center\" class=\"mesInd\"> <strong>$" . number_format($totsiva,2,'.',',') . " &nbsp;</strong></td>";
		echo "<td align=\"center\" class=\"mesInd\"> <strong>" . number_format($por,2,'.',',') . " &nbsp;%</strong></td>
		<td align=\"center\" class=\"mesInd\"> <strong> ".$reg['pagotip']. " &nbsp;</strong></td>";
	
        	//}	
	
    	}
	
	echo "<tr><td align=\"right\" class=\"totMes\" colspan=\"2\"><strong>TOTALES X MESERO: </strong></td>	
		        
				   <td align=\"center\" class=\"totMes\"> <strong>$ $totc </strong></td> 
		            <td align=\"center\" class=\"totMes\"> <strong>$ $totp </strong></td>
		              <td align=\"center\" class=\"totMes\"> <strong>$ $tots </strong></td>
						<td align=\"center\" class=\"totMes\"> &nbsp; </td>";
						
						$totpr+=$totp;
						$totse+=$tots;
						$totve+=$totc;
						
						
	}
	
	echo "<tr> 
			<td class=\"estiloSubTotal\" colspan=\"2\"> TOTALES</td>  						
			<td class=\"estiloSubTotal\" align=\"right\">$".number_format(($totve),2,'.',',')."</td> 						
			<td class=\"estiloSubTotal\" align=\"right\">$".number_format(($totpr),2,'.',',')."</td> 
			<td class=\"estiloSubTotal\" align=\"right\">$".number_format(($totse),2,'.',',')."</td> 												
			<td class=\"estiloSubTotal\"></td>  
		</tr>";
}	
	mysqli_close($con);
	?>
    </table>
  </form>
</div>
</body>
</html>
