# Flag:
# 1  auch nicht fertige Batches tilten

use utf8;
use warnings; no warnings "redefine";
use strict;
use Dbase::Help qw(Do DoFn DoSelect);
use Loader qw(log_update valid_fnbatch line_in);

sub delete_fnbatch($;$$) {
	my($id,$kn,$flag) = @_;
	$flag=0 unless defined $flag;

	return undef if $id =~ /^\d+$/ and DoFn("select count(*) from fnbatch where id = $id") == 0;
	return undef unless valid_fnbatch($id,1,$kn);

	my($status,$mandant) = DoFn("select status,mandant from fnbatch where id = $id");

	return $id if not $flag&1 and $status != 3 and $status != 4 and line_in("Erst das geheime Paßwort: ",1) ne "geheim";

	log_update("fnbatch","id",$id,undef,"-");

	Do("delete from fnbatch where id=$id");
	
	return undef;
}
1;
