<?php 
session_start();

require('../cfg/res.php');
require('../cfg/cfg.php');
include('php_gene1.php')

?>
<?php

$fecha1 = date('Y-m-j');
$nuevafecha = strtotime ( '-1 month' , strtotime ( $fecha1 ) ) ;
$xfecha1 = date ( 'Y/m/j' , $nuevafecha );
$xfecha1= date('Y/m/'.'1');
$xfecha2= date('Y/m/d');

$sql_datesp='SET lc_time_names = "es_UY"';
$res_datesp=mysql_query($sql_datesp,$link_vcrx);



$xfgrou='';
if(isset($_POST['fgrou']) && !empty($_POST['fgrou']))
{$xfgrou=$_POST['fgrou'];}


$xfentt='4';
if(isset($_POST['fentt']) && !empty($_POST['fentt']))
{$xfentt=$_POST['fentt'];}


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


$sql_itemu ='update item0 set ';
$sql_itemu.='item_pvp1=(item_puni*(1+item_ice/100))*(1+item_iva/100)+item_irbp ';
$sql_itemu.='where item_pvp1=0 or item_pvp1 is null';
$res_itemu=mysql_query($sql_itemu,$link_vcrx);
// echo mysql_error();

$sql_iteml='select * from item00 where ';
$sql_iteml.='(';

if(isset($_POST['fecha_ini']) && !empty($_POST['fecha_ini']) && isset($_POST['fecha_fin']) && !empty($_POST['fecha_fin']))
{
	$xfecha1=$_POST['fecha_ini'];
	$xfecha2=$_POST['fecha_fin'];
}

	$xanios=date('Y',strtotime($xfecha2b))-date('Y',strtotime($xfecha1b))+1;
	$xanio1=date('Y',strtotime($xfecha1b));
	$xanio2=date('Y',strtotime($xfecha2b));

	$dias=intval(strtotime($xfecha2b) - strtotime($xfecha1b))/60/60/24;
  $anios=date('Y',strtotime($xfecha2))-date('Y',strtotime($xfecha1));

// $sql_iteml.='(date_format(item_idate,"%Y-%m-%d") BETWEEN "'.$xfecha1.'" and "'.$xfecha2.'") or item_idate is null';
// $sql_iteml.='(item_idate BETWEEN "'.$xfecha1.'" and "'.$xfecha2.'") or item_idate is null';
$sql_iteml.='1=1';
$sql_iteml.=')';

$sql_iteml=str_replace(')(',')||(',$sql_iteml);


if(isset($_POST['item']) && !empty($_POST['item']))
{
//  	$sql_iteml.=' and  (item_codigo in ';
// 	$sql_iteml.='(select distinct item from inve1,inve2 where idnum1=idnum2 and (date_format(fecha,"%Y-%m-%d") BETWEEN "'.$xfecha1.'" and "'.$xfecha2.'"))';
//  	$sql_iteml.=')';
	$xfitem=$_POST['item'];
}


if(isset($_POST['item']) && !empty($_POST['item']))
{
	$sql_iteml.=' and  (item_codigo like "'.$_POST['item'].'%" or item_descri like "%'.$_POST['item'].'%" ) ';
	$xfitem=$_POST['item'];
}




if(isset($_POST['fcdad']) && !empty($_POST['fcdad']))
{
	$sql_iteml.=' and  (prvc_descri like "%'.$_POST['fcdad'].'%" or item_cdad like "'.$_POST['fcdad'].'%" or cdad_descri like "%'.$_POST['fcdad'].'%"  ) ';
	$xfcdad=$_POST['fcdad'];
}

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

if(isset($_POST['fzsub']) && !empty($_POST['fzsub']))
{
	$sql_iteml.=' and  (item_zsub like "'.$_POST['fzsub'].'%" or zsub_descri like "%'.$_POST['fzsub'].'%" ) ';
	$xfzsub=$_POST['fzsub'];
}

if(isset($_POST['fmrca']) && !empty($_POST['fmrca']))
{
	$sql_iteml.=' and  (item_mrca like "'.$_POST['fmrca'].'%" or mrca_descri like "%'.$_POST['fmrca'].'%" ) ';
	$xfmrca=$_POST['fmrca'];
}

if(isset($_POST['fmdlo']) && !empty($_POST['fmdlo']))
{
	$sql_iteml.=' and  (item_mdlo like "'.$_POST['fmdlo'].'%" or item_modelo like "%'.$_POST['fmdlo'].'%" ) ';
	$xfmdlo=$_POST['fmdlo'];
}

if(isset($_POST['fvndd']) && !empty($_POST['fvndd']))
{
	$sql_iteml.=' and  (item_vndd like "'.$_POST['fvndd'].'%" or vndd_descri like "%'.$_POST['fvndd'].'%" ) ';
	$xfvndd=$_POST['fvndd'];
}


