<?php session_start();?>
<?php include('../_cfg/config.php');?>
<?php include('php_gene1.php'); ?>
<?php include('php_session.php');?>

<?php //foreach($_POST as $campo => $valor){${$campo}=$valor;} ?>

<?php $orient=$_POST['orient']; ?>
<?php $pant=$_POST['pant']; ?>
<?php $ctlg=$_POST['ctlg']; ?>
<?php $docu=$_POST['docu']; ?>
<?php $idnum=$_POST['idnum']; ?>
<?php $item=$_POST['item']; ?>
<?php $busq=$_POST['busq']; ?>
<?php $stat=$_POST['stat']; ?>
<?php $fecha1=$_POST['fecha1']; ?>
<?php $fecha2=$_POST['fecha2']; ?>

<?php $orient=$_POST['orient']; ?>

<?php
if($ctlg=='' or $ctlg=='undefined'){$ctlg='item';}
if($docu==''){$docu='CAR1';}


$sql_puni='update item0 set item_puni=item_pvp1/(1+(item_iva/100)) where item_ctlg=1 and item_pvp1>0 and item_pvp1 is not null and (item_puni=0 or item_puni is null) ';
$res_puni=msql_query($sql_puni,$link_vcrx);

// $sql_raiz='update item0 set item_raiz=item_mdlo where item_codigo like "20100%" ';
// $res_raiz=msql_query($sql_raiz,$link_vcrx);

$sql_raiz='update item0 set item_rfer=item_raiz ';
$res_raiz=msql_query($sql_raiz,$link_vcrx);

$sql_raiz='update item0 set item_raiz=substring(item_codigo,1,10) where item_codigo like "2010%" ';
$res_raiz=msql_query($sql_raiz,$link_vcrx);

$sql_raiz='update item0 set item_rfer=substring(item_codigo,1,10) where item_codigo like "2010%" ';
$res_raiz=msql_query($sql_raiz,$link_vcrx);

// echo '*/*/*/*/*'.$sql_raiz.msql_error();


$idcarr=get_carr();


$verpvp=0;
if($user_tipo!='invi' and $user_tipo!=''){$verpvp=1;}

$xfontsize=12;
if($mobile=='true' and $orient=='V'){$xfontsize=30;}
// if($mobile=='true' and $orient=='H'){$xfontsize=20;}

// $busq=$_GET['busq'];
// $lsub=$_GET['lsub'];
// $item=$_GET['item'];
// $orde=$_GET['orde'];

$sel_bus='';
if($busq!='todo')
{
	$busca=strtoupper(alltrim($busq));
	$busca=explode(' ',$busca);
	for ($cbusca=0; $cbusca<count($busca); $cbusca++)
	{
		$sel_bus.='and (';
		$sel_bus.='item_descri like "%'.$busca[$cbusca].'%"';
    if(strtoupper($busca[$cbusca])=='NIÑ')
    {$sel_bus.='or item_descri like "%'.$busca[$cbusca].'%"';}
    $sel_bus.='or item_tlla like "%'.$busca[$cbusca].'%"';
		$sel_bus.='or tlla_descri like "%'.$busca[$cbusca].'%"';
		$sel_bus.='or item_lsub like "%'.$busca[$cbusca].'%"';
		$sel_bus.='or lsub_descri like "%'.$busca[$cbusca].'%"';
		$sel_bus.=')';
	}
}

// echo '****'.$item;

$sql_ctlg ='select * from item0 ';
$sql_ctlg.=' left join lsub0 on item_lsub=lsub_codigo ';
$sql_ctlg.=' left join tlla0 on item_tlla=tlla_codigo ';
$sql_ctlg.=' left join mrca0 on item_mrca=mrca_codigo ';
$sql_ctlg.=' left join kldd0 on item_kldd=kldd_codigo ';
$sql_ctlg.=' where item_codigo>100000 ';
// $sql_ctlg.=' and item_codigo=item_raiz ';
$sql_ctlg.=' and length(trim(item_codigo))>=6 ';
$sql_ctlg.=' and item_codigo!=item_raiz ';
$sql_ctlg.=' and item_ctlg=1 ';
$sql_ctlg.=' and item_puni>0 ';
if($lsub!="")
{$sql_ctlg.=' and item_lsub like "'.$lsub.'%"';}
if($item!="" and $item!='undefined')
{$sql_ctlg.=' and item_codigo like "'.$item.'%"';}
if($busq!="" and $busq!='undefined')
{$sql_ctlg.=$sel_bus;}
// $sql_ctlg.=' and item_codigo like "1400%"';
// $sql_ctlg.=' and (item_codigo like "105613%" or item_codigo like "111508%") ';
// $sql_ctlg.=' and item_status!="I"';
// $sql_ctlg.=' and item_status!="X"';

