<?php
class impr_invdisp1
{
	
	function impr_invdisp1($bode,$lsub,$mdlo,$fecha1,$fecha2,$posi,$cero,$nega,$ctlg)
	{
		require('../cfg/res.php');


		if (mb_stristr('clie.prov',substr($_SESSION['user_vcrx_tipo'],0,4)))
			{$enti='M';
			if (substr($docu,0,1)=='O')
				{$tabla='clie';
				}
			
			if (substr($docu,0,1)=='F')
				{$tabla='vtas';
				}
			}


$sql_idisp='select * from invdisp where ';

if(isset($_GET['fposi']) && ($_GET['fposi']=='true'))
{$xfposi=$_GET['fposi'];}
else
{$xfposi='false';}

if(isset($_GET['fcero']) && ($_GET['fcero']=='true'))
{$xfcero=$_GET['fcero'];}
else
{$xfcero='false';}

if(isset($_GET['fnega']) && ($_GET['fnega']=='true'))
{$xfnega=$_GET['fnega'];}
else
{$xfnega='false';}




if($xfposi=='false' && $xfnega=='false' && $xfcero=='false')
{$xfposi='true';}
$sql_idisp.='(';

if($xfposi=='true')
{$sql_idisp.='(dispo>0)';}

if($xfcero=='true')
{$sql_idisp.='(saldo=0)';}

if($xfnega=='true')
{$sql_idisp.='(saldo<0)';}

$sql_idisp.=')';
$sql_idisp=str_replace(')(',')||(',$sql_idisp);


if(isset($_GET['flsub']) && !empty($_GET['flsub']))
{
	$sql_idisp.=' and  (item_lsub like "'.$_GET['flsub'].'%" or lsub_descri like "%'.$_GET['flsub'].'%" ) ';
	$xflsub=$_GET['flsub'];
}

if(isset($_GET['fmrca']) && !empty($_GET['fmrca']))
{
	$sql_idisp.=' and  (item_mrca like "'.$_GET['fmrca'].'%" ) ';
	$xfmrca=$_GET['fmrca'];
}



if(isset($_GET['fmdlo']) && !empty($_GET['fmdlo']))
{
	$sql_idisp.=' and  (item like "%'.$_GET['fmdlo'].'%" ) ';
	$xfmdlo=$_GET['fmdlo'];
}


if(isset($_GET['fctlg']) && !empty($_GET['fctlg']))
{
	$sql_idisp.=' and  (item_nctlg ='.$_GET['fctlg'].' )';
	$xfctlg=$_GET['fctlg'];
}

if(isset($_GET['fcodi']) && !empty($_GET['fcodi']))
{
	$xfcodi=$_GET['fcodi'];
}
switch ($xfcodi)
{
	case '1': $item_codi='item';break;
	case '2': $item_codi='item_codigov';break;
	case '3': $item_codi='item_ean';break;
	default : $item_codi='item';break;
}



if(isset($_GET['forde']) && !empty($_GET['forde']))
{
	$xforde=$_GET['forde'];
}
switch ($xforde)
{
	case '1': $xorder=$item_codi.',';break;
	case '2': $xorder='item_descri,';break;
	default : $xorder='';break;
}


$sql_idisp.=' order by lsub_descri,'.$xorder.$item_codi;



//echo $sql_idisp;
$res_idisp=mysql_query($sql_idisp,$link_vcrx);



		$sql_user='select *from user00 where user_cedula like"'.$_SESSION['user_vcrx_id'].'%"';
		$res_user=mysql_query($sql_user,$link_vcrx);
		$xuser=mysql_result($res_user,0,'enti_nom1').' '.mysql_result($res_user,0,'enti_ape1');



?>


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>INVENTARIO DISPONIBLE</title>

<style type="text/css">
BODY{font-family: courier new;}

</style>



</head>


<body>


<div align="center">
<div align="center" style="width:1150px; font-size:12px;">
<div align="center" style="font-size:18px; font-weight: bold; border:#000 solid 1px; background: #F7F7F7; margin:2px;"><strong>INVENTARIO</div>

<table width="90%" cellspacing="0" cellpadding="2">
<tr valign="top">
<td width="50%">
<!----++++++++++------>
<table border="1" width="100%" cellpadding="2" cellspacing="0" style="border-collapse:collapse">
<tr>
	<th width="50%" style="background: #F7F7F7;">PARAMETROS</th>
	<th></th>
</tr>
<tr>
	<td>SALDOS</td>
	<td>
	<?php if($xfposi=='true'){echo '/POSITIVOS';}?>
	<?php if($xfcero=='true'){echo '/AGOTADOS';}?>
	<?php if($xfnega=='true'){echo '/NEGATIVOS';}?>
	</td>
</tr>
<tr>
	<td>HASTA</td>
	<td><?php echo date_format(date_create($fecha2),'d/M/Y');?></td>
</tr>
<tr>
	<td>LINEA</td>
	<td><?php if(empty($xflsub)){echo 'TODOS';}else{echo $xflsub;}?></td>
</tr>
<tr>
	<td>MARCA</td>
	<td><?php if(empty($xfmrca)){echo 'TODOS';}else{echo $xfmrca;}?></td>
</tr>
<tr>
	<td>MODELO</td>
	<td><?php if(empty($xfmdlo)){echo 'TODOS';}else{echo $xfmdlo;}?></td>
</tr>
<tr>
	<td>CATALOGO</td>
	<td><?php if(empty($xfctlg)){echo 'TODOS';}else{echo $xfctlg;}?></td>
</tr>
</table>
<!----++++++++++------>
</td>



<td>
<!----++++++++++------>
<table border="1" width="100%" cellspacing="0" cellpadding="2" style="border-collapse:collapse">
<tr>
	<th width="50%"  style="background: #F7F7F7;">I N F O</th>
	<th></th>    
</tr>
<tr>
	<td align="right">USUARIO:</td>
	<td><?php echo $_SESSION['user_vcrx_id'].' / '.$xuser;?></td>
</tr>
<tr>
	<td align="right">FECHA / HORA :</td>
	<td><?php echo date('d/M/Y H:m:s');?></td>
</tr>
<tr>
	<td align="right">ORDENADO X :</td>
	<td><?php if($xforde=='1'){echo 'CODIGO';}else{echo 'DESCRIPCION';}?></td>
</tr>
<tr>
	<td align="right">CODIGO :</td>
	<td>
	<?php
	 if($xfcodi=='1'){echo 'SISTEMA';}
	 if($xfcodi=='2'){echo 'AUXILIAR';}
	 if($xfcodi=='3'){echo 'EAN (Barras)';}
	?>
	</td>
</tr>
</table>
<!----++++++++++------>
</td>

</tr>
</table>
<!----++++++++++------>


<hr/>
<table border="0" width="90%" cellpadding="2" cellspacing="0" style="border-collapse:collapse">
<tr align="center" style="background: #F7F7F7; border-top:solid 1px#000;border-bottom:solid 1px#000">
    	<th width="15%">LINEA</th>	
	<th width="1%">CODIGO</th>
	<th>DESCRI</th>
	<th>MARCA/MODELO</th>
	<th>CTLG</th>
	<th width="1%">SALDO</th>
	<th width="1%">RESER</th>
	<th width="1%">DISPO</th>
</tr>
<?php
$filax=1;
$ttotal = 0;
$ttcomi = 0;
$titems = 0;
$pmdlo ='';
$umdlo ='';

$res_idisp=mysql_query($sql_idisp,$link_vcrx);
while($r_idisp=mysql_fetch_assoc($res_idisp))
{
$titems++;
$duni=$r_idisp['item_duni'];

?>


<?php	
if ($r_idisp['item_modelo']==$umdlo)
{if($umdlo==$pmdlo){$filax=1;}}
else
{if($umdlo!=$pmdlo){}else{$filax=3;}}
$pmdlo=$umdlo;
$umdlo=$r_idisp['item_modelo'];
?>

<tr style=" <?php if($filax>=3){echo 'border-top:dotted 1px #000;';$filax=1;}else{$filax++;} ?>" >

    	<td align="center"><?php echo $r_idisp['lsub_descri']; ?></td>	
	<td align="left"><?php echo $r_idisp[$item_codi];?></td>
	<td><?php echo $r_idisp['item_descri'];?></td>
	<td><?php echo $r_idisp['item_mrca'].'/'.$r_idisp['item_modelo'];?></td>
	<td align="center"><?php if($r_idisp['item_nctlg']>0){echo $r_idisp['item_nctlg'];}?></td>
   	<td align="right"><?php if($r_idisp['saldo']<0){echo '<font color="red">';} ?> <?php echo number_format($r_idisp['saldo'],$duni);?></td>
	<td align="right"><?php if( $r_idisp['reser']!=0){echo number_format($r_idisp['reser'],$duni);}?></td>
   	<td align="right"><?php if($r_idisp['dispo']<0){echo '<font color="red">';} ?> <?php echo number_format($r_idisp['dispo'],$duni);?></td>

</tr>


<?php	
}
?>


<tr align="right" style="font-weight:bolder;border-top:solid 1px#000">
	<td></td>
	<td><?php echo number_format($titems,0);?></td>
	<td align="left">Items</td>
	<td></td>
	<td></td>
	<td></td>
	<td></td>
	<td></td>
</tr>
</table>
</div>
</div>
<?php		
}
}
?>
</html>