<?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");
//
$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']);	
//
if($CM=="VS_JUN"){
	$ALM=trim($P1);	
	$PRO=vbval($P2);
	$CAN=vbval($P3);
	$UNI=vbval($P4);
	$ALM="TODOS";
	$XXX=0;
	if($ALM=="TODOS"){
		$XXX=gn("SUM(pro_sto - pro_sep)",
				"t_productos",
				"pro_id=$PRO AND ".
				"pro_pie=$UNI");		
	}else{
		$ALM=gn("id_almacen","almacenes","alm_obs='$ALM'");
		$XXX=gn("SUM(sp_cantidad)",
				"stocks_presentaciones",
				"sp_id_almacen=$ALM AND ".
				"sp_id_producto=$PRO AND ".
				"sp_presentacion=$UNI");
	}
	echo $XXX;
	return;
}
//
if($CM=="Z"){
	
}
//
if($CM=="VS"){
	$ALM=trim($P1);	
	$PRO=vbval($P2);
	$CAN=vbval($P3);
	$UNI=vbval($P4);
	if($ALM=="TODOS"){
		echo gn("SUM(sp_cantidad)",
				"stocks_presentaciones",
				"sp_id_producto=$PRO AND ".
				"sp_presentacion=$UNI");		
	}else{
		$ALM=gn("id_almacen","almacenes","alm_obs='$ALM'");
		echo gn("SUM(sp_cantidad)",
				"stocks_presentaciones",
				"sp_id_almacen=$ALM AND ".
				"sp_id_producto=$PRO AND ".
				"sp_presentacion=$UNI");
	}
	return;
}
//
if($CM=="VM"){
	$ID=vbval($P1);
	$COM_=gn("id_com","cotizaciones","id_cotizacion=$ID");
	$SER_=gn("iser","cotizaciones","id_cotizacion=$ID");
	$NUM_=gn("inum","cotizaciones","id_cotizacion=$ID");
	$CX=gn("count(*)","cobroz",
		   "cob_id_com=$COM_ AND cob_icser=$SER_ AND ".
		   "cob_icnum=$NUM_ AND cob_anu='NO'");		   
	//if($CX>0){
	//	echo "COB";
	//	return;
	//}
	$CX=gn("COUNT(*)","ventas","ven_id_com=-3 AND ven_id_ven=$ID AND anu='N'");
	if($CX>0){
		echo "VE";
		return;
	}	
	$CX=gn("COUNT(*)","guias","id_comr=-3 AND id_ref=$ID AND anu='N'");
	if($CX>0){
		echo "GR";
		return;
	}
	$CX=gn("COUNT(*)","ginterna","gi_id_cotizacion=$ID AND gi_anu='N'");
	if($CX>0){
		echo "GI";
		return;
	}
	echo "OK";
}

?>