if($lsub!='')
{$sql_ctlg.=' and  item_lsub like "'.$lsub.'%"';}

$sql_ctlg.=' group by item_raiz ';

$sql_ctlg.=' order by ';
// $sql_ctlg.=' order by item_raiz,';
if($orde!='' and $orde!='undefined')
{$sql_ctlg.=' '.$orde.',';}
$sql_ctlg.=' item_descri,item_codigo ';

if($busq=="" or $busq=='undefined')
{
  $sql_ctlg=str_replace('order by ','order by item_codigo desc,',$sql_ctlg);
  $sql_ctlg=str_replace('where item_puni>0','where item_puni>0 and item_codigo in (select imgi_item from imgi0) ',$sql_ctlg);
  $sql_ctlg.=' limit 20 ';
}

// $res_ctlg=msql_query($sql_ctlg,$link_vcrx);

// echo explain_sql($sql_ctlg);

?>

<?php ob_start(); ?>
<resultado>
<pant1>

<div id="taginicial" style="float:inherit;"></div>		
<table id="tpant0" cellpadding="2" width="100%" border="0"
						 style="font-size:<?php echo $xfontsize; ?>px;border-collapse:collapse;  ">
	<tr><?php $pidtxt='lsub'; $pcaption='LINEA'; $ptabla='lsub'; $ptodos=1; $psize=$xfontsize;
		$pwhere='lsub_codigo in(select distinct item_lsub from item0 where item_ctlg=1)';
// 		include('vrselopt.php'); 
		?>
	</tr>
	<tr><?php $pidtxt='pru'; $pcaption='CLIES'; $pdocu='FC10'; $ptodos=0; $psize=$xfontsize;?>
	</tr>
	<tr style="display:none;">
		<?php $pidtxt='busq';  $pcaption='buscar'; $ptabla='busq'; $psize=$xfontsize;
				if($orient=='H'){$plong=100;}else{$plong=30;};
		include('vrgettxt.php'); ?>
	</tr>
</table>	
<div width="100%" style="overflow:auto;">
<?php if($mobile=='true'){?>	
<br>
<?php } ?>
	
<?php $classtab='filtro'; ?>
<?php $classcol=$classtab.'_coligua'; ?>
<table id="filtro" cellpadding="2" width="100%" border="0" class="<?php echo $classtab?>"
			 onclick="resizeTab('<?php echo $classtab?>','<?php echo $classcol; ?>');"  onmouseover="this.onclick();"
			style="font-size:<?php echo $xfontsize; ?>px;border-collapse:collapse;  ">
	<tr>
	<td width="8%">
		<?php $pidtxt='f_todo';  $pcaption='VER TODO'; $psize=$xfontsize;
