<?php
 
session_start();
include("DMMYSQLG.php");
include("DSA1000.php");
include("DMMYSQLG.php");
?>
<html>
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>
<?php
 
	include("DF30000.inc");
	//cargamos arrays de Linea, Grupo, Marca
	//linea
	$sqllinea = mysqli_query($con ,"select * from dglineas order by des_linea");
	//grupo
	$sqlgrupo = mysqli_query($con ,"select * from dgbasico order by des_basico");
	//marca
	$sqlmarca = mysqli_query($con ,"select * from dxmarcas order by des_marca");
	//almacen
	$sqlalmacen = mysqli_query($con ,"select * from dgalmacen order by desc_almacen");
?>


<body>
<?php
 
$ayuda = 'DI4600A_PR.php';
include("DYAYUDA.php");
?>

<div align="center">
  <form name="form1" method="post" action="">
    <table width="686"  align="center">
      <tr>
			<th colspan="2">IMPRESION DE MARBETES </th>
      </tr>
      <tr>
        <td>
		  <div align="center" class="Estilo2">
		    <div align="center">Linea:</div>
		  </div>	    </td>
        <td width="320"><select name="sellinea" id="sellinea">
    	  <option value="NO">NO</option>
	      <?php

			  while($fasqllinea = mysqli_fetch_array($sqllinea)){
			  	if($_POST['sellinea'] == $fasqllinea["linea"]) echo  '<option value="'.$fasqllinea["linea"].'" selected >'.$fasqllinea["des_linea"].'</option>';
				else echo  '<option value="'.$fasqllinea["linea"].'">'.$fasqllinea["des_linea"].'</option>';
		  }
		  ?>
        </select></td>
      </tr>
      <tr>
        <td><div align="center"><span class="Estilo2">Grupo</span>:</div></td>
        <td><select name="selgrupo" id="selgrupo">
    	  <option value="NO">NO</option>
	      <?php

			  while($fasqlgrupo = mysqli_fetch_array($sqlgrupo)){
			  	if($_POST['selgrupo'] == $fasqlgrupo["gpo_basico"]) echo  '<option value="'.$fasqlgrupo["gpo_basico"].'" selected >'.$fasqlgrupo["des_basico"].'</option>';
				else echo  '<option value="'.$fasqlgrupo["gpo_basico"].'">'.$fasqlgrupo["des_basico"].'</option>';
		  }
		  ?>
        </select>
		&nbsp;</td>
      </tr>
      <tr>
        <td>
		  <div align="center" class="Estilo2">
		    <div align="center">Marca:</div>
		  </div>	    </td>
        
		<td>
		<select name="selmarca" id="selmarca">
    	  <option value="NO">NO</option>
	      <?php

			  while($fasqlmarca = mysqli_fetch_array($sqlmarca)){
			  	if($_POST['selmarca'] == $fasqlmarca["cve_marca"]) echo '<option value="'.$fasqlmarca["cve_marca"].'" selected >'.$fasqlmarca["des_marca"].'</option>';
				else echo '<option value="'.$fasqlmarca["cve_marca"].'">'.$fasqlmarca["des_marca"].'</option>';
		  }
		  ?>
        </select>
		&nbsp;</td>
      </tr>
	  
      
      <tr>
        <td><div align="center">Almacen:</div>
        <div align="center"></div></td>
        <td><select name="almacen" onChange="MM_jumpMenu('parent',this,0)">
          <option>ALMACEN </option>
		  <?php

			  while($fasqlalmacen = mysqli_fetch_array($sqlalmacen)){
			  	if($_POST['selalmacen'] == $fasqlalmacen["desc_almacen"]) echo  '<option value="'.$fasqlalmacen["desc_almacen"].'" selected >'.$fasqlalmacen["desc_almacen"].'</option>';
				else echo  '<option value="'.$fasqlalmacen["almacen"].'">'.$fasqlalmacen["des_almacen"].'</option>';
		  }
		  ?>
        </select></td>
      </tr>
      <tr>
        <td colspan="2"><div align="center">
          <input name="botbuscar" type="submit" id="botbuscar" value="Procesar" />
        </div></td>
      </tr>
    </table>
  </form>
</div>
<div align="center">

  <form name="frm1" id="frm1" method="post" action="" >
   <input name="fechafin" type="hidden" id="fechafin" value="<?php
echo $_POST['fechafin'];?>">
   <input name="fechaini" type="hidden" id="fechaini" value="<?php
echo $_POST['fechaini'];?>">
    <br>
     <table width="746"  align="center">
      <tr>
        <th colspan="12"><div align="center">
          <input name="botimprimir" type="button" id="botimprimir" onClick="openpage('DI46000_IM.php','_self')" value="Imprimir">
        </div>        </th>
      </tr>
      <tr>
        <th nowrap>No. Parte</th>
        <th nowrap>Descripcion</th>
        <th nowrap>Linea</th>
        <th nowrap>Grupo</th>
        <th nowrap>Marca</th>
       </tr>
