<?php
//error_reporting(E_ALL);
//ini_set('display_errors', 1);
session_start();
include("DMMYSQLG.php");
include("DSA1000.php");
include("DF30000.inc");
include("DF80000.php");
include("DFJQUERY.inc");
include("JQUERY.inc");
$comida=0;
$bebida=0;
$granTotVen=0;
$granDesVen=0;
$granPro=0;
$granSer=0;
$granSalVen=0;
$numVen=0;
?>
<html>
<head>
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></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;}

.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;	
}
.granTotAb{
	font-family:Arial, Helvetica, sans-serif;
	font-size:12px;
	font-weight:bold;
	text-align:left;
	background-color:#00CC33;
	color:#000000;	
}

.detFacTr{
	font-family:Arial, Helvetica, sans-serif;
	font-size:16px;
	 ;	

}
.detFacL{
	text-align:left;
	 ;	
}
.detFacR{
	text-align:right;
	 ;	
}
.detFacC{
	text-align:center;
	 ;	
}
.Estilo16 {color: #FFFFFF}

-->
</style>
</head>
 
<body>
<?php
$sq_tipven = mysqli_query($con ,"select * from dgtipven");//Datos para combo setipven 
$sq_pvta = mysqli_query($con ,"select * from ptventa");//Datos para combo punto de venta 
?>
<div align="center">
<form name="frm1" id="frm1" method="post" action="">
  <table border="0" align="center">
    	<tr>
    	  <th colspan="2">REPORTE DE CAJERO </th>
		</tr>
  	<tr>
     	  <td><span class="Estilo16">Punto de Venta:</span></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 style="display:none">
     	  <td><span class="Estilo16">Tipo Venta:</span></td>
        	<td>
            	<div align="left">
            	  <select name="setipven" id="setipven">
            	    <option value="T">---- TODAS ----</option>
            	    <?php
 
						while ($dt_tipven = mysqli_fetch_array($sq_tipven)){
							if($dt_tipven['tip_ven'] == $_POST['setipven']) 
								echo '<option value="'.$dt_tipven['tip_ven'].'" selected>'.$dt_tipven['des_tipven'].'</option>';
							else
								echo '<option value="'.$dt_tipven['tip_ven'].'">'.$dt_tipven['des_tipven'].'</option>';
						}
					?>
          	    </select>
       	        </div></td>
      	</tr>
      	<tr>
      	  <td colspan="2" nowrap>
		    <div align="center" class="estiloFecha">
                          <?php $fecf=(isset($_POST['fecini']))?$_POST['fecini']:date('d/m/Y');?>
			  Del 
			  <input name="fecini" type="text" class="Estilo3 datefrom" id="fecini" size="15" value="<?=$fecf?>"
			  	<?php
 
					if(isset($_POST['fecini']))
						echo 'value="'.$_POST['fecini'].'"'; 
				  	else
				    	echo 'value="'.date('d/m/Y').'"'; 
				?>>		      
	  	  al 
	         
				  	

	          <input name="fecfin" type="text" class="Estilo3 dateto" id="fecfin" size="15" 
			<?php
 
				if(isset($_POST['fecfin']))
			  		echo 'value="'.$_POST['fecfin'].'"'; 
			  	else
			  		echo 'value="'.date('d/m/Y').'"'; 
			?>>
	  
          </div></td>
       	</tr>
      	<tr>
      	  <td>Cajero:</td>
      	  <td><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;</td>
   	  </tr>
      	<tr>
      	  <td colspan="2"><div align="center">
      	    <select name="tip_rep" id="tip_rep">
      	      <option value="R" <?php if(isset($_REQUEST['tip_rep'])&&$_REQUEST['tip_rep']=="R") echo 'selected';?>>RESUMEN</option>
      	      <option value="D" <?php if(isset($_REQUEST['tip_rep'])&&$_REQUEST['tip_rep']=="D") echo 'selected';?>>DETALLE</option>
   	          </select>
   	      </div></td>
   	  </tr>
      	<tr>
      	  <td colspan="2"><div align="center">
       		  <input name="boproc" type="submit" id="boproc" value="Procesar" onClick="openpage('rep_cajeros_PR.php','_self')" />
       	  </div></td>
       	</tr>
	</table>

  <table border="0">
    	<tr>
        	<th colspan="10">
          	<div align="left">
            	<input type="button" name="bot4" value="Imprimir" onClick="openpage('rep_cajeros_IMM.php','_self')">
          	</div>			</th>
      	</tr>
  <tr>
    	  <th colspan="10" align="justify"><?php
 if (isset($_POST["setipvent"])&&$_POST["setipvent"]=="T"){
					echo "TIP. VTA.: ";
					echo "TODAS"; 
					} else 
					{
					@$bus = mysqli_query($con ,"SELECT * FROM ptventa WHERE nparte1= '".$_POST['setipvent']."'");
					$re = mysqli_fetch_array($bus);
					echo "TIP. VTA.: ";
					echo $re['np_desc1'];
					}			
				 ?></th>
  	  </tr>
    	<tr>
    	  <th colspan="10"><?php
 if (isset($_POST["secodven"])&&$_POST["secodven"]=="T"){
					echo "CAJERO: ";
					echo "TODOS"; 
					} else 
					{
					@$bus1 = mysqli_query($con ,"SELECT * FROM dgcatven WHERE cod_ven = '".$_POST['secodven']."'");
					$re1 = mysqli_fetch_array($bus1);
					echo "CAJERO: ";
					echo $re1['nom_ven'];
					echo ' ';
					echo $re1['ap_pat_ven']; 
					echo ' ';
					echo $re1['ap_mat_ven'];
					}			
				 ?></th>
  	  </tr>
	 	<tr class="typeagre">
	 	  <td width="42"><div align="center">Folio Vta.</div></td>
		  <td width="22">Cant.</td>
		  <td width="42">Alimentos</td>
		  <!--td><div align="center">Extras</div></td-->
 		  <td width="32"><div align="center">Bebidas</div></td>
		  <td width="69"><div align="center">Precio Uni.</div></td>
  		  <td width="41"><div align="center">Subtotal</div></td>
		  <td width="45">Descuento</td>
		  <td width="40"> Nrta Entr X Cta</td>		  
		  <td width="34">  Nrta Entr X Cta (S)</td>
  		  <td width="32">Total</td>
	 	</tr>
		

<?php


require_once("PV00000_CL.php");

if ( isset($_POST["boproc"])){

$datos['tipRep']=$_REQUEST['tip_rep'];
//$vard=(isset(dgpeMema($data)))?dgpeMema($data):"";
$vard=(isset($data))?$data:NULL;
$dgPEmema=new dgpeMema($vard);

$sq_dgpeMEma=$dgPEmema->report_getDiarias();
	
	while($reg = mysqli_fetch_array($sq_dgpeMEma)){
	if (($reg['folp']<=0) || ($reg['folp']=='')){
//------suma de productos
	@$s = mysqli_query($con ,"SELECT SUM($memaDet.pre_bas*$memaDet.can_ref) as sumat, sum($memaDet.imp_des) as desCuento  FROM $memaDet, $table, $mema WHERE $memaDet.cons_ven='".$reg['folVen']."' and $table.pedido='".$reg['folVen']."' and $memaDet.cons_ven=$mema.fol_ven and $mema.cancela=0 and $table.cancelado=0 and $memaDet.cancela=0");
		echo mysqli_error($con);
		while($r = mysqli_fetch_array($s)){
		$suma=$r["sumat"];
		$desCuento=$r['desCuento'];
		}		
////---------------------------------

        @$sqal = mysqli_query($con ,"SELECT sum(can_ref*pre_bas) as totAli from $memaDet inner join dginventp on dginventp.nparte1=$memaDet.nparte1 left join $mema on $memaDet.cons_ven=$mema.fol_ven where $memaDet.cons_ven='".$reg['folVen']."' and $memaDet.cancela=0 and dginventp.tipo='1' and $mema.cancela='0' group by $memaDet.nparte1");
		while ($com=mysqli_fetch_array($sqal)){
		$comida += $com['totAli'];
		}

		@$sqbb = mysqli_query($con ,"SELECT sum(can_ref*pre_bas) as totBeb from $memaDet inner join dginventp on dginventp.nparte1=$memaDet.nparte1 left join $mema on $memaDet.cons_ven=$mema.fol_ven where $memaDet.cons_ven='".$reg['folVen']."' and $memaDet.cancela=0 and dginventp.tipo='2' and $mema.cancela='0' group by $memaDet.nparte1");
		while ($beb=mysqli_fetch_array($sqbb)){
		$bebida += $beb['totBeb'];
		}	
	
////---------------------------------
		@$sq = mysqli_query($con ,"SELECT sum(can_ref) as can_ref,pre_bas,nparte1 from $memaDet where cons_ven='".$reg['folVen']."' and cancela=0 ");
		echo mysqli_error($con);
		while($rg = mysqli_fetch_array($sq)){
			if ($datos['tipRep']=='D'){
			echo '<tr class="detFacTr">';
			echo '<td class="detFacR">'.$reg['conVen'].'&nbsp;</td>'; //orden
			echo '<td class="detFacC">'.$rg['can_ref'].'&nbsp;</td>';		//cant	 
			@$al = mysqli_query($con ,"SELECT * from dginventp where nparte1='".$rg['nparte1']."' and tipo=1"); //tipo=1 alimento
			$al1 = mysqli_fetch_array($al);
                        //$val=(isset($al1['lim_vta1']))?$al1['lim_vta1']:0;
                        //$vrc=(isset($rg['can_ref']))?$rg['can_ref']:0;
			$qw=$al1['lim_vta1']*$rg['can_ref'];
                        
			echo '<td class="detFacL">'.number_format(floatval($qw!="0.00")?($qw):floatval("&nbsp;"),2,'.',',').'&nbsp;</td>';  //desc alim
			@$beb = mysqli_query($con ,"SELECT * from dginventp where nparte1='".$rg['nparte1']."' and tipo=2"); //tipo=2 bebidas
			$beb1 = mysqli_fetch_array($beb);
			echo '<td class="detFacL">'.number_format(($beb1['lim_vta1']*$rg['can_ref']),2,'.',',').'&nbsp;</td>';  //desc ext			
			echo '<td class="detFacR">'.number_format(($rg['pre_bas']*$rg['can_ref']),2,'.',',').'</td>';  //precio unit
			echo '<td class="detFacR"></td>';
			echo '<td class="detFacR"></td>';			
			echo '<td class="detFacR"></td>';						
			echo '</tr>';		
			}
		} //una venta
		
	//IMPRESION DE CUENTAS NO PAGADAS
	if (($reg["impPag"]==0.00) && (isset($reg["tippag"])&&$reg["tippag"]=='') && ($reg["cancela"]==0)) {
		if ($datos['tipRep']=='D'){
		echo '<tr class="granTotAb">';
		echo '<td class="granTotAb">'.$reg['conVen'].'&nbsp;</td>';   //orden
		echo '<td class="granTotAb" >'.$reg['fecVen'].'&nbsp;</td>';	//fecha			
		echo '<td class="granTotAb">'.$reg['dptvta'].' | '.$reg['dmesa'].'</td>';   //mesa	
		echo '<td class="granTotAb" colspan="2">'.$reg['codVen'].' '.$reg['nomVen'].'&nbsp;</td>';	//operador				
		echo '<td class="granTotAb" colspan="5"> <div align="center">CUENTA ABIERTA</div></td>';  //cortesia
		echo '</tr>';		
		$numVen++;
		}
	}else	if (($reg["impPag"]==0.00) && ($reg["cancela"]==1)) { //CUENTAS CANCELADAS
		if ($datos['tipRep']=='D'){
		echo '<tr class="granTotCan">';
		echo '<td class="granTotCan">'.$reg['conVen'].'&nbsp;</td>';   //orden
		echo '<td class="granTotCan" >'.$reg['fecVen'].'&nbsp;</td>';	//fecha					
		echo '<td class="granTotCan">'.$reg['dptvta'].' | '.$reg['dmesa'].'</td>';   //orden	
		echo '<td class="granTotCan" colspan="2">'.$reg['codVen'].' '.$reg['nomVen'].'&nbsp;</td>';	//operador				
		echo '<td class="granTotCan" colspan="5"> <div align="center">CANCELADO</div></td>';  //cortesia
		echo '</tr>';		
		$numVen++;
		}
	} else {
		if ($datos['tipRep']=='D'){
		echo '<tr class="granTotParR">';
                $vrc=(isset($reg['con_ven']))?$reg['con_ven']:"";
		echo '<td class="granTotParR">'.$vrc.'&nbsp;</td>';   //orden
		echo '<td class="granTotParL" >'.$reg['fecVen'].'&nbsp;</td>';	//fecha	
		echo '<td class="granTotParL">'.$reg['dptvta'].' | '.$reg['dmesa'].'</td>';   //orden				
		echo '<td class="granTotParL" colspan="2">'.$reg['nomVen'].'</td>';	//operador						
		echo '<td class="granTotParR">'.number_format($suma,2,'.',',').'</td>';  //porcentaje descuento	
		echo '<td class="granTotParR">'.number_format($desCuento,2,'.',',').'</td>';  //cortesia
		echo '<td class="granTotParR">'.number_format($reg['propina'],2,'.',',').'</td>';  //propina		
		echo '<td class="granTotParR">'.number_format($reg['servicio'],2,'.',',').'</td>'; //subtotal	
		echo '<td class="granTotParR">'.number_format($sumtot=($suma+$reg['propina']+$reg['servicio']-$desCuento),2,'.',',').'</td>';						
		echo '</tr>';	
		}			
		//SUMA DE TOTALES							
		
		$vrd=(isset($reg['descuento']))?$reg['descuento']:"";
		$desc=$suma*($vrd/100);
		
		$reg['propina'];
		$suma;
		//$reg["iva_ven"];
		$sumtot=($suma+$reg['propina']+$reg['servicio']-$desCuento);
		
		$granDesVen +=$desCuento;  //descuento
		
		$granTotVen +=$suma;  //subtotal
		//$granPagVen +=$reg["iva_ven"];  //iva
		if($reg["impPag"]!=0){
		 $granSalVen +=$sumtot;  //total
		}
		$granPro    +=($reg['propina']);  //propina		
		$granSer    +=($reg['servicio']);  //propina		
		$numVen++;
		}
	} //totales
	
} 
	echo '<tr> 
			<td class=\"granTotL\" colspan=\"2\">TOTALES</td>
			<td class=\"granTotR\">'.number_format($comida,2,'.',',').'</td> 
			<td class=\"granTotR\">'.number_format($bebida,2,'.',',').'</td> 
			<td class=\"granTotR\"></td> 
			<td class=\"granTotR\">'.number_format($granTotVen,2,'.',',').'</td> 
			<td class=\"granTotR\">'.number_format($granDesVen,2,'.',',').'</td> 
			<td class=\"granTotR\">'.number_format($granPro,2,'.',',').'</td> 			 						
			<td class=\"granTotR\">'.number_format($granSer,2,'.',',').'</td>  										
			<td class=\"granTotR\">'.number_format($granSalVen,2,'.',',').'</td>												
		</tr>';		
}
?>	
    </table>
  </form>
</div>
</body>
</html>