1 #=====================================================================
 
   6 #   Email: p.reetz@linet-services.de
 
   7 #     Web: http://www.lx-office.org
 
  10 # This program is free software; you can redistribute it and/or modify
 
  11 # it under the terms of the GNU General Public License as published by
 
  12 # the Free Software Foundation; either version 2 of the License, or
 
  13 # (at your option) any later version.
 
  15 # This program is distributed in the hope that it will be useful,
 
  16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  18 # GNU General Public License for more details.
 
  19 # You should have received a copy of the GNU General Public License
 
  20 # along with this program; if not, write to the Free Software
 
  21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
  22 #======================================================================
 
  25 #======================================================================
 
  30 use SL::DATEV::KNEFile;
 
  35   $main::lxdebug->enter_sub();
 
  38   my $field_len = shift;
 
  39   my $fill_char = shift;
 
  40   my $alignment = shift || 'right';
 
  42   my $text_len  = length $text;
 
  44   if ($field_len < $text_len) {
 
  45     $text = substr $text, 0, $field_len;
 
  47   } elsif ($field_len > $text_len) {
 
  48     my $filler = ($fill_char) x ($field_len - $text_len);
 
  49     $text      = $alignment eq 'right' ? $filler . $text : $text . $filler;
 
  52   $main::lxdebug->leave_sub();
 
  58   $main::lxdebug->enter_sub();
 
  60   my ($self, $myconfig, $form) = @_;
 
  63   my $dbh = $form->dbconnect($myconfig);
 
  65   $query = qq|SELECT * FROM datev|;
 
  66   $sth   = $dbh->prepare($query);
 
  67   $sth->execute || $form->dberror($query);
 
  69   my $ref = $sth->fetchrow_hashref(NAME_lc);
 
  71   map { $form->{$_} = $ref->{$_} } keys %$ref;
 
  75   $main::lxdebug->leave_sub();
 
  78 sub save_datev_stamm {
 
  79   $main::lxdebug->enter_sub();
 
  81   my ($self, $myconfig, $form) = @_;
 
  84   my $dbh = $form->dbconnect_noauto($myconfig);
 
  86   $query = qq|DELETE FROM datev|;
 
  87   $dbh->do($query) || $form->dberror($query);
 
  89   $query = qq|INSERT INTO datev
 
  90               (beraternr, beratername, dfvkz, mandantennr, datentraegernr, abrechnungsnr) VALUES
 
  92     . $dbh->quote($form->{beraternr}) . qq|,|
 
  93     . $dbh->quote($form->{beratername}) . qq|,|
 
  94     . $dbh->quote($form->{dfvkz}) . qq|,
 
  96     . $dbh->quote($form->{mandantennr}) . qq|,|
 
  97     . $dbh->quote($form->{datentraegernr}) . qq|,|
 
  98     . $dbh->quote($form->{abrechnungsnr}) . qq|)|;
 
  99   $sth = $dbh->prepare($query);
 
 100   $sth->execute || $form->dberror($query);
 
 105   $main::lxdebug->leave_sub();
 
 109   $main::lxdebug->enter_sub();
 
 111   my ($self, $myconfig, $form) = @_;
 
 114   if ($form->{exporttype} == 0) {
 
 115     @rc = &kne_buchungsexport($myconfig, $form);
 
 117     @rc = &kne_stammdatenexport($myconfig, $form);
 
 120   $main::lxdebug->leave_sub();
 
 126   $main::lxdebug->enter_sub();
 
 128   my ($self, $myconfig, $form) = @_;
 
 130   # connect to database
 
 131   my $dbh = $form->dbconnect_noauto($myconfig);
 
 134   $main::lxdebug->leave_sub();
 
 138   $main::lxdebug->enter_sub();
 
 140   my ($zeitraum, $monat, $quartal, $transdatefrom, $transdateto) = @_;
 
 142   $fromto = "transdate >= ";
 
 147   if ($zeitraum eq "monat") {
 
 149       $monat eq "1" && do {
 
 150         $form->{fromdate} = "1.1.$jahr";
 
 151         $form->{todate}   = "31.1.$jahr";
 
 154       $monat eq "2" && do {
 
 155         $form->{fromdate} = "1.2.$jahr";
 
 157         #this works from 1901 to 2099, 1900 and 2100 fail.
 
 158         $leap = ($jahr % 4 == 0) ? "29" : "28";
 
 159         $form->{todate} = "$leap.2.$jahr";
 
 162       $monat eq "3" && do {
 
 163         $form->{fromdate} = "1.3.$jahr";
 
 164         $form->{todate}   = "31.3.$jahr";
 
 167       $monat eq "4" && do {
 
 168         $form->{fromdate} = "1.4.$jahr";
 
 169         $form->{todate}   = "30.4.$jahr";
 
 172       $monat eq "5" && do {
 
 173         $form->{fromdate} = "1.5.$jahr";
 
 174         $form->{todate}   = "31.5.$jahr";
 
 177       $monat eq "6" && do {
 
 178         $form->{fromdate} = "1.6.$jahr";
 
 179         $form->{todate}   = "30.6.$jahr";
 
 182       $monat eq "7" && do {
 
 183         $form->{fromdate} = "1.7.$jahr";
 
 184         $form->{todate}   = "31.7.$jahr";
 
 187       $monat eq "8" && do {
 
 188         $form->{fromdate} = "1.8.$jahr";
 
 189         $form->{todate}   = "31.8.$jahr";
 
 192       $monat eq "9" && do {
 
 193         $form->{fromdate} = "1.9.$jahr";
 
 194         $form->{todate}   = "30.9.$jahr";
 
 197       $monat eq "10" && do {
 
 198         $form->{fromdate} = "1.10.$jahr";
 
 199         $form->{todate}   = "31.10.$jahr";
 
 202       $monat eq "11" && do {
 
 203         $form->{fromdate} = "1.11.$jahr";
 
 204         $form->{todate}   = "30.11.$jahr";
 
 207       $monat eq "12" && do {
 
 208         $form->{fromdate} = "1.12.$jahr";
 
 209         $form->{todate}   = "31.12.$jahr";
 
 214       "'" . $form->{fromdate} . "' and transdate <= '" . $form->{todate} . "'";
 
 217   elsif ($zeitraum eq "quartal") {
 
 220         "'01.01." . $jahr . "' and transdate <= '31.03." . $jahr . "'";
 
 221     } elsif ($quartal == 2) {
 
 223         "'01.04." . $jahr . "' and transdate <= '30.06." . $jahr . "'";
 
 224     } elsif ($quartal == 3) {
 
 226         "'01.07." . $jahr . "' and transdate <= '30.09." . $jahr . "'";
 
 227     } elsif ($quartal == 4) {
 
 229         "'01.10." . $jahr . "' and transdate <= '31.12." . $jahr . "'";
 
 233   elsif ($zeitraum eq "zeit") {
 
 234     $fromto            .= "'" . $transdatefrom . "' and transdate <= '" . $transdateto . "'";
 
 235     my ($yy, $mm, $dd)  = $main::locale->parse_date(\%main::myconfig, $transdatefrom);
 
 239   $main::lxdebug->leave_sub();
 
 241   return ($fromto, $jahr);
 
 244 sub _get_transactions {
 
 245   $main::lxdebug->enter_sub();
 
 249   my $myconfig =  \%main::myconfig;
 
 250   my $form     =  $main::form;
 
 252   my $dbh      =  $form->get_standard_dbh($myconfig);
 
 256   $fromto      =~ s/transdate/ac\.transdate/g;
 
 258   my %taxes    =  selectall_as_map($form, $dbh, qq|SELECT id, rate FROM tax|, 'id', 'rate');
 
 261     qq|SELECT ac.oid, ac.transdate, ac.trans_id,ar.id, ac.amount, ac.taxkey,
 
 262          ar.invnumber, ar.duedate, ar.amount as umsatz,
 
 264          c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id,
 
 265          t.chart_id, t.rate, t.id AS taxid, t.taxkey AS taxtaxkey
 
 266        FROM acc_trans ac,ar ar, customer ct, chart c
 
 267        LEFT JOIN tax t ON (t.chart_id = c.id)
 
 269          AND (ac.trans_id = ar.id)
 
 270          AND (ac.trans_id = ar.id)
 
 271          AND (ar.customer_id = ct.id)
 
 272          AND (ac.chart_id = c.id)
 
 276        SELECT ac.oid, ac.transdate, ac.trans_id,ap.id, ac.amount, ac.taxkey,
 
 277          ap.invnumber, ap.duedate, ap.amount as umsatz,
 
 279          c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id,
 
 280          t.chart_id, t.rate, t.id AS taxid, t.taxkey AS taxtaxkey
 
 281        FROM acc_trans ac, ap ap, vendor ct, chart c
 
 282        LEFT JOIN tax t ON (t.chart_id = c.id)
 
 284          AND (ac.trans_id = ap.id)
 
 285          AND (ap.vendor_id = ct.id)
 
 286          AND (ac.chart_id = c.id)
 
 290        SELECT ac.oid, ac.transdate, ac.trans_id,gl.id, ac.amount, ac.taxkey,
 
 291          gl.reference AS invnumber, gl.transdate AS duedate, ac.amount as umsatz,
 
 292          gl.description AS name,
 
 293          c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id,
 
 294          t.chart_id, t.rate, t.id AS taxid, t.taxkey AS taxtaxkey
 
 295        FROM acc_trans ac, gl gl, chart c
 
 296        LEFT JOIN tax t ON (t.chart_id = c.id)
 
 298          AND (ac.trans_id = gl.id)
 
 299          AND (ac.chart_id = c.id)
 
 301        ORDER BY trans_id, oid|;
 
 303   my $sth     = prepare_execute_query($form, $dbh, $query);
 
 307   while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
 
 309     if (($counter % 500) == 0) {
 
 313     my $trans    = [ $ref ];
 
 315     my $count    = $ref->{amount};
 
 318     while (abs($count) > 0.01 || $firstrun) {
 
 319       my $ref2 = $sth->fetchrow_hashref(NAME_lc);
 
 322       push @{ $trans }, $ref2;
 
 324       $count    += $ref2->{amount};
 
 328     my %taxid_taxkeys = ();
 
 330     if (scalar(@{$trans}) <= 2) {
 
 331       push @{ $form->{DATEV} }, $trans;
 
 335     for my $j (0 .. (scalar(@{$trans}) - 1)) {
 
 336       if (abs($trans->[$j]->{'amount'}) > abs($absumsatz)) {
 
 337         $absumsatz     = $trans->[$j]->{'amount'};
 
 340       if (($trans->[$j]->{'taxtaxkey'}) && ($trans->[$j]->{'taxid'})) {
 
 341         $taxid_taxkeys{$trans->[$j]->{'taxtaxkey'}}     = $trans->[$j]->{'taxid'};
 
 345     my $ml = ($trans->[0]->{'umsatz'} > 0) ? 1 : -1;
 
 346     for my $j (0 .. (scalar(@{$trans}) - 1)) {
 
 347       if (   ($j != $notsplitindex)
 
 348           && ($trans->[$j]->{'chart_id'}  eq "")
 
 349           && (   $trans->[$j]->{'taxkey'} eq ""
 
 350               || $trans->[$j]->{'taxkey'} eq "0"
 
 351               || $trans->[$j]->{'taxkey'} eq "1"
 
 352               || $trans->[$j]->{'taxkey'} eq "10"
 
 353               || $trans->[$j]->{'taxkey'} eq "11")) {
 
 355         map { $new_trans{$_} = $trans->[$notsplitindex]->{$_}; } keys %{ $trans->[$notsplitindex] };
 
 357         $absumsatz               += $trans->[$j]->{'amount'};
 
 358         $new_trans{'amount'}      = $trans->[$j]->{'amount'} * (-1);
 
 359         $new_trans{'umsatz'}      = abs($trans->[$j]->{'amount'}) * $ml;
 
 360         $trans->[$j]->{'umsatz'}  = abs($trans->[$j]->{'amount'}) * $ml;
 
 362         push @splits, [ \%new_trans, $trans->[$j] ];
 
 363         push @{ $form->{DATEV} }, $splits[-1];
 
 365       } elsif (($j != $notsplitindex) && ($trans->[$j]->{'chart_id'} eq "")) {
 
 366         $absumsatz += ($trans->[$j]->{'amount'} * (1 + $taxes{ $taxid_taxkeys{$trans->[$j]->{'taxkey'}} }));
 
 369         map { $new_trans{$_} = $trans->[$notsplitindex]->{$_}; } keys %{ $trans->[$notsplitindex] };
 
 371         my $tax_rate             = 1 + $taxes{ $taxid_taxkeys{$trans->[$j]->{'taxkey'}} };
 
 372         $new_trans{'amount'}     = $form->round_amount(($trans->[$j]->{'amount'} * $tax_rate * -1), 2);
 
 373         $new_trans{'umsatz'}     = abs($form->round_amount(($trans->[$j]->{'amount'} * $tax_rate), 2)) * $ml;
 
 374         $trans->[$j]->{'umsatz'} = abs($form->round_amount(($trans->[$j]->{'amount'} * $tax_rate), 2)) * $ml;
 
 376         push @splits, [ \%new_trans, $trans->[$j] ];
 
 377         push @{ $form->{DATEV} }, $splits[-1];
 
 381     if (abs($absumsatz) > 0.01) {
 
 382       push @errors, "Datev-Export fehlgeschlagen! Bei Transaktion $trans->[0]->{trans_id} ($absumsatz)\n";
 
 388   $form->error(join("<br>\n", @errors)) if (@errors);
 
 390   $main::lxdebug->leave_sub();
 
 393 sub make_kne_data_header {
 
 394   $main::lxdebug->enter_sub();
 
 396   my ($myconfig, $form, $fromto, $start_jahr) = @_;
 
 398   my $jahr = $start_jahr;
 
 405   my $header  = "\x1D\x181";
 
 406   $header    .= _fill($form->{datentraegernr}, 3, '0');
 
 407   $header    .= ($fromto) ? "11" : "13"; # Anwendungsnummer
 
 408   $header    .= _fill($form->{dfvkz}, 2, '0');
 
 409   $header    .= _fill($form->{beraternr}, 7, '0');
 
 410   $header    .= _fill($form->{mandantennr}, 5, '0');
 
 411   $header    .= _fill($form->{abrechnungsnr} . $jahr, 6, '0');
 
 413   $fromto         =~ s/transdate|>=|and|\'|<=//g;
 
 414   my ($from, $to) =  split /   /, $fromto;
 
 419     my ($fday, $fmonth, $fyear) = split(/\./, $from);
 
 420     if (length($fmonth) < 2) {
 
 421       $fmonth = "0" . $fmonth;
 
 423     if (length($fday) < 2) {
 
 426     $from = $fday . $fmonth . substr($fyear, -2, 2);
 
 434     my ($tday, $tmonth, $tyear) = split(/\./, $to);
 
 435     if (length($tmonth) < 2) {
 
 436       $tmonth = "0" . $tmonth;
 
 438     if (length($tday) < 2) {
 
 441     $to = $tday . $tmonth . substr($tyear, -2, 2);
 
 449     $header .= $primanota;
 
 452   $header .= _fill($form->{passwort}, 4, '0');
 
 453   $header .= " " x 16;       # Anwendungsinfo
 
 454   $header .= " " x 16;       # Inputinfo
 
 458   my $versionssatz  = $form->{exporttype} == 0 ? "\xB5" . "1," : "\xB6" . "1,";
 
 460   my $dbh           = $form->get_standard_dbh($myconfig);
 
 461   my $query         = qq|SELECT accno FROM chart LIMIT 1|;
 
 462   my $ref           = selectfirst_hashref_query($form, $dbh, $query);
 
 464   $versionssatz    .= length $ref->{accno};
 
 465   $versionssatz    .= ",";
 
 466   $versionssatz    .= length $ref->{accno};
 
 467   $versionssatz    .= ",SELF" . "\x1C\x79";
 
 469   $header          .= $versionssatz;
 
 471   $main::lxdebug->leave_sub();
 
 477   $main::lxdebug->enter_sub();
 
 479   my ($date, $six) = @_;
 
 481   ($day, $month, $year) = split(/\./, $date);
 
 484     $day = substr($day, 1, 1);
 
 486   if (length($month) < 2) {
 
 487     $month = "0" . $month;
 
 489   if (length($year) > 2) {
 
 490     $year = substr($year, -2, 2);
 
 494     $date = $day . $month . $year;
 
 496     $date = $day . $month;
 
 499   $main::lxdebug->leave_sub();
 
 504 sub trim_leading_zeroes {
 
 512 sub make_ed_versionset {
 
 513   $main::lxdebug->enter_sub();
 
 515   my ($header, $filename, $blockcount, $fromto) = @_;
 
 517   my $versionset  = "V" . substr($filename, 2, 5);
 
 518   $versionset    .= substr($header, 6, 22);
 
 521     $versionset .= "0000" . substr($header, 28, 19);
 
 524     $versionset .= $datum . "001" . substr($header, 28, 4);
 
 527   $versionset .= _fill($blockcount, 5, '0');
 
 528   $versionset .= "001";
 
 530   $versionset .= substr($header, -12, 10) . "    ";
 
 531   $versionset .= " " x 53;
 
 533   $main::lxdebug->leave_sub();
 
 539   $main::lxdebug->enter_sub();
 
 541   my ($form, $fileno) = @_;
 
 543   my $ev_header  = _fill($form->{datentraegernr}, 3, ' ', 'left');
 
 545   $ev_header    .= _fill($form->{beraternr}, 7, ' ', 'left');
 
 546   $ev_header    .= _fill($form->{beratername}, 9, ' ', 'left');
 
 548   $ev_header    .= (_fill($fileno, 5, '0')) x 2;
 
 549   $ev_header    .= " " x 95;
 
 551   $main::lxdebug->leave_sub();
 
 556 sub kne_buchungsexport {
 
 557   $main::lxdebug->enter_sub();
 
 559   my ($myconfig, $form) = @_;
 
 563   my $export_path = $main::userspath . "/";
 
 564   my $filename    = "ED00000";
 
 572   <body>Export in Bearbeitung<br>
 
 573   Buchungssätze verarbeitet:
 
 576   ($fromto, $start_jahr) =
 
 577     &get_dates($form->{zeitraum}, $form->{monat},
 
 578                $form->{quartal},  $form->{transdatefrom},
 
 579                $form->{transdateto});
 
 580   _get_transactions($fromto);
 
 582   print qq|<br>2. Durchlauf:|;
 
 583   while (scalar(@{ $form->{DATEV} })) {
 
 586     my $ed_filename = $export_path . $filename;
 
 587     push(@filenames, $filename);
 
 588     $header = &make_kne_data_header($myconfig, $form, $fromto, $start_jahr);
 
 590     my $kne_file = SL::DATEV::KNEFile->new();
 
 591     $kne_file->add_block($header);
 
 593     while (scalar(@{ $form->{DATEV} }) > 0) {
 
 594       $transaction = shift @{ $form->{DATEV} };
 
 595       $trans_lines = scalar(@{$transaction});
 
 597       if (($counter % 500) == 0) {
 
 607       my $buchungstext   = "";
 
 609       my $datevautomatik = 0;
 
 612       my %umlaute = ('ä' => 'ae',
 
 619       for (my $i = 0; $i < $trans_lines; $i++) {
 
 620         if ($trans_lines == 2) {
 
 621           if (abs($transaction->[$i]->{'amount'}) > abs($umsatz)) {
 
 622             $umsatz = $transaction->[$i]->{'amount'};
 
 625           if (abs($transaction->[$i]->{'umsatz'}) > abs($umsatz)) {
 
 626             $umsatz = $transaction->[$i]->{'umsatz'};
 
 629         if ($transaction->[$i]->{'datevautomatik'}) {
 
 632         if ($transaction->[$i]->{'taxkey'}) {
 
 633           $taxkey = $transaction->[$i]->{'taxkey'};
 
 635         if ($transaction->[$i]->{'charttax'}) {
 
 636           $charttax = $transaction->[$i]->{'charttax'};
 
 638         if (   ($transaction->[$i]->{'id'} eq $transaction->[$i]->{'chart_id'})
 
 639             && ($trans_lines > 2)) {
 
 640           undef($transaction->[$i]);
 
 641         } elsif ($transaction->[$i]->{'amount'} > 0) {
 
 648       # Umwandlung von Umlauten und Sonderzeichen in erlaubte Zeichen bei Textfeldern
 
 649       foreach $umlaut (keys(%umlaute)) {
 
 650         $transaction->[$haben]->{'invnumber'} =~ s/${umlaut}/${umlaute{$umlaut}}/g;
 
 651         $transaction->[$haben]->{'name'}      =~ s/${umlaut}/${umlaute{$umlaut}}/g;
 
 654       $transaction->[$haben]->{'invnumber'} =~ s/[^0-9A-Za-z\$\%\&\*\+\-\/]//g;
 
 655       $transaction->[$haben]->{'name'}      =~ s/[^0-9A-Za-z\$\%\&\*\+\-\ \/]//g;
 
 657       $transaction->[$haben]->{'invnumber'} =  substr($transaction->[$haben]->{'invnumber'}, 0, 12);
 
 658       $transaction->[$haben]->{'name'}      =  substr($transaction->[$haben]->{'name'}, 0, 30);
 
 659       $transaction->[$haben]->{'invnumber'} =~ s/\ *$//;
 
 660       $transaction->[$haben]->{'name'}      =~ s/\ *$//;
 
 662       if ($trans_lines >= 2) {
 
 664         $gegenkonto = "a" . trim_leading_zeroes($transaction->[$haben]->{'accno'});
 
 665         $konto      = "e" . trim_leading_zeroes($transaction->[$soll]->{'accno'});
 
 666         if ($transaction->[$haben]->{'invnumber'} ne "") {
 
 667           $belegfeld1 = "\xBD" . $transaction->[$haben]->{'invnumber'} . "\x1C";
 
 670         $datum .= &datetofour($transaction->[$haben]->{'transdate'}, 0);
 
 671         $waehrung = "\xB3" . "EUR" . "\x1C";
 
 672         if ($transaction->[$haben]->{'name'} ne "") {
 
 673           $buchungstext = "\x1E" . $transaction->[$haben]->{'name'} . "\x1C";
 
 675         if ($transaction->[$haben]->{'duedate'} ne "") {
 
 676           $belegfeld2 = "\xBE" . &datetofour($transaction->[$haben]->{'duedate'}, 1) . "\x1C";
 
 680       $umsatz       = $kne_file->format_amount(abs($umsatz), 0);
 
 681       $umsatzsumme += $umsatz;
 
 682       $kne_file->add_block("+" . $umsatz);
 
 684       if (   ( $datevautomatik || $taxkey)
 
 685           && (!$datevautomatik || ($datevautomatik && ($charttax ne $taxkey)))) {
 
 686         $kne_file->add_block("\x6C" . (!$datevautomatik ? $taxkey : "4"));
 
 689       $kne_file->add_block($gegenkonto);
 
 690       $kne_file->add_block($belegfeld1);
 
 691       $kne_file->add_block($belegfeld2);
 
 692       $kne_file->add_block($datum);
 
 693       $kne_file->add_block($konto);
 
 694       $kne_file->add_block($buchungstext);
 
 695       $kne_file->add_block($waehrung . "\x79");
 
 698     my $mandantenendsumme = "x" . $kne_file->format_amount($umsatzsumme / 100.0, 14) . "\x79\x7a";
 
 700     $kne_file->add_block($mandantenendsumme);
 
 703     open(ED, "> $ed_filename") or die "can't open outputfile: $!\n";
 
 704     print(ED $kne_file->get_data());
 
 707     $ed_versionset[$fileno] = &make_ed_versionset($header, $filename, $kne_file->get_block_count(), $fromto);
 
 711   #Make EV Verwaltungsdatei
 
 712   $ev_header = &make_ev_header($form, $fileno);
 
 713   $ev_filename = $export_path . $evfile;
 
 714   push(@filenames, $evfile);
 
 715   open(EV, "> $ev_filename") or die "can't open outputfile: EV01\n";
 
 716   print(EV $ev_header);
 
 718   foreach $file (@ed_versionset) {
 
 719     print(EV $ed_versionset[$file]);
 
 722   print qq|<br>Done. <br>
 
 725   $main::lxdebug->leave_sub();
 
 730 sub kne_stammdatenexport {
 
 731   $main::lxdebug->enter_sub();
 
 733   my ($myconfig, $form) = @_;
 
 734   $form->{abrechnungsnr} = "99";
 
 739   <body>Export in Bearbeitung<br>
 
 744   my $export_path = $main::userspath . "/";
 
 745   my $filename    = "ED00000";
 
 751   my $remaining_bytes = 256;
 
 752   my $total_bytes     = 256;
 
 753   my $buchungssatz    = "";
 
 755   my $ed_filename = $export_path . $filename;
 
 756   push(@filenames, $filename);
 
 757   open(ED, "> $ed_filename") or die "can't open outputfile: $!\n";
 
 758   $header = &make_kne_data_header($myconfig, $form, "");
 
 759   $remaining_bytes -= length($header);
 
 761   # connect to database
 
 762   my $dbh = $form->dbconnect($myconfig);
 
 764   my (@where, @values) = ((), ());
 
 765   if ($form->{accnofrom}) {
 
 766     push @where, 'c.accno >= ?';
 
 767     push @values, $form->{accnofrom};
 
 769   if ($form->{accnoto}) {
 
 770     push @where, 'c.accno <= ?';
 
 771     push @values, $form->{accnoto};
 
 774   my $where_str = ' WHERE ' . join(' AND ', map { "($_)" } @where) if (scalar @where);
 
 776   my $query     = qq|SELECT c.accno, c.description
 
 781   my $sth = $dbh->prepare($query);
 
 782   $sth->execute(@values) || $form->dberror($query);
 
 784   while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
 
 785     if (($remaining_bytes - length("t" . $ref->{'accno'})) <= 6) {
 
 786       $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
 
 787       $buchungssatz .= "\x00" x $fuellzeichen;
 
 789       $total_bytes = ($blockcount) * 256;
 
 791     $buchungssatz .= "t" . $ref->{'accno'};
 
 792     $remaining_bytes = $total_bytes - length($buchungssatz . $header);
 
 793     $ref->{'description'} =~ s/[^0-9A-Za-z\$\%\&\*\+\-\/]//g;
 
 794     $ref->{'description'} = substr($ref->{'description'}, 0, 40);
 
 795     $ref->{'description'} =~ s/\ *$//;
 
 798         ($remaining_bytes - length("\x1E" . $ref->{'description'} . "\x1C\x79")
 
 801       $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
 
 802       $buchungssatz .= "\x00" x $fuellzeichen;
 
 804       $total_bytes = ($blockcount) * 256;
 
 806     $buchungssatz .= "\x1E" . $ref->{'description'} . "\x1C\x79";
 
 807     $remaining_bytes = $total_bytes - length($buchungssatz . $header);
 
 812   print(ED $buchungssatz);
 
 813   $fuellzeichen = 256 - (length($header . $buchungssatz . "z") % 256);
 
 814   $dateiende = "\x00" x $fuellzeichen;
 
 816   print(ED $dateiende);
 
 819   #Make EV Verwaltungsdatei
 
 821     &make_ed_versionset($header, $filename, $blockcount, $fromto);
 
 823   $ev_header = &make_ev_header($form, $fileno);
 
 824   $ev_filename = $export_path . $evfile;
 
 825   push(@filenames, $evfile);
 
 826   open(EV, "> $ev_filename") or die "can't open outputfile: EV01\n";
 
 827   print(EV $ev_header);
 
 829   foreach $file (@ed_versionset) {
 
 830     print(EV $ed_versionset[$file]);
 
 837   print qq|<br>Done. <br>
 
 840   $main::lxdebug->leave_sub();