<?php
 
session_start();
include("DMMYSQLG.php");
include("DSA1000.php");
include("DF30000.inc");
include("DF80000.php");
include('JQUERY.inc');
?>
<html>
<head>
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>

<script language="javascript1.5" type="text/javascript">
function recargar(){
frm1.submit();
frm1.submit();
}
</script>
<style type="text/css">
<!--
.estiloFecha {
	font-size: 12px;
	font-weight: bold;
}
.Estilo3 {border: 1px; font-family :urw gothic l; color: #000099; background-color: #dbe0e9;}
.Estilo4 {font-size: 12px}

.granTotL{
	font-family:Arial, Helvetica, sans-serif;
	font-size:14px;
	font-weight:bold;
	text-align:left;
	background-color:#0080FF;
	 ;
}
.granTotR{
	font-family:Arial, Helvetica, sans-serif;
	font-size:14px;
	font-weight:bold;
	text-align:right;
	background-color:#0080FF;
	 ;	
}
.granTotParL{
	font-family:Arial, Helvetica, sans-serif;
	font-size:12px;
	font-weight:bold;
	text-align:left;
	background-color:#9DCEFF;
	color:#000000;
}
.granTotParR{
	font-family:Arial, Helvetica, sans-serif;
	font-size:12px;
	font-weight:bold;
	text-align:right;
	background-color:#9DCEFF;
	color:#000000;	
}
.granTotCan{
	font-family:Arial, Helvetica, sans-serif;
	font-size:12px;
	font-weight:bold;
	text-align:right;
	background-color:#FF0000;
	color:#000000;	
}
.detFacTr{
	font-family:Arial, Helvetica, sans-serif;
	font-size:16px;

}
.detFacL{
	text-align:left;
}
.detFacR{
	text-align:right;
}
-->
</style>
</head>
<body>
<?php
 

$sq_tipven = mysqli_query($con ,"select * from dgtipven");//Datos para combo setipven 



?>
<div align="center">
<form name="frm1" id="frm1" method="post" action="">
  <table width="301"  align="center" >
    	<tr>
    	  <th colspan="2">COMANDA DE ALIMENTOS</th>
		</tr>
       	<tr>
     	  <td width="44">Fecha:</td>
        	<td width="191">
		    <div align="center" class="estiloFecha">
            	    <?php
 $varf=isset($dt_empres['fec_alta'])?$dt_empres['fec_alta']: date('Y/m/d');
 
 					
 echo chfecha($varf,'Y-m-d','d/m/Y');
					?>
		<input name="fecha" id="fecha" type="hidden" value="<?php
 echo $varf; ?>">			
   	          </div></td>
      	</tr>
      	<tr>
      	  <td colspan="2"><div align="center">
       		  <input name="boproc" type="submit" id="boproc" value="Actualizar" onClick="recargar();"/>
       	  </div></td>
       	</tr>
	</table>

  <table border="0" width="100%" >
    <?php

	$arrBus[]="dgpemema.fec_ven='".$varf."' AND dgpemema.cancelado!=1 and cancela!=1 and pagado!='S'";	
	
 	$WHERE="WHERE ".implode(" AND ",$arrBus);		
	@$sql = mysqli_query($con ,"
		SELECT 
			dgpemema.fol_ven,
			dgpemema.con_ven,
			dgpemema.tip_ven,
			dgpemema.fec_ven,
			dgpemema.cod_ven,
			dgpemema.iva_ven,
			ctmeser.np_desc1 as nomVen,
			dgpemema.tot_ven,
			dgpemema.imp_pag,
			dgpemema.sub_ven,
			fpos.mesa as mesa,
			ctmesas.np_desc1 as dmesa,
			ctarea.np_desc1 as  darea,
			ptventa.np_desc1 as dptvta,
			dgger_cajerosj.acc_hor as hora,
			fpropina.tip as propina,
			dgger_cajerosj.tip_mov as tipag,
			dgtippag.desc_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  dgtippag ON dgtippag.tip_pag=dgger_cajerosj.tip_mov								
			left JOIN dgcatven ON dgpemema.cod_ven=dgcatven.cod_ven
			
		$WHERE
		ORDER BY 
			dgpemema.con_ven");
	echo mysqli_error($con);
//	".$dt_empres['fec_alta']."
if (mysqli_num_rows($sql)!=0)
{?>
    	<tr>
        	<th colspan="16">
          	<div align="left">
            	<input type="submit" name="bot4" value="Borrar Despachado">
          	</div>			</th>
      	</tr>
	 	<tr class="typeagre">
	 	  <td><div align="center">Num. Ord.</div></td>
		  <td>Alimentos</td>
		  <td><div align="center"></div></td>
  		  <td colspan="5"><div align="center">Comentario</div></td>
	 	</tr>

<?php
 
	while($reg = mysqli_fetch_array($sql)){
//------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=0 and dgger_cajerosj.cancelado=0 and dgpemema.cancelado!=1 ");
		echo mysqli_error($con);
		while($r = mysqli_fetch_array($s)){
		$suma=$r["sumat"];
		}
////---------------------------------	

//------suma de productos solo cortesia
	@$cr = mysqli_query($con ,"SELECT SUM(dgpememd.pre_bas*dgpememd.can_ref) as sumat FROM dgpememd, dgger_cajerosj, dgger_cajerosd, dgpemema WHERE dgpememd.cons_ven='".$reg['fol_ven']."' and dgpememd.cons_ven=dgger_cajerosj.pedido and dgger_cajerosj.n_rec=dgger_cajerosd.n_rec and dgger_cajerosd.tip_pag=3 and dgger_cajerosj.cancelado=0 and dgpemema.cancelado!=1");
		echo mysqli_error($con);
		while($ccr = mysqli_fetch_array($cr)){
		$sumacr=$ccr["sumat"];
		}
////---------------------------------
		@$sq = mysqli_query($con ,"SELECT dgpememd.*,dginventp.np_desc1 FROM dgpememd INNER JOIN dginventp ON dgpememd.nparte1 = dginventp.nparte1 WHERE dgpememd.cons_ven='".$reg['fol_ven']."' and dgpememd.despachado!=2 and dgpememd.cancela=0 and dginventp.tipo=1 group by dginventp.nparte1 order by dginventp.np_desc1");
		echo mysqli_error($con);

		while($rg = mysqli_fetch_array($sq)){
			echo '<tr class="detFacTr">'; ?>
			<td class="detFacR"><input name="idvt[]"  id="idvt_<?php
 echo $rg['fol_ven1']; ?>" type="checkbox" value="<?php
 echo $rg['fol_ven1']; ?>"  <?php
 if ($rg['despachado']==1) { echo 'checked'; } ?> >&nbsp;</td>
		<?php
	
		@$al = mysqli_query($con ,"SELECT * from dginventp where np_desc1='".$rg['np_desc1']."' and tipo=1"); //and gpo_basico!=82
		$al1 = mysqli_fetch_array($al);
			echo '<td class="detFacL">'.$al1['np_desc1'].'&nbsp;</td>';  //desc alim	
			echo '<td class="detFacR" colspan="5">'.$rg['comenta'].'</td>';  //precio unit
			echo '</tr>';		
			$des=$rg["por_des"];
			$total=$rg["total_cd"];
			$desc=$rg["cancelado"];
		} //una venta
		
		//impresion de reportes cancelados
	if (($reg["imp_pag"]==0.00) && ($reg["cancela"]==1)) {
		echo '<tr class="granTotCan">';
		echo '<td class="granTotCan">'.$reg["con_ven"].'&nbsp;</td>';   //orden
		echo '<td class="granTotCan" >'.chfecha($reg['fec_ven'],'Y-m-d','d/m/Y').'&nbsp;</td>';	//fecha		
		echo '<td class="granTotCan" colspan="2" >'.$reg["cod_ven"].' '.$reg["nomVen"].'&nbsp;</td>';	//operador				
		echo '<td class="granTotCan" colspan="7"><div align="center">   C A N C E L A D O  </div> </td>';  //cortesia
		echo '</tr>';		
		$granCorVenc +=$sumacr;  //cortesia
		$granTotVenc +=$suma;  //subtotal
		$granPagVenc +=$reg["iva_ven"];  //iva
		$granSalVenc +=($reg["tot_ven"]);  //total
		$granProc    +=($reg["propina"]);  //propina	
		$numVen++;
	} else {
		echo '<tr class="granTotParR">';
		echo '<td class="granTotParR">'.$reg["con_ven"].'&nbsp;</td>';   //orden
		echo '<td class="granTotParL" >'.chfecha($reg['fec_ven'],'Y-m-d','d/m/Y').'&nbsp;</td>';	//fecha		
		echo '<td class="granTotParL" colspan="2" >'.$reg["cod_ven"].' '.$reg["nomVen"].'&nbsp;</td>';	//operador				
		echo '<td class="granTotParL" colspan="3">'.$reg['dptvta'].'</td>';  //punto vta
		echo '<td class="granTotParL" colspan="3">'.$reg["dmesa"].'</td>';  //mesa
		echo '</tr>';				
		$granCorVen +=$sumacr;  //cortesia
		$granTotVen +=$suma;  //subtotal
		$granPagVen +=$reg["iva_ven"];  //iva
		$granSalVen +=($reg["tot_ven"]);  //total
		$granPro    +=($reg["propina"]);  //propina				
		$numVen++;
		}
		
		
	
	} //totales
/*	echo "<tr> 
			<td class=\"granTotL\" colspan=\"11\">Numero Ventas: $numVen</td>  						
		</tr>";*/

} ?>
	
    </table>
	
<?php
 
if(isset($_POST['boproc'])?$_POST['boproc']:""){

	if (isset($_POST['idvt'])?$_POST['idvt']:""){
		$i=0;
		foreach ($_POST['idvt'] as $fol){
		 $folio[$i]=$fol;
		mysqli_query($con ,"UPDATE dgpememd set despachado=1 where fol_ven1=".$folio[$i]."");
		echo mysqli_error($con);
		$i++;
		}
	}	
echo '<meta content="0; url=ven_alimentos_PR.php" HTTP-EQUIV="REFRESH">';	
}

if(isset($_POST['bot4'])?$_POST['bot4']:""){
	if ($_POST['idvt']){
		$i=0;
		foreach ($_POST['idvt'] as $fol){
		 $folio[$i]=$fol;
		mysqli_query($con ,"UPDATE dgpememd set despachado=2 where fol_ven1=".$folio[$i]."");
		$i++;
		}
	}	
	echo '<meta content="0; url=ven_alimentos_PR.php" HTTP-EQUIV="REFRESH">';
	
}
?>
  </form>

</div>
</body>
</html>