<?php
include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");

//
$KIL=0;
$OK=0;
$NO_OK=0;
$ER=0;
$s="SELECT * FROM cobroz_ventas WHERE cv_cob_anu='NO' ORDER BY id_cv";
$rs=grs($s);
while($r=$rs->fetch_assoc()){
	$ID_CV=$r['id_cv'];
	$VEN_ID=$r['cv_id_ven'];
	$COB_ID=$r['cv_id_cob'];
	$VX=gn("count(*)","ventas","id_venta=$VEN_ID");
	$CX=gn("count(*)","cobroz","id_cobro=$COB_ID");
	if($VX==1 && $CX==1){
		$VEN_COT_KOD=VEN_GET_COT_KOD($VEN_ID);
		$COB_COT_KOD=COB_GET_COT_KOD($COB_ID);
		if($VEN_COT_KOD!=$COB_COT_KOD){
			echo "ERROR : VENTA =".$VEN_ID." VENTA->COT_COD = ".$VEN_COT_KOD." // COBRO = ".$COB_ID." COBRO->COT_COD = ".$COB_COT_KOD."<br>";
			$s="DELETE FROM cobroz_ventas WHERE id_cv=$ID_CV";
			ejt($s);
			$KIL++;
		}else{
			$VEN_COB=gn("ven_cob_kod","ventas","id_venta=$VEN_ID");		
			if($VEN_COB==$COB_ID){
				$OK++;
			}else{
				$ER++;				
				echo "CORREGIR : VENTA =".$VEN_ID." VENTA->VEN_COB=".$VEN_COB." DEBERIA SER : ".$COB_ID."<br>";			
			}
		}
	}else{
		echo "INCOHERENCIA : VX=".$VX." / VENTA = ".$VEN_ID." / CX=".$CX." COBRO = ".$COB_ID."<br>";
		$s="DELETE FROM cobroz_ventas WHERE id_cv=$ID_CV";
		ejt($s);
		$KIL++;
	}
}
echo "OK=".$OK."<br>";
echo "NO_OK=".$NO_OK."<br>";
echo "ER=".$ER."<br>";
echo "KIL=".$KIL."<br>";
?>