<?php
include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
$COD=V($_GET['COD']);
if(strlen($COD)>0){	
	if($COD=="TODOS"){
		$s="SELECT pro_id,pro_pie FROM t_productos ORDER BY id_pro";
	}else{
		$s="SELECT pro_id,pro_pie FROM t_productos WHERE pro_cod='$COD' ORDER BY id_pro";
	}
	$rs = grs($s);
	while ($r = $rs->fetch_assoc()){
		$_IDP=$r['pro_id'];
		$_PIE=$r['pro_pie'];
		$_TRA=gn("SUM(CA)","vcom_control","IDP=$_IDP AND PIE=$_PIE AND ANU='N' AND ET='SI' ");
//echo "SELECT * FROM vcot_control WHERE IDP=$_IDP AND PIE=$_PIE AND ANU='N' AND PRI='1'";
		$_SEP=gn("SUM(CA_CONTROL - DEJ)","vcot_control","IDP=$_IDP AND PIE=$_PIE AND ANU='N' AND PRI='1'") ;
		//echo $_SEP."<br>";	
		$_SEP=$_SEP + gn("SUM(CA_CONTROL - DEJ)","vven_control","IDP=$_IDP AND PIE=$_PIE AND ANU='N' AND PRI=1 ");
		//echo $_SEP."<br>";
		$s="UPDATE t_productos SET pro_sep=$_SEP,pro_etr=$_TRA WHERE pro_id=$_IDP AND pro_pie=$_PIE";
		ejt($s);
		//echo $s."<br>";
	}
	echo "OK";
}

?>