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 #======================================================================
34 $main::lxdebug->enter_sub();
37 my $field_len = shift;
38 my $fill_char = shift;
39 my $alignment = shift || 'right';
41 my $text_len = length $text;
43 if ($field_len < $text_len) {
44 $text = substr $text, 0, $field_len;
46 } elsif ($field_len > $text_len) {
47 my $filler = ($fill_char) x ($field_len - $text_len);
48 $text = $alignment eq 'right' ? $filler . $text : $text . $filler;
51 $main::lxdebug->leave_sub();
57 $main::lxdebug->enter_sub();
59 my ($self, $myconfig, $form) = @_;
62 my $dbh = $form->dbconnect($myconfig);
64 $query = qq|SELECT * FROM datev|;
65 $sth = $dbh->prepare($query);
66 $sth->execute || $form->dberror($query);
68 my $ref = $sth->fetchrow_hashref(NAME_lc);
70 map { $form->{$_} = $ref->{$_} } keys %$ref;
74 $main::lxdebug->leave_sub();
77 sub save_datev_stamm {
78 $main::lxdebug->enter_sub();
80 my ($self, $myconfig, $form) = @_;
83 my $dbh = $form->dbconnect_noauto($myconfig);
85 $query = qq|DELETE FROM datev|;
86 $dbh->do($query) || $form->dberror($query);
88 $query = qq|INSERT INTO datev
89 (beraternr, beratername, dfvkz, mandantennr, datentraegernr, abrechnungsnr) VALUES
91 . $dbh->quote($form->{beraternr}) . qq|,|
92 . $dbh->quote($form->{beratername}) . qq|,|
93 . $dbh->quote($form->{dfvkz}) . qq|,
95 . $dbh->quote($form->{mandantennr}) . qq|,|
96 . $dbh->quote($form->{datentraegernr}) . qq|,|
97 . $dbh->quote($form->{abrechnungsnr}) . qq|)|;
98 $sth = $dbh->prepare($query);
99 $sth->execute || $form->dberror($query);
104 $main::lxdebug->leave_sub();
108 $main::lxdebug->enter_sub();
110 my ($self, $myconfig, $form) = @_;
113 if ($form->{exporttype} == 0) {
114 @rc = &kne_buchungsexport($myconfig, $form);
116 @rc = &kne_stammdatenexport($myconfig, $form);
119 $main::lxdebug->leave_sub();
125 $main::lxdebug->enter_sub();
127 my ($self, $myconfig, $form) = @_;
129 # connect to database
130 my $dbh = $form->dbconnect_noauto($myconfig);
133 $main::lxdebug->leave_sub();
137 $main::lxdebug->enter_sub();
139 my ($zeitraum, $monat, $quartal, $transdatefrom, $transdateto) = @_;
141 $fromto = "transdate >= ";
146 if ($zeitraum eq "monat") {
148 $monat eq "1" && do {
149 $form->{fromdate} = "1.1.$jahr";
150 $form->{todate} = "31.1.$jahr";
153 $monat eq "2" && do {
154 $form->{fromdate} = "1.2.$jahr";
156 #this works from 1901 to 2099, 1900 and 2100 fail.
157 $leap = ($jahr % 4 == 0) ? "29" : "28";
158 $form->{todate} = "$leap.2.$jahr";
161 $monat eq "3" && do {
162 $form->{fromdate} = "1.3.$jahr";
163 $form->{todate} = "31.3.$jahr";
166 $monat eq "4" && do {
167 $form->{fromdate} = "1.4.$jahr";
168 $form->{todate} = "30.4.$jahr";
171 $monat eq "5" && do {
172 $form->{fromdate} = "1.5.$jahr";
173 $form->{todate} = "31.5.$jahr";
176 $monat eq "6" && do {
177 $form->{fromdate} = "1.6.$jahr";
178 $form->{todate} = "30.6.$jahr";
181 $monat eq "7" && do {
182 $form->{fromdate} = "1.7.$jahr";
183 $form->{todate} = "31.7.$jahr";
186 $monat eq "8" && do {
187 $form->{fromdate} = "1.8.$jahr";
188 $form->{todate} = "31.8.$jahr";
191 $monat eq "9" && do {
192 $form->{fromdate} = "1.9.$jahr";
193 $form->{todate} = "30.9.$jahr";
196 $monat eq "10" && do {
197 $form->{fromdate} = "1.10.$jahr";
198 $form->{todate} = "31.10.$jahr";
201 $monat eq "11" && do {
202 $form->{fromdate} = "1.11.$jahr";
203 $form->{todate} = "30.11.$jahr";
206 $monat eq "12" && do {
207 $form->{fromdate} = "1.12.$jahr";
208 $form->{todate} = "31.12.$jahr";
213 "'" . $form->{fromdate} . "' and transdate <= '" . $form->{todate} . "'";
216 elsif ($zeitraum eq "quartal") {
219 "'01.01." . $jahr . "' and transdate <= '31.03." . $jahr . "'";
220 } elsif ($quartal == 2) {
222 "'01.04." . $jahr . "' and transdate <= '30.06." . $jahr . "'";
223 } elsif ($quartal == 3) {
225 "'01.07." . $jahr . "' and transdate <= '30.09." . $jahr . "'";
226 } elsif ($quartal == 4) {
228 "'01.10." . $jahr . "' and transdate <= '31.12." . $jahr . "'";
232 elsif ($zeitraum eq "zeit") {
233 $fromto .= "'" . $transdatefrom . "' and transdate <= '" . $transdateto . "'";
234 my ($yy, $mm, $dd) = $main::locale->parse_date(\%main::myconfig, $transdatefrom);
238 $main::lxdebug->leave_sub();
240 return ($fromto, $jahr);
243 sub _get_transactions {
244 $main::lxdebug->enter_sub();
248 my $myconfig = \%main::myconfig;
249 my $form = $main::form;
251 my $dbh = $form->get_standard_dbh($myconfig);
255 $fromto =~ s/transdate/ac\.transdate/g;
257 my %taxes = selectall_as_map($form, $dbh, qq|SELECT id, rate FROM tax|, 'id', 'rate');
260 qq|SELECT ac.oid, ac.transdate, ac.trans_id,ar.id, ac.amount, ac.taxkey,
261 ar.invnumber, ar.duedate, ar.amount as umsatz,
263 c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id,
264 t.chart_id, t.rate, t.id AS taxid, t.taxkey AS taxtaxkey
265 FROM acc_trans ac,ar ar, customer ct, chart c
266 LEFT JOIN tax t ON (t.chart_id = c.id)
268 AND (ac.trans_id = ar.id)
269 AND (ac.trans_id = ar.id)
270 AND (ar.customer_id = ct.id)
271 AND (ac.chart_id = c.id)
275 SELECT ac.oid, ac.transdate, ac.trans_id,ap.id, ac.amount, ac.taxkey,
276 ap.invnumber, ap.duedate, ap.amount as umsatz,
278 c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id,
279 t.chart_id, t.rate, t.id AS taxid, t.taxkey AS taxtaxkey
280 FROM acc_trans ac, ap ap, vendor ct, chart c
281 LEFT JOIN tax t ON (t.chart_id = c.id)
283 AND (ac.trans_id = ap.id)
284 AND (ap.vendor_id = ct.id)
285 AND (ac.chart_id = c.id)
289 SELECT ac.oid, ac.transdate, ac.trans_id,gl.id, ac.amount, ac.taxkey,
290 gl.reference AS invnumber, gl.transdate AS duedate, ac.amount as umsatz,
291 gl.description AS name,
292 c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id,
293 t.chart_id, t.rate, t.id AS taxid, t.taxkey AS taxtaxkey
294 FROM acc_trans ac, gl gl, chart c
295 LEFT JOIN tax t ON (t.chart_id = c.id)
297 AND (ac.trans_id = gl.id)
298 AND (ac.chart_id = c.id)
300 ORDER BY trans_id, oid|;
302 my $sth = prepare_execute_query($form, $dbh, $query);
306 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
308 if (($counter % 500) == 0) {
312 my $trans = [ $ref ];
314 my $count = $ref->{amount};
317 while (abs($count) > 0.01 || $firstrun) {
318 my $ref2 = $sth->fetchrow_hashref(NAME_lc);
321 push @{ $trans }, $ref2;
323 $count += $ref2->{amount};
327 my %taxid_taxkeys = ();
329 if (scalar(@{$trans}) <= 2) {
330 push @{ $form->{DATEV} }, $trans;
334 for my $j (0 .. (scalar(@{$trans}) - 1)) {
335 if (abs($trans->[$j]->{'amount'}) > abs($absumsatz)) {
336 $absumsatz = $trans->[$j]->{'amount'};
339 if (($trans->[$j]->{'taxtaxkey'}) && ($trans->[$j]->{'taxid'})) {
340 $taxid_taxkeys{$trans->[$j]->{'taxtaxkey'}} = $trans->[$j]->{'taxid'};
344 my $ml = ($trans->[0]->{'umsatz'} > 0) ? 1 : -1;
345 for my $j (0 .. (scalar(@{$trans}) - 1)) {
346 if ( ($j != $notsplitindex)
347 && ($trans->[$j]->{'chart_id'} eq "")
348 && ( $trans->[$j]->{'taxkey'} eq ""
349 || $trans->[$j]->{'taxkey'} eq "0"
350 || $trans->[$j]->{'taxkey'} eq "1"
351 || $trans->[$j]->{'taxkey'} eq "10"
352 || $trans->[$j]->{'taxkey'} eq "11")) {
354 map { $new_trans{$_} = $trans->[$notsplitindex]->{$_}; } keys %{ $trans->[$notsplitindex] };
356 $absumsatz += $trans->[$j]->{'amount'};
357 $new_trans{'amount'} = $trans->[$j]->{'amount'} * (-1);
358 $new_trans{'umsatz'} = abs($trans->[$j]->{'amount'}) * $ml;
359 $trans->[$j]->{'umsatz'} = abs($trans->[$j]->{'amount'}) * $ml;
361 push @splits, [ \%new_trans, $trans->[$j] ];
362 push @{ $form->{DATEV} }, $splits[-1];
364 } elsif (($j != $notsplitindex) && ($trans->[$j]->{'chart_id'} eq "")) {
365 $absumsatz += ($trans->[$j]->{'amount'} * (1 + $taxes{ $taxid_taxkeys{$trans->[$j]->{'taxkey'}} }));
368 map { $new_trans{$_} = $trans->[$notsplitindex]->{$_}; } keys %{ $trans->[$notsplitindex] };
370 my $tax_rate = 1 + $taxes{ $taxid_taxkeys{$trans->[$j]->{'taxkey'}} };
371 $new_trans{'amount'} = $form->round_amount(($trans->[$j]->{'amount'} * $tax_rate * -1), 2);
372 $new_trans{'umsatz'} = abs($form->round_amount(($trans->[$j]->{'amount'} * $tax_rate), 2)) * $ml;
373 $trans->[$j]->{'umsatz'} = abs($form->round_amount(($trans->[$j]->{'amount'} * $tax_rate), 2)) * $ml;
375 push @splits, [ \%new_trans, $trans->[$j] ];
376 push @{ $form->{DATEV} }, $splits[-1];
380 if (abs($absumsatz) > 0.01) {
381 push @errors, "Datev-Export fehlgeschlagen! Bei Transaktion $trans->[0]->{trans_id} ($absumsatz)\n";
387 $form->error(join("<br>\n", @errors)) if (@errors);
389 $main::lxdebug->leave_sub();
392 sub make_kne_data_header {
393 $main::lxdebug->enter_sub();
395 my ($myconfig, $form, $fromto, $start_jahr) = @_;
397 my $jahr = $start_jahr;
404 my $header = "\x1D\x181";
405 $header .= _fill($form->{datentraegernr}, 3, '0');
406 $header .= ($fromto) ? "11" : "13"; # Anwendungsnummer
407 $header .= _fill($form->{dfvkz}, 2, '0');
408 $header .= _fill($form->{beraternr}, 7, '0');
409 $header .= _fill($form->{mandantennr}, 5, '0');
410 $header .= _fill($form->{abrechnungsnr} . $jahr, 6, '0');
412 $fromto =~ s/transdate|>=|and|\'|<=//g;
413 my ($from, $to) = split / /, $fromto;
418 my ($fday, $fmonth, $fyear) = split(/\./, $from);
419 if (length($fmonth) < 2) {
420 $fmonth = "0" . $fmonth;
422 if (length($fday) < 2) {
425 $from = $fday . $fmonth . substr($fyear, -2, 2);
433 my ($tday, $tmonth, $tyear) = split(/\./, $to);
434 if (length($tmonth) < 2) {
435 $tmonth = "0" . $tmonth;
437 if (length($tday) < 2) {
440 $to = $tday . $tmonth . substr($tyear, -2, 2);
448 $header .= $primanota;
451 $header .= _fill($form->{passwort}, 4, '0');
452 $header .= " " x 16; # Anwendungsinfo
453 $header .= " " x 16; # Inputinfo
457 my $versionssatz = $form->{exporttype} == 0 ? "\xB5" . "1," : "\xB6" . "1,";
459 my $dbh = $form->get_standard_dbh($myconfig);
460 my $query = qq|SELECT accno FROM chart LIMIT 1|;
461 my $ref = selectfirst_hashref_query($form, $dbh, $query);
463 $versionssatz .= length $ref->{accno};
464 $versionssatz .= ",";
465 $versionssatz .= length $ref->{accno};
466 $versionssatz .= ",SELF" . "\x1C\x79";
468 $header .= $versionssatz;
470 $main::lxdebug->leave_sub();
476 $main::lxdebug->enter_sub();
478 my ($date, $six) = @_;
480 ($day, $month, $year) = split(/\./, $date);
483 $day = substr($day, 1, 1);
485 if (length($month) < 2) {
486 $month = "0" . $month;
488 if (length($year) > 2) {
489 $year = substr($year, -2, 2);
493 $date = $day . $month . $year;
495 $date = $day . $month;
498 $main::lxdebug->leave_sub();
504 $main::lxdebug->enter_sub();
506 my ($umsatz, $stellen) = @_;
509 ($vorkomma, $nachkomma) = split(/\./, $umsatz);
512 for ($i = $stellen; $i >= $stellen + 2 - length($vorkomma); $i--) {
516 for ($i = 3; $i > length($nachkomma); $i--) {
519 $umsatz = $vorkomma . substr($nachkomma, 0, 2);
521 $main::lxdebug->leave_sub();
526 sub make_ed_versionset {
527 $main::lxdebug->enter_sub();
529 my ($header, $filename, $blockcount, $fromto) = @_;
531 my $versionset = "V" . substr($filename, 2, 5);
532 $versionset .= substr($header, 6, 22);
535 $versionset .= "0000" . substr($header, 28, 19);
538 $versionset .= $datum . "001" . substr($header, 28, 4);
541 $versionset .= _fill($blockcount, 5, '0');
542 $versionset .= "001";
544 $versionset .= substr($header, -12, 10) . " ";
545 $versionset .= " " x 53;
547 $main::lxdebug->leave_sub();
553 $main::lxdebug->enter_sub();
555 my ($form, $fileno) = @_;
557 my $ev_header = _fill($form->{datentraegernr}, 3, ' ', 'left');
559 $ev_header .= _fill($form->{beraternr}, 7, ' ', 'left');
560 $ev_header .= _fill($form->{beratername}, 9, ' ', 'left');
562 $ev_header .= (_fill($fileno, 5, '0')) x 2;
563 $ev_header .= " " x 95;
565 $main::lxdebug->leave_sub();
570 sub kne_buchungsexport {
571 $main::lxdebug->enter_sub();
573 my ($myconfig, $form) = @_;
577 my $export_path = $main::userspath . "/";
578 my $filename = "ED00000";
586 <body>Export in Bearbeitung<br>
587 Buchungssätze verarbeitet:
590 ($fromto, $start_jahr) =
591 &get_dates($form->{zeitraum}, $form->{monat},
592 $form->{quartal}, $form->{transdatefrom},
593 $form->{transdateto});
594 _get_transactions($fromto);
596 print qq|<br>2. Durchlauf:|;
597 while (scalar(@{ $form->{DATEV} })) {
599 my $remaining_bytes = 256;
600 my $total_bytes = 256;
602 my $buchungssatz = "";
604 my $ed_filename = $export_path . $filename;
605 push(@filenames, $filename);
606 open(ED, "> $ed_filename") or die "can't open outputfile: $!\n";
607 $header = &make_kne_data_header($myconfig, $form, $fromto, $start_jahr);
608 $remaining_bytes -= length($header);
610 while (scalar(@{ $form->{DATEV} }) > 0) {
611 $transaction = shift @{ $form->{DATEV} };
612 $trans_lines = scalar(@{$transaction});
614 if (($counter % 500) == 0) {
629 %umlaute = ('ä' => 'ae',
637 for (my $i = 0; $i < $trans_lines; $i++) {
638 if ($trans_lines == 2) {
639 if (abs($transaction->[$i]->{'amount'}) > abs($umsatz)) {
640 $umsatz = $transaction->[$i]->{'amount'};
643 if (abs($transaction->[$i]->{'umsatz'}) > abs($umsatz)) {
644 $umsatz = $transaction->[$i]->{'umsatz'};
647 if ($transaction->[$i]->{'datevautomatik'}) {
650 if ($transaction->[$i]->{'taxkey'}) {
651 $taxkey = $transaction->[$i]->{'taxkey'};
653 if ($transaction->[$i]->{'charttax'}) {
654 $charttax = $transaction->[$i]->{'charttax'};
656 if ( ($transaction->[$i]->{'id'} eq $transaction->[$i]->{'chart_id'})
657 && ($trans_lines > 2)) {
658 undef($transaction->[$i]);
659 } elsif ($transaction->[$i]->{'amount'} > 0) {
666 $umsatzsumme += abs($umsatz);
668 # Umwandlung von Umlauten und Sonderzeichen in erlaubte Zeichen bei Textfeldern
669 foreach $umlaut (keys(%umlaute)) {
670 $transaction->[$haben]->{'invnumber'} =~
671 s/${umlaut}/${umlaute{$umlaut}}/g;
672 $transaction->[$haben]->{'name'} =~ s/${umlaut}/${umlaute{$umlaut}}/g;
675 $transaction->[$haben]->{'invnumber'} =~ s/[^0-9A-Za-z\$\%\&\*\+\-\/]//g;
676 $transaction->[$haben]->{'name'} =~ s/[^0-9A-Za-z\$\%\&\*\+\-\ \/]//g;
678 $transaction->[$haben]->{'invnumber'} =
679 substr($transaction->[$haben]->{'invnumber'}, 0, 12);
680 $transaction->[$haben]->{'name'} =
681 substr($transaction->[$haben]->{'name'}, 0, 30);
682 $transaction->[$haben]->{'invnumber'} =~ s/\ *$//;
683 $transaction->[$haben]->{'name'} =~ s/\ *$//;
685 if ($trans_lines >= 2) {
687 $gegenkonto = "a" . $transaction->[$haben]->{'accno'};
688 $konto = "e" . $transaction->[$soll]->{'accno'};
689 if ($transaction->[$haben]->{'invnumber'} ne "") {
691 "\xBD" . $transaction->[$haben]->{'invnumber'} . "\x1C";
694 $datum .= &datetofour($transaction->[$haben]->{'transdate'}, 0);
695 $waehrung = "\xB3" . "EUR" . "\x1C";
696 if ($transaction->[$haben]->{'name'} ne "") {
697 $buchungstext = "\x1E" . $transaction->[$haben]->{'name'} . "\x1C";
699 if ($transaction->[$haben]->{'duedate'} ne "") {
701 . &datetofour($transaction->[$haben]->{'duedate'}, 1) . "\x1C";
705 if (($remaining_bytes - length("+" . &formatumsatz($umsatz, 0))) <= 6) {
706 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
707 $buchungssatz .= "\x00" x $fuellzeichen;
709 $total_bytes = ($blockcount) * 256;
711 $umsatz = abs($umsatz);
712 $vorzeichen = ($umsatz > 0) ? "+" : "-";
713 $buchungssatz .= $vorzeichen . &formatumsatz($umsatz, 0);
714 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
716 if ( ($taxkey || $datevautomatik)
717 && (!$datevautomatik || ($datevautomatik && ($charttax ne $taxkey)))) {
718 if (($remaining_bytes - length("\x6C" . "11")) <= 6) {
720 ($blockcount * 256 - length($buchungssatz . $header));
721 $buchungssatz .= "\x00" x $fuellzeichen;
723 $total_bytes = ($blockcount) * 256;
725 if (!$datevautomatik) {
726 $buchungssatz .= "\x6C" . $taxkey;
728 $buchungssatz .= "\x6C" . "4";
730 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
733 if (($remaining_bytes - length($gegenkonto)) <= 6) {
734 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
735 $buchungssatz .= "\x00" x $fuellzeichen;
737 $total_bytes = ($blockcount) * 256;
739 $buchungssatz .= $gegenkonto;
740 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
742 if (($remaining_bytes - length($belegfeld1)) <= 6) {
743 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
744 $buchungssatz .= "\x00" x $fuellzeichen;
746 $total_bytes = ($blockcount) * 256;
748 $buchungssatz .= $belegfeld1;
749 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
751 if (($remaining_bytes - length($belegfeld2)) <= 6) {
752 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
753 $buchungssatz .= "\x00" x $fuellzeichen;
755 $total_bytes = ($blockcount) * 256;
757 $buchungssatz .= $belegfeld2;
758 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
760 if (($remaining_bytes - length($datum)) <= 6) {
761 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
762 $buchungssatz .= "\x00" x $fuellzeichen;
764 $total_bytes = ($blockcount) * 256;
766 $buchungssatz .= $datum;
767 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
769 if (($remaining_bytes - length($konto)) <= 6) {
770 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
771 $buchungssatz .= "\x00" x $fuellzeichen;
773 $total_bytes = ($blockcount) * 256;
775 $buchungssatz .= $konto;
776 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
778 if (($remaining_bytes - length($buchungstext)) <= 6) {
779 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
780 $buchungssatz .= "\x00" x $fuellzeichen;
782 $total_bytes = ($blockcount) * 256;
784 $buchungssatz .= $buchungstext;
785 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
787 if (($remaining_bytes - (length($waehrung . "\x79"))) <= 6) {
788 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
789 $buchungssatz .= "\x00" x $fuellzeichen;
791 $total_bytes = ($blockcount) * 256;
793 $buchungssatz .= $waehrung . "\x79";
794 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
799 "x" . &formatumsatz($umsatzsumme, 14) . "\x79" . "\x7a";
801 256 - (length($header . $buchungssatz . $mandantenendsumme) % 256);
802 $dateiende = "\x00" x $fuellzeichen;
804 print(ED $buchungssatz);
805 print(ED $mandantenendsumme);
806 print(ED $dateiende);
809 $ed_versionset[$fileno] =
810 &make_ed_versionset($header, $filename, $blockcount, $fromto);
814 #Make EV Verwaltungsdatei
815 $ev_header = &make_ev_header($form, $fileno);
816 $ev_filename = $export_path . $evfile;
817 push(@filenames, $evfile);
818 open(EV, "> $ev_filename") or die "can't open outputfile: EV01\n";
819 print(EV $ev_header);
821 foreach $file (@ed_versionset) {
822 print(EV $ed_versionset[$file]);
825 print qq|<br>Done. <br>
828 $main::lxdebug->leave_sub();
833 sub kne_stammdatenexport {
834 $main::lxdebug->enter_sub();
836 my ($myconfig, $form) = @_;
837 $form->{abrechnungsnr} = "99";
842 <body>Export in Bearbeitung<br>
847 my $export_path = $main::userspath . "/";
848 my $filename = "ED00000";
854 my $remaining_bytes = 256;
855 my $total_bytes = 256;
856 my $buchungssatz = "";
858 my $ed_filename = $export_path . $filename;
859 push(@filenames, $filename);
860 open(ED, "> $ed_filename") or die "can't open outputfile: $!\n";
861 $header = &make_kne_data_header($myconfig, $form, "");
862 $remaining_bytes -= length($header);
864 # connect to database
865 my $dbh = $form->dbconnect($myconfig);
868 qq|SELECT c.accno, c.description FROM chart c WHERE c.accno >=|
869 . $dbh->quote($form->{accnofrom}) . qq|
871 . $dbh->quote($form->{accnoto}) . qq| ORDER BY c.accno|;
873 $sth = $dbh->prepare($query);
874 $sth->execute || $form->dberror($query);
876 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
877 if (($remaining_bytes - length("t" . $ref->{'accno'})) <= 6) {
878 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
879 $buchungssatz .= "\x00" x $fuellzeichen;
881 $total_bytes = ($blockcount) * 256;
883 $buchungssatz .= "t" . $ref->{'accno'};
884 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
885 $ref->{'description'} =~ s/[^0-9A-Za-z\$\%\&\*\+\-\/]//g;
886 $ref->{'description'} = substr($ref->{'description'}, 0, 40);
887 $ref->{'description'} =~ s/\ *$//;
890 ($remaining_bytes - length("\x1E" . $ref->{'description'} . "\x1C\x79")
893 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
894 $buchungssatz .= "\x00" x $fuellzeichen;
896 $total_bytes = ($blockcount) * 256;
898 $buchungssatz .= "\x1E" . $ref->{'description'} . "\x1C\x79";
899 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
904 print(ED $buchungssatz);
905 $fuellzeichen = 256 - (length($header . $buchungssatz . "z") % 256);
906 $dateiende = "\x00" x $fuellzeichen;
908 print(ED $dateiende);
911 #Make EV Verwaltungsdatei
913 &make_ed_versionset($header, $filename, $blockcount, $fromto);
915 $ev_header = &make_ev_header($form, $fileno);
916 $ev_filename = $export_path . $evfile;
917 push(@filenames, $evfile);
918 open(EV, "> $ev_filename") or die "can't open outputfile: EV01\n";
919 print(EV $ev_header);
921 foreach $file (@ed_versionset) {
922 print(EV $ed_versionset[$file]);
929 print qq|<br>Done. <br>
932 $main::lxdebug->leave_sub();