<?php
session_start();
include("DMMYSQLG.php");
include("DSA1000.php");
include("DF30000.inc");
include("JQUERY.inc");
$totCAN=0;
$nr=0;
?>
<html>
<HEAD> 
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>
<meta name="tipo_contenido" content="text/html;" http-equiv="content-type" charset="utf-8">
</HEAD>
<body>
<div align="center">
  <form name="frm1" id="frm1" method="post" action="">
    <table width="541" border="0">
	<tr>
        <th colspan="2">ENTRADAS DE ALMACEN </th>
      </tr>
	  <tr>
              <th width="252"> <input name="r1" type="radio" value="clave" tabindex="1" <?php
 if(isset($_POST['r1'])&&$_POST['r1']=='clave') echo 'checked';?> /> X PROVEEDOR            
 <select name="proveedor" id="proveedor"> 
      <option value="">---------SELECCIONE---------</option>
          <?php
$sql = mysqli_query($con ,"SELECT * FROM fproveedores where t1='ACTIVO' order by np_desc1 ");
while($reg=mysqli_fetch_array($sql)){
	if($_POST['fproovedor']==$reg['np_desc1'] ){
		echo '<option value="' . $reg['nparte1'] . '" selected>' . $reg['np_desc1'] . '</option>';
	}else{
		echo '<option value="' . $reg['nparte1'] . '">' . $reg['np_desc1'] . '</option>';
	}
}			
?>       
 </select>
        </th>
		<th width="152"><input name="prods" placeholder="numero de producto"/><br/> <input name="r1" type="radio" value="paso" tabindex="1" <?php
 if(isset($_POST['r1'])&&$_POST['r1']=='paso') echo 'checked';?>/>
		<select name="select">
         <option value="0"<?php
 if(isset($_REQUEST['select'])&&$_REQUEST['select']=="0") echo 'selected';?>>ALMACEN</option>
          <option value="1"<?php
 if(isset($_REQUEST['select'])&&$_REQUEST['select']=="1") echo 'selected';?>>DIRECTO</option>
			<option value="2"<?php
 if(isset($_REQUEST['select'])&&$_REQUEST['select']=="2") echo 'selected';?>>POR ALMACEN</option>
          </select></th>
      </tr>  
      <tr >
        <td> <div align="center" class="Estilo19"><img src="magnifier.png" alt="Buscar" onClick="alert('Buscar')" /> <strong>PERIODO</strong> </div></td>
        <td style="color:#000">
          <strong>De:</strong>
          <input name="fec" type="text" class="emplea datefrom" id="fec" size="9" maxlength="20"
			<?php
				if(isset($_POST['fec'])){ //este es el truco
					echo 'value="' . $_POST['fec'] .  '"';
				}else{
					echo 'value="'.date("d/m/Y").'"';
				}
			?>onkeypress="return soloNumeros(event)"
		/>
            <strong>A:</strong>
          <input name="fec2" type="text" class="emplea dateto" id="fec2" size="9" maxlength="20"
			<?php
				if(isset($_POST['fec2'])){ //este es el truco
					echo 'value="' . $_POST['fec2'] .  '"';
				}else{
					echo 'value="'.date("d/m/Y").'"';
				}
			?>onkeypress="return soloNumeros(event)"
		/>
            </td>
      </tr>
      <tr>
        <td colspan="2">
            <div align="center">
              <input name="Submit" type="button" class="original" onClick="openpage('AL31000_PR.php','_self')" value="Buscar"/>
			  <input name="bot4" type="button" class="bot_WsW" onClick="openpage('AL31000_IM.php','_self')" value="PDF"/>        
		  </div></td>
      </tr>
    </table>   
  </form>