if(isset($_POST['frcdd']) && !empty($_POST['frcdd']))
{
	$sql_iteml.=' and  (item_rcdd like "'.$_POST['frcdd'].'%" or rcdd_descri like "%'.$_POST['frcdd'].'%" ) ';
	$xfrcdd=$_POST['frcdd'];
}


if(isset($_POST['fctlg']) && !empty($_POST['fctlg']))
{
	$sql_iteml.=' and  (item_nctlg like "'.$_POST['fctlg'].'%")';
	$xfctlg=$_POST['fctlg'];
}

$xfcost='false';
if(isset($_POST['fcost']) && !empty($_POST['fcost']))
{$xfcost=$_POST['fcost'];}

$xfpuni='false';
if(isset($_POST['fpuni']) && !empty($_POST['fpuni']))
{$xfpuni=$_POST['fpuni'];}

$xfpvp='false';
if(isset($_POST['fpvp']) && !empty($_POST['fpvp']))
{$xfpvp=$_POST['fpvp'];}

$xfdcto='false';
if(isset($_POST['fdcto']) && !empty($_POST['fdcto']))
{$xfdcto=$_POST['fdcto'];}

$xfice='false';
if(isset($_POST['fice']) && !empty($_POST['fice']))
{$xfice=$_POST['fice'];}

$xfiva='false';
if(isset($_POST['fiva']) && !empty($_POST['fiva']))
{$xfiva=$_POST['fiva'];}

$xmcost='false';
if(isset($_POST['mcost']) && !empty($_POST['mcost']))
{$xmcost=$_POST['mcost'];}

$xmpuni='false';
if(isset($_POST['mpuni']) && !empty($_POST['mpuni']))
{$xmpuni=$_POST['mpuni'];}

$xmpvp='false';
if(isset($_POST['mpvp']) && !empty($_POST['mpvp']))
{$xmpvp=$_POST['mpvp'];}

$xmdcto='false';
if(isset($_POST['mdcto']) && !empty($_POST['mdcto']))
{$xmdcto=$_POST['mdcto'];}

$xmice='false';
if(isset($_POST['mice']) && !empty($_POST['mice']))
{$xmice=$_POST['mice'];}

$xmiva='false';
if(isset($_POST['miva']) && !empty($_POST['miva']))
{$xmiva=$_POST['miva'];}


if($xmcost=='true'){$xfcost='false';}
if($xmpuni=='true'){$xfpuni='false';}
if($xmpvp=='true'){$xfpvp='false';}
if($xmdcto=='true'){$xfdcto='false';}
if($xmice=='true'){$xfice='false';}
if($xmiva=='true'){$xfiva='false';}

	$sql_iteml.=' and(item_status!="X") ';
	$sql_iteml.=' and(item_status!="O") ';


$xforde='D';
if(isset($_POST['forde']) && !empty($_POST['forde']))
{$xforde=$_POST['forde'];}

switch ($xfgrou)
{

	case 'T':$xgroup='tpro_descri,item_tpro ';break;
	case 'V':$xgroup='vndd_descri,item_vndd ';break;
	case 'R':$xgroup='rcdd_descri,item_rcdd ';break;
	case 'Z':$xgroup='zsub_descri,item_zsub ';break;
	case 'L':$xgroup='lsub_descri,item_lsub ';break;
// 	case 'R':$xgroup='item_at10 ';break;
	case 'C':$xgroup='cdad_descri, item_cdad ';break;
	default :$xgroup='item_descri, item_codigo';break;
}

// $xgroup='';
switch ($xforde)
{
	case 'D':$xorder=$xgroup.',item_descri,item_codigo';break;
	case 'C':$xorder=$xgroup.',item_codigo';break;
}

//$sql_iteml.=' group by '.$xgroup;
$sql_iteml.=' order by '.$xorder;
$res_iteml=mysql_query($sql_iteml,$link_vcrx);
$totreg = mysql_num_rows($res_iteml);
// echo str_repeat('-',date('s')*2).'';
// echo $sql_iteml;
// echo explain_sql($sql_iteml);

