
| Current Path : /home/ift/52_procpy/finance/misc/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : //home/ift/52_procpy/finance/misc/IfTRules_ift.pm |
package DivBasicF::IfTRules_ift;
use strict;
use Data::Dumper;
sub DELIVER { 2 }
#***********************************************************************************
sub new {
my $class = shift;
my $self = {};
bless($self,$class);
my $file = shift;
my $files = [];
if (!($file)) { # Kontofile suchen
opendir(DDIR,".");
while (0 == 0) {
$file = readdir(DDIR);
last if (!$file);
next if ($file !~ /\.(csv|kto|sql)$/ or $file =~ /^sync/);
push(@$files,$file);
}
closedir(DDIR);
} else {
$files = [$file];
}
if ($#$files > 0) {
print "Ambiguous, found files: " . Dumper($files); exit;
}
if (!@$files) {
print "No file found.\n"; exit;
}
if (!(-f($files->[0]))) {
print "File $file does not exist.\n"; exit;
}
open(FFILE,"<".$files->[0]);
$self->{'TEXT'} = join("",<FFILE>);
close(FFILE);
$self->{'FILE'} = $files->[0];
return($self);
}
#***********************************************************************************
sub store {
my $self = shift;
my $text = shift;
open(FFILE,">".$self->{'FILE'});
print FFILE $text;
close(FFILE);
return($text);
}
#***********************************************************************************
#***********************************************************************************
sub render_kasse {
my $self = shift;
my $text = shift;
my $mode = shift;
my $person = shift;
my $o; my $o1; my $o2; my $o3; my @ee; my $zeile; my $zeile1; my $p1;
my $text1 = "";
$text =~ s/^\n(\d\d)\.(\d\d)\.(9\d) /\n19$3$2$1 /;
$text =~ s/^\n(\d\d)\.(\d\d)\.(\d\d) /\n20$3$2$1 /;
while ($text =~ s/\n(\d\d\d\d\d\d\d\d\;.*?)\n/\n---INSERT---\n/s) {
$o = $1;
$o =~ s/[\,\; ]+$//;
$o =~ s/\"\;\"/ /gs;
$o =~ s/\"//gs;
$o =~ s/\;\+\+/\;qq/;
$o =~ s/\;\+\-/\;qw/;
next if ($o !~ /^(\d\d\d\d\d\d\d\d)\;(.*?)\;(.*)$/);
$o1 = $1; $o2 = $2; $o3 = $3;
$o2 =~ s/,/\./;
$o2 = sprintf("%3.2f",$o2);
$p1 = "cgabriel";
if ($o3 =~ /(mherrschel|tjungblut|arjasanow|ccsengery|ddienlin)/) {
$p1 = $1;
} else {
$p1 = "mherrschel" if ($o3 =~ /Copy/);
}
# print "XX: $person $p1 $o3\n"; sleep 1;
next if ($p1 ne $person);
if ($mode == 1) {
1;
} else {
$text1 = $text1 . "$o1 -"."$o2 - 13-9999 0.00 $o3\n";
}
}
$text =~ s/\n---INSERT---\n/$text1/s;
$text =~ s/---INSERT---\n//gs;
return($text);
}
#*******************************************************************************************
sub render_sparkasse {
my $self = shift;
my $text = shift || $self->{'TEXT'};
my @files = @_;
my $o; my $o1; my $zeile; my $zeile1; my @ee; my $type;
my $text1 = "";
foreach $o (@files) {
next if ($o =~ /^(.*)\~$/);
$type = `file -i '$o'`;
print "File: $type\n";
if ($type =~ /charset\=(\S+)/) {
$o1 = $1;
if ($o1 ne "utf-8" and $o1 =~ /(iso|ascii)/) {
system("cp " . $o . " " . $o . "~");
print("iconv -f $o1 -t utf-8 $o\n");
system("iconv -f $o1 -t utf-8 $o"."~ > $o");
}
}
open(FFILE,"<".$o);
$text1 = $text1 . join("",<FFILE>);
close(FFILE);
}
$text1 =~ s/\"//gs;
$text1 =~ s/(\d+\,\d+)([^\n]+)(ABWA\+)F/$1$2AxBxWxAx\+F/g;
$text1 =~ s/(GUTSCHRIFT)([^\n]+)(AxBxWxAx\+)F/$1$2ABWA\+F/g;
while ($text1 =~ s/\n(.[^\n]*?\;|.[^\n]*?\;FOLGE)LASTSCHRIFT(.[^;]*?)(218\/129\/)([\d ]+)([^;]*?)([\d\. ]+,[\d ]+)(E ?U ?R|)/\n$1LASTSCHRIFT$2$3$4/) {
$text1 = $text1 . $1 . "LXXXSCHRIFT" . $2 . $3 . $4 . $5 . " " . $6 . $7 .
";FINANZAMT FUERTH;76201500;76000000;-"."---BETRAG---;EUR;Umsatz gebucht\n";
$o1 = $6;
$o1 = "XX" . $o1 if ($5 =~ / / and $o1 !~ /^ *\d\d\d\d\ /);
$o1 =~ s/^\./XX/gs;
$o1 =~ s/\.//gs;
$o1 =~ s/ //gs;
$o1 = substr($o1,4);
$text1 =~ s/---BETRAG---/$o1/;
$text1 =~ s/ +/ /gs;
}
$text1 =~ s/LXXXSCHRIFT/LASTSCHRIFT/g;
# print $text1; exit;
my $text2 = "\n";
foreach $zeile (split(/\n/,$text1)) {
next if ($zeile =~ /218\/129\/10296 *\;* *Finanzkasse Schwabach *\;* *DE/);
next if ($zeile =~ /\;STEUERNR\. +218\/129\/10296 +\;/);
next if ($zeile =~ /(Umsatz +vorgemerkt|AxBxWxAx\+F)/);
# print "--> " . $zeile . "\n";
@ee = split(/\;/,$zeile);
$ee[8] =~ s/\,/./gs; # Betrag
next if ($ee[8] * 1 == 0);
$ee[4] = $ee[3] . " " . $ee[4] . " " . $ee[5] . " " . $ee[6] . " " . $ee[7]; # Bemerkungsfeld
$ee[4] =~ s/ +/ /g;
next if ($ee[2] !~ /^(.*)\.(.*)\..*(..)$/); # Datumsfeld
$zeile1 = "20" . $3 . $2 . $1 . " " . $ee[8] . " - " . "13-9999" .
" 0.00 " . $ee[4] . "\n";
$zeile1 =~ s/[\\\(\)\{\}\*\#]/ /g;
# next if (substr($zeile,0,4) ne $jahr);
$text2 = $text2 . $zeile1;
}
return($self->store($text.$text2));
}
#*******************************************************************************************
sub render_flessabank {
my $self = shift;
my $text = shift || $self->{'TEXT'};
my @files = @_;
my $o; my $o1; my $zeile; my $zeile1; my @ee; my $type;
my $text1 = "";
foreach $o (@files) {
next if ($o =~ /^(.*)\~$/);
$type = `file -i '$o'`;
print "File: $type\n";
if ($type =~ /charset\=(\S+)/) {
$o1 = $1;
if ($o1 ne "utf-8" and $o1 =~ /(iso|ascii)/) {
system("cp " . $o . " " . $o . "~");
print("iconv -f $o1 -t utf-8 $o\n");
system("iconv -f $o1 -t utf-8 $o"."~ > $o");
}
}
open(FFILE,"<".$o);
$text1 = $text1 . join("",<FFILE>) . "\n";
close(FFILE);
}
$text1 =~ s/ä/ae/gs;
$text1 =~ s/ö/oe/gs;
$text1 =~ s/ü/ue/gs;
$text1 =~ s/Ä/Ae/gs;
$text1 =~ s/Ö/Oe/gs;
$text1 =~ s/Ü/Ue/gs;
$text1 =~ s/ß/ss/gs;
$text1 =~ s/
//gs;
$text1 =~ s/\n//gs;
$text1 =~ s/\"\"/"\n"/gs;
$text1 =~ s/\"//gs;
$text1 =~ s/\n\s+/\n/gs;
$text1 =~ s/SEPA.?Ueberweisung//gs;
$text1 =~ s/TAN\:\d\d\d\d\d\d//gs;
$text1 =~ s/(\d+\,\d+)([^\n]+)(ABWA\+)F/$1$2AxBxWxAx\+F/g;
$text1 =~ s/(GUTSCHRIFT)([^\n]+)(AxBxWxAx\+)F/$1$2ABWA\+F/g;
while ($text1 =~ s/\n(.[^\n]*?\;|.[^\n]*?\;FOLGE)LASTSCHRIFT(.[^;]*?)(218\/129\/)([\d ]+)([^;]*?)([\d\. ]+,[\d ]+)(E ?U ?R|)/\n$1LASTSCHRIFT$2$3$4/) {
$text1 = $text1 . $1 . "LXXXSCHRIFT" . $2 . $3 . $4 . $5 . " " . $6 . $7 .
";FINANZAMT FUERTH;76201500;76000000;-"."---BETRAG---;EUR;Umsatz gebucht\n";
$o1 = $6;
$o1 = "XX" . $o1 if ($5 =~ / / and $o1 !~ /^ *\d\d\d\d\ /);
$o1 =~ s/^\./XX/gs;
$o1 =~ s/\.//gs;
$o1 =~ s/ //gs;
$o1 = substr($o1,4);
$text1 =~ s/---BETRAG---/$o1/;
$text1 =~ s/ +/ /gs;
}
$text1 =~ s/LXXXSCHRIFT/LASTSCHRIFT/g;
my $text2 = "\n";
foreach $zeile (split(/\n/,$text1)) {
next if ($zeile =~ /218\/129\/10296 *\;* *Finanzkasse Schwabach *\;* *DE/);
next if ($zeile =~ /\;STEUERNR\. +218\/129\/10296 +\;/);
next if ($zeile =~ /(Umsatz +vorgemerkt|AxBxWxAx\+F)/);
# print "--> " . $zeile . "\n";
@ee = split(/\;/,$zeile);
$ee[11] =~ s/\.//gs; # Betrag
$ee[11] =~ s/\,/./gs; # Betrag
if ($ee[12] eq "S") { $ee[11] = "-" . $ee[11] }
next if ($ee[11] * 1 == 0);
$ee[4] = $ee[3] . " " . $ee[4] . " " . $ee[5] . " " . $ee[6] . " " . $ee[7] . " " . $ee[8]; # Bemerkungsfeld
$ee[4] =~ s/ +/ /g;
next if ($ee[1] !~ /^(.*)\.(.*)\..*(..)$/); # Datumsfeld
$zeile1 = "20" . $3 . $2 . $1 . " " . $ee[11] . " - " . "13-9999" .
" 0.00 " . $ee[4] . "\n";
$zeile1 =~ s/[\\\(\)\{\}\*\#]/ /g;
# next if (substr($zeile,0,4) ne $jahr);
$text2 = $text2 . $zeile1;
}
return($self->store($text.$text2));
}
#*******************************************************************************************
sub render_rechnungen {
my $self = shift;
my $text = shift || $self->{'TEXT'};
my @files = @_;
my $zeile;
if (!@files) {
opendir(DDIR,".");
while ($zeile = readdir(DDIR)) {
next if ($zeile !~ /\.tex$/);
push(@files,$zeile);
}
}
close(DDIR);
$text =~ s/\n[^\n]+Rechnung[^\n]+//gs;
foreach $zeile (@files) {
open(FFILE,"<".$zeile);
next if ($zeile !~ s/^.*?(Rechnung)\_(\d+)\_(\d+)\_(.*?)\_(.*?)\..*$/qq$1 $4 $5/);
next if (join("",<FFILE>) !~ /^.*?Rechnung +(\d\d\d\d)\-(\d\d\d).*?([0123]\d)\.([01]\d)\.(\d\d)(\d\d).*?Gesamt.*?(\d+),(\d\d)/s);
$text = $text . "$5$6$4$3 -$7.$8 12-840" . sprintf("%1u",int $4/4+1) . " -misc-$6$2 0.00 $zeile\n";
close(FFILE);
}
return($self->store($text));
}
#*******************************************************************************************
sub render_planung {
my $self = shift;
my $text = shift || $self->{'TEXT'};
my $zeile; my $o;
my $text1 = "";
foreach $zeile (split(/\n/,$text)) {
if ($zeile !~ /(-soll .* Plan|-ist .* Ist)/) {
$text1 = $text1 . $zeile . "\n";
}
}
while ($text =~ s/\n(\S+)\-(\S+) +(\d\d\d\d\d\d)\_(\d\d\d\d\d\d) +(\-?\d+\.\d\d) *\n/\n/s) {
$text1 = $text1 . "20" . $4 . " " . $5 . " -$1-$2-soll 30-4998-$2-$1 0.00 Plan\n" .
"20" . sprintf("%6u",$3) . " " . $5 . " -$1-$2-ist 30-4999 0.00 Ist " .
"\{-$1-$2+$1-$2-soll+$1-$2-ist\}\n";
# "20" . $3 . " 1.00 -" . $1 . " 32-Restaufwand 0.00 Restaufwand\n";
}
return($self->store($text1));
}
#*******************************************************************************************
sub render_dornbirn {
my $self = shift;
my $text = shift;
my $o; my $o1; my @ee; my $zeile; my $zeile1;
my $text1 = "";
while ($text =~ s/\n\"(.*?)\"\n/\n---INSERT---\n/s) {
$o = $1;
$o =~ s/\"\;\"/ /gs;
$o =~ s/\"//gs;
next if ($o =~ /^\*/);
next if ($o !~ /^(.*?)\s+(\d\d)\.(\d\d)\.(\d\d\d\d)\s+(.+)\,(\d+)/);
next if ("$5.$6" eq "0.00");
$o1 = "$4$3$2 $5.$6 - 13-9999 0.00 $1\n";
$text1 = $text1 . $o1;
}
$text =~ s/\n---INSERT---\n/$text1/s;
$text =~ s/---INSERT---\n//gs;
return($text);
}
#*******************************************************************************************
sub render_consors {
my $self = shift;
my $text = shift || $self->{'TEXT'};
my @files = @_;
my $o; my $o1; my $zeile; my $zeile1; my @ee; my $type;
my $text1 = "";
foreach $o (@files) {
next if ($o =~ /^(.*)\~$/);
$type = `file -i '$o'`;
print "File: $type\n";
if ($type =~ /charset\=(\S+)/) {
$o1 = $1;
if ($o1 ne "utf-8" and $o1 =~ /(iso|ascii)/) {
system("cp " . $o . " " . $o . "~");
print("iconv -f $o1 -t utf-8 $o\n");
system("iconv -f $o1 -t utf-8 $o"."~ > $o");
}
}
open(FFILE,"<".$o);
$text1 = $text1 . join("",<FFILE>);
close(FFILE);
}
$text1 =~ s/\"//gs;
my $text2 = "\n";
foreach $zeile (split(/\n/,$text1)) {
@ee = split(/\;/,$zeile);
$ee[9] =~ s/\.//gs; # Betrag
$ee[9] =~ s/\,/./gs; # Betrag
$ee[9] =~ s/\+//gs; # Betrag
$ee[5] =~ s/\.//gs; # Betrag
$ee[5] =~ s/\,/./gs; # Betrag
$ee[5] =~ s/\+//gs; # Betrag
if ($ee[9] * 1 != 0) {
$ee[4] = $ee[2] . " " . $ee[3] . " " . $ee[4] . " " . $ee[5] . " " . $ee[6] . " " . $ee[7] . " " . $ee[8]; # Bemerkungsfeld
}
elsif ($ee[5] * 1 != 0) {
$ee[4] = $ee[2] . " " . $ee[3] . " " . $ee[4]; # Bemerkungsfeld
$ee[9] = $ee[5];
}
$ee[4] =~ s/[\\\(\)\{\}\*\#]/ /g;
$ee[4] =~ s/ +/ /g;
next if ($ee[1] !~ /^(.*)\.(.*)\.(.*)$/); # Datumsfeld
$zeile1 = $3 . $2 . $1 . " " . $ee[9] . " - " . "13-9999" .
" 0.00 " . $ee[4] . "\n";
# next if (substr($zeile,0,4) ne $jahr);
$text2 = $text2 . $zeile1;
}
my $jahr = 2000;
if ($text =~ /\n(\d\d\d\d)(\d\d\d\d) +/) {
$jahr = $1;
}
$text1 =~ s///gs;
$text1 =~ s/BONIFIKATION/< x > BONIFIKATION/gs;
while ($text1 =~ s/\n(\S+ *\S*) +(\d\d)\.(\d\d)\. +(\d\d\d\d) +\d\d\.\d\d\. +([\d\.]+,\d\d[\-\+]?)\n +([^\n]+?) +\< *([^\n]+?) *\> +([^\n]+)//s) {
$o = $5;
$zeile = "$jahr$3$2 ---BETRAG--- - 13-9999 0.00 $1 $6 $7 $8\n";
$o =~ s/\.//gs; # Betrag
$o =~ s/\,/./gs; # Betrag
$o =~ s/\+//gs; # Betrag
$o =~ s/^(.*)\-$/-$1/;
$zeile =~ s/---BETRAG---/$o/;
$zeile =~ s/ +/ /;
$text2 = $text2 . $zeile;
}
while ($text1 =~ s/\n(ABSCHLUSS|GEBUEHREN) +(\d\d)\.(\d\d)\. +(\d\d\d\d) +\d\d\.\d\d\. +([\d\.]+,\d\d[\-\+]?)\n//s) {
$o = $5;
$zeile = "$jahr$3$2 ---BETRAG--- - 13-9999 0.00 $1 Ktogebuehren und Zinsen\n";
$o =~ s/\.//gs; # Betrag
$o =~ s/\,/./gs; # Betrag
$o =~ s/\+//gs; # Betrag
$o =~ s/^(.*)\-$/-$1/;
$zeile =~ s/---BETRAG---/$o/;
$zeile =~ s/ +/ /;
$text2 = $text2 . $zeile;
}
return($self->store($text.$text2));
}
#*******************************************************************************************
sub render_commerzbank {
my $self = shift;
my $text = shift || $self->{'TEXT'};
my @files = @_;
my $o; my $o1; my @ee; my $zeile; my $zeile1; my $text2; my $zaehler; my $o2; my $o3;
my $type; my $text1;
foreach $o (@files) {
next if ($o =~ /^(.*)\~$/);
$type = `file -i '$o'`;
print "File: $type\n";
if ($type =~ /charset\=(\S+)/) {
$o1 = $1;
if ($o1 ne "utf-8" and $o1 =~ /(iso|ascii)/) {
system("cp " . $o . " " . $o . "~");
print("iconv -f $o1 -t utf-8 $o\n");
system("iconv -f $o1 -t utf-8 $o"."~ > $o");
}
}
open(FFILE,"<".$o);
$text = $text . join("",<FFILE>);
close(FFILE);
}
# $text =~ s/ä/ae/gs;
# $text =~ s/ö/oe/gs;
# $text =~ s/ü/ue/gs;
# $text =~ s/Ä/Ae/gs;
# $text =~ s/Ö/Oe/gs;
# $text =~ s/Ü/Ue/gs;
# $text =~ s/ß/ss/gs;
$text =~ s/
//gs;
# while ($text =~ s/\n[^\n]*[Uu]ebersicht[^\n]*\n/\n/s) { 1; }
my $text2 = "\n";
my $text3 = "\n";
my $text5 = "\n";
while ($text =~ s/\n(\d\d)\.(\d\d)\.(\d\d\d\d)\;[^\n]+?\;[^\n]+?\;\"?([^\n]+?)\"?\;\+?(\-?[\d\.]+),(\d\d)\;([^\n]*)\n/\n/s) {
$zeile = "$3$2$1 $5.$6 - 13-9999 0.00 $4\n";
$zeile =~ s/( \-?\d+)\.(\d\d\d\.\d\d )/$1$2/;
$zeile =~ s/[\\\(\)\{\}\*\#]/ /g;
$text3 = $text3 . $zeile;
}
my $text0 = "";
while ($text =~ s/^(.*?)---READIN---(.*?)---READIN---(.*)$/$1$3/s) {
$text0 = $text0 . $2 . "\n";
}
$text0 =~ s/\n(Alter|Neuer) Kontostand v(.*?.20)(\d\d)\n(.*?)\n/\n/gs;
my $jahr = "20$3";
# print $text; exit;
my $text9 = "";
if ($text =~ s/^(.*?)(\<html\>.*\<\/html>)(.*)$/$1---INSERT---\n$3/s) {
$text9 = $2;
}
elsif ($text =~ s/^(.*?)(pgf.html.*Valuta)(.*?)(pgf.html.*)$/$1\n---INSERT---\n/s) {
$text9 = $3;
}
while ($text9 =~ s/^(.*)(\<title\>commerzbanking.*?Zeitpunkt des letzten)(.*)$/$1\n$3/s) { 1; }
$text9 =~ s/\<br\>/ /gsi;
$zaehler = 0;
while ($text9 =~ s/tablehead1\"\>(.+?)\<\/span//) {
$o = $1;
$zaehler = $zaehler + 1;
if ($zaehler == 1) {
$o1 = $o;
$o1 =~ s/^(\d+)\.(\d+)\.(\d+)/$3$2$1/;
}
elsif ($zaehler == 2) {
$o2 = $o;
$o2 =~ s/\<BR\>/ /g;
}
elsif ($zaehler == 3) {
$zaehler = 0;
if ($text9 =~ s/class\=\"(green|red|number)\"\>(.+?)\<\/span//s) {
$o3 = $2;
$o3 =~ s/\.//gs;
$o3 =~ s/\+//gs;
$o3 =~ s/\,/\./gs;
if ($o3 =~ s/\-//gs) { $o3 = "-" . $o3; }
}
$zeile = $o1 . " " . $o3 . " - " . "13-9999" . " 0.00 " . $o2 . "\n";
$text2 = $text2 . $zeile;
}
}
while ($text9 =~ s/(\d\d)\.(\d\d)\.(\d\d\d\d)(.*?)(\n\d\d\.\d\d\.\d\d\d\d).*?\n([\d\.]+),(\d\d)(\-?)/XXXX/s) {
$zeile = "$3$2$1 $8$6.$7 - 13-9999 0.00 ";
$o3 = $4;
$zeile =~ s/( \-?\d+)\.(\d\d\d\.\d\d )/$1$2/;
$o3 =~ s/\n/ /gs;
$o3 =~ s/ +/ /gs;
$o3 =~ s/^\s*(.*?)\s*$/$1/gs;
$text2 = $text2 . $zeile . $o3 . "\n";
}
# while ($text9 =~ s/(\d\d)(\d\d)(\d\d\d\d) +(-?[\d\.]+) +(.*)/XXXX/) {
# $zeile = "$1$2$3 $4 - 13-9999 0.00 $5";
# $text2 = $text2 . $zeile . $o3 . "\n";
# }
$text =~ s/\n---INSERT---\n/$text2/s;
$text =~ s/\n +(\S+) +\n/\n/gs;
$text =~ s/\n *(\S+) *\n/\n/gs;
my $status = 0;
my $buch1 = "";
my @ee = (split(/\n/,$text0));
my @betraege = ();
foreach $o (@ee) {
$o =~ s/BEZUEGE +/BEZUEGE./;
if ($o =~ /Buchungsdat.*\: +\d\d\.\d\d\.\d\d\d\d/i) {
$status = 1;
}
elsif ($o =~ /^Angaben.*Valuta *$/) {
$status = 1;
next;
}
elsif ($o =~ /(Einwendungen|geduldeten|Der angegebene)/) {
$status = 0;
next;
}
elsif ($o =~ /^(\S.*?) +(\d\d)\.(\d\d) *$/) {
$buch1 = $buch1 . $1;
$text5 = $text5 . "$jahr$3$2 ---BETRAG--- - 13-9999 0.00 " . $buch1 . " \n";
$buch1 = "";
}
elsif ($o =~ /^[\d\.]+\,\d\d\-? *$/ or $o =~ /^Folges/) {
$buch1 = "";
$status = 0;
if ($o =~ /([\d\.]+\,\d\d)(\-?) *$/) {
$o1 = "$2$1";
$o1 =~ s/\.//g;
$o1 =~ s/,/\./g;
push(@betraege,$o1);
}
}
elsif ($status == 1) {
$buch1 = $buch1 . $o . " ";
$buch1 =~ s/ +/ /gs;
}
}
foreach $o (@betraege) {
$text5 =~ s/---BETRAG---/$o/;
}
# print $text5; exit;
# print $text.$text3.$text5; exit;
return($self->store($text.$text3.$text5."\n\n Commerzbank 0.00\n"));
}
#*******************************************************************************************
sub beitragsnachweise {
my $self = shift;
my $text = shift || $self->{'TEXT'};
my @files = @_;
my $zeile; my $text1; my $datum; my $monat; my $fehler; my $remark; my $kk; my $o;
while ( $text =~ s/\n([^\n]+)-meldung([^\n]+)\n/\n/gs ) { 1; }
# return($text);
if (!@files) {
opendir(DDIR,".");
while ($zeile = readdir(DDIR)) {
unlink($zeile) if ($zeile =~ /\.txt$/);
unlink($zeile) if ($zeile =~ /~$/);
if ($zeile =~ s/^(.*)\.pdf$/$1/) {
system("ps2ascii $zeile.pdf > $zeile.txt");
push(@files,$1);
}
elsif ($zeile =~ s/^(.*)\.(lexware|manuell)/$1/) {
system("cp $zeile.$2 $zeile.txt");
push(@files,$1);
}
}
}
close(DDIR);
$text =~ s/\n[^\n]+Rechnung[^\n]+//gs;
my $skip_korrektur = {};
open(GFILE,">>fehlerreport.txt");
foreach $zeile (reverse sort @files) {
$remark = "";
$kk = "";
$fehler = 0;
open(FFILE,"<$zeile.txt");
$text1 = join("",<FFILE>);
close(FFILE);
print "ZZ: $zeile\n";
$text1 =~ s/([aou])\"/$1e/gs;
$text1 =~ s/([AOU])\"/$1E/gs;
$text1 =~ s/(s)\"/ss/gs;
$text1 =~ s/\n- /- /gs;
if ($text1 =~ /Zeitraum +von +(\d+)\.(\d+)\.(\d+)/) { # Beitragsmeldungen
$datum = $3;
$monat = $2;
next if ($text1 !~ /bis +(\d+)\.$monat\.$datum/);
}
if ($text1 =~ /(oranmeldung|nmeldungszeitraum).*?Januar +(\d\d\d\d)/s) { $datum = $2; $monat = "01"; } # UStVA, LST
elsif ($text1 =~ /(oranmeldung|nmeldungszeitraum).*?Februar +(\d\d\d\d)/s) { $datum = $2; $monat = "02"; }
elsif ($text1 =~ /(oranmeldung|nmeldungszeitraum).*?M..?rz +(\d\d\d\d)/s) { $datum = $2; $monat = "03"; }
elsif ($text1 =~ /(oranmeldung|nmeldungszeitraum).*?April +(\d\d\d\d)/s) { $datum = $2; $monat = "04"; }
elsif ($text1 =~ /(oranmeldung|nmeldungszeitraum).*?Mai +(\d\d\d\d)/s) { $datum = $2; $monat = "05"; }
elsif ($text1 =~ /(oranmeldung|nmeldungszeitraum).*?Juni +(\d\d\d\d)/s) { $datum = $2; $monat = "06"; }
elsif ($text1 =~ /(oranmeldung|nmeldungszeitraum).*?Juli +(\d\d\d\d)/s) { $datum = $2; $monat = "07"; }
elsif ($text1 =~ /(oranmeldung|nmeldungszeitraum).*?August +(\d\d\d\d)/s) { $datum = $2; $monat = "08"; }
elsif ($text1 =~ /(oranmeldung|nmeldungszeitraum).*?September +(\d\d\d\d)/s) { $datum = $2; $monat = "09"; }
elsif ($text1 =~ /(oranmeldung|nmeldungszeitraum).*?Oktober +(\d\d\d\d)/s) { $datum = $2; $monat = "10"; }
elsif ($text1 =~ /(oranmeldung|nmeldungszeitraum).*?November +(\d\d\d\d)/s) { $datum = $2; $monat = "11"; }
elsif ($text1 =~ /(oranmeldung|nmeldungszeitraum).*?Dezember +(\d\d\d\d)/s) { $datum = $2; $monat = "12"; }
elsif ($text1 =~ /1\. +Kalenderviertel.* +(\d\d\d\d)/) { $datum = $1; $monat = "03"; }
elsif ($text1 =~ /2\. +Kalenderviertel.* +(\d\d\d\d)/) { $datum = $1; $monat = "06"; }
elsif ($text1 =~ /3\. +Kalenderviertel.* +(\d\d\d\d)/) { $datum = $1; $monat = "09"; }
elsif ($text1 =~ /4\. +Kalenderviertel.* +(\d\d\d\d)/) { $datum = $1; $monat = "12"; }
elsif ($text1 =~ /(\d\d\d\d)\!\!/) { $datum = $1; $monat = "12"; }
elsif ($text1 =~ /Kalenderjahr +(\d\d\d\d)/) { $datum = $1; $monat = "12"; }
if ($text1 =~ /msatzst.*(oranmeldung|nmeldungszeitraum)/s) { # USt
$kk = "UST";
$remark = "USTVA $datum$monat"."01";
}
elsif ($text1 =~ /ohnste.*nmeldungszeitraum/s) { # LSt
$kk = "LST";
$remark = "LST 99999999";
}
if ($text1 =~ /Umsatzsteuer(vorausz|erkl)/) { # UStErkl
$remark = $1;
# if ($remark eq "vorausz") { $monat = "00"; $remark = "USTVorausz "; }
if ($remark eq "erkl") { $monat = "13"; $remark = "USTErkl "; }
$kk ="UST";
$datum = "0000";
if ($text =~ /\n(\d\d\d\d)/s) {
$datum = $1;
}
$remark = $remark . $datum . "1231";
}
if ($text1 =~ /Einzugsstelle.*Betriebsnummer +(\d+)(.*?)Name +([^\n]+)/s) { # Beitragsmeldungen
$remark = $3 . " " . $1;
$remark =~ s/^(Debeka|Techniker|BKK Mobil Oil|Minijob-Zentrale|SBK|TKK|AOK Bayern|AOK Hessen|Knappschaft|DAK|Barmer|BARMER GEK|BKK Verkehrsbau Union)(.*)( \d\d\d\d\d\d\d\d)/$1$3/;
$kk = $1 . "______";
$kk =~ s/ //gs;
$kk = substr(uc($kk),0,6);
if ($kk eq "KNAPPS") { $kk = "MINIJO"; }
if ($kk eq "BKKVER" and $monat eq "03" and $text1 =~ / 90,60/) {
$monat = "04";
$text1 =~ s/03\.2008/04\.2008/g
} # falsches Datum bei einem Beitragsnachweis fuer die BKK futur
}
if ($remark =~ / (\d\d\d\d\d\d\d\d)/) {
print( `pwd`. "mv $zeile.txt $zeile\_$datum\_$monat.txt\n");
system("mv $zeile.txt $kk\_$zeile\_$datum\_$monat.txt");
}
# next if ($fehler);
next if ($text1 =~ /Lexware/);
next if ($skip_korrektur->{"$kk.$datum.$monat"});
$skip_korrektur->{"$kk.$datum.$monat"} = 1;
# print "RR: $monat $zeile $kk $remark\n"; sleep 1;
while ($text1 =~ s/(einheitliche|Umlage|Beitr)(.*?) +(\d+)\,(\d\d)//) { # Beitragsmeldungen
$zeile = "$datum$monat"."20 -$3.$4 - 13-9999 0.00 $remark, $1$2\n";
next if ($zeile =~ /ohne +Sozialausgleich/);
$text = $text . $zeile;
}
while ($text1 =~ s/(83|42|41|49|61|62|63|64|820) +(\-?[0-9\.]+\,\d\d+)/-x-x-x-/) { # UStVA und UStErkl, LST
$zeile = $2;
$o = $1;
next if ($remark =~ /^UST/ and $o !~ /^(83|820)/);
next if ($remark =~ /^LST/ and $o =~ /^(83|820)/);
if ($o eq "42") { $remark = "LST $datum$monat"."22 einzubehaltende Lohnsteuer"; }
if ($o eq "41") { $remark = "LST $datum$monat"."22 pauschale Lohnsteuer"; }
if ($o eq "49") { $remark = "LST $datum$monat"."22 Solidaritaetszuschlag"; }
if ($o eq "61") { $remark = "LST $datum$monat"."22 Kirchensteuer evangelisch"; }
if ($o eq "62") { $remark = "LST $datum$monat"."22 Kirchensteuer roem-kath"; }
if ($o eq "63") { $remark = "LST $datum$monat"."22 Kirchensteuer alt-kath"; }
if ($o eq "64") { $remark = "LST $datum$monat"."22 Kirchensteuer israelitisch"; }
# print "WWW: $kk $remark $zeile $o\n";
# next if ($kk eq "LST" and $remark !~ /LST/);
$zeile =~ s/\.//gs;
$zeile =~ s/\,/\./gs;
$zeile = "$datum$monat"."20 -$zeile - 13-9999 0.00 $remark\n";
$zeile =~ s/1320/1221/; # UStErklaerung
# $zeile =~ s/0020/0103/; # UStVorauszahlung
$zeile =~ s/20 -/22 -/ if ($zeile =~ /LST/);
$zeile =~ s/--//;
$text = $text . $zeile;
# $remark = "abcxyz123";
}
}
close(GFILE);
return($self->store($text));
}
#*******************************************************************************************
1;