<?php
	 
if(isset($_POST['botbuscar'])){
	//se da formato a fechas
	$fec = $_POST['fechaini'];
	include('DF20000.php');
	$fec_ini=$f_m;
	$fec = $_POST['fechafin'];
	include('DF20000.php');
	$fec_fin=$f_m;

	if($_POST['sellinea']=='NO'){$lin="dginvent.linea <>'.'";}else{$lin="dginvent.linea ='".$_POST['sellinea']."'";}
	if($_POST['selgrupo']=='NO'){$gpo="dginvent.gpo_basico <>'.'";}else{$gpo="dginvent.gpo_basico ='".$_POST['selgrupo']."'";}
	if($_POST['selmarca']=='NO'){$mar="dginvent.cve_marca <>'.'";}else{$mar="dginvent.cve_marca ='".$_POST['selmarca']."'";}

	$bus="select dginvent.*,dglineas.*,dgbasico.*,dxmarcas.* from dginvent INNER JOIN dglineas INNER JOIN dgbasico INNER JOIN dxmarcas on dglineas.linea = dginvent.linea on dgbasico.gpo_basico = dginvent.gpo_basico on dxmarcas.cve_marca = dginvent.cve_marca where $lin and $gpo and $mar order by des_linea,des_basico,des_marca,np_desc1";


	echo '<input name="tipbus" id ="tipbus" type="hidden" value="'.$bus.'">';
	$sqlbus = mysqli_query($con ,$bus);
}
else{
		$sqlbus = NULL;
		echo '<input name="tipbus" id ="tipbus" type="hidden" value="'.' '.'">';
}
$axo = substr($fec_ini,0,4);
$mes = substr($fec_ini,5,2);
$dia = substr($fec_ini,8,2);

while(@$fasqlbus = mysqli_fetch_array($sqlbus)){
	/*se da formato a la fecha*/
	$fec1=$fasqlbus["uc_fec_doc"];
	include('DF20000.php');
	@$sq_invacu = mysqli_fetch_array(mysqli_query($con ,"select * from dginvacu where nparte1='".$fasqlbus['nparte1']."' and axo <='$axo' and mes <='$mes' order by axo,mes desc"));
	$sdo_ini = 0;
	if($sq_invacu['nparte1']=$fasqlbus['nparte1'] and $sq_invacu['axo'].$sq_invacu['mes'] == $axo.$mes) $sdo_ini = $sq_invacu['exi_ini'];// Saldo Inicial Mes
	if($sq_invacu['nparte1']=$fasqlbus['nparte1'] and $sq_invacu['axo'].$sq_invacu['mes'] < $axo.$mes) $sdo_ini = $sq_invacu['exi_fin'];// Saldo Inicial Mes

	if($dia >'01'){
		$f_ini = $axo.'-'.$mes.'-01';
		$f1=$fec_ini;$fr_fec='AMD';$fr_fecr='Ymd';$sep_fecr='-';$dia_sum = -1;
		include('DF70000.php');
		$f_fin = $fec_new;
		@$sq_cardex = mysqli_fetch_array(mysqli_query($con ,"select sum(mov_ent) as tent, sum(mov_sal) as tsal from dgcardex where nparte1 = '".$fasqlbus['nparte1']."' and fec_mov between '$f_ini' and '$f_fin'")); 
	$sdo_ini = $sdo_ini + $sq_cardex['tent'] - $sq_cardex['tsal'];
	}
	$f_ini = $fec_ini;$f_fin = $fec_fin;
	@$sq_cardex = mysqli_fetch_array(mysqli_query($con ,"select sum(mov_ent) as tent, sum(mov_sal) as tsal from dgcardex where nparte1 = '".$fasqlbus['nparte1']."' and fec_mov between '$f_ini' and '$f_fin'")); 
	$sdo_fin = $sdo_ini + $sq_cardex['tent'] - $sq_cardex['tsal'];
	echo '<tr>';
	echo '<td nowrap>'.$fasqlbus["nparte1"].'&nbsp</td>';
	echo '<td nowrap>'.$fasqlbus["np_desc1"].'&nbsp</td>';
	echo '<td nowrap>'.$fasqlbus["des_linea"].'&nbsp</td>';
	echo '<td nowrap>'.$fasqlbus["des_basico"].'&nbsp</td>';
	echo '<td nowrap>'.$fasqlbus["des_marca"].'&nbsp</td>';

    echo '</tr>';
}
?>	  
</table>
</form>
</div>
</body>
</html>