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();
36 my ($self, $myconfig, $form) = @_;
39 my $dbh = $form->dbconnect($myconfig);
41 $query = qq|SELECT * FROM datev|;
42 $sth = $dbh->prepare($query);
43 $sth->execute || $form->dberror($query);
45 my $ref = $sth->fetchrow_hashref(NAME_lc);
47 map { $form->{$_} = $ref->{$_} } keys %$ref;
51 $main::lxdebug->leave_sub();
54 sub save_datev_stamm {
55 $main::lxdebug->enter_sub();
57 my ($self, $myconfig, $form) = @_;
60 my $dbh = $form->dbconnect_noauto($myconfig);
62 $query = qq|DELETE FROM datev|;
63 $dbh->do($query) || $form->dberror($query);
65 $query = qq|INSERT INTO datev
66 (beraternr, beratername, dfvkz, mandantennr, datentraegernr, abrechnungsnr) VALUES
68 . $dbh->quote($form->{beraternr}) . qq|,|
69 . $dbh->quote($form->{beratername}) . qq|,|
70 . $dbh->quote($form->{dfvkz}) . qq|,
72 . $dbh->quote($form->{mandantennr}) . qq|,|
73 . $dbh->quote($form->{datentraegernr}) . qq|,|
74 . $dbh->quote($form->{abrechnungsnr}) . qq|)|;
75 $sth = $dbh->prepare($query);
76 $sth->execute || $form->dberror($query);
81 $main::lxdebug->leave_sub();
85 $main::lxdebug->enter_sub();
87 my ($self, $myconfig, $form) = @_;
90 if ($form->{exporttype} == 0) {
91 @rc = &kne_buchungsexport($myconfig, $form);
93 @rc = &kne_stammdatenexport($myconfig, $form);
96 $main::lxdebug->leave_sub();
102 $main::lxdebug->enter_sub();
104 my ($self, $myconfig, $form) = @_;
106 # connect to database
107 my $dbh = $form->dbconnect_noauto($myconfig);
110 $main::lxdebug->leave_sub();
114 $main::lxdebug->enter_sub();
116 my ($zeitraum, $monat, $quartal, $transdatefrom, $transdateto) = @_;
118 $fromto = "transdate >= ";
123 if ($zeitraum eq "monat") {
125 $monat eq "1" && do {
126 $form->{fromdate} = "1.1.$jahr";
127 $form->{todate} = "31.1.$jahr";
130 $monat eq "2" && do {
131 $form->{fromdate} = "1.2.$jahr";
133 #this works from 1901 to 2099, 1900 and 2100 fail.
134 $leap = ($jahr % 4 == 0) ? "29" : "28";
135 $form->{todate} = "$leap.2.$jahr";
138 $monat eq "3" && do {
139 $form->{fromdate} = "1.3.$jahr";
140 $form->{todate} = "31.3.$jahr";
143 $monat eq "4" && do {
144 $form->{fromdate} = "1.4.$jahr";
145 $form->{todate} = "30.4.$jahr";
148 $monat eq "5" && do {
149 $form->{fromdate} = "1.5.$jahr";
150 $form->{todate} = "31.5.$jahr";
153 $monat eq "6" && do {
154 $form->{fromdate} = "1.6.$jahr";
155 $form->{todate} = "30.6.$jahr";
158 $monat eq "7" && do {
159 $form->{fromdate} = "1.7.$jahr";
160 $form->{todate} = "31.7.$jahr";
163 $monat eq "8" && do {
164 $form->{fromdate} = "1.8.$jahr";
165 $form->{todate} = "31.8.$jahr";
168 $monat eq "9" && do {
169 $form->{fromdate} = "1.9.$jahr";
170 $form->{todate} = "30.9.$jahr";
173 $monat eq "10" && do {
174 $form->{fromdate} = "1.10.$jahr";
175 $form->{todate} = "31.10.$jahr";
178 $monat eq "11" && do {
179 $form->{fromdate} = "1.11.$jahr";
180 $form->{todate} = "30.11.$jahr";
183 $monat eq "12" && do {
184 $form->{fromdate} = "1.12.$jahr";
185 $form->{todate} = "31.12.$jahr";
190 "'" . $form->{fromdate} . "' and transdate <= '" . $form->{todate} . "'";
193 elsif ($zeitraum eq "quartal") {
196 "'01.01." . $jahr . "' and transdate <= '31.03." . $jahr . "'";
197 } elsif ($quartal == 2) {
199 "'01.04." . $jahr . "' and transdate <= '30.06." . $jahr . "'";
200 } elsif ($quartal == 3) {
202 "'01.07." . $jahr . "' and transdate <= '30.09." . $jahr . "'";
203 } elsif ($quartal == 4) {
205 "'01.10." . $jahr . "' and transdate <= '31.12." . $jahr . "'";
209 elsif ($zeitraum eq "zeit") {
211 "'" . $transdatefrom . "' and transdate <= '" . $transdateto . "'";
214 $main::lxdebug->leave_sub();
219 sub _get_transactions {
220 $main::lxdebug->enter_sub();
224 my $myconfig = \%main::myconfig;
225 my $form = $main::form;
227 my $dbh = $form->get_standard_dbh($myconfig);
229 $fromto =~ s/transdate/ac\.transdate/g;
231 my %taxes = selectall_as_map($form, $dbh, qq|SELECT id, rate FROM tax|, 'id', 'rate');
234 qq|SELECT ac.oid, ac.transdate, ac.trans_id,ar.id, ac.amount, ac.taxkey,
235 ar.invnumber, ar.duedate, ar.amount as umsatz,
237 c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id,
238 t.chart_id, t.rate, t.id AS taxid, t.taxkey AS taxtaxkey
239 FROM acc_trans ac,ar ar, customer ct, chart c
240 LEFT JOIN tax t ON (t.chart_id = c.id)
242 AND (ac.trans_id = ar.id)
243 AND (ac.trans_id = ar.id)
244 AND (ar.customer_id = ct.id)
245 AND (ac.chart_id = c.id)
249 SELECT ac.oid, ac.transdate, ac.trans_id,ap.id, ac.amount, ac.taxkey,
250 ap.invnumber, ap.duedate, ap.amount as umsatz,
252 c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id,
253 t.chart_id, t.rate, t.id AS taxid, t.taxkey AS taxtaxkey
254 FROM acc_trans ac, ap ap, vendor ct, chart c
255 LEFT JOIN tax t ON (t.chart_id = c.id)
257 AND (ac.trans_id = ap.id)
258 AND (ap.vendor_id = ct.id)
259 AND (ac.chart_id = c.id)
263 SELECT ac.oid, ac.transdate, ac.trans_id,gl.id, ac.amount, ac.taxkey,
264 gl.reference AS invnumber, gl.transdate AS duedate, ac.amount as umsatz,
265 gl.description AS name,
266 c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id,
267 t.chart_id, t.rate, t.id AS taxid, t.taxkey AS taxtaxkey
268 FROM acc_trans ac, gl gl, chart c
269 LEFT JOIN tax t ON (t.chart_id = c.id)
271 AND (ac.trans_id = gl.id)
272 AND (ac.chart_id = c.id)
274 ORDER BY trans_id, oid|;
276 my $sth = prepare_execute_query($form, $dbh, $query);
281 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
283 if (($counter % 500) == 0) {
287 my $trans = [ $ref ];
289 my $count = $ref->{amount};
292 while (abs($count) > 0.01 || $firstrun) {
293 my $ref2 = $sth->fetchrow_hashref(NAME_lc);
296 push @{ $trans }, $ref2;
298 $count += $ref2->{amount};
302 my %taxid_taxkeys = ();
304 if (scalar(@{$trans}) <= 2) {
305 push @{ $form->{DATEV} }, $trans;
309 for my $j (0 .. (scalar(@{$trans}) - 1)) {
310 if (abs($trans->[$j]->{'amount'}) > abs($absumsatz)) {
311 $absumsatz = $trans->[$j]->{'amount'};
314 if (($trans->[$j]->{'taxtaxkey'}) && ($trans->[$j]->{'taxid'})) {
315 $taxid_taxkeys{$trans->[$j]->{'taxtaxkey'}} = $trans->[$j]->{'taxid'};
318 $ml = ($trans->[0]->{'umsatz'} > 0) ? 1 : -1;
319 for my $j (0 .. (scalar(@{$trans}) - 1)) {
320 if ( ($j != $notsplitindex)
321 && ($trans->[$j]->{'chart_id'} eq "")
322 && ( $trans->[$j]->{'taxkey'} eq ""
323 || $trans->[$j]->{'taxkey'} eq "0"
324 || $trans->[$j]->{'taxkey'} eq "1"
325 || $trans->[$j]->{'taxkey'} eq "10"
326 || $trans->[$j]->{'taxkey'} eq "11")) {
328 map({ $blubb{$_} = $trans->[$notsplitindex]->{$_}; } keys(%{ $trans->[$notsplitindex] }));
330 $absumsatz += $trans->[$j]->{'amount'};
331 $blubb{'amount'} = $trans->[$j]->{'amount'} * (-1);
332 $blubb{'umsatz'} = abs($trans->[$j]->{'amount'}) * $ml;
333 $trans->[$j]->{'umsatz'} = abs($trans->[$j]->{'amount'}) * $ml;
335 push @{ $splits[$g] }, \%blubb; #$trans->[$notsplitindex];
336 push @{ $splits[$g] }, $trans->[$j];
337 push @{ $form->{DATEV} }, \@{ $splits[$g] };
341 } elsif (($j != $notsplitindex) && ($trans->[$j]->{'chart_id'} eq "")) {
342 $absumsatz += ($trans->[$j]->{'amount'} * (1 + $taxes{ $taxid_taxkeys{$trans->[$j]->{'taxkey'}} }));
345 map({ $blubb{$_} = $trans->[$notsplitindex]->{$_}; } keys(%{ $trans->[$notsplitindex] }));
347 $test = 1 + $taxes{ $taxid_taxkeys{$trans->[$j]->{'taxkey'}} };
348 $blubb{'amount'} = $form->round_amount(($trans->[$j]->{'amount'} * $test * -1), 2);
349 $blubb{'umsatz'} = abs($form->round_amount(($trans->[$j]->{'amount'} * $test), 2)) * $ml;
350 $trans->[$j]->{'umsatz'} = abs($form->round_amount(($trans->[$j]->{'amount'} * $test), 2)) * $ml;
352 push @{ $splits[$g] }, \%blubb;
353 push @{ $splits[$g] }, $trans->[$j];
354 push @{ $form->{DATEV} }, \@{ $splits[$g] };
359 if (abs($absumsatz) > 0.01) {
360 $form->error("Datev-Export fehlgeschlagen! Bei Transaktion $trans->[0]->{trans_id} $absumsatz\n");
366 $main::lxdebug->leave_sub();
369 sub make_kne_data_header {
370 $main::lxdebug->enter_sub();
372 my ($myconfig, $form, $fromto) = @_;
374 # connect to database
375 my $dbh = $form->dbconnect($myconfig);
381 $anwendungsnr = ($fromto) ? "\x31\x31" : "\x31\x33";
382 while (length($form->{datentraegernr}) < 3) {
383 $form->{datentraegernr} = "\x30" . $form->{datentraegernr};
386 $header = "\x1D\x18\x31" . $form->{datentraegernr} . $anwendungsnr;
388 $dfvkz = $form->{dfvkz};
389 while (length($dfvkz) < 2) {
390 $dfvkz = "\x30" . $dfvkz;
394 $beraternr = $form->{beraternr};
395 while (length($beraternr) < 7) {
396 $beraternr = "\x30" . $beraternr;
398 $header .= $beraternr;
400 $mandantennr = $form->{mandantennr};
401 while (length($mandantennr) < 5) {
402 $mandantennr = "\x30" . $mandantennr;
404 $header .= $mandantennr;
406 $abrechnungsnr = $form->{abrechnungsnr} . $jahr;
407 while (length($abrechnungsnr) < 6) {
408 $abrechnungsnr = "\x30" . $abrechnungsnr;
410 $header .= $abrechnungsnr;
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);
446 $primanota = "\x30\x30\x31";
447 $header .= $primanota;
450 $passwort = $form->{passwort};
451 while (length($passwort) < 4) {
452 $passwort = "\x30" . $passwort;
454 $header .= $passwort;
456 $anwendungsinfo = "\x20" x 16;
457 $header .= $anwendungsinfo;
458 $inputinfo = "\x20" x 16;
459 $header .= $inputinfo;
464 if ($form->{exporttype} == 0) {
465 $versionssatz = "\xB5" . "1,";
467 $versionssatz = "\xB6" . "1,";
470 $query = qq| select accno from chart limit 1|;
471 $sth = $dbh->prepare($query);
472 $sth->execute || $form->dberror($query);
473 my $ref = $sth->fetchrow_hashref(NAME_lc);
475 $accnolength = $ref->{accno};
478 $versionssatz .= length($accnolength);
479 $versionssatz .= ",";
480 $versionssatz .= length($accnolength);
481 $versionssatz .= ",SELF" . "\x1C\x79";
485 $header .= $versionssatz;
487 $main::lxdebug->leave_sub();
493 $main::lxdebug->enter_sub();
495 my ($date, $six) = @_;
497 ($day, $month, $year) = split(/\./, $date);
500 $day = substr($day, 1, 1);
502 if (length($month) < 2) {
503 $month = "0" . $month;
505 if (length($year) > 2) {
506 $year = substr($year, -2, 2);
510 $date = $day . $month . $year;
512 $date = $day . $month;
515 $main::lxdebug->leave_sub();
521 $main::lxdebug->enter_sub();
523 my ($umsatz, $stellen) = @_;
526 ($vorkomma, $nachkomma) = split(/\./, $umsatz);
529 for ($i = $stellen; $i >= $stellen + 2 - length($vorkomma); $i--) {
533 for ($i = 3; $i > length($nachkomma); $i--) {
536 $umsatz = $vorkomma . substr($nachkomma, 0, 2);
538 $main::lxdebug->leave_sub();
543 sub make_ed_versionset {
544 $main::lxdebug->enter_sub();
546 my ($header, $filename, $blockcount, $fromto) = @_;
548 $versionset = "V" . substr($filename, 2, 5);
549 $versionset .= substr($header, 6, 22);
551 $versionset .= "0000" . substr($header, 28, 19);
553 $datum = "\x20" x 16;
554 $versionset .= $datum . "001" . substr($header, 28, 4);
556 while (length($blockcount) < 5) {
557 $blockcount = "0" . $blockcount;
559 $versionset .= $blockcount;
560 $versionset .= "001";
561 $versionset .= "\x20\x31";
562 $versionset .= substr($header, -12, 10) . " ";
563 $versionset .= "\x20" x 53;
565 $main::lxdebug->leave_sub();
571 $main::lxdebug->enter_sub();
573 my ($form, $fileno) = @_;
574 $datentraegernr = $form->{datentraegernr};
575 $beraternummer = $form->{beraternr};
576 $beratername = $form->{beratername};
577 $anzahl_dateien = $fileno;
579 while (length($datentraegernr) < 3) {
580 $datentraegernr .= " ";
583 while (length($beraternummer) < 7) {
584 $beraternummer .= " ";
587 while (length($beratername) < 9) {
591 while (length($anzahl_dateien) < 5) {
592 $anzahl_dateien = "0" . $anzahl_dateien;
596 $datentraegernr . "\x20\x20\x20" . $beraternummer . $beratername . "\x20";
597 $ev_header .= $anzahl_dateien . $anzahl_dateien;
598 $ev_header .= "\x20" x 95;
600 $main::lxdebug->leave_sub();
605 sub kne_buchungsexport {
606 $main::lxdebug->enter_sub();
608 my ($myconfig, $form) = @_;
612 my $export_path = $main::userspath . "/";
613 my $filename = "ED00000";
621 <body>Export in Bearbeitung<br>
622 Buchungssätze verarbeitet:
626 &get_dates($form->{zeitraum}, $form->{monat},
627 $form->{quartal}, $form->{transdatefrom},
628 $form->{transdateto});
629 _get_transactions($fromto);
631 print qq|<br>2. Durchlauf:|;
632 while (scalar(@{ $form->{DATEV} })) {
634 my $remaining_bytes = 256;
635 my $total_bytes = 256;
637 my $buchungssatz = "";
639 my $ed_filename = $export_path . $filename;
640 push(@filenames, $filename);
641 open(ED, "> $ed_filename") or die "can't open outputfile: $!\n";
642 $header = &make_kne_data_header($myconfig, $form, $fromto);
643 $remaining_bytes -= length($header);
645 while (scalar(@{ $form->{DATEV} }) > 0) {
646 $transaction = shift @{ $form->{DATEV} };
647 $trans_lines = scalar(@{$transaction});
649 if (($counter % 500) == 0) {
664 %umlaute = ('ä' => 'ae',
672 for (my $i = 0; $i < $trans_lines; $i++) {
673 if ($trans_lines == 2) {
674 if (abs($transaction->[$i]->{'amount'}) > abs($umsatz)) {
675 $umsatz = $transaction->[$i]->{'amount'};
678 if (abs($transaction->[$i]->{'umsatz'}) > abs($umsatz)) {
679 $umsatz = $transaction->[$i]->{'umsatz'};
682 if ($transaction->[$i]->{'datevautomatik'}) {
685 if ($transaction->[$i]->{'taxkey'}) {
686 $taxkey = $transaction->[$i]->{'taxkey'};
688 if ($transaction->[$i]->{'charttax'}) {
689 $charttax = $transaction->[$i]->{'charttax'};
691 if ( ($transaction->[$i]->{'id'} eq $transaction->[$i]->{'chart_id'})
692 && ($trans_lines > 2)) {
693 undef($transaction->[$i]);
694 } elsif ($transaction->[$i]->{'amount'} > 0) {
701 $umsatzsumme += abs($umsatz);
703 # Umwandlung von Umlauten und Sonderzeichen in erlaubte Zeichen bei Textfeldern
704 foreach $umlaut (keys(%umlaute)) {
705 $transaction->[$haben]->{'invnumber'} =~
706 s/${umlaut}/${umlaute{$umlaut}}/g;
707 $transaction->[$haben]->{'name'} =~ s/${umlaut}/${umlaute{$umlaut}}/g;
710 $transaction->[$haben]->{'invnumber'} =~ s/[^0-9A-Za-z\$\%\&\*\+\-\/]//g;
711 $transaction->[$haben]->{'name'} =~ s/[^0-9A-Za-z\$\%\&\*\+\-\ \/]//g;
713 $transaction->[$haben]->{'invnumber'} =
714 substr($transaction->[$haben]->{'invnumber'}, 0, 12);
715 $transaction->[$haben]->{'name'} =
716 substr($transaction->[$haben]->{'name'}, 0, 30);
717 $transaction->[$haben]->{'invnumber'} =~ s/\ *$//;
718 $transaction->[$haben]->{'name'} =~ s/\ *$//;
720 if ($trans_lines >= 2) {
722 $gegenkonto = "a" . $transaction->[$haben]->{'accno'};
723 $konto = "e" . $transaction->[$soll]->{'accno'};
724 if ($transaction->[$haben]->{'invnumber'} ne "") {
726 "\xBD" . $transaction->[$haben]->{'invnumber'} . "\x1C";
729 $datum .= &datetofour($transaction->[$haben]->{'transdate'}, 0);
730 $waehrung = "\xB3" . "EUR" . "\x1C";
731 if ($transaction->[$haben]->{'name'} ne "") {
732 $buchungstext = "\x1E" . $transaction->[$haben]->{'name'} . "\x1C";
734 if ($transaction->[$haben]->{'duedate'} ne "") {
736 . &datetofour($transaction->[$haben]->{'duedate'}, 1) . "\x1C";
740 if (($remaining_bytes - length("+" . &formatumsatz($umsatz, 0))) <= 6) {
741 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
742 $buchungssatz .= "\x00" x $fuellzeichen;
744 $total_bytes = ($blockcount) * 256;
746 $umsatz = abs($umsatz);
747 $vorzeichen = ($umsatz > 0) ? "+" : "-";
748 $buchungssatz .= $vorzeichen . &formatumsatz($umsatz, 0);
749 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
751 if ( ($taxkey || $datevautomatik)
752 && (!$datevautomatik || ($datevautomatik && ($charttax ne $taxkey)))) {
753 if (($remaining_bytes - length("\x6C" . "11")) <= 6) {
755 ($blockcount * 256 - length($buchungssatz . $header));
756 $buchungssatz .= "\x00" x $fuellzeichen;
758 $total_bytes = ($blockcount) * 256;
760 if (!$datevautomatik) {
761 $buchungssatz .= "\x6C" . $taxkey;
763 $buchungssatz .= "\x6C" . "4";
765 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
768 if (($remaining_bytes - length($gegenkonto)) <= 6) {
769 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
770 $buchungssatz .= "\x00" x $fuellzeichen;
772 $total_bytes = ($blockcount) * 256;
774 $buchungssatz .= $gegenkonto;
775 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
777 if (($remaining_bytes - length($belegfeld1)) <= 6) {
778 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
779 $buchungssatz .= "\x00" x $fuellzeichen;
781 $total_bytes = ($blockcount) * 256;
783 $buchungssatz .= $belegfeld1;
784 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
786 if (($remaining_bytes - length($belegfeld2)) <= 6) {
787 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
788 $buchungssatz .= "\x00" x $fuellzeichen;
790 $total_bytes = ($blockcount) * 256;
792 $buchungssatz .= $belegfeld2;
793 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
795 if (($remaining_bytes - length($datum)) <= 6) {
796 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
797 $buchungssatz .= "\x00" x $fuellzeichen;
799 $total_bytes = ($blockcount) * 256;
801 $buchungssatz .= $datum;
802 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
804 if (($remaining_bytes - length($konto)) <= 6) {
805 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
806 $buchungssatz .= "\x00" x $fuellzeichen;
808 $total_bytes = ($blockcount) * 256;
810 $buchungssatz .= $konto;
811 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
813 if (($remaining_bytes - length($buchungstext)) <= 6) {
814 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
815 $buchungssatz .= "\x00" x $fuellzeichen;
817 $total_bytes = ($blockcount) * 256;
819 $buchungssatz .= $buchungstext;
820 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
822 if (($remaining_bytes - (length($waehrung . "\x79"))) <= 6) {
823 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
824 $buchungssatz .= "\x00" x $fuellzeichen;
826 $total_bytes = ($blockcount) * 256;
828 $buchungssatz .= $waehrung . "\x79";
829 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
834 "x" . &formatumsatz($umsatzsumme, 14) . "\x79" . "\x7a";
836 256 - (length($header . $buchungssatz . $mandantenendsumme) % 256);
837 $dateiende = "\x00" x $fuellzeichen;
839 print(ED $buchungssatz);
840 print(ED $mandantenendsumme);
841 print(ED $dateiende);
844 $ed_versionset[$fileno] =
845 &make_ed_versionset($header, $filename, $blockcount, $fromto);
849 #Make EV Verwaltungsdatei
850 $ev_header = &make_ev_header($form, $fileno);
851 $ev_filename = $export_path . $evfile;
852 push(@filenames, $evfile);
853 open(EV, "> $ev_filename") or die "can't open outputfile: EV01\n";
854 print(EV $ev_header);
856 foreach $file (@ed_versionset) {
857 print(EV $ed_versionset[$file]);
860 print qq|<br>Done. <br>
863 $main::lxdebug->leave_sub();
868 sub kne_stammdatenexport {
869 $main::lxdebug->enter_sub();
871 my ($myconfig, $form) = @_;
872 $form->{abrechnungsnr} = "99";
877 <body>Export in Bearbeitung<br>
882 my $export_path = $main::userspath . "/";
883 my $filename = "ED00000";
889 my $remaining_bytes = 256;
890 my $total_bytes = 256;
891 my $buchungssatz = "";
893 my $ed_filename = $export_path . $filename;
894 push(@filenames, $filename);
895 open(ED, "> $ed_filename") or die "can't open outputfile: $!\n";
896 $header = &make_kne_data_header($myconfig, $form, "");
897 $remaining_bytes -= length($header);
899 # connect to database
900 my $dbh = $form->dbconnect($myconfig);
903 qq|SELECT c.accno, c.description FROM chart c WHERE c.accno >=|
904 . $dbh->quote($form->{accnofrom}) . qq|
906 . $dbh->quote($form->{accnoto}) . qq| ORDER BY c.accno|;
908 $sth = $dbh->prepare($query);
909 $sth->execute || $form->dberror($query);
911 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
912 if (($remaining_bytes - length("t" . $ref->{'accno'})) <= 6) {
913 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
914 $buchungssatz .= "\x00" x $fuellzeichen;
916 $total_bytes = ($blockcount) * 256;
918 $buchungssatz .= "t" . $ref->{'accno'};
919 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
920 $ref->{'description'} =~ s/[^0-9A-Za-z\$\%\&\*\+\-\/]//g;
921 $ref->{'description'} = substr($ref->{'description'}, 0, 40);
922 $ref->{'description'} =~ s/\ *$//;
925 ($remaining_bytes - length("\x1E" . $ref->{'description'} . "\x1C\x79")
928 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
929 $buchungssatz .= "\x00" x $fuellzeichen;
931 $total_bytes = ($blockcount) * 256;
933 $buchungssatz .= "\x1E" . $ref->{'description'} . "\x1C\x79";
934 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
939 print(ED $buchungssatz);
940 $fuellzeichen = 256 - (length($header . $buchungssatz . "z") % 256);
941 $dateiende = "\x00" x $fuellzeichen;
943 print(ED $dateiende);
946 #Make EV Verwaltungsdatei
948 &make_ed_versionset($header, $filename, $blockcount, $fromto);
950 $ev_header = &make_ev_header($form, $fileno);
951 $ev_filename = $export_path . $evfile;
952 push(@filenames, $evfile);
953 open(EV, "> $ev_filename") or die "can't open outputfile: EV01\n";
954 print(EV $ev_header);
956 foreach $file (@ed_versionset) {
957 print(EV $ed_versionset[$file]);
964 print qq|<br>Done. <br>
967 $main::lxdebug->leave_sub();