<?php
 
	//buscar la nota
	$bus = mysqli_query($con ,"select * from dvnotcrd where n_reg = '$bbus'");
	$rr = mysqli_fetch_array($bus);
	//saco la cantidad
	$t = $rr['total'];
	//resto al saldo deudor
	$bus = mysqli_query($con ,"select * from dxbascpt where codigo = '".$rr['codigo']."'");
	$rrr = mysqli_fetch_array($bus);
	$cc = $rrr['sal_deu'] - $t;
	$bus = mysqli_query($con ,"update dxbascpt set sal_deu = '$cc' where codigo = '".$rr['codigo']."'");

	//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 valores otra vez
	@$sqlr = mysqli_query($con ,"select * from dvredocl where codigo = '".$rr['codigo']."' and num_doc = '".$rr['num_doc']."'");
	@$rep=mysqli_fetch_array($sqlr);
	$nc = $rep['tot_not'] + $n2;
	$bus = mysqli_query($con ,"update dvredocl set tot_not = '$nc' where codigo = '".$rr['codigo']."' and num_doc = '".$rr['num_doc']."'");
	@$sqlr = mysqli_query($con ,"select * from dvredocl where codigo = '".$rr['codigo']."' and num_doc = '".$rr['num_doc']."'");
	@$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 = '".$rr['codigo']."' and num_doc = '".$rr['num_doc']."'");


?>