<?php
	//IMPORTACIONES LQ	
	include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
	//
	function yy($s){
		if(strlen(trim($s))==0){
			return "<";
		}else{
			$s=strtoupper($s);
			$s=str_replace("Á","A",$s);
			$s=str_replace("É","E",$s);
			$s=str_replace("Í","I",$s);
			$s=str_replace("Ó","O",$s);
			$s=str_replace("Ú","U",$s);
			$s=str_replace("Ñ","<N>",$s);
			return $s;
		}
	}
	//
	$Z="|";
	$CAB="";
	$DET="";
	//
	$CM=V($_GET['C']);
	$P1=V($_GET['P1']);
	$P2=V($_GET['P2']);
	$P3=V($_GET['P3']);
	$P4=V($_GET['P4']);
	$P5=V($_GET['P5']);
	$P6=V($_GET['P6']);
	$P7=V($_GET['P7']);
	//
	$EMP=$P3;
	$SER=vbval($P1);
	$NUM=vbval($P2);
	//
	if($CM=="P_EMP_SER_NUM"){
		$EMP=V($_GET['P1']);
		$SER=vbval(V($_GET['P2']));
		$NUM=vbval(V($_GET['P3']));
		$CX=gn("count(*)","vginterna","EMPC='$EMP' AND ISER=$SER AND INUM=$NUM");
		if($CX==0){
			echo "NO_REGISTRADO";
			return;
		}
		$SER=gn("ID","vginterna","EMPC='$EMP' AND ISER=$SER AND INUM=$NUM");
		$CM="P_ID_EX";		
	}
	//
	if($CM=="P_ID_EX"){				
		$ID=$SER;		
		if($ID==0){
			echo "NR";
			return;
		}
		//
		$DET="";
		//
		$GI_ALM=y(gs("ALM","vginterna","ID=$ID"));
		$GI_SER=y(gs("SER","vginterna","ID=$ID"));
		$GI_NUM=y(gs("NUM","vginterna","ID=$ID"));
		$FE_D=y(gs("DATE_FORMAT(FEC,'%d')","vginterna","ID=$ID"));
		$FE_M=y(gs("DATE_FORMAT(FEC,'%m')","vginterna","ID=$ID"));
		$FE_A=y(gs("DATE_FORMAT(FEC,'%y')","vginterna","ID=$ID"));
		$CLI=yy(gs("CLI","vginterna","ID=$ID"));
		$CAR=yy(gs("CAR","vginterna","ID=$ID"));
		$COT_SER=y(gs("COT_SER","vginterna","ID=$ID"));
		$COT_NUM=y(gs("COT_NUM","vginterna","ID=$ID"));
		$COT_EMP=y(gs("EMPC","vginterna","ID=$ID"));
		$GI_FEC=y(gs("DATE_FORMAT(FEC,'%d-%m-%Y')","vginterna","ID=$ID"));
		//
		$COT_KOD=gn("ID_COT","vginterna","ID=$ID");
		$VENDEDOR=y(gs("VEN","vcotizaciones","ID=".$COT_KOD));
		//
		$CAB=$GI_ALM."|".$GI_SER."|".$GI_NUM."|".$FE_D."|".$FE_M."|".$FE_A."|".$CLI."|".$CAR."|".$COT_SER."|".$COT_NUM."|".$COT_EMP."|".$GI_FEC."|".$VENDEDOR;
		//
		$s="SELECT PRO_COD as COD,PRO_DES as DES, PIEZAS as PIE, CA as CAN 
		FROM vginterna_det WHERE ID=$ID ORDER BY CX";
		$rs = grs($s);			
		while ($r = $rs->fetch_assoc()){
			$COD=y($r['COD']);			
            $DES=yy($r['DES']);
			$PIE=y($r['PIE']);	
			$CAN=y($r['CAN']);					
			$DET=$DET.$COD.$Z.$DES.$Z.$PIE.$Z.$CAN."=";
		}
		$DAT=$CAB."'".$DET."'PROCESO_COMPLETADO";
		echo $DAT;return;	
	}
?>