// 		$ponclick='{location.href="?ctlg='.$ctlg.'&busq=todo"}';
		$ponclick='{location.href="?scri=ctlg_gmny&busq=todo&"}';
		include('vrbutton.php'); ?>
	</td>
	<td width="8%">
		<?php $pidtxt='f_blusas';  $pcaption='BLUSAS'; $psize=$xfontsize;
		$ponclick='{location.href="?ctlg='.$ctlg.'&busq=blus&"}';
		$ponclick='{location.href="?scri=ctlg_gmny&busq=blus&"}';
		include('vrbutton.php'); ?>
	</td>
	<td width="8%">
		<?php $pidtxt='f_faldas';  $pcaption='FALDAS'; $psize=$xfontsize;
		$ponclick='{location.href="?ctlg='.$ctlg.'&busq=fald&"}';
		$ponclick='{location.href="?scri=ctlg_gmny&busq=fald&"}';
		include('vrbutton.php'); ?>
	</td>
	<td width="8%">
		<?php $pidtxt='f_enterizo';  $pcaption='ENTERIZOS'; $psize=$xfontsize;
		$ponclick='{location.href="?ctlg='.$ctlg.'&busq=enterizo&"}';
		$ponclick='{location.href="?scri=ctlg_gmny&busq=enterizo&"}';
		include('vrbutton.php'); ?>
	</td>
	<td width="8%">
		<?php $pidtxt='f_short';  $pcaption='SHORTS'; $psize=$xfontsize;
		$ponclick='{location.href="?ctlg='.$ctlg.'&busq=short&"}';
		$ponclick='{location.href="?scri=ctlg_gmny&busq=short&"}';
		include('vrbutton.php'); ?>
	</td>
	<td width="8%">
		<?php $pidtxt='f_vestido';  $pcaption='VESTIDOS'; $psize=$xfontsize;
		$ponclick='{location.href="?ctlg='.$ctlg.'&busq=vestido&"}';
		$ponclick='{location.href="?scri=ctlg_gmny&busq=vestido&"}';
		include('vrbutton.php'); ?>
	</td>
	<td width="8%">
		<?php $pidtxt='f_leggi';  $pcaption='LEGGINS'; $psize=$xfontsize;
		$ponclick='{location.href="?ctlg='.$ctlg.'&busq=leggin&"}';
		$ponclick='{location.href="?scri=ctlg_gmny&busq=leggin&"}';
		include('vrbutton.php'); ?>
	</td>
	<td width="8%">
		<?php $pidtxt='f_camisa';  $pcaption='CAMISAS'; $psize=$xfontsize;
		$ponclick='{location.href="?ctlg='.$ctlg.'&busq=camisa&"}';
		$ponclick='{location.href="?scri=ctlg_gmny&busq=camisa&"}';
		include('vrbutton.php'); ?>
	</td>
	<td width="8%">
		<?php $pidtxt='f_camiseta';  $pcaption='CAMISETAS'; $psize=$xfontsize;
		$ponclick='{location.href="?ctlg='.$ctlg.'&busq=camiseta&"}';
		$ponclick='{location.href="?scri=ctlg_gmny&busq=camiseta&"}';
		include('vrbutton.php'); ?>
	</td>
	<td width="8%">
		<?php $pidtxt='f_pantalon';  $pcaption='PANTALONES'; $psize=$xfontsize;
		$ponclick='{location.href="?ctlg='.$ctlg.'&busq=pantalon&"}';
		$ponclick='{location.href="?scri=ctlg_gmny&busq=pantalon&"}';
		include('vrbutton.php'); ?>
	</td>
	<td width="8%">
		<?php $pidtxt='f_pijama';  $pcaption='PIJAMAS'; $psize=$xfontsize;
		$ponclick='{location.href="?ctlg='.$ctlg.'&busq=pijama&"}';
		$ponclick='{location.href="?scri=ctlg_gmny&busq=pijama&"}';
		include('vrbutton.php'); ?>
	</td>
	<td width="8%">
		<?php  $pidtxt='f_ninio';  $pcaption='NIÑ@S'; $psize=$xfontsize;
		$ponclick='{location.href="?ctlg='.$ctlg.'&busq=niÑ&"}';
		$ponclick='{location.href="?scri=ctlg_gmny&busq=niÑ&"}';
		include('vrbutton.php'); ?>
	</td>
	</tr>
</table>	
<?php if($mobile=='true'){?>	
<br>
<?php } ?>
</div>
	<?php //echo '**'.$user_tipo;?>
<hr>
<?php $crow=0; ?>
<?php $ccol=0; ?>
  
  
  
<?php $res_ctlg=msql_query($sql_ctlg,$link_vcrx); ?>  
<?php
//      echo '*/*/'.$sql_ctlg;
//   echo explain_sql($sql_ctlg);
  ?>
	
<?php if(msql_num_rows($res_ctlg)==0){?>
	<?php echo 'NO SE ENCONTRARON RESULTADOS...'; ?>
<?php } ?>

  
  
<?php msql_data_seek($res_ctlg,0); ?>  
  
<?php while($aso_ctlg=msql_fetch_assoc($res_ctlg)){ ?>
	<?php $crow++; ?> 
	<?php
// echo $crow;                                                 
                                                 
		$item_codigo=$aso_ctlg['item_codigo'];
		$item_raiz=$aso_ctlg['item_raiz'];
		$item_descri=$aso_ctlg['item_descri'];
		$item_kldd=$aso_ctlg['item_kldd'];
		$item_kldd=$aso_ctlg['kldd_descri'].' /'.$aso_ctlg['item_composi'];
		$item_mrca=$aso_ctlg['item_mrca'];
		$mrca_descri=$aso_ctlg['mrca_descri'];
		$mrca_descri=ucwords(strtolower($mrca_descri)); 
		$item_modelo=substr($aso_ctlg['item_modelo'],0,6);
	?>
	<?php				
      $sql_tlla ='';
// 		$sql_tlla.='select * from item0 ';
		$sql_tlla.='select distinct item_codigo,tlla_codigo,tlla_descri from item0 ';
		$sql_tlla.='left join tlla0 ';
		$sql_tlla.='on item_tlla=tlla_codigo ';
		$sql_tlla.='where item_tlla!="" ';
// 		$sql_tlla.='and length(trim(item_codigo))>8 ';
		$sql_tlla.='and item_ctlg="1" ';
		$sql_tlla.='and item_codigo like "'.$item_raiz.'%" ';
		$sql_tlla.='order by item_codigo';
		$xstock=0;
		$ctallas=0;
	?>

	<div align="center" style="border:solid 0px;	float:left;
				<?php if($orient=='H' and $user_tipo=='invi'){echo'width:45%;padding:1%;';}?>
				<?php if($orient=='H' and $user_tipo!='invi' and $verpvp==0){echo'width:45%;padding:1%;';}?>
				<?php if($orient=='H' and $user_tipo!='invi' and $verpvp==1){echo'width:45%;padding:1%;';}?>
			 ">
<!-- 		<hr> -->
<!-- 		<table id="tpant0" cellpadding="2" width="<?php echo $screenw/2;?>px" border="0" -->
		<table id="tpant1" cellpadding="2" border="0" align="center"
						 style="font-size:<?php echo $xfontsize; ?>px;border-collapse:collapse;  ">
			<tr valign="top">
				<td width="<?php if($orient=='V'){echo "50%";}else{echo "40%";}?>" align="center"
						style="font-size:<?php echo $xfontsize;?>px; height:<?php if($orient=='H'){echo $screenh*(.6).'px';} ?>">
							<div style="font-weight:bold;">
							<?php echo 'CODIGO : '.$item_raiz; ?>
							</div>
					
					<?php if($orient=='V' and $verpvp==0) { ?>
					<?php 
// 						msql_select_db('vcrxol_gnya',$link_vcrx); 
            $_SESSION['link_vcrx']='';
            include('../../gnya/_cfg/config.php');
						$sql_gnya='select * from item0 where item_codigo like "'.$aso_ctlg['item_codigo'].'%" order by item_puni desc ';
						$res_gnya=msql_query($sql_gnya,$link_vcrx);
						if(msql_num_rows($res_gnya)>0)
						{
							$puni=msql_result($res_gnya,0,'item_puni');
							$iva=msql_result($res_gnya,0,'item_iva');
						}
// 						msql_select_db($cfg_data,$link_vcrx); 
            $_SESSION['link_vcrx']='';
            include('../_cfg/config.php');
					?>
					<?php //echo '************ '.$item_descri; ?>
							<div style="font-weight:bold;">
					<?php	echo 'M:'; ?>
							</div>
							<div style="font-weight:bold;">
					<?php	echo 'P.V.P. $ '. number_format($puni*(1+($iva/100)),2) ; ?>
							</div>
					<?php
							echo 'TALLAS : ';
							$res_tlla=msql_query($sql_tlla,$link_vcrx);
							while($aso_tlla=msql_fetch_assoc($res_tlla))
							{ echo ' .'.substr($aso_tlla['tlla_descri'],0,3);}
					?>
					<?php }	?>
						<?php
						$sql_imgi='select * from imgi0 where imgi_item like "'.$item_raiz.'%" order by imgi_defa desc, imgi_file';
						$res_imgi=msql_query($sql_imgi,$link_vcrx);
						?>
						<?php if(msql_num_rows($res_imgi)>0){?>
							<?php $pidtxt=$item_raiz; $ptabla='imgi'; $pcodigo=$item_raiz; include('vrsayimgs.php');?>
						<?php } ?>
				<table width="100%">
				<tr>
				<td width ="1%" align="left">
				<?php 	$pidtxt='inicio'.$item_raiz; $pcaption='▲'; $ptitle="Ir al Inicio"; $psize=$xfontsize; $pabrev='▲';
				$ponclick="{document.getElementById('taginicial').scrollIntoView();}";
				include('vrbutton.php'); ?>
				</td>
				<td width="90%">
				</td>
				<td width="1%" align="right">
				<?php 	
				$pidtxt='final'.$item_raiz; $pcaption='▼'; $ptitle="Ir al Final"; $psize=$xfontsize; $pabrev='▼';
				$ponclick="{document.getElementById('tagfinal').scrollIntoView();}";
				include('vrbutton.php');
				?>
				</td>
				</tr>	
				</table>

				</td>
				<?php if($orient=='H'){?>
				<td style="padding:15px; font-size:<?php echo $xfontsize;?>px;" >
<!-- 					<br> -->
					<div style="font-size:18px;">
					<?php echo $item_descri; ?>
                         </div>
					<div style="font-size:16px; font-style:italic;">
					<?php echo 'TEJIDO : '.$item_kldd; ?>
                         </div>
							<div style="font-weight:bold;font-style:italic;font-size:75%;">
					<?php	echo ucwords($mrca_descri); ?>
							</div>
					<div style="font-weight:bold;">
					<?php if($verpvp==0){ ?>
					<?php 
            $_SESSION['link_vcrx']='';
            include('../../gnya/_cfg/config.php');
						$sql_gnya='select * from item0 where item_codigo like "'.$aso_ctlg['item_codigo'].'%" order by item_puni desc ';
						$res_gnya=msql_query($sql_gnya,$link_vcrx);
						if(msql_num_rows($res_gnya)>0)
						{
							$puni=msql_result($res_gnya,0,'item_puni');
							$iva=msql_result($res_gnya,0,'item_iva');
						}
            $_SESSION['link_vcrx']='';
            include('../_cfg/config.php');
					?>
					<?php	if($puni>0){echo 'P.V.P. $ '. number_format($puni*(1+($iva/100)),2);} ?>
					<br>
					<?php } ?>
					<?php if($verpvp==1){?>
					<?php	echo 'P.V.P. $ '. number_format($aso_ctlg['item_puni']*(1+($aso_ctlg['item_iva']/100)),2); ?>
					<br>
					<?php } ?>
					</div>
					<br>
					<?php	echo 'TALLAS :'; ?>
					<?php if($verpvp==0){ ?>
						<div>
						<?php
							$res_tlla=msql_query($sql_tlla,$link_vcrx);
							while($aso_tlla=msql_fetch_assoc($res_tlla))
							{echo ' '.substr($aso_tlla['tlla_descri'],0,3).'.  ';}
						?>
						</div>
					<?php }else{ ?>
					<?php if($orient=='H'){ ?>
					<table id="tallas"<?php echo $item_raiz; ?> cellpadding="2" width="10%" border="0"
						 style="font-size:<?php echo $xfontsize; ?>px;border-collapse:collapse;  ">
            <tr>
              <td>
                <?php
//                               explain_sql($sql_tlla);
                ?>
              </td>
            </tr>
						<tr>
						<?php
						$res_tlla=msql_query($sql_tlla,$link_vcrx);
						while($aso_tlla=msql_fetch_assoc($res_tlla))
						{
// 							$xstock+=sal_item($aso_tlla['item_codigo']);
							$ctallas++;

							$pidtxt=$item_raiz.$aso_tlla['tlla_codigo'];
							$pcaption=substr($aso_tlla['tlla_descri'],0,30);
							$plong=3; $pdefa=1; $pobj=2; $psize=$xfontsize*.9; 
							include('vrgetval.php');
						}
						?>
						</tr>
						<tr>
						<?php
// 						$res_tlla=msql_query($sql_tlla,$link_vcrx);
            msql_data_seek($res_tlla,0);
						while($aso_tlla=msql_fetch_assoc($res_tlla))
						{
// 							$xstock+=sal_item($aso_tlla['item_codigo']);
							$ctallas++;
						?>
						<td>
						<?php 	$pidtxt='a_'.$item_raiz.$aso_tlla['tlla_codigo']; $pcaption='Agregar'; $psize=$xfontsize;
							$ponclick="add_carr('".$idcarr."','".$aso_tlla['item_codigo']."','".$item_raiz.$aso_tlla['tlla_codigo']."')";
							include('vrbutton.php'); ?>
						</td>
						<?php
						}
						?>
						</tr>
					</table>
					<?php }?>
					<?php } ?>
				</td>
				<?php } ?>
				<?php if($orient=='V' and $verpvp==1){?>
				<td style="font-size:<?php echo $xfontsize;?>px;">
					<br>
					<div style="font-size:30px;">
					<?php echo $item_descri; ?>
					<div>
					<?php if($verpvp==1){?>
					<?php	echo 'P.V.P. $ '. number_format($aso_ctlg['item_puni']*(1+($aso_ctlg['item_iva']/100)),2);	 ?>
					<br>
					<?php } ?>
					<br>
					<?php		echo 'TALLAS:'; ?>
					<?php if($verpvp==0){ ?>
						<div>
						<?php
							$res_tlla=msql_query($sql_tlla,$link_vcrx);
							while($aso_tlla=msql_fetch_assoc($res_tlla))
							{ echo ' '.substr($aso_tlla['tlla_descri'],0,3).'.  ';}
						?>
						</div>
					<?php }else{ ?>
					<?php { ?>
					<br><br>
					<table id="tallas"<?php echo $item_raiz; ?> cellpadding="2" width="100%" border="0" 
						 style="font-size:<?php echo $xfontsize; ?>px;border-collapse:collapse; ">
						<?php
						$res_tlla=msql_query($sql_tlla,$link_vcrx);
						while($aso_tlla=msql_fetch_assoc($res_tlla))
						{
						?>
						<tr>
						<?php
// 							$xstock+=sal_item($aso_tlla['item_codigo']);
							$ctallas++;

							$pidtxt=$item_raiz.$aso_tlla['tlla_codigo'];
							$pcaption=substr($aso_tlla['tlla_descri'],0,30);
							$plong=3; $pdefa=1; $pobj=3; $psize=$xfontsize; 
							$poptn1=1;$poptn2=36;
							include('vrselopt.php');
						?>
						<td align="right" width="30%">
						<?php 	$pidtxt='a_'.$item_raiz.$aso_tlla['tlla_codigo']; $pcaption='Agregar'; $psize=$xfontsize;
							$ponclick="add_carr('".$idcarr."','".$aso_tlla['item_codigo']."','".$item_raiz.$aso_tlla['tlla_codigo']."')";
							include('vrbutton.php'); ?>
							
						</td>
						</tr>
						<tr><td><br></td></tr>
						<?php }	?>
					</table>
					<?php } ?>
					<?php } ?>
				</td>
				<?php } ?>
<!-- 				<td></td> -->
			</tr>
					
					
		</table>
		<hr size="5" noshade>
		<?php if ($mobile=='true'){ ?>
<!-- 		<hr><hr> -->
		<?php } ?>
					
	</div>
<?php}?>

    <div id="tagfinal" style="float:inherit;"></div>		
	
		
</pant1>		
</resultado>

<?php $obstart = ob_get_clean(); ?>
<?php $obstart = alltrim($obstart) ?>
<?php echo $obstart;	?>

		