use utf8;
use warnings; no warnings "redefine";
use strict;
use Loader qw(line_in log_update check_perm);
use Dbase::Help qw(Do qquote DoFn);
use Dbase::Globals qw(def_or_minus);
use Fehler qw(problem);

sub set_buchung_mtext($$;$) {
	my($rech,$seq,$kn) = @_;

	return undef unless check_perm("verwaltung");

	my $inh;
	my $mtext = "";
	my $mtext1;
	while(1) {
		$mtext1 = line_in(($mtext eq "") ? "Rechnungstext: " : "             : ");
		last if $mtext1 =~ /^\s*$/; last if $mtext1 eq "-";
		$inh=$mtext1 if not defined $inh;
		$mtext .= "|" if $mtext ne "";
		$mtext .= $mtext1;
	}
	return undef if $mtext eq "";
	return problem "Buchungen ohne Text gibt es nicht!\n"
		if $inh eq "-";
	return $mtext unless $rech;

	log_update("buchung","rnr",$rech,"seq",$seq,undef,"buchtext","mtext",undef,def_or_minus(DoFn("select buchtext from buchung where rnr=$rech and seq=$seq")));
	Do("update buchung set mtext=${\qquote $mtext}, buchtext=${\qquote $inh,1} where rnr=$rech and seq=$seq");
	1;
}
1;
