<?php
ini_set("session.cookie_lifetime",60*60*10);
ini_set("session.gc_maxlifetime", 60*60*10);
	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']);
	$StrPar8=V($_GET['TxtPar8']);
	
	///////////////////////////////////////////////////////////////////////
	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("LINEA","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=="G_PROD"){
		$StrId=gn("id_producto","productos","pro_codigo='$StrPar'");
		$S_COD=gs("COD","vproductos","ID=$StrId");
		$S_DES=gs("DESCRIPCION","vproductos","ID=$StrId");	
		echo "<input name=\"PRO_TxtCOD\" type=\"hidden\" id=\"PRO_TxtCOD\" value=\"$S_COD\"/>
		<input name=\"PRO_TxtDES\" type=\"hidden\" id=\"PRO_TxtDES\" value=\"$S_DES\"/>";
		return;	

	}

	if($StrCmd=="V_AGRE_V"){
		$StrALM=$StrPar;
		$StrCOD=$StrPar2;
		$StrPRE=$StrPar3;
		$StrCAN=$StrPar4;
		$StrUNI=$StrPar5;
		$StrGT="";
		//
		$IDAlm=gn("id_almacen","almacenes","alm_obs='$StrALM'");
		$IDPro=gn("id_producto","productos","pro_codigo='$StrCOD'");
		//
		$S_Stock=gn("sp_cantidad","stocks_presentaciones","sp_id_almacen=$IDAlm AND sp_id_producto=$IDPro AND 
		sp_presentacion=$StrUNI");
		//
		if(strlen($StrGT)==0){
			if($S_Stock<=0)$StrGT="1";			
		}
		//
		if(strlen($StrGT)==0){
			if($S_Stock<$StrCAN)$StrGT="2";			
		}
		echo $StrGT;
		return;	
	}

	if($StrCmd=="V_AGRE_T"){
		$StrALM=$StrPar;
		$StrCOD=$StrPar2;
		$StrCAN=$StrPar3;
		$StrUNI=$StrPar4;
		$StrGT="";
		//
		$IDAlm=gn("id_almacen","almacenes","alm_obs='$StrALM'");
		$IDPro=gn("id_producto","productos","pro_codigo='$StrCOD'");
		//
		$S_Stock=gn("sp_cantidad","stocks_presentaciones",
					"sp_id_almacen=$IDAlm AND sp_id_producto=$IDPro AND sp_presentacion=$StrUNI");
		//
		if(strlen($StrGT)==0){
			if($S_Stock<=0)$StrGT="1";			
		}
		//
		if(strlen($StrGT)==0){
			if($S_Stock<$StrCAN)$StrGT="2";			
		}
		echo $StrGT;
		return;	
	}


	if($StrCmd=="V_PROD"){
		$StrCOD=$StrPar;
		$StrALM=$StrPar2;
		$StrCan=$StrPar3;
		$StrDe1=$StrPar4;
		$StrUXC=$StrPar5;
		$StrACI=$StrPar6;
		$StrDe2=$StrPar7;
		$StrEmp=$StrPar8;
		$StrGT="";	
		//
		if(strlen($StrEmp)>0){
			$StrEmp=gn("id_emp","empresas","emp_nomc='$StrEmp'");
			$IDAlm=gn("id_almacen","almacenes",
					  "alm_obs='$StrALM' AND alm_id_empresa=$StrEmp");
		}else{
			$IDAlm=gn("id_almacen","almacenes","alm_obs='$StrALM'");
		}
		$IDPro=gn("id_producto","productos","pro_codigo='$StrCOD'");
		

		if(strlen($StrGT)==0){
			if(gn("count(*)","stocks_presentaciones",
				  "sp_id_almacen=$IDAlm AND sp_id_producto=$IDPro AND 
				   sp_presentacion=$StrUXC")==0){
			$StrGT="1";	
			}
		}
		if(strlen($StrGT)==0){
			$B_Stock=gn("sp_cantidad",
					    "stocks_presentaciones",
						"sp_id_almacen=$IDAlm AND 
						sp_id_producto=$IDPro AND sp_presentacion=$StrUXC");
			if($StrDe1>$B_Stock)$StrGT="2";	
		}
		if(strlen($StrGT)==0){
			if(gn("count(*)","stocks_presentaciones","sp_id_almacen=$IDAlm AND sp_id_producto=$IDPro AND 
				sp_presentacion=$StrDe2")==0 && $StrDe2!=0){
			$StrGT="3";	
			}
		}
		if(strlen($StrGT)==0){
			$D_Stock=gs("sp_cantidad","stocks_presentaciones","sp_id_almacen=$IDAlm AND sp_id_producto=$IDPro AND
			 sp_presentacion=$StrDe2");
			if(strlen($D_Stock)!=""){
			if($StrACI>$D_Stock)$StrGT="4";	
			}
		} 		
		//
		if(strlen($StrGT)==0){			
			$CT=(($StrCan*$StrDe1)/$StrACI)+$StrDe2;
			if($StrDe2==0){	
				$s="UPDATE stocks_presentaciones SET 
				sp_cantidad=sp_cantidad-$StrDe1
				WHERE sp_id_almacen=$IDAlm AND sp_id_producto=$IDPro AND sp_presentacion=$StrUXC";
				ejt($s);
			
				if(gn("count(*)","stocks_presentaciones","sp_id_almacen=$IDAlm AND sp_id_producto=$IDPro AND 
				 	sp_presentacion=$StrUXC-$StrCan")==0 && ($StrUXC-$StrCan)>0){
					$s="INSERT INTO stocks_presentaciones VALUES ($IDAlm,$IDPro,$StrUXC-$StrCan,$StrDe1,$PRO_SI)";
					ejt($s);					
				}else{
					$s="UPDATE stocks_presentaciones SET 
					sp_cantidad=sp_cantidad+$StrDe1
					WHERE sp_id_almacen=$IDAlm AND sp_id_producto=$IDPro AND sp_presentacion=$StrUXC-$StrCan";
					ejt($s);
				}
				//				
				if(gn("count(*)","stocks_presentaciones","sp_id_almacen=$IDAlm AND sp_id_producto=$IDPro AND 
				 	sp_presentacion=$CT")==0 && $CT>0){
					$s="INSERT INTO stocks_presentaciones VALUES ($IDAlm,$IDPro,$CT,$StrACI,$PRO_SI)";
					ejt($s);
				}else{
					$s="UPDATE stocks_presentaciones SET 
					sp_cantidad=sp_cantidad+$StrACI
					WHERE sp_id_almacen=$IDAlm AND sp_id_producto=$IDPro AND sp_presentacion=$CT";
					ejt($s);
				}
			}
			//------------------------------------------------------------------------------------
			if($StrDe2>0){
				$s="UPDATE stocks_presentaciones SET 
				sp_cantidad=sp_cantidad-$StrDe1
				WHERE sp_id_almacen=$IDAlm AND sp_id_producto=$IDPro AND sp_presentacion=$StrUXC";
				ejt($s);
				//
				$s="UPDATE stocks_presentaciones SET 
				sp_cantidad=sp_cantidad-$StrACI
				WHERE sp_id_almacen=$IDAlm AND sp_id_producto=$IDPro AND sp_presentacion=$StrDe2";
				ejt($s);
			
				if(gn("count(*)","stocks_presentaciones","sp_id_almacen=$IDAlm AND sp_id_producto=$IDPro AND 
				 	sp_presentacion=$StrUXC-$StrCan")==0 && ($StrUXC-$StrCan)>0){
					$s="INSERT INTO stocks_presentaciones VALUES ($IDAlm,$IDPro,$StrUXC-$StrCan,$StrDe1,$PRO_SI)";
					ejt($s);
				}else{
					$s="UPDATE stocks_presentaciones SET 
					sp_cantidad=sp_cantidad+$StrDe1
					WHERE sp_id_almacen=$IDAlm AND sp_id_producto=$IDPro AND sp_presentacion=$StrUXC-$StrCan";
					ejt($s);
				}

				if(gn("count(*)","stocks_presentaciones","sp_id_almacen=$IDAlm AND sp_id_producto=$IDPro AND 
				 	sp_presentacion=$CT")==0 && $CT>0){
					$s="INSERT INTO stocks_presentaciones VALUES ($IDAlm,$IDPro,$CT,$StrACI,$PRO_SI)";
					ejt($s);
				}else{
					$s="UPDATE stocks_presentaciones SET 
					sp_cantidad=sp_cantidad+$StrACI
					WHERE sp_id_almacen=$IDAlm AND sp_id_producto=$IDPro AND sp_presentacion=$CT";
					ejt($s);
				}			
			}
			T_P_ACT($IDPro);
		}	

		echo $StrGT;
		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=$StrPar;
		$StrCod=gs("COD","vproductos","ID=$StrId");
		$StrDes=gs("DESCRIPCION","vproductos","ID=$StrId");
		$StrPre=gn("PV_MAX","vproductos","ID=$StrId");
		//YA NO SE USA EL PRECIO MINIMO
		$StrPreM=$StrPre;//gn("PV_MIN","vproductos","ID=$StrId");
		$StrMar=gn("LINEA","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=="VENTAS_PROD_FILTRAR"){
		$Mar=$StrPar3."%";
		$Cod=$StrPar4."%";
		$Alm_=gn("id_almacen","almacenes","alm_obs='".$StrPar2."'");
		if(strlen($StrPar2)==0 || $StrPar2=="TODOS")$StrPar2="%";
		$s="<table width=\"758\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#d4e3e5\" class=\"estilo777\" style=\"table-layout:fixed\">";
		$t=$s;
		$s="";
		$sql="SELECT ID_PRO,COD,LEFT(DES,45),ROUND(PV_MIN,1),ROUND(PV_MAX,1),
			  LEFT(MAR,35),ROUND(SUM(STOCK),1) FROM vstocks 
			  WHERE COD LIKE '$Cod' AND DES LIKE '%$StrPar%' AND MAR LIKE '$Mar' AND ALM LIKE '$StrPar2' 
			  GROUP BY ID_PRO,COD,DES,PV_MIN,PV_MAX,MAR 
			  ORDER BY DES";
		$result = grs($sql);
		$cx=0;
		$s=$s."<tr ondblclick=\"z('0')\">";
		$s=$s."<td  width=\"125px\"></td>";
		$s=$s."<td  width=\"330px\"></td>";
		$s=$s."<td  width=\"110px\"></td>";
		$s=$s."<td  align=\"right\" width=\"50px\"></td>";
		$s=$s."<td  align=\"right\" width=\"57px\"></td>";
		$s=$s."<td  align=\"right\" width=\"53px\"></td>";
		$s=$s."</tr>";
		
		while ($row = $result->fetch_row()){		 
          $s=$s."<tr ondblclick=\"z('$row[0]')\">";
		  $s=$s."<td>".$row[1]."</td>";
		  $s=$s."<td>".$row[2]."</td>";
		  $s=$s."<td>".$row[5]."</td>";
		  $s=$s."<td  align=\"right\">".$row[3]."</td>";
		  $s=$s."<td  align=\"right\">".$row[4]."</td>";
		  $s=$s."<td  align=\"right\">".$row[6]."</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."%";
		///////////////////////////////////////////////////////////////////////
		$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,ROUND(PC_SOL,3),ROUND(PC_SOL * $StrTC,3),LINEA FROM vproductos 
			  WHERE DESCRIPCION LIKE '%$StrPar%' AND LINEA LIKE '$StrMar' AND COD Like '$StrCod' AND USO='SI' 
			  ORDER BY 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."</tr>";
		while ($row = $result->fetch_row()){
          $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>$row[3]</td>";
		  $s=$s."<td>$row[4]</td>";
          $s=$s."</tr>";
		}
		if($s!=""){
        $s=$t.$s."</table>";		
		}		
		echo $s;	
	}	
	if($StrCmd=="K_PROD_FILTRAR"){
		$StrTC=gs("valor","valores","dato='T_CAMBIO'");		
		$StrMar=$StrPar2."%";
		$StrCod=$StrPar3."%";
		///////////////////////////////////////////////////////////////////////
		$s="<table width=\"700\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#d4e3e5\" class=\"estilo777\" style=\"table-layout:fixed\">";
		$t=$s;
		$s="";
		$sql="SELECT ID,COD,DESCRIPCION,ROUND(PC_SOL,3),ROUND(PC_SOL * $StrTC,3),LINEA FROM vproductos 
			  WHERE DESCRIPCION LIKE '%$StrPar%' AND LINEA LIKE '$StrMar' AND COD Like '$StrCod' AND USO='SI' 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=\"108\"></td>";
		$s=$s."<td  width=\"473\"></td>";
		$s=$s."<td  width=\"65\"></td>";
		$s=$s."<td  width=\"54\"></td>";
	    $s=$s."</tr>";
		while ($row = $result->fetch_row()){
          $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>$row[3]</td>";
		  $s=$s."<td>$row[4]</td>";
          $s=$s."</tr>";
		}
		if($s!=""){
        $s=$t.$s."</table>";		
		}		
		echo $s;	
	}	

	if($StrCmd=="AJ_PROD_FILTRAR"){
		$StrTC=gs("valor","valores","dato='T_CAMBIO'");		
		$Mar=$StrPar3."%";
		$Cod=$StrPar4."%";
		$Alm_=gn("id_almacen","almacenes","alm_obs='".$StrPar2."'");
		$s="<table width=\"758\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#d4e3e5\" class=\"estilo777\" style=\"table-layout:fixed\">";
		$t=$s;
		$s="";
		$sql="SELECT ID_PRO,COD,LEFT(DES,45),
			 ROUND(PC_SOL,3),ROUND(PC_SOL / $StrTC,3),LEFT(MAR,35),ROUND(STOCK,1) 
			 FROM vstocks 
			 WHERE COD LIKE '$Cod' AND DES LIKE '%$StrPar%' AND 
			 MAR LIKE '$Mar' AND ID_ALM =$Alm_ 
			 ORDER BY DES";
		$result = grs($sql);
		$cx=0;
		$s=$s."<tr >";
		$s=$s."<td  width=\"125px\"></td>";
		$s=$s."<td  width=\"330px\"></td>";
		$s=$s."<td  width=\"110px\"></td>";
		$s=$s."<td  align=\"right\" width=\"50px\"></td>";
		$s=$s."<td  align=\"right\" width=\"57px\"></td>";
		$s=$s."<td  align=\"right\" width=\"53px\"></td>";
	    $s=$s."</tr>";
		
		while ($row = $result->fetch_row()){		 
          $s=$s."<tr ondblclick=\"z('$row[0]')\">";
		  $s=$s."<td>".VV($row[1])."</td>";
		  $s=$s."<td>".$row[2]."</td>";
		  $s=$s."<td>".$row[5]."</td>";
		  $s=$s."<td>$row[3]</td>";
		  $s=$s."<td>$row[4]</td>";
		  $s=$s."<td>$row[6]</td>";
          $s=$s."</tr>";
		}
		if($s!=""){
        $s=$t.$s."</table>";		
		}		
		echo $s;	
	}

	if($StrCmd=="A_FILTRAR_PRO"){
		$StrTC=gs("valor","valores","dato='T_CAMBIO'");		
		$Mar=$StrPar3."%";
		$Cod=$StrPar4."%";
		$Alm_=gn("id_almacen","almacenes","alm_obs='".$StrPar2."'");
		$s="<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#d4e3e5\" class=\"estilo777\" style=\"table-layout:fixed\">";
		$t=$s;
		$s="";
		$sql="SELECT ID,COD,DESCRIPCION,MARCA 
			 FROM vproductos 
			 WHERE COD LIKE '$Cod' AND DESCRIPCION LIKE '%$StrPar%' AND 
			 MARCA LIKE '$Mar'
			 ORDER BY DESCRIPCION";
		$result = grs($sql);
		$cx=0;
		$s=$s."<tr >";
		$s=$s."<td  width=\"16%\"></td>";
		$s=$s."<td  width=\"36%\"></td>";
		$s=$s."<td  width=\"50%\"></td>";
	    $s=$s."</tr>";
		
		while ($row = $result->fetch_row()){		 
          $s=$s."<tr ondblclick=\"z('$row[0]')\">";
		  $s=$s."<td>".$row[1]."</td>";
		  $s=$s."<td>".$row[2]."</td>";
		  $s=$s."<td>".$row[3]."</td>";
          $s=$s."</tr>";
		}
		if($s!=""){
        $s=$t.$s."</table>";		
		}		
		echo $s;	
	}	
	echo "";
?>