</div> 
<div align="center">
  <form method="post" action="" >
    <?php
	?>
	<div style="height:450px; overflow:scroll; width:1150;" align="center">
	<table width="87%" align="center" bordercolor=" " bordercolordark=" ">
      <tr>
        <th width="75"><div align="center">FECHA</div></th>
        <th width="141"><div align="center">ARTICULO</div></th>
		<th width="85"><div align="center">FACTURA</div></th>
        <th width="65"><div align="center">DEPARTAMENTO</div></th>
		<!--<th width="111"><div align="center">PRECIO</div></th>-->
		<th width="84"><div align="center">ENTRADA</div></th>
		<th width="97"><div align="center">COSTO</div></th>
		<th width="42"><div align="center">P.P.</div></th>
		<th width="64"><div align="center">TOTAL</div></th>			
      </tr>
	<?php
	  require_once("AL00000_CL.php");
	  $vd=(isset($data))?$data:0;
	  $dgREqdev=new dgreQdev($vd);
      $sql_dgreqdev=$dgREqdev->report_getEntradas();
	  $fec = isset($_POST['fec'])?$_POST['fec']:"";
	  include('DF20000.php');
	  $fecha_inicial = isset($f_m)?$f_m:"";
	  $fec = isset($_POST['fec2'])?$_POST['fec2']:"";
	  include('DF20000.php');
	  $fecha_final = isset($f_m)?$f_m:"";
	$vs=(isset($_POST['submit']))?$_POST['submit']:"";
	$tipEst=isset($_POST['r1'])?$_POST['r1']:"";  
        
	if($vs=="" && $tipEst=="clave" && empty($_POST['proveedor'])){
            echo '<input name="tip_bus" type="hidden" value="clave">';
	  	@$sql = mysqli_query($con ,"SELECT * FROM dgreqdev where fec_ven between '$fecha_inicial' and '$fecha_final'");   
        }else{
//         echo '<input name="tip_bus" type="hidden" value="paso">';
		@$sql = mysqli_query($con ,"SELECT * FROM dgreqdev where fec_ven between '$fecha_inicial' and '$fecha_final' and tip_ven ='".$_POST['proveedor']."' ");
        }