?>
<table id="tabla_cxccli" width="100%" border="0" cellspacing="0" cellpadding="2" style="border-collapse:collapse;font-size:12px; border:#000000 solid 1px;">
<tr style="border-bottom:#000000 solid 2px; ">
	<th align="center">M</th>
  <th align="center">I</th>
	<th>LINEA</th>
	<th>CODIGO</th>
	<th>B/S</th>
	<th>DESCRI</th>
	<?php if($xfcost=='true' or $xmcost=='true'){?>
	<th align="center">COSTO</th>
	<?php } ?>
	<?php if($xfpuni=='true' or $xmpuni=='true'){?>
	<th align="center">P.UNIT</th>
	<?php } ?>
	<?php if($xfpvp=='true' or $xmpvp=='true'){?>
	<th align="center">P.V.P.</th>
	<?php } ?>
	<?php if($xfdcto=='true' or $xmdcto=='true'){?>
	<th align="center">DCTO.</th>
	<?php } ?>
	<?php if($xfice=='true' or $xmice=='true'){?>
	<th align="center">%ICE</th>
	<?php } ?>
	<?php if($xfiva=='true' or $xmiva=='true'){?>
	<th align="center">%IVA</th>
	<?php } ?>
	<?php if($xmcost=='true' or $xmpuni=='true' or $xmpcp1=='true' or $xmpvp=='true' or $xmpvp=='true' or $xmdcto=='true' or $xmice=='true' or $xmiva=='true' or $xmirbp=='true'){?>
  <th></th>
  <th></th>
  <?php } ?>
	<th>MARCA/MODELO</th>
	<th>UMDD</th>
	<th>LADO</th>
	<th>TLLA</th>
	<th>COLOR</th>
<!-- 	<th>PROVEEDOR</th> -->
	<th>CTLG</th>
	<th>#cat-pag</th>
	<th>CAIR</th>
	<th width="1%"></th>
