<?php
include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
$s="select sp_id_producto as ID_PRO 
	from stocks_presentaciones 
	WHERE sp_id_producto=32181 AND sp_presentacion=72 
	GROUP BY 1";
$rs=grs($s);
while($r=$rs->fetch_assoc()){
	$PRO=$r['ID_PRO'];
	$z="SELECT sp_presentacion as PIE
		FROM stocks_presentaciones 
		WHERE sp_id_producto=$PRO AND sp_presentacion=72 GROUP BY 1";
	$rz=grs($z);
	while($z=$rz->fetch_assoc()){
		$PIE=$z['PIE'];
		echo "PIEZAS=".$PIE."<br>";
		echo "==================================================<br>";
		$TOT_COM=gn("SUM(CA)","vkar_com","ID_PRO=$PRO AND ET='NO' AND UNI=$PIE");
		echo "TOT COM=".$TOT_COM."<br>";
		
		$TOT_GIA=gn("SUM(CA)","vkar_gui","ID_PRO=$PRO AND UNI=$PIE");	
		echo "TOT GIA=".$TOT_GIA."<br>";
		
		$TOT_GIN=gn("SUM(CA)","vkar_gui_int","ID_PRO=$PRO AND PIE=$PIE");
		echo "TOT GIN=".$TOT_GIN."<br>";
		
		$TOT_AJP_SAL=gn("SUM(CA)","vkar_ajup","ID_PRO=$PRO AND ACC='Q' AND PIE=$PIE");	
		echo "TOT AJP SAL=".$TOT_AJP_SAL."<br>";
					
		$TOT_AJP_ING=gn("SUM(CA)","vkar_ajup","ID_PRO=$PRO AND ACC='A' AND PIE=$PIE");	
		echo "TOT AJP ING=".$TOT_AJP_ING."<br>";
		
		//TRANSFORMACIONES
		$TOT_VEN=gn("SUM(CA)","vkar_ven","ID_PRO=$PRO AND UNI=$PIE");	
		echo "TOT VEN=".$TOT_VEN."<br>";
		
		$TOT_DEV=gn("SUM(CA)","vkar_devoluciones","ID_PRO=$PRO AND PIE=$PIE");
		echo "TOT DEV=".$TOT_DEV."<br>";
		
	}
		
}
?>