//        if($vs=="" && $tipEst=="clave"){
//		
//		echo '<input name="tip_bus" type="hidden" value="clave">';
//	  	@$sql = mysqli_query($con ,"SELECT * FROM dgreqdev where fec_ven between '$fecha_inicial' and '$fecha_final'");
		
	if($vs==""&&$tipEst=="paso"){
	
		echo '<input name="tip_bus" type="hidden" value="paso">';
		@$sql = mysqli_query($con ,"SELECT * FROM dgreqdev where fec_ven between '$fecha_inicial' and '$fecha_final'");
	}
	while($reg = mysqli_fetch_array($sql))
	{
	  	$nr = $nr + 1;
		$v1 = $nr / 2;
		$v2 = (int) ($nr / 2);
		  if($v1 == $v2){
		 	$col ="";
		   }else{
			$col ="";
		   }
		   
		 
		
		echo "<tr>";
		echo "<td style='#9B0F1A'> <div align='center' style='color:#fff !important'><strong>" . $reg["fol_ven"] . "&nbsp;</strong></div></td>";
		$proveedor=mysqli_fetch_array(mysqli_query($con ,"SELECT np_desc1 FROM fproveedores where nparte1='".$reg['tip_ven']."'"));
		echo "<td style='#9B0F1A' colspan='2'> <div align='center' style='color:#fff !important'><strong>" . $proveedor["np_desc1"] . "&nbsp;</strong></div></td>";
		
		$fec1=isset($reg["fec_fac"])?$reg["fec_fac"]:"";
		include('DF20000.php');
		echo "<td style='".$col."'> <div align='center'><strong>" .(isset($reg['fol_fac'])&&$reg['fol_fac']!=""?($f_f):"&nbsp;"). "&nbsp;</strong></div></td>"; 
        echo "<td style='".$col."'> <div align='center'>"; 
        
echo "</div></td></tr>";
   
	
	if ($vs=="" && $tipEst=="clave"){
	$dataBus=" dgreqded.cons_ven='".$reg['fol_ven']."' ";
	
	}elseif($vs=="" && $tipEst=="paso"){
	$dataBus=" dgreqded.cons_ven='".$reg['fol_ven']."' AND fagrupadores.paso='".$_POST['select']."'";
	}
	
	$WHERE= "WHERE".$dataBus."";
	 
	$reqDed=mysqli_query($con ,"SELECT * FROM dgreqded 
	LEFT JOIN farticulos on farticulos.nparte1=dgreqded.nparte1
	LEFT JOIN fagrupadores on fagrupadores.np_desc1=farticulos.t8 
	$WHERE");
	
	$totIVA=0;
	$totTOTAL=0;
	$totSUB=0;
	while($req = mysqli_fetch_array($reqDed))
	{
		echo "<tr>";
		//echo "<td> <div align='center'><strong></strong></div></td>";
                $fec1=$reg["fec_ven"];
		include('DF20000.php');
		echo "<td class=\"totArt\"> <div align='center'><strong>" . $f_f . "&nbsp;</strong></div></td>";
                $articulo=mysqli_fetch_array(mysqli_query($con ,"SELECT nparte1,np_desc1,cos_prom FROM farticulos WHERE nparte1='".$req['nparte1']."'"));
                echo "<td> <div align='left' style='color:#fff'><strong>".$articulo["nparte1"]." | " . $articulo["np_desc1"] . "</strong></div></td>";
		echo "<td> <div align='center'><strong>" . number_format($reg["trefe"],2,'.',',') . "&nbsp</strong></div></td>";
        $medida=mysqli_fetch_array(mysqli_query($con ,"SELECT codigo FROM dgmedida WHERE nparte1='".$req['pais']."'"));
		echo "<td> <div align='center'><strong>" . $medida["codigo"] . "&nbsp;</strong></div></td>";
		echo "<td> <div align='center'><strong>" . number_format($req["can_ref"],2,'.',',') . "&nbsp</strong></div></td>";
                echo "<td> <div align='center'><strong>" . $req["pre_uni"] . "&nbsp;</strong></div></td>";
                //print_r($req["pre_uni"]);
                echo "<td> <div align='center'><strong>" . number_format($articulo["cos_prom"],2,'.',',') . "&nbsp;</strong></div></td>";
		echo "<td> <div align='center'><strong>" . $req["total_cd"] . "&nbsp;</strong></div></td>";
                echo "<td> <div align='center'><strong>&nbsp;</strong></div></td></tr>";
	   $totTOTAL2+=$req["total_cd"];
            $totCAN=$totCAN+$req["can_ref"];
            $totCOSTO=$totCOSTO+$req["pre_uni"];
            
	   
}
        echo "<tr>";		
        echo "<td> <div align='center'><strong>&nbsp;</strong></div></td>";
        echo "</tr>";
		     @$rpo = mysqli_query($con ,"SELECT 
	          distinct(farticulos.sub) as almacen,
			  falmacen.np_desc1 as alm 
	           FROM 
	            dgreqded 
	             inner join farticulos on dgreqded.nparte1=farticulos.nparte1
				  inner join fagrupadores on fagrupadores.np_desc1=farticulos.t8
				   inner join falmacen on falmacen.nparte1=farticulos.sub  
	                $WHERE");
			         while($rows = mysqli_fetch_array($rpo))
			          {
				       echo "<tr>";
                        echo "<td colspan='2'> <div align='center'></div></td>";
						 echo "<td class=\"totAlm\" colspan='3'> <div align='center'><strong> " . $rows["alm"] . "</strong></div></td>";
			
			@$rpos = mysqli_query($con ,"SELECT 	
	         sum(dgreqded.subtotal) as suBtotal,
	          sum(dgreqded.des) as deScuento
	           FROM 
	            dgreqded 
	             inner join farticulos on dgreqded.nparte1=farticulos.nparte1
				  inner join fagrupadores on fagrupadores.np_desc1=farticulos.t8 
	              $WHERE AND farticulos.sub='".$rows['almacen']."'");
			         while($dfdsa=mysqli_fetch_array($rpos)){
			          $tcd2=$dfdsa["suBtotal"]-$dfdsa["deScuento"];
			           echo "<td class=\"totAlm\"> <div align='center'><strong>$ " . number_format($tcd2,2,'.',',') . "</strong></div></td></tr>";
			            }				
			}
	}
	        echo "<tr>";
                echo "<td > <div align='right'><strong> &nbsp; </strong></div></td>";
                echo "<td > <div align='right'><strong> &nbsp; </strong></div></td>";
                echo "<td > <div align='right'><strong> &nbsp; </strong></div></td>";
             echo "<td > <div align='right'><strong> TOTALES : </strong></div></td>";
			  echo "<td class=\"totAlm\"> <div align='center'><strong> " . number_format($totCAN,2,'.',',')  ." </strong></div></td>";
                          echo "<td class=\"totArt\"> <div align='center'><strong>$ " . number_format($totCOSTO,2,'.',',') . "&nbsp;</strong></div></td>";
		echo "<td class=\"totArt\"> <div align='center'><strong>&nbsp;</strong></div></td>";
                echo "<td class=\"totArt\"> <div align='center'><strong>$ " . number_format($totTOTAL2,2,'.',',') . "</strong></div></td></tr>";
                          mysqli_close($con);
	?>
    </table>
	</div>
  </form>
</div>
</body>
</html><?php
 /* 100 LISTO ULTIMA ACTUALIACION 21/AGOSTO/2012
             225 LISTO ULTIMA ACTUALIACION 27/AGOSTO/2013 */ ?>