</tr>
<?php //echo '1';?>
<?php 
$filax=0;
while($r_iteml=mysql_fetch_assoc($res_iteml))
{
// $duni=$r_iteml['item_duni'];
?>
<?php //echo '2';?>
<tr class="filax" id="<?php echo $r_iteml['idnum1']; ?>" align="center" style=" <?php if($filax>=4){echo 'border-top:dotted 1px #000;';$filax=1;}else{$filax++;} ?>" >

<td align="center">
	<a href="nitem.php?idx=<?php echo $r_iteml['item_codigo']; ?>" target="_blank">
	<img src="http://vcrxol.com/_img/ico_edit.png" width="20" title="Modificar  <?php echo $r_iteml['item_codigo'];?>"  />
	</a>
	</td>
<td align="center">
	<a href="fitem.php?idx=<?php echo $r_iteml['item_codigo'];?>"  target="_blank">
	<img src="http://vcrxol.com/_img/print2.png" width="20"/>
	</a>
  <input type="image"  src="http://vcrxol.com/_img/barcode.png" width="20"  title="Imprimir ETQ <?php echo $r_iteml['item_codigo'];?>" onclick="abriretiqueta(<?php echo $r_iteml['item_codigo'];?>);" />
	</td>

	
	
	
	<td align="center"><?php echo'<span title="'.$r_iteml['item_lsub'].'">'.$r_iteml['lsub_descri'].'</span>';?></td>
  <td align="left">
		<a href="#" onClick="entil1d('<?php echo $xfgrou; ?>','<?php echo $r_iteml['item_codigo']; ?>',this);">
		<?php if($xfcodi=='1'){?>
		<?php echo '<div><span title="'.$r_iteml['item_codigov'].'">'.$r_iteml['item_codigo'].'</span></div>';?>
		<?php } ?>
		<?php if($xfcodi=='2'){?>
		<?php echo'<div><span title="'.$r_iteml['item_codigo'].'">'.$r_iteml['item_codigov'].'</span></div>';?>
		<?php } ?>
		<?php if($xfcodi=='3'){?>
		<?php echo'<div><span title="'.$r_iteml['item_codigov'].'">'.$r_iteml['item_ean'].'</span></div>';?>
		<?php } ?>
		</a> 
	</td>
	<td align="center"><?php echo'<span title="'.$r_iteml['item_bser'].'">'.$r_iteml['item_bser'].'</span>';?></td>
	<td align="left">
		<?php echo'<div><span title="'.$r_iteml['item_descri'].'">'.$r_iteml['item_descri'].'<br>'.$r_iteml['item_descri2'].'</span></div>';?>
	</td>
	<?php if($xfcost=='true'){?>
	<td align="right"><?php echo number_format($r_iteml['item_pcp1'],$r_iteml['item_dval']);?></td>
	<?php } ?>
	<?php if($xmcost=='true'){?>
	<?php $pidtxt='pcp1_'.$r_iteml['item_codigo']; $pobj=1; $pdefa=number_format($r_iteml['item_pcp1'],$r_iteml['item_dval']);  include('vrgetval.php'); ?>
	<?php } ?>

	<?php if($xfpuni=='true'){?>
	<td align="right"><?php echo number_format($r_iteml['item_puni'],$r_iteml['item_dval']);?></td>
	<?php } ?>
	<?php if($xmpuni=='true'){?>
	<?php $pidtxt='puni_'.$r_iteml['item_codigo']; $pobj=1; $pdefa=number_format($r_iteml['item_puni'],$r_iteml['item_dpre']);  include('vrgetval.php'); ?>
	<?php } ?>

	<?php if($xfpvp=='true'){?>
	<td align="right"><?php echo number_format($r_iteml['item_pvp'],$r_iteml['item_dval']);?></td>
	<?php } ?>
	<?php if($xmpvp=='true'){?>
	<?php $pidtxt='pvp_'.$r_iteml['item_codigo']; $pobj=1; $pdefa=number_format($r_iteml['item_pvp'],$r_iteml['item_dpre']);  include('vrgetval.php'); ?>
	<?php } ?>
	
	<?php if($xfdcto=='true'){?>
	<td align="right"><?php echo number_format($r_iteml['item_dcto'],2).'';?></td>
	<?php } ?>
	<?php if($xmdcto=='true'){?>
	<?php $pidtxt='dcto_'.$r_iteml['item_codigo']; $pobj=1; $pdefa=number_format($r_iteml['item_dcto'],$r_iteml['item_dval']);  include('vrgetval.php'); ?>
	<?php } ?>
	
	<?php if($xfice=='true'){?>
	<td align="right"><?php echo number_format($r_iteml['item_ice'],2).'';?></td>
	<?php } ?>
	<?php if($xmice=='true'){?>
	<?php $pidtxt='ice_'.$r_iteml['item_codigo']; $pobj=1; $pdefa=number_format($r_iteml['item_ice'],$r_iteml['item_dval']);  include('vrgetval.php'); ?>
	<?php } ?>
	
	<?php if($xfiva=='true'){?>
	<td align="right"><?php echo number_format($r_iteml['item_iva'],2).'';?></td>
	<?php } ?>
	<?php if($xmiva=='true'){?>
	<?php $pidtxt='iva_'.$r_iteml['item_codigo']; $pobj=1; $pdefa=number_format($r_iteml['item_iva'],$r_iteml['item_dval']);  include('vrgetval.php'); ?>
	<?php } ?>

	<?php if($xmcost=='true' or $xmpuni=='true' or $xmpcp1=='true' or $xmpvp=='true' or $xmdcto=='true' or $xmice=='true' or $xmiva=='true' or $xmirbp=='true'){?>
	<td><?php $pidtxt='graba_'.$r_iteml['item_codigo']; $pobj=1; $pcaption='Modif'; $ponclick='_modi("'.$r_iteml['item_codigo'].'")'; include('vrbutton.php'); ?></td>
  <td><span id="error_<?php echo $r_iteml['item_codigo'];?>"></span> </td>
	<?php } ?>
  
	
	<td align="center"><?php echo'<span title="'.$r_iteml['item_mrca'].'">'.$r_iteml['mrca_descri'].'/'.$r_iteml['item_modelo'].'</span>';?></td>
	<td align="center"><?php echo'<span title="'.$r_iteml['item_umdd'].'">'.$r_iteml['item_umdd'].'</span>';?></td>
	<td align="center"><?php echo'<span title="'.$r_iteml['item_lado'].'">'.$r_iteml['item_lado'].'</span>';?></td>
	<td align="center"><?php echo'<span title="'.$r_iteml['item_tlla'].'">'.$r_iteml['item_tlla'].'</span>';?></td>
	<td align="center"><?php echo'<span title="'.$r_iteml['item_clor'].'">'.$r_iteml['item_clor'].'</span>';?></td>
<!-- 	<td align="center"><?php echo'<span title="'.$r_iteml['item_provee'].'">'.$r_iteml['item_provee'].'</span>';?></td> -->
	<td align="center">
		<?php  $pidtxt='chkctlg'.$r_iteml['item_codigo']; $pdefa=$r_iteml['item_ctlg']; $ptabla="item"; $pline=$r_iteml['item_codigo']; $pcolu="ctlg"; include('vrchkbox.php'); ?>	
  </td>
	<td align="center"><?php echo'<span title="'.$r_iteml['item_nctlg'].'">'.$r_iteml['item_nctlg'].'-'.fillzero($r_iteml['item_pctlg'],2).'</span>';?></td>
	<td align="center"><?php echo'<span title="'.$r_iteml['cair_descri'].'">'.$r_iteml['item_cair'].'</span>';?></td>
	<td align="center" style="font-family:courier;"><?php echo'<span title="'.$r_iteml['item_idate'].'"><font size="1">'.date_format(date_create($r_entil['item_idate']),"d-m-y H:i:s").'</font></span>';?></td>

	
<!-- 	
	<th>UMDD</th>
	<th>LADO</th>
	<th>TLLA</th>
	<th>COLOR</th>
	<th>PROVEEDOR</th>
	<th>CAIR</th>
	
	 -->
	
	
	
</tr>
<?php }?>


</table>
</div>