<?php 
session_start();
include("DMMYSQLG.php");
include("DSA1000.php");
include("DMMYSQLG.php");
include("DF30000.inc");
include("JQUERY.inc");
$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="586" border="0">
	<tr>
        <th colspan="2">SALIDAS DE ALMACEN </th>
      </tr>
	  
	  <tr>
        <th width="291"> <input name="r1" type="radio" value="clave" tabindex="1" <?php
 if(isset($_POST['r1'])&&$_POST['r1']=='clave') echo 'checked';?> /> 
        X DEPARTAMENTO 
        <select name="departamento" id="departamento">
      <option value="">---------SELECCIONE---------</option>
          <?php
$sql = mysqli_query($con ,"SELECT * FROM fdepartamento where t1='ACTIVO' order by np_desc1 ");
while($reg=mysqli_fetch_array($sql)){
	if($_POST['departamento']==$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="285"><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" id="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';?>>TOTAL</option>
		  <option value="3"<?php
 if(isset($_REQUEST['select'])&&$_REQUEST['select']=="3") echo 'selected';?>>POR ALMACEN</option>
			<option value="4"<?php
if(isset($_REQUEST['select'])&&$_REQUEST['select']=="4") echo 'selected';?>>DETALLADAS POR ALMACEN</option>
        </select></th>
        
      </tr>
	  
	  
      <tr>
        <td> <div align="right" class="Estilo19"><img src="magnifier.png" alt="Buscar" onClick="alert('Buscar')" /> <strong>PERIODO</strong> </div></td>
        <td>
          <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('AL32000_PR.php','_self')" value="Buscar"/>
			  <input name="bot4" type="button" class="bot_WsW" onClick="openpage('AL32000_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="116"><div align="center">REQUISICION</div></th>
        <th width="228"><div align="center">ARTICULO</div></th>
		<th width="118"><div align="center">CANTIDAD</div></th>
        <th width="91"><div align="center">UNIDAD</div></th>
		<th width="154"><div align="center">PRECIO</div></th>	
		<th width="92"><div align="center">TOTAL</div></th>				-->
      <th width="116"><div align="center">ALMACEN / FECHA</div></th>
        <th width="196"><div align="center">ARTICULO</div></th>
        <th width="116"><div align="center">FACTURA</div></th>
        <th width="116"><div align="center">DEPTO</div></th>
        <th width="116"><div align="center">SALIDAS</div></th>
        <th width="116"><div align="center">COSTO</div></th>
        <th width="116"><div align="center">P.P</div></th>
        <th width="116"><div align="center">TOTAL</div></th>
      </tr>
	<?php
	  $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:"";
	$tipEst=isset($_POST['r1'])?$_POST['r1']:"";  
        if($vps=="" && $tipEst=="clave" && empty($_POST['departamento'])){
            echo '<input name="tip_bus" type="hidden" value="clave">';
	  	@$sql = mysqli_query($con ,"SELECT * FROM dgrequie where fec_ven between '$fecha_inicial' and '$fecha_final'");		
        }else{
            echo '<input name="tip_bus" type="hidden" value="clave">';
	  	@$sql = mysqli_query($con ,"SELECT * FROM dgrequie where fec_ven between '$fecha_inicial' and '$fecha_final' and tip_ven='".$_POST['departamento']."'");		
//        }
//	if($tipEst=="clave"){	
//		echo '<input name="tip_bus" type="hidden" value="clave">';
//	  	@$sql = mysqli_query($con ,"SELECT * FROM dgrequie where fec_ven between '$fecha_inicial' and '$fecha_final'");		
//               
        }if($tipEst=="paso"){
        
	
		echo '<input name="tip_bus" type="hidden" value="paso">';
		@$sql = mysqli_query($con ,"SELECT * FROM dgrequie 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'></div></td>";
		
		$tipVen=explode('.',$reg['tip_ven']);
		
		$proveedor1=mysqli_fetch_array(mysqli_query($con ,"SELECT np_desc1 FROM fdepartamento where nparte1='$tipVen[0]'"));
		$proveedor2=mysqli_fetch_array(mysqli_query($con ,"SELECT np_desc1 FROM fdepartamento where nparte1='$tipVen[1]'"));
		
		echo "<td style='#9B0F1A'>  <div align='center'><strong>" . $proveedor1["np_desc1"] . "".($proveedor2['np_desc1']!=""?(" | ".$proveedor2['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>";
   
	$vps=(isset($_POST['submit']))?$_POST['submit']:"";
	if ($vps==""&&$_POST['r1']=="clave"){
	$dataBus=" dgrequid.cons_ven='".$reg['fol_ven']."' ";
	
	}elseif($vps=="" && $_POST['r1']=="paso"){
	$dataBus=" dgrequid.cons_ven='".$reg['fol_ven']."' AND fagrupadores.paso='".$_POST['select']."'";
	}
	
	$WHERE= "WHERE".$dataBus."";
	 
	$reqDed=mysqli_query($con ,"SELECT * FROM dgrequid 
	LEFT JOIN farticulos on farticulos.nparte1=dgrequid.nparte1
	LEFT JOIN fagrupadores on fagrupadores.np_desc1=farticulos.t8 
	$WHERE");
//	echo "SELECT * FROM dgrequid 
//	LEFT JOIN farticulos on farticulos.nparte1=dgrequid.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>";
                 $fec1=$reg["fec_ven"];
		include('DF20000.php');
		//echo "<td> <div align='center'><strong>" . $reg["folio_control"] . "&nbsp;</strong></div></td>";
		echo "<td> <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'><strong>".$articulo["nparte1"]." | " . $articulo["np_desc1"] . "</strong></div></td>";
		echo "<td> <div align='center'><strong>" . $reg["folio_control"] . "&nbsp;</strong></div></td>";
                echo "<td> <div align='center'><strong>" . $reg["tip_ven"] . "&nbsp;</strong></div></td>";
		echo "<td> <div align='center'><strong>" . $req["can_ref"] . "&nbsp</strong></div></td>";
        $medida=mysqli_fetch_array(mysqli_query($con ,"SELECT nparte1,np_desc1,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>" . $req["pre_uni"] . "&nbsp;</strong></div></td>";
		echo "<td> <div align='center'><strong>" . $articulo["cos_prom"] . "&nbsp;</strong></div></td>";
                echo "<td> <div align='center'><strong>" . $req["subtotal"] . "&nbsp;</strong></div></td>";
		
	   $totsal+=$req["can_ref"];
	   //$totTOTAL+=$req["total_cd"];
         //  print_r($req["subtotal"]);
	   $totSUB2+=$req["subtotal"];
	   
}
        echo "<tr>";
//		echo "<td colspan=\"2\"> </td>";
//		echo "<td colspan='2' class=\"totArt\"> <div align='right'><strong>TOTALES : </strong></div></td>";
//      //  echo "<td class=\"totArt\"> <div align='center'><strong>" . $totosal . "&nbsp;</strong></div></td>";
//		echo "<td class=\"totArt\"> <div align='center'><strong>" . $totsal . "&nbsp;</strong></div></td>";
////		echo "<td class=\"totArt\"> <div align='center'><strong>$ " . number_format($totSUB,2,'.',',') . "&nbsp;</strong></div></td>";
//		//echo "<td class=\"totArt\"> <div align='center'><strong>" . $req["des"] . "&nbsp;</strong></div></td>";
//		//echo "<td class=\"totArt\"> <div align='center'><strong>$ " . number_format($totIVA,2,'.',',') . "&nbsp;</strong></div></td>";
//		//echo "<td class=\"totArt\"> <div align='center'><strong>$ " . number_format($totTOTAL,2,'.',',') . "</strong></div></td></tr>";
		
		     @$rpo = mysqli_query($con ,"SELECT 
	          distinct(farticulos.sub) as almacen,
			  falmacen.np_desc1 as alm 
	           FROM 
	            dgrequid 
	             inner join farticulos on dgrequid.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 class=\"totAlm\" colspan='2'> <div align='center'><strong> " . $rows["alm"] . "</strong></div></td>";
			
			@$rpos = mysqli_query($con ,"SELECT 	
	         sum(dgrequid.subtotal) as suBtotal,
	          sum(dgrequid.des) as deScuento
	           FROM 
	            dgrequid 
	             inner join farticulos on dgrequid.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"];
//			          print_r($totSUB);
//                                  print_r($tcd2); 
                                  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($totsal,2,'.',',')  ." </strong></div></td>";
                          echo "<td class=\"totArt\"> <div align='center'><strong>&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($totSUB2,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 */ ?>
