<?php
include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
$s="SELECT dt_id_und as ID_UND FROM ges_invoice_det GROUP BY dt_id_und";
$rs=grs($s);
while($r=$rs->fetch_assoc()){
	$ID_UND=$r['ID_UND'];
	$CX=gn("count(*)","ges_unidades","id_und=$ID_UND");
	if($CX==0){
		$s="UPDATE ges_invoice_det SET dt_id_und=0 WHERE dt_id_und=$ID_UND";
		ejt($s);
		echo $s."<br>";
	}
	
}
echo "OK INVOICE <br>";

$s="SELECT pro_id_und as ID_UND FROM ges_productos GROUP BY pro_id_und";
$rs=grs($s);
while($r=$rs->fetch_assoc()){
	$ID_UND=$r['ID_UND'];
	$CX=gn("count(*)","ges_unidades","id_und=$ID_UND");
	if($CX==0){
		$s="UPDATE ges_productos SET pro_id_und=0 WHERE pro_id_und=$ID_UND";
		ejt($s);
		echo $s."<br>";
	}
	
}
echo "OK PRODUCTOS <br>";


$s="SELECT xls_pro_id_und as ID_UND FROM ges_productos_referencias GROUP BY xls_pro_id_und";
$rs=grs($s);
while($r=$rs->fetch_assoc()){
	$ID_UND=$r['ID_UND'];
	$CX=gn("count(*)","ges_unidades","id_und=$ID_UND");
	if($CX==0){
		$s="UPDATE ges_productos_referencias SET xls_pro_id_und=0 WHERE xls_pro_id_und=$ID_UND";
		ejt($s);
		echo $s."<br>";
	}
	
}
echo "OK REFERENCIAS <br>";


?>