<?php

	$sqlr = mysqli_query($con ,"select * from dvnotcrd where n_reg = '$n5'");
	$rep=mysqli_fetch_array($sqlr);
	$can1 = $rep['total'];
	//sumar a dxbascpt restar saldo deudo
	$ss = mysqli_query($con ,"select * from dxbascpt where codigo = '$n2'");
	$rr=mysqli_fetch_array($ss);
	$can = $rr['sal_deu'] + $can1;
	$bus = mysqli_query($con ,"update dxbascpt set sal_deu = '$can' where codigo = '$n2'");
	//borrar el registro
	@$sqlr = mysqli_query($con ,"select * from dvnotcrd where n_reg = '$n5'");
	@$rep=mysqli_fetch_array($sqlr);
	$ccc = $rep['total'];
	$sqlx = mysqli_query($con ,"delete from dvnotcrd where n_reg = '$n5'");
	@$rr=mysqli_fetch_array($sqlx); 
	//volver a calcular el total del encabezado
	$sqlr = mysqli_query($con ,"select * from dvnotcrd where n_nota = '$n1'");
	while($reps=mysqli_fetch_array($sqlr)){
		$iii += $reps['iva_sub'];
		$sss += $reps['sub_tot'];
		$ttt += $reps['total'];
	} 
	$bus = mysqli_query($con ,"update dvnotcre set iva_not = '$iii',sub_not='$sss',tot_not='$ttt' where n_reg = '$n1'");
	//sumar para sacar saldo de dvredocl
	@$sqlr = mysqli_query($con ,"select * from dvredocl where codigo = '$n2' and num_doc = '$n3'");
	@$rep=mysqli_fetch_array($sqlr);
	$nc = $rep['tot_not'] - $ccc;
	$bus = mysqli_query($con ,"update dvredocl set tot_not = '$nc' where codigo = '$n2' and num_doc = '$n3'");
	@$sqlr = mysqli_query($con ,"select * from dvredocl where codigo = '$n2' and num_doc = '$n3'");
	@$rep=mysqli_fetch_array($sqlr);
	$cc = $rep['tot_doc'] - ($rep['tot_pag'] + $rep['tot_not']);
	@$bus = mysqli_query($con ,"update dvredocl set tot_sal = '$cc' where codigo = '$n2' and num_doc = '$n3'");
?>