<?php
	session_start();
	include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
	//
	$StrCmd=V($_GET['Cmd']);
	$StrPar=V($_GET['TxtPar']);
	$StrPar2=V($_GET['TxtPar2']);
	$StrPar3=V($_GET['TxtPar3']);
	$StrPar4=V($_GET['TxtPar4']);
	$StrPar5=V($_GET['TxtPar5']);
	$StrPar6=V($_GET['TxtPar6']);
	$StrPar7=V($_GET['TxtPar7']);	
	///////////////////////////////////////////////////////////////////////
	if($StrCmd=="INVOICE_FILTRAR"){
		$StrTC=gs("valor","valores","dato='T_CAMBIO'");		
		$StrMar=$StrPar2."%";
		$StrCod=$StrPar3."%";
		$StrCod=str_replace("@","+",$StrCod);
		$StrDes=$StrPar."%";
		$StrDes=str_replace("@","+",$StrDes);
		$StrAlm=$StrPar4;
		$StrAlm_=gn("id_almacen","almacenes","alm_nombre='$StrAlm'");
		///////////////////////////////////////////////////////////////////////		
		///////////////////////////////////////////////////////////////////////
		$s="<table width=\"1080\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\"  style=\"table-layout:fixed\">";
		$t=$s;
		$s="";
		//
		$FF=STR_OK(str_replace("@","+",$StrPar));
		$LL=explode(" ",$FF);
		$WW="";
		if(count($LL)>0){
			for($i=0;$i<count($LL);$i++){
				if(strlen(trim($LL[$i]))>0){
					$WW=$WW." CONCAT(LINEA,' ',MODELO,' ',DESCRIPCION) LIKE '%".$LL[$i]."%' AND";
				}
			}
		}
		//
		if(strlen($WW)>0){
			$WW="(".vbmid($WW,1,strlen($WW)-3).")";
		}else{
			$WW="CONCAT(LINEA,' ',MODELO,' ',DESCRIPCION) LIKE '%".$Des."%'";
		}
		//
		$sql="SELECT CONCAT('@ ',' * ',':','z(',ID,')>'),							
							CONCAT('%',COD,';'),														
							CONCAT('%',SUBSTRING(LINEA,1,13),';'),							
							CONCAT('%',TRIM(LEFT(DESCRIPCION,45)),';'),							
							CONCAT('%',ROUND(PC_SOL,1),';'),
							CONCAT('%',ROUND(PC_SOL / $StrTC,1),';#'), ID							
							FROM vproductos WHERE $WW AND COD Like '$StrCod' ORDER BY DESCRIPCION,COD";	
														
		$sql="SELECT CONCAT('@ ',' * ',':','z(',ID,')>'),							
							CONCAT('%',COD,';'),														
							CONCAT('%',SUBSTRING(LINEA,1,13),';'),							
							CONCAT('%',TRIM(LEFT(DESCRIPCION,45)),';'),							
							CONCAT('%',ROUND(PC_SOL,1),';'),
							CONCAT('%',ROUND(PC_SOL / $StrTC,1),';#'), ID							
							FROM vproductos WHERE $WW AND COD Like '$StrCod' ORDER BY DESCRIPCION,COD";								

		$result = grs($sql);
		$cx=0;
		//
		$s=$s."<tr id=\"z0\" ondblclick=\"z('0')\" tabindex=\"0\">";
		$s=$s."<td  width=\"128px\"></td>";
		$s=$s."<td  width=\"142px\"></td>";
		$s=$s."<td  width=\"555px\"></td>";
		$s=$s."<td  width=\"56px\"></td>";
		$s=$s."<td  width=\"56px\"></td>";
		$s=$s."<td  width=\"56px\"></td>";
		$s=$s."<td  width=\"40px\"></td>";
	    $s=$s."</tr>";
		//
		while ($row =$result->fetch_assoc()){
			$cx++;
			$STOCK=gn("stock","stocks","id_producto=$row[ID] AND id_almacen=$StrAlm_");		  
		  	$F="id=\"z".$cx."\" tabindex=\"$cx\" ";
		  	$s=$s.str_replace("*",$F,$row[0]).$row[1].$row[2].$row[3]."%".$STOCK.";".$row[4].$row[5];        	 
		}
		if($s!=""){
	        $s=$t.$s."</table>";		
		}		
		echo $s;	
	}
	///////////////////////////////////////////////////////////////////////
	if($StrCmd=="ST_RUC"){
		$StrER="El numero Ruc ingresado es invalido";
		$StrRuc=$StrPar;
		$StrTD="<b>Direcci&#xF3;n.</b><br/>";
		$StrTT="</small><br/>";
		$StrTE="<b>Tel&#xE9;fono(s).</b><br/>";
		$RSunat = file_get_contents("http://www.sunat.gob.pe/w/wapS01Alias?ruc=$StrRuc");
		$iPos=strpos($RSunat,$StrER);
		if($iPos>0){
			echo "Numero ruc invalido";
			return;
		}
		$iPos=strpos($RSunat,$StrRuc)+strlen($StrRuc)+3;
		$iPos2=strpos($RSunat,"<br/>");
		$StrRS=substr($RSunat,$iPos,$iPos2 - $iPos);
		//
		$iPos=strpos($RSunat,$StrTD)+strlen($StrTD);
		$RSunat=substr($RSunat,$iPos);
		$iPos=strpos($RSunat,$StrTT);
		$StrDI=substr($RSunat,0,$iPos);
		//
		$iPos=strpos($RSunat,$StrTE)+strlen($StrTE);
		$RSunat=substr($RSunat,$iPos);
		$iPos=strpos($RSunat,$StrTT);
		$StrTE=substr($RSunat,0,$iPos);
		$s="<input name=\"T_RS\" type=\"hidden\" id=\"T_RS\" value=\"$StrRS\"/>";
        $s=$s."<input name=\"T_DI\" type=\"hidden\" id=\"T_DI\" value=\"$StrDI\"/>";
        $s=$s."<input name=\"T_TE\" type=\"hidden\" id=\"T_TE\" value=\"$StrTE\"/>";
		echo $s;
	}
	///////////////////////////////////////////////////////////////////////
	if($StrCmd=="GET_RUC"){
		echo gs("RUC","vproveedores","NOMBRE='$StrPar'");	
		return;
	}
	///////////////////////////////////////////////////////////////////////
	if($StrCmd=="CLI_GET_SALDO_DOL"){
		if(strlen($StrPar)==0) $StrPar="0";
		if(!is_numeric($StrPar)) $StrPar="0";
		$TOT=gn("SUM(tot)","ventas",
				  "id_cliente=$StrPar AND 
				  anu='N' AND id_tip_pag='CR' AND mon='D'");
		$PAE=gn("SUM(total)","cobros","id_cliente=$StrPar AND anu='N' AND mon='D'");
		$TOT=round($TOT - $PAE,2);
		echo $TOT;
		return;
	}
	if($StrCmd=="CLI_GET_SALDO_SOL"){
		if(strlen($StrPar)==0) $StrPar="0";
		if(!is_numeric($StrPar)) $StrPar="0";
		$TOT=gn("SUM(tot)","ventas",
				  "id_cliente=$StrPar AND 
				  anu='N' AND id_tip_pag='CR' AND mon='S'");
		$PAE=gn("SUM(total)","cobros","id_cliente=$StrPar AND anu='N' AND mon='S'");
		$TOT=round($TOT - $PAE,2);
		echo $TOT;
		return;
	}
	///////////////////////////////////////////////////////////////////////
	if($StrCmd=="PROV_GET_SALDO_DOL"){
		if(strlen($StrPar)==0) $StrPar="0";
		if(!is_numeric($StrPar)) $StrPar="0";
		$TOT=gn("SUM(total)","compras",
				  "id_proveedor=$StrPar AND 
				  anulado='N' AND id_tip_pag='CR' AND moneda='D'");
		$PAE=gn("SUM(total)","pagos","id_proveedor=$StrPar AND anu='N' AND mon='D'");
		$TOT=round($TOT - $PAE,2);
		echo $TOT;
		return;
	}
	if($StrCmd=="PROV_GET_SALDO_SOL"){
		if(strlen($StrPar)==0) $StrPar="0";
		if(!is_numeric($StrPar)) $StrPar="0";
		$TOT=gn("SUM(total)","compras",
				  "id_proveedor=$StrPar AND 
				  anulado='N' AND id_tip_pag='CR' AND moneda='S'");
		$PAE=gn("SUM(total)","pagos","id_proveedor=$StrPar AND anu='N' AND mon='S'");
		$TOT=round($TOT - $PAE,2);
		echo $TOT;
		return;
	}
	///////////////////////////////////////////////////////////////////////
	if($StrCmd=="GET_PROVEEDOR"){
		echo gs("NOMBRE","vproveedores","RUC='$StrPar'");	
		return;
	}
	///////////////////////////////////////////////////////////////////////
	if($StrCmd=="COMPRAS_GET_PROD_DATOS_X_ID"){
		$StrId=$StrPar;
		$StrCod=gs("COD","vproductos","ID=$StrId");
		$StrDes=gs("DESCRIPCION","vproductos","ID=$StrId");
		$StrPre=gn("PC_SOL","vproductos","ID=$StrId");
		$StrMar=gs("MARCA","vproductos","ID=$StrId");
		echo "<input name=\"Pro_TxtId\" type=\"hidden\" id=\"Pro_TxtId\" value=\"$StrId\"/>
		<input name=\"Pro_TxtDes\" type=\"hidden\" id=\"Pro_TxtDes\" value=\"$StrDes\"/>
		<input name=\"Pro_TxtCod\" type=\"hidden\" id=\"Pro_TxtCod\" value=\"$StrCod\"/>
		<input name=\"Pro_TxtMarca\" type=\"hidden\" id=\"Pro_TxtMarca\" value=\"$StrMar\"/>
        <input name=\"Pro_TxtPre\" type=\"hidden\" id=\"Pro_TxtPre\" value=\"$StrPre\"/>";
		return;
	}
	

	///////////////////////////////////////////////////////////////////////	
	if($StrCmd=="GET_PROD_DATOS"){
		$StrId=gn("ID","vproductos","COD='$StrPar'");
		$StrCod=gs("COD","vproductos","ID=$StrId");
		$StrDes=gs("DESCRIPCION","vproductos","ID=$StrId");
		$StrPre=gn("PC_SOL","vproductos","ID=$StrId");
		$StrMar=gs("MARCA","vproductos","ID=$StrId");
		echo "<input name=\"Pro_TxtId\" type=\"hidden\" id=\"Pro_TxtId\" value=\"$StrId\"/>
		<input name=\"Pro_TxtDes\" type=\"hidden\" id=\"Pro_TxtDes\" value=\"$StrDes\"/>
		<input name=\"Pro_TxtCod\" type=\"hidden\" id=\"Pro_TxtCod\" value=\"$StrCod\"/>
		<input name=\"Pro_TxtMar\" type=\"hidden\" id=\"Pro_TxtMarca\" value=\"$StrMar\"/>
        <input name=\"Pro_TxtPre\" type=\"hidden\" id=\"Pro_TxtPre\" value=\"$StrPre\"/>";
		return;
	}	
	if($StrCmd=="GET_PROD_DATOS_C"){
		$StrId=gn("ID","vproductos","COD='$StrPar'");
		$StrCod=gs("COD","vproductos","ID=$StrId");
		$StrDes=gs("DESCRIPCION","vproductos","ID=$StrId");
		$StrPre=gn("PC_SOL","vproductos","ID=$StrId");
		$StrMar=gs("MARCA","vproductos","ID=$StrId");
		echo "<input name=\"Pro_TxtId\" type=\"hidden\" id=\"Pro_TxtId\" value=\"$StrId\"/>
		<input name=\"Pro_TxtDes\" type=\"hidden\" id=\"Pro_TxtDes\" value=\"$StrDes\"/>
		<input name=\"Pro_TxtCod\" type=\"hidden\" id=\"Pro_TxtCod\" value=\"$StrCod\"/>
		<input name=\"Pro_TxtMar\" type=\"hidden\" id=\"Pro_TxtMarca\" value=\"$StrMar\"/>
        <input name=\"Pro_TxtPre\" type=\"hidden\" id=\"Pro_TxtPre\" value=\"$StrPre\"/>";
		return;
	}	
	///////////////////////////////////////////////////////////////////////	
	if($StrCmd=="VEN_GET_PROD_DATOS"){
		$StrId=gn("ID","vproductos","COD='$StrPar'");
		$StrCod=gs("COD","vproductos","ID=$StrId");
		$StrDes=gs("DESCRIPCION","vproductos","ID=$StrId");
		$StrPre=gn("PV_MAX","vproductos","ID=$StrId");
		$StrPreM=gn("PV_MIN","vproductos","ID=$StrId");
		$StrMar=gn("MARCA","vproductos","ID=$StrId");
		echo "<input name=\"Pro_TxtId\" type=\"hidden\" id=\"Pro_TxtId\" value=\"$StrId\"/>
		<input name=\"Pro_TxtDes\" type=\"hidden\" id=\"Pro_TxtDes\" value=\"$StrDes\"/>
		<input name=\"Pro_TxtCod\" type=\"hidden\" id=\"Pro_TxtCod\" value=\"$StrCod\"/>
		<input name=\"Pro_TxtMarca\" type=\"hidden\" id=\"Pro_TxtMarca\" value=\"$StrMar\"/>
        <input name=\"Pro_TxtPre\" type=\"hidden\" id=\"Pro_TxtPre\" value=\"$StrPre\"/>
		<input name=\"Pro_TxtPreM\" type=\"hidden\" id=\"Pro_TxtPreM\" value=\"$StrPreM\"/>";		
		return;
	}		
	if($StrCmd=="VEN_GET_PROD_DATOS_X_ID"){
		$StrId=vbval($StrPar);
		$StrAl=$StrPar2;
		$Opc=vbval($StrPar3);
		//
		$StrAl=gn("id_almacen","almacenes","alm_nombre='$StrAl'");		
		$StrCod=gs("COD","vproductos","ID=$StrId");
		$StrDes=gs("DESCRIPCION","vproductos","ID=$StrId");
		$StrPre=gn("PV_MAX","vproductos","ID=$StrId");
		$PRECIO=gn("pxs_precio","precios","pxs_id_almacen=$StrAl AND pxs_id_producto=$StrId");
		if($PRECIO==0){
			$PRECIO=$StrPre;
		}
		$StrPreM=gn("PV_MIN","vproductos","ID=$StrId");
		$StrMar=gn("MARCA","vproductos","ID=$StrId");
		$PXU=gn("PXU","vproductos","ID=$StrId");
		$PXC=gn("PXC","vproductos","ID=$StrId");
		$PXM=gn("PXM","vproductos","ID=$StrId");
		$MND=gs("MND","vproductos","ID=$StrId");
		if($Opc==0){
			$PCO=gn("PC_SOL","vproductos","ID=$StrId");
		}else{
			$PCO="**.*";
		}
		$STO=gn("SUM(stock)","stocks","id_producto=$StrId");
		//
		if($Opc==0){
			if($MND=="S")$MND="S/ ";		
			if($MND=="D")$MND="$ ";
		}else{
			$MND="* ";
		}
		$PCO=$MND.$PCO;
		echo "<input name=\"Pro_TxtId\" type=\"hidden\" id=\"Pro_TxtId\" value=\"$StrId\"/>
		<input name=\"Pro_TxtDes\" type=\"hidden\" id=\"Pro_TxtDes\" value=\"$StrDes\"/>
		<input name=\"Pro_TxtCod\" type=\"hidden\" id=\"Pro_TxtCod\" value=\"$StrCod\"/>
		<input name=\"Pro_TxtMarca\" type=\"hidden\" id=\"Pro_TxtMarca\" value=\"$StrMar\"/>
        <input name=\"Pro_TxtPre\" type=\"hidden\" id=\"Pro_TxtPre\" value=\"$PRECIO\"/>
		<input name=\"Pro_TxtPreM\" type=\"hidden\" id=\"Pro_TxtPreM\" value=\"$StrPreM\"/>
		<input name=\"TXT_PXU\" type=\"hidden\" id=\"TXT_PXU\" value=\"$PXU\"/>
		<input name=\"TXT_PXC\" type=\"hidden\" id=\"TXT_PXC\" value=\"$PCO\"/>
		<input name=\"TXT_PXM\" type=\"hidden\" id=\"TXT_PXM\" value=\"$STO\"/>
		";		
		return;
	}
	///////////////////////////////////////////////////////////////////////
	if($StrCmd=="VENTAS_PROD_FILTRAR"){
		$Alm_=gn("id_almacen","almacenes","alm_nombre='".$StrPar2."'");
		$Mar=$StrPar3."%";
		$Cod=$StrPar4."%";
		$Opc=vbval($StrPar5);
		$Cod=str_replace("@","+",$Cod)."%";
		$Des=str_replace("@","+",$StrPar)."%";
		$FA="";
		//if(GetC("almacenes","alm_bus_a='1' AND id_almacen=$Alm_")>0){
			$Des="%".$Des;
			$FA="%";
		//}		

		$s="<table width=\"1000\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\"  style=\"table-layout:fixed\">";
		$t=$s;
		$s="";
		//
		$FF=STR_OK(str_replace("@","+",$StrPar));		
		$LL=explode(" ",$FF);
		$WW="";
		if(count($LL)>0){
			for($i=0;$i<count($LL);$i++){
				if(strlen(trim($LL[$i]))>0){
					$WW=$WW." CONCAT(LIN,' ',MODELO,' ',DES) LIKE '%".$LL[$i]."%' AND";
				}
			}
		}
		//+++
		if(strlen($WW)>0){
			$WW="(".vbmid($WW,1,strlen($WW)-3).")";
		}else{
			//$WW="CONCAT(LIN,' ',DES,' ',MAR) LIKE '".$Des."$FA'";
			$WW="CONCAT(LIN,' ',DES,' ',MAR) LIKE '%".$Des."%'";
		}
		// 
		//$sql="SELECT CONCAT('@ ', '\"z(', '\'',ID_PRO, '\')\">', 
		if($Opc==0){
			$sql="SELECT CONCAT('@ ',' * ',':','z(',ID_PRO,')>'),							
								CONCAT('%',COD,';'),							
								CONCAT('%',SUBSTRING(LIN,1,13),';'),							
								CONCAT('%',TRIM(LEFT(DES,45)),';'),	
								CONCAT('%',TRIM(LEFT(MAR,45)),';'),							
								CONCAT('%',ROUND(PXU,2),';'),						
								CONCAT('%',ROUND(STOCK,0),';'),
								CONCAT('%',MND,' ',ROUND(PC_SOL,2),';')
								FROM vstocks 
								WHERE COD LIKE '$Cod' AND ".$WW." AND ID_ALM =$Alm_ ORDER BY DES";	
		}else{
			$sql="SELECT CONCAT('@ ',' * ',':','z(',ID_PRO,')>'),							
							CONCAT('%',COD,';'),							
							CONCAT('%',SUBSTRING(LIN,1,13),';'),							
							CONCAT('%',TRIM(LEFT(DES,45)),';'),	
							CONCAT('%',TRIM(LEFT(MAR,45)),';'),							
							CONCAT('%',ROUND(PXU,2),';'),						
							CONCAT('%',ROUND(STOCK,0),';'),
							CONCAT('%','*',' ','**.*',';')
							FROM vstocks 
							WHERE COD LIKE '$Cod' AND ".$WW." AND ID_ALM =$Alm_ ORDER BY DES";	
		}
		$result = grs($sql);
		$cx=0;
		$s=$s."<tr ondblclick=\"z('0')\">";
		$s=$s."<td  width=\"94px\"></td>";
		$s=$s."<td  width=\"200px\"></td>";
		$s=$s."<td  width=\"280px\"></td>";
		$s=$s."<td  width=\"110px\"></td>";
		$s=$s."<td  align=\"right\" width=\"100px\"></td>";
		$s=$s."<td  align=\"right\" width=\"53px\"></td>";
		$s=$s."<td  align=\"right\" width=\"100px\"></td>";
		$s=$s."<td  align=\"right\" width=\"47px\"></td>";
		$s=$s."</tr>";
		
		while ($row =$result->fetch_assoc()){
		  $cx++;
		  //
		  $F="id=\"z".$cx."\" tabindex=\"$cx\" ";
		  $s=$s.str_replace("*",$F,$row[0]).$row[1].$row[2].$row[3].$row[4].$row[5].$row[6].$row[7];
		}
		if($s!=""){
        $s=$t.$s."</table>";		
		}		
		echo $s;	
	}	
	///////////////////////////////////////////////////////////////////////
	if($StrCmd=="KARDEX_PROD_FILTRAR"){
		$StrTC=gs("valor","valores","dato='T_CAMBIO'");		
		$StrMar=$StrPar2."%";
		$StrCod=$StrPar3."%";
		$StrAlm=$StrPar4."%";
		$StrCod=str_replace("@","+",$StrCod);
		$StrDes="%".$StrPar."%";
		$StrDes=str_replace("@","+",$StrDes);
		$StrAlm_=gn("id_almacen","almacenes","alm_nombre='$StrAlm'");
		///////////////////////////////////////////////////////////////////////
		$s="<table width=\"1080\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" class=\"estilo777\" style=\"table-layout:fixed\">";
		$t=$s;
		$s="";
		

		$sql="SELECT CONCAT('@ ',' * ',':','z(',ID,')>'),
				CONCAT('%',COD,';'),
				CONCAT('%',TRIM(LEFT(FAB,45)),';'),
				CONCAT('%',TRIM(LEFT(MODELO,45)),';'),
				CONCAT('%',TRIM(LEFT(DESCRIPCION,45)),';'),
				CONCAT('%',ROUND(PC_SOL,1),';'),
				CONCAT('%',ROUND(PC_SOL / $StrTC,1),';#')
				FROM vproductos 
				WHERE DESCRIPCION LIKE '$StrDes' AND MARCA LIKE '$StrMar' AND COD Like '$StrCod' ORDER BY DESCRIPCION,COD";
				
		$result = grs($sql);
		$cx=0;
		

		//
		$s=$s."<tr id=\"z0\" ondblclick=\"z('0')\" tabindex=\"0\">";
		$s=$s."<td  width=\"70px\"></td>";
		$s=$s."<td  width=\"70px\"></td>";
		$s=$s."<td  width=\"100px\"></td>";
		$s=$s."<td  width=\"368px\"></td>";
		$s=$s."<td  width=\"65px\"></td>";
		$s=$s."<td  width=\"54px\"></td>";
		//$s=$s."<td  width=\"40px\"></td>";
	    $s=$s."</tr>";
		while ($row = $result->fetch_row()){
			$cx++;
		  //$Stock=gn("stock","stocks","id_producto=$row[1]");	
		  
			$F="id=\"z".$cx."\" tabindex=\"$cx\" ";		
			$s=$s.str_replace("*",$F,$row[0]).$row[1].$row[2].$row[3].$row[4].$row[5].$row[6];
		  
         /* $s=$s."<tr ondblclick=\"z('$row[0]')\">";
		  $s=$s."<td>".VV($row[1])."</td>";
		  $s=$s."<td>".VV(substr($row[6],0,40))."</td>";
		  $s=$s."<td>".VV(substr($row[7],0,40))."</td>";
		  $s=$s."<td>".VV(substr($row[2],0,40))."</td>";
 		  //$s=$s."<td>$Stock</td>";
		  $s=$s."<td>$row[3]</td>";
		  $s=$s."<td>$row[4]</td>";
          $s=$s."</tr>";	*/	 
		}
		if($s!=""){
        $s=$t.$s."</table>";		
		}		
		echo $s;	
	}
	///////////////////////////////////////////////////////////////////////
	if($StrCmd=="COMPRAS_PROD_FILTRAR"){
		$StrTC=gs("valor","valores","dato='T_CAMBIO'");		
		$StrMar=$StrPar2."%";
		$StrCod=$StrPar3."%";
		$StrAlm=$StrPar4."%";
		$StrCod=str_replace("@","+",$StrCod);
		$StrDes=$StrPar."%";
		$StrDes=str_replace("@","+",$StrDes);
		$StrAlm_=gn("id_almacen","almacenes","alm_nombre='$StrAlm'");
		///////////////////////////////////////////////////////////////////////
		$s="<table width=\"755\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#d4e3e5\" class=\"estilo777\" style=\"table-layout:fixed\">";
		$t=$s;
		$s="";
		$sql="SELECT ID,COD,DESCRIPCION,PC_SOL,ROUND(PC_SOL / $StrTC,1),MARCA ".
		     "FROM vproductos ".
			 "WHERE ".
			 "DESCRIPCION LIKE '$StrDes' AND MARCA LIKE '$StrMar' AND COD Like '$StrCod' ORDER BY DESCRIPCION,COD";

		$result = grs($sql);
		$cx=0;
		//onmouseover=\"this.style.backgroundColor='#ffff66'\" onmouseout=\"this.style.backgroundColor='#d4e3e5'\" 
		//
		$s=$s."<tr >";
		$s=$s."<td  width=\"90px\"></td>";
		$s=$s."<td  width=\"240px\"></td>";
		$s=$s."<td  width=\"80px\"></td>";
		$s=$s."<td  width=\"40px\"></td>";
		$s=$s."<td  width=\"40px\"></td>";
		//$s=$s."<td  width=\"40px\"></td>";
	    $s=$s."</tr>";
		while ($row = $result->fetch_row()){
		  //$Stock=gn("stock","stocks","id_producto=$row[1]");	
          $s=$s."<tr ondblclick=\"z('$row[0]')\">";
		  $s=$s."<td>".VV($row[1])."</td>";
		  $s=$s."<td>".VV(substr($row[2],0,40))."</td>";
		  $s=$s."<td>".VV(substr($row[5],0,35))."</td>";
 		  //$s=$s."<td>$Stock</td>";
		  $s=$s."<td>$row[3]</td>";
		  $s=$s."<td>$row[4]</td>";
          $s=$s."</tr>";		 
		}
		if($s!=""){
        $s=$t.$s."</table>";		
		}		
		echo $s;	
	}
	//-------------------------------------------------------------------------------------
	if($StrCmd=="FILTRAR_GUIA"){
		$StrTC=gs("valor","valores","dato='T_CAMBIO'");		
		$StrMar=$StrPar2."%";
		$StrCod=$StrPar3."%";
			$StrCod=str_replace("@","+",$StrCod);
		$StrAlm=$StrPar4;
		$StrDes="%".$StrPar."%";
			$StrDes=str_replace("@","+",$StrDes);
		$StrAlm_=gn("id_almacen","almacenes","alm_nombre='$StrAlm'");
		///////////////////////////////////////////////////////////////////////
		$s="<table width=\"1080\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"table-layout:fixed\">";
		$t=$s;
		$s="";
		//			
		$sql="SELECT CONCAT('@ ',' * ',':','z(',ID,')>'),
				CONCAT('%',COD,';'),
				CONCAT('%',TRIM(LEFT(LINEA,45)),';'),
				CONCAT('%',TRIM(LEFT(DESCRIPCION,45)),';'),
				CONCAT('%',TRIM(LEFT(MARCA,45)),';'),			  
				CONCAT('%',ROUND(PC_SOL,1),';'),
				CONCAT('%',ROUND(PC_SOL / $StrTC,1),';#')
				FROM vproductos 
				WHERE DESCRIPCION LIKE '$StrDes' AND ".
				"MARCA LIKE '$StrMar' AND ".
				"COD Like '$StrCod' ORDER BY DESCRIPCION,COD";
					
		$result = grs($sql);
		$cx=0;
		//onmouseover=\"this.style.backgroundColor='#ffff66'\" onmouseout=\"this.style.backgroundColor='#d4e3e5'\" 
		//
		$s=$s."<tr id=\"z0\" ondblclick=\"z('0')\" tabindex=\"0\">";
		$s=$s."<td  width=\"128px\"></td>";
		$s=$s."<td  width=\"155px\"></td>";
		$s=$s."<td  width=\"400px\"></td>";
		$s=$s."<td  width=\"142px\"></td>";
		$s=$s."<td  width=\"56px\"></td>";
		$s=$s."<td  width=\"56px\"></td>";
		$s=$s."<td  width=\"56px\"></td>";
		$s=$s."<td  width=\"56px\"></td>";
	    $s=$s."</tr>";
		//
		while ($row = $result->fetch_row()){
			$cx++;
			$Stock=gn("stock","stocks","id_producto=$row[0] AND id_almacen=$StrAlm_");				
			$F="id=\"z".$cx."\" tabindex=\"$cx\" ";		
			$s=$s.str_replace("*",$F,$row[0]).$row[1].$row[2].$row[3].$row[4]."%".$Stock.";".$row[5].$row[6];
 			
		}
		if($s!=""){
	        $s=$t.$s."</table>";		
		}		
		echo $s;	
	}
//-------------------------------------------------------------------------------------
	if($StrCmd=="FILTRAR_TRASFERENCIA"){
		$StrTC=gs("valor","valores","dato='T_CAMBIO'");		
		$StrMar=$StrPar2."%";
		$StrCod=$StrPar3."%";
		$StrCod=str_replace("@","+",$StrCod);
		$StrDes=$StrPar."%";
		$StrDes="%".str_replace("@","+",$StrDes);
		$StrAlm=$StrPar4;
		$StrAlm_=gn("id_almacen","almacenes","alm_nombre='$StrAlm'");
		///////////////////////////////////////////////////////////////////////
		$s="<table width=\"1080\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" class=\"estilo777\" style=\"table-layout:fixed\">";
		$t=$s;
		$s="";
		//
		$sql="SELECT CONCAT('@ ',' * ',':','z(',ID,')>'),
			  CONCAT('%',COD,';'),
			  CONCAT('%',TRIM(LEFT(DESCRIPCION,45)),';'),
			  CONCAT('%',ROUND(PC_SOL,1),';'),
			  CONCAT('%',ROUND(PC_SOL / $StrTC,1),';#'),
			  CONCAT('%',TRIM(LEFT(MARCA,35)),';'),
			  CONCAT('%',TRIM(LEFT(LINEA,35)),';'),ID
			  FROM vproductos 
			  WHERE DESCRIPCION LIKE '$StrDes' AND MARCA LIKE '$StrMar' AND COD Like '$StrCod' 
			  ORDER BY DESCRIPCION,COD";
		$result = grs($sql);
		$cx=0;
		//onmouseover=\"this.style.backgroundColor='#ffff66'\" onmouseout=\"this.style.backgroundColor='#d4e3e5'\" 
		//
		$s=$s."<tr >";
		$s=$s."<td  width=\"80px\"></td>";
		$s=$s."<td  width=\"180px\"></td>";
		$s=$s."<td  width=\"415px\"></td>";
		$s=$s."<td  width=\"120px\"></td>";
		$s=$s."<td  width=\"56px\"></td>";
		$s=$s."<td  width=\"56px\"></td>";
		$s=$s."<td  width=\"56px\"></td>";
		$s=$s."<td  width=\"56px\"></td>";
	    $s=$s."</tr>";
		while ($row = $result->fetch_assoc()){
			$cx++;	
			$Stock=gn("stock","stocks","id_producto=$row[ID] AND id_almacen=$StrAlm_");
			
			$F="id=\"z".$cx."\" tabindex=\"$cx\" ";
			$s=$s.str_replace("*",$F,$row[0]).$row[1].$row[6].$row[2].$row[5]."%".$Stock.";".$row[3].$row[4];
		  
          /*$s=$s."<tr ondblclick=\"z('$row[0]')\">";
		  $s=$s."<td>".VV($row[1])."</td>";
		  $s=$s."<td>".VV(substr($row[6],0,35))."</td>";
		  $s=$s."<td>".VV(substr($row[7],0,35))."</td>";
		  $s=$s."<td>".VV(substr($row[2],0,40))."</td>";
		  $s=$s."<td>".VV(substr($row[5],0,35))."</td>";
 		  $s=$s."<td>$Stock</td>";
		  $s=$s."<td>$row[3]</td>";
		  $s=$s."<td>$row[4]</td>";
          $s=$s."</tr>";
		  */	 
		}
		if($s!=""){
        $s=$t.$s."</table>";		
		}		
		echo $s;	
	}
//-------------------------------------------------------------------------------------
	if($StrCmd=="FILTRAR_COMPRAS"){
		$StrTC=gs("valor","valores","dato='T_CAMBIO'");		
		$StrMar=$StrPar2."%";
		$StrCod=$StrPar3."%";
		$StrCod=str_replace("@","+",$StrCod);
		$StrDes=$StrPar."%";
		$StrDes=str_replace("@","+",$StrDes);
		$StrAlm=$StrPar4;
		$StrAlm_=gn("id_almacen","almacenes","alm_nombre='$StrAlm'");
		///////////////////////////////////////////////////////////////////////		
		///////////////////////////////////////////////////////////////////////
		$s="<table width=\"1080\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\"  style=\"table-layout:fixed\">";
		$t=$s;
		$s="";
		//
		$FF=STR_OK(str_replace("@","+",$StrPar));
		$LL=explode(" ",$FF);
		$WW="";
		if(count($LL)>0){
			for($i=0;$i<count($LL);$i++){
				if(strlen(trim($LL[$i]))>0){
					$WW=$WW." CONCAT(LINEA,' ',MODELO,' ',DESCRIPCION) LIKE '%".$LL[$i]."%' AND";
				}
			}
		}
		//
		if(strlen($WW)>0){
			$WW="(".vbmid($WW,1,strlen($WW)-3).")";
		}else{
			$WW="CONCAT(LINEA,' ',MODELO,' ',DESCRIPCION) LIKE '%".$Des."%'";
		}
		//
		$sql="SELECT CONCAT('@ ',' * ',':','z(',ID,')>'),							
							CONCAT('%',COD,';'),														
							CONCAT('%',SUBSTRING(LINEA,1,13),';'),							
							CONCAT('%',TRIM(LEFT(DESCRIPCION,45)),';'),							
							CONCAT('%',ROUND(PC_SOL,1),';'),
							CONCAT('%',ROUND(PC_SOL / $StrTC,1),';#'), ID							
							FROM vproductos WHERE $WW AND COD Like '$StrCod' ORDER BY DESCRIPCION,COD";								

		$result = grs($sql);
		$cx=0;
		//
		$s=$s."<tr id=\"z0\" ondblclick=\"z('0')\" tabindex=\"0\">";
		$s=$s."<td  width=\"128px\"></td>";
		$s=$s."<td  width=\"142px\"></td>";
		$s=$s."<td  width=\"555px\"></td>";
		$s=$s."<td  width=\"56px\"></td>";
		$s=$s."<td  width=\"56px\"></td>";
		$s=$s."<td  width=\"56px\"></td>";
		$s=$s."<td  width=\"40px\"></td>";
	    $s=$s."</tr>";
		//
		while ($row = $result->fetch_assoc()){
			$cx++;
		  	//$Stock=gn("stock","stocks","id_producto=$row[ID] AND id_almacen=$StrAlm_");	
			
			$STOCK=gn("stock","stocks","id_producto=$row[ID] AND id_almacen=$StrAlm_");
		  
		  	$F="id=\"z".$cx."\" tabindex=\"$cx\" ";
		  	$s=$s.str_replace("*",$F,$row[0]).$row[1].$row[2].$row[3]."%".$STOCK.";".$row[4].$row[5];
         /* $s=$s."<tr ondblclick=\"z('$row[ID]')\">";
		  $s=$s."<td>".VV($row['COD'])."</td>";
		  $s=$s."<td>".VV($row['FAK'])."</td>";
		  $s=$s."<td>".VV($row['MOK'])."</td>";
		  $s=$s."<td>".VV($row['LIK'])."</td>";
		  $s=$s."<td>".VV($row['DEK'])."</td>";
 		  $s=$s."<td>$Stock</td>";
		  $s=$s."<td>$row[PK1]</td>";
		  $s=$s."<td>$row[PK2]</td>";
          $s=$s."</tr>";
		  */		 
		}
		if($s!=""){
        $s=$t.$s."</table>";		
		}		
		echo $s;	
	}
//-------------------------------------------------------------------------------------
	if($StrCmd=="FIL_STOCK_MIN"){
		$Alm_=gn("id_almacen","almacenes","alm_nombre='".$StrPar."'");
		$Cod=$StrPar2."%";
		//$Cod=str_replace("@","+",$Cod);
		$Des="%".$StrPar3."%";
		//$Des=str_replace("@","+",$Des);
		$Mar=$StrPar4."%";

		
		$s="<table width=\"1125px\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" class=\"estilo777\" style=\"table-layout:fixed\">";
		$t=$s;
		$s="";
		
		/*$sql="SELECT ID_PRO,ID_ALM,COD,DES,MAR,FAB,MODELO FROM vstocks 
			  WHERE COD LIKE '$Cod' AND DES LIKE '$Des' AND MAR LIKE '$Mar' AND ID_ALM=$Alm_ 
			  ORDER BY DES";*/

		$sql="SELECT CONCAT('@ ',' * ',':','z(',ID_PRO,')>'),							
							CONCAT('%',COD,';'),
							CONCAT('%',SUBSTRING(DES,1,13),';'),
							CONCAT('%',SUBSTRING(MAR,1,13),';#'),
							CONCAT('%',SUBSTRING(FAB,1,45),';'),
							CONCAT('%',SUBSTRING(MODELO,1,45),';')																
							FROM vstocks  WHERE COD LIKE '$Cod' AND DES LIKE '$Des' AND MAR LIKE '$Mar' AND ID_ALM=$Alm_ 
			  				ORDER BY DES";
			  
		$result = grs($sql);
		
		$cx=0;
		$s=$s."<tr id=\"z0\" ondblclick=\"z('0')\" tabindex=\"0\">";
		$s=$s."<td  width=\"117px\"></td>";
		$s=$s."<td  width=\"117px\"></td>";
		$s=$s."<td  width=\"117px\"></td>";
		$s=$s."<td  width=\"314px\"></td>";
		$s=$s."<td  width=\"110px\"></td>";
	    $s=$s."</tr>";
		
		
		
		while ($row = $result->fetch_row()){		 
         /* $s=$s."<tr style=\"background:#FFFFFF; color:#000; font-size:14px;\" ondblclick=\"z('$row[0]')\">";
		  $s=$s."<td>".$row[2]."</td>";
		  $s=$s."<td>".$row[5]."</td>";
		  $s=$s."<td>".$row[6]."</td>";
		  $s=$s."<td>".$row[3]."</td>";
		  $s=$s."<td>".$row[4]."</td>";
          $s=$s."</tr>";*/
		  
		$cx++;
		
		$F="id=\"z".$cx."\" tabindex=\"$cx\" ";
		$s=$s.str_replace("*",$F,$row[1]).$row[4].$row[5].$row[2].$row[3];
		//$s=$s.str_replace("*",$F,$row[2]).$row[1].$row[2].$row[3].$row[4];
		}

		
		if($s!=""){
        $s=$t.$s."</table>";		
		}		
		echo $s;
		
	}
//
if($StrCmd=="FIL_STOCK_MIN_ID"){
	$StrId=$StrPar;
	$StrCod=gs("COD","vproductos","ID=$StrId");
	$StrDes=gs("DESCRIPCION","vproductos","ID=$StrId");
	$StrMar=gn("MARCA","vproductos","ID=$StrId");
	//
	echo "<input name=\"TCod\" type=\"hidden\" id=\"TCod\" value=\"$StrCod\"/>
	<input name=\"TDes\" type=\"hidden\" id=\"TDes\" value=\"$StrDes\"/>
	<input name=\"T_ID\" type=\"hidden\" id=\"T_ID\" value=\"$StrId\"/>
	<input name=\"TMar\" type=\"hidden\" id=\"TMar\" value=\"$StrMar\"/>";	
	return;
}
//-------------------------------------------------------------------------------------


	if($StrCmd=="AJ_PROD_FILTRAR"){
		$StrTC=gs("valor","valores","dato='T_CAMBIO'");		
		$Mar=$StrPar3."%";
		$Cod=$StrPar4."%";
		$Cod=str_replace("@","+",$Cod);
		$Des=$StrPar."%";
		$Des="%".str_replace("@","+",$Des);
		$Alm_=gn("id_almacen","almacenes","alm_nombre='".$StrPar2."'");
		$s="<table width=\"820\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"table-layout:fixed\">";
		$t=$s;
		$s="";
		//
		$sql="SELECT CONCAT('@ ',' * ',':','z(',ID_PRO,')>'),
				CONCAT('%',COD,';'),	
				CONCAT('%',TRIM(LEFT(LIN,35)),';'),
				CONCAT('%',TRIM(LEFT(DES,45)),';'),	
				CONCAT('%',TRIM(LEFT(MAR,35)),';'),		  
				CONCAT('%',ROUND(PC_SOL,1),';'),
				CONCAT('%',ROUND(PC_SOL / $StrTC,1),';'),				
				CONCAT('%',STOCK,';#')				
				FROM vstocks 
				WHERE COD LIKE '$Cod' AND DES LIKE '$Des' AND 
				MAR LIKE '$Mar' AND ID_ALM =$Alm_ 
				ORDER BY DES";
		//
		$cx=0;
		$s=$s."<tr id=\"z0\" ondblclick=\"z('0')\" tabindex=\"0\">";
		$s=$s."<td  width=\"90px\"></td>";
		$s=$s."<td  width=\"170px\"></td>";
		$s=$s."<td  width=\"380px\"></td>";
		$s=$s."<td  width=\"140px\"></td>";
		$s=$s."<td  align=\"right\" width=\"50px\"></td>";
		$s=$s."<td  align=\"right\" width=\"50px\"></td>";
	    $s=$s."</tr>";
		
		$result = grs($sql);
		while ($row =$result->fetch_assoc()){
			$cx++;			
			$F="id=\"z".$cx."\" tabindex=\"$cx\" ";		
			$s=$s.str_replace("*",$F,$row[0]).$row[1].$row[2].$row[3].$row[4].$row[7]; 			
		}
		if($s!=""){
        $s=$t.$s."</table>";		
		}		
		echo $s;	
	}	
	echo "";
?>
