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);
280 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
282 if (($counter % 500) == 0) {
286 my $trans = [ $ref ];
288 my $count = $ref->{amount};
291 while (abs($count) > 0.01 || $firstrun) {
292 my $ref2 = $sth->fetchrow_hashref(NAME_lc);
295 push @{ $trans }, $ref2;
297 $count += $ref2->{amount};
301 my %taxid_taxkeys = ();
303 if (scalar(@{$trans}) <= 2) {
304 push @{ $form->{DATEV} }, $trans;
308 for my $j (0 .. (scalar(@{$trans}) - 1)) {
309 if (abs($trans->[$j]->{'amount'}) > abs($absumsatz)) {
310 $absumsatz = $trans->[$j]->{'amount'};
313 if (($trans->[$j]->{'taxtaxkey'}) && ($trans->[$j]->{'taxid'})) {
314 $taxid_taxkeys{$trans->[$j]->{'taxtaxkey'}} = $trans->[$j]->{'taxid'};
318 my $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 { $new_trans{$_} = $trans->[$notsplitindex]->{$_}; } keys %{ $trans->[$notsplitindex] };
330 $absumsatz += $trans->[$j]->{'amount'};
331 $new_trans{'amount'} = $trans->[$j]->{'amount'} * (-1);
332 $new_trans{'umsatz'} = abs($trans->[$j]->{'amount'}) * $ml;
333 $trans->[$j]->{'umsatz'} = abs($trans->[$j]->{'amount'}) * $ml;
335 push @splits, [ \%new_trans, $trans->[$j] ];
336 push @{ $form->{DATEV} }, $splits[-1];
338 } elsif (($j != $notsplitindex) && ($trans->[$j]->{'chart_id'} eq "")) {
339 $absumsatz += ($trans->[$j]->{'amount'} * (1 + $taxes{ $taxid_taxkeys{$trans->[$j]->{'taxkey'}} }));
342 map { $new_trans{$_} = $trans->[$notsplitindex]->{$_}; } keys %{ $trans->[$notsplitindex] };
344 my $tax_rate = 1 + $taxes{ $taxid_taxkeys{$trans->[$j]->{'taxkey'}} };
345 $new_trans{'amount'} = $form->round_amount(($trans->[$j]->{'amount'} * $tax_rate * -1), 2);
346 $new_trans{'umsatz'} = abs($form->round_amount(($trans->[$j]->{'amount'} * $tax_rate), 2)) * $ml;
347 $trans->[$j]->{'umsatz'} = abs($form->round_amount(($trans->[$j]->{'amount'} * $tax_rate), 2)) * $ml;
349 push @splits, [ \%new_trans, $trans->[$j] ];
350 push @{ $form->{DATEV} }, $splits[-1];
354 if (abs($absumsatz) > 0.01) {
355 $form->error("Datev-Export fehlgeschlagen! Bei Transaktion $trans->[0]->{trans_id} $absumsatz\n");
361 $main::lxdebug->leave_sub();
364 sub make_kne_data_header {
365 $main::lxdebug->enter_sub();
367 my ($myconfig, $form, $fromto) = @_;
369 # connect to database
370 my $dbh = $form->dbconnect($myconfig);
376 $anwendungsnr = ($fromto) ? "\x31\x31" : "\x31\x33";
377 while (length($form->{datentraegernr}) < 3) {
378 $form->{datentraegernr} = "\x30" . $form->{datentraegernr};
381 $header = "\x1D\x18\x31" . $form->{datentraegernr} . $anwendungsnr;
383 $dfvkz = $form->{dfvkz};
384 while (length($dfvkz) < 2) {
385 $dfvkz = "\x30" . $dfvkz;
389 $beraternr = $form->{beraternr};
390 while (length($beraternr) < 7) {
391 $beraternr = "\x30" . $beraternr;
393 $header .= $beraternr;
395 $mandantennr = $form->{mandantennr};
396 while (length($mandantennr) < 5) {
397 $mandantennr = "\x30" . $mandantennr;
399 $header .= $mandantennr;
401 $abrechnungsnr = $form->{abrechnungsnr} . $jahr;
402 while (length($abrechnungsnr) < 6) {
403 $abrechnungsnr = "\x30" . $abrechnungsnr;
405 $header .= $abrechnungsnr;
407 $fromto =~ s/transdate|>=|and|\'|<=//g;
408 my ($from, $to) = split / /, $fromto;
413 my ($fday, $fmonth, $fyear) = split(/\./, $from);
414 if (length($fmonth) < 2) {
415 $fmonth = "0" . $fmonth;
417 if (length($fday) < 2) {
420 $from = $fday . $fmonth . substr($fyear, -2, 2);
428 my ($tday, $tmonth, $tyear) = split(/\./, $to);
429 if (length($tmonth) < 2) {
430 $tmonth = "0" . $tmonth;
432 if (length($tday) < 2) {
435 $to = $tday . $tmonth . substr($tyear, -2, 2);
441 $primanota = "\x30\x30\x31";
442 $header .= $primanota;
445 $passwort = $form->{passwort};
446 while (length($passwort) < 4) {
447 $passwort = "\x30" . $passwort;
449 $header .= $passwort;
451 $anwendungsinfo = "\x20" x 16;
452 $header .= $anwendungsinfo;
453 $inputinfo = "\x20" x 16;
454 $header .= $inputinfo;
459 if ($form->{exporttype} == 0) {
460 $versionssatz = "\xB5" . "1,";
462 $versionssatz = "\xB6" . "1,";
465 $query = qq| select accno from chart limit 1|;
466 $sth = $dbh->prepare($query);
467 $sth->execute || $form->dberror($query);
468 my $ref = $sth->fetchrow_hashref(NAME_lc);
470 $accnolength = $ref->{accno};
473 $versionssatz .= length($accnolength);
474 $versionssatz .= ",";
475 $versionssatz .= length($accnolength);
476 $versionssatz .= ",SELF" . "\x1C\x79";
480 $header .= $versionssatz;
482 $main::lxdebug->leave_sub();
488 $main::lxdebug->enter_sub();
490 my ($date, $six) = @_;
492 ($day, $month, $year) = split(/\./, $date);
495 $day = substr($day, 1, 1);
497 if (length($month) < 2) {
498 $month = "0" . $month;
500 if (length($year) > 2) {
501 $year = substr($year, -2, 2);
505 $date = $day . $month . $year;
507 $date = $day . $month;
510 $main::lxdebug->leave_sub();
516 $main::lxdebug->enter_sub();
518 my ($umsatz, $stellen) = @_;
521 ($vorkomma, $nachkomma) = split(/\./, $umsatz);
524 for ($i = $stellen; $i >= $stellen + 2 - length($vorkomma); $i--) {
528 for ($i = 3; $i > length($nachkomma); $i--) {
531 $umsatz = $vorkomma . substr($nachkomma, 0, 2);
533 $main::lxdebug->leave_sub();
538 sub make_ed_versionset {
539 $main::lxdebug->enter_sub();
541 my ($header, $filename, $blockcount, $fromto) = @_;
543 $versionset = "V" . substr($filename, 2, 5);
544 $versionset .= substr($header, 6, 22);
546 $versionset .= "0000" . substr($header, 28, 19);
548 $datum = "\x20" x 16;
549 $versionset .= $datum . "001" . substr($header, 28, 4);
551 while (length($blockcount) < 5) {
552 $blockcount = "0" . $blockcount;
554 $versionset .= $blockcount;
555 $versionset .= "001";
556 $versionset .= "\x20\x31";
557 $versionset .= substr($header, -12, 10) . " ";
558 $versionset .= "\x20" x 53;
560 $main::lxdebug->leave_sub();
566 $main::lxdebug->enter_sub();
568 my ($form, $fileno) = @_;
569 $datentraegernr = $form->{datentraegernr};
570 $beraternummer = $form->{beraternr};
571 $beratername = $form->{beratername};
572 $anzahl_dateien = $fileno;
574 while (length($datentraegernr) < 3) {
575 $datentraegernr .= " ";
578 while (length($beraternummer) < 7) {
579 $beraternummer .= " ";
582 while (length($beratername) < 9) {
586 while (length($anzahl_dateien) < 5) {
587 $anzahl_dateien = "0" . $anzahl_dateien;
591 $datentraegernr . "\x20\x20\x20" . $beraternummer . $beratername . "\x20";
592 $ev_header .= $anzahl_dateien . $anzahl_dateien;
593 $ev_header .= "\x20" x 95;
595 $main::lxdebug->leave_sub();
600 sub kne_buchungsexport {
601 $main::lxdebug->enter_sub();
603 my ($myconfig, $form) = @_;
607 my $export_path = $main::userspath . "/";
608 my $filename = "ED00000";
616 <body>Export in Bearbeitung<br>
617 Buchungssätze verarbeitet:
621 &get_dates($form->{zeitraum}, $form->{monat},
622 $form->{quartal}, $form->{transdatefrom},
623 $form->{transdateto});
624 _get_transactions($fromto);
626 print qq|<br>2. Durchlauf:|;
627 while (scalar(@{ $form->{DATEV} })) {
629 my $remaining_bytes = 256;
630 my $total_bytes = 256;
632 my $buchungssatz = "";
634 my $ed_filename = $export_path . $filename;
635 push(@filenames, $filename);
636 open(ED, "> $ed_filename") or die "can't open outputfile: $!\n";
637 $header = &make_kne_data_header($myconfig, $form, $fromto);
638 $remaining_bytes -= length($header);
640 while (scalar(@{ $form->{DATEV} }) > 0) {
641 $transaction = shift @{ $form->{DATEV} };
642 $trans_lines = scalar(@{$transaction});
644 if (($counter % 500) == 0) {
659 %umlaute = ('ä' => 'ae',
667 for (my $i = 0; $i < $trans_lines; $i++) {
668 if ($trans_lines == 2) {
669 if (abs($transaction->[$i]->{'amount'}) > abs($umsatz)) {
670 $umsatz = $transaction->[$i]->{'amount'};
673 if (abs($transaction->[$i]->{'umsatz'}) > abs($umsatz)) {
674 $umsatz = $transaction->[$i]->{'umsatz'};
677 if ($transaction->[$i]->{'datevautomatik'}) {
680 if ($transaction->[$i]->{'taxkey'}) {
681 $taxkey = $transaction->[$i]->{'taxkey'};
683 if ($transaction->[$i]->{'charttax'}) {
684 $charttax = $transaction->[$i]->{'charttax'};
686 if ( ($transaction->[$i]->{'id'} eq $transaction->[$i]->{'chart_id'})
687 && ($trans_lines > 2)) {
688 undef($transaction->[$i]);
689 } elsif ($transaction->[$i]->{'amount'} > 0) {
696 $umsatzsumme += abs($umsatz);
698 # Umwandlung von Umlauten und Sonderzeichen in erlaubte Zeichen bei Textfeldern
699 foreach $umlaut (keys(%umlaute)) {
700 $transaction->[$haben]->{'invnumber'} =~
701 s/${umlaut}/${umlaute{$umlaut}}/g;
702 $transaction->[$haben]->{'name'} =~ s/${umlaut}/${umlaute{$umlaut}}/g;
705 $transaction->[$haben]->{'invnumber'} =~ s/[^0-9A-Za-z\$\%\&\*\+\-\/]//g;
706 $transaction->[$haben]->{'name'} =~ s/[^0-9A-Za-z\$\%\&\*\+\-\ \/]//g;
708 $transaction->[$haben]->{'invnumber'} =
709 substr($transaction->[$haben]->{'invnumber'}, 0, 12);
710 $transaction->[$haben]->{'name'} =
711 substr($transaction->[$haben]->{'name'}, 0, 30);
712 $transaction->[$haben]->{'invnumber'} =~ s/\ *$//;
713 $transaction->[$haben]->{'name'} =~ s/\ *$//;
715 if ($trans_lines >= 2) {
717 $gegenkonto = "a" . $transaction->[$haben]->{'accno'};
718 $konto = "e" . $transaction->[$soll]->{'accno'};
719 if ($transaction->[$haben]->{'invnumber'} ne "") {
721 "\xBD" . $transaction->[$haben]->{'invnumber'} . "\x1C";
724 $datum .= &datetofour($transaction->[$haben]->{'transdate'}, 0);
725 $waehrung = "\xB3" . "EUR" . "\x1C";
726 if ($transaction->[$haben]->{'name'} ne "") {
727 $buchungstext = "\x1E" . $transaction->[$haben]->{'name'} . "\x1C";
729 if ($transaction->[$haben]->{'duedate'} ne "") {
731 . &datetofour($transaction->[$haben]->{'duedate'}, 1) . "\x1C";
735 if (($remaining_bytes - length("+" . &formatumsatz($umsatz, 0))) <= 6) {
736 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
737 $buchungssatz .= "\x00" x $fuellzeichen;
739 $total_bytes = ($blockcount) * 256;
741 $umsatz = abs($umsatz);
742 $vorzeichen = ($umsatz > 0) ? "+" : "-";
743 $buchungssatz .= $vorzeichen . &formatumsatz($umsatz, 0);
744 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
746 if ( ($taxkey || $datevautomatik)
747 && (!$datevautomatik || ($datevautomatik && ($charttax ne $taxkey)))) {
748 if (($remaining_bytes - length("\x6C" . "11")) <= 6) {
750 ($blockcount * 256 - length($buchungssatz . $header));
751 $buchungssatz .= "\x00" x $fuellzeichen;
753 $total_bytes = ($blockcount) * 256;
755 if (!$datevautomatik) {
756 $buchungssatz .= "\x6C" . $taxkey;
758 $buchungssatz .= "\x6C" . "4";
760 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
763 if (($remaining_bytes - length($gegenkonto)) <= 6) {
764 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
765 $buchungssatz .= "\x00" x $fuellzeichen;
767 $total_bytes = ($blockcount) * 256;
769 $buchungssatz .= $gegenkonto;
770 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
772 if (($remaining_bytes - length($belegfeld1)) <= 6) {
773 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
774 $buchungssatz .= "\x00" x $fuellzeichen;
776 $total_bytes = ($blockcount) * 256;
778 $buchungssatz .= $belegfeld1;
779 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
781 if (($remaining_bytes - length($belegfeld2)) <= 6) {
782 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
783 $buchungssatz .= "\x00" x $fuellzeichen;
785 $total_bytes = ($blockcount) * 256;
787 $buchungssatz .= $belegfeld2;
788 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
790 if (($remaining_bytes - length($datum)) <= 6) {
791 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
792 $buchungssatz .= "\x00" x $fuellzeichen;
794 $total_bytes = ($blockcount) * 256;
796 $buchungssatz .= $datum;
797 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
799 if (($remaining_bytes - length($konto)) <= 6) {
800 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
801 $buchungssatz .= "\x00" x $fuellzeichen;
803 $total_bytes = ($blockcount) * 256;
805 $buchungssatz .= $konto;
806 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
808 if (($remaining_bytes - length($buchungstext)) <= 6) {
809 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
810 $buchungssatz .= "\x00" x $fuellzeichen;
812 $total_bytes = ($blockcount) * 256;
814 $buchungssatz .= $buchungstext;
815 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
817 if (($remaining_bytes - (length($waehrung . "\x79"))) <= 6) {
818 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
819 $buchungssatz .= "\x00" x $fuellzeichen;
821 $total_bytes = ($blockcount) * 256;
823 $buchungssatz .= $waehrung . "\x79";
824 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
829 "x" . &formatumsatz($umsatzsumme, 14) . "\x79" . "\x7a";
831 256 - (length($header . $buchungssatz . $mandantenendsumme) % 256);
832 $dateiende = "\x00" x $fuellzeichen;
834 print(ED $buchungssatz);
835 print(ED $mandantenendsumme);
836 print(ED $dateiende);
839 $ed_versionset[$fileno] =
840 &make_ed_versionset($header, $filename, $blockcount, $fromto);
844 #Make EV Verwaltungsdatei
845 $ev_header = &make_ev_header($form, $fileno);
846 $ev_filename = $export_path . $evfile;
847 push(@filenames, $evfile);
848 open(EV, "> $ev_filename") or die "can't open outputfile: EV01\n";
849 print(EV $ev_header);
851 foreach $file (@ed_versionset) {
852 print(EV $ed_versionset[$file]);
855 print qq|<br>Done. <br>
858 $main::lxdebug->leave_sub();
863 sub kne_stammdatenexport {
864 $main::lxdebug->enter_sub();
866 my ($myconfig, $form) = @_;
867 $form->{abrechnungsnr} = "99";
872 <body>Export in Bearbeitung<br>
877 my $export_path = $main::userspath . "/";
878 my $filename = "ED00000";
884 my $remaining_bytes = 256;
885 my $total_bytes = 256;
886 my $buchungssatz = "";
888 my $ed_filename = $export_path . $filename;
889 push(@filenames, $filename);
890 open(ED, "> $ed_filename") or die "can't open outputfile: $!\n";
891 $header = &make_kne_data_header($myconfig, $form, "");
892 $remaining_bytes -= length($header);
894 # connect to database
895 my $dbh = $form->dbconnect($myconfig);
898 qq|SELECT c.accno, c.description FROM chart c WHERE c.accno >=|
899 . $dbh->quote($form->{accnofrom}) . qq|
901 . $dbh->quote($form->{accnoto}) . qq| ORDER BY c.accno|;
903 $sth = $dbh->prepare($query);
904 $sth->execute || $form->dberror($query);
906 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
907 if (($remaining_bytes - length("t" . $ref->{'accno'})) <= 6) {
908 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
909 $buchungssatz .= "\x00" x $fuellzeichen;
911 $total_bytes = ($blockcount) * 256;
913 $buchungssatz .= "t" . $ref->{'accno'};
914 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
915 $ref->{'description'} =~ s/[^0-9A-Za-z\$\%\&\*\+\-\/]//g;
916 $ref->{'description'} = substr($ref->{'description'}, 0, 40);
917 $ref->{'description'} =~ s/\ *$//;
920 ($remaining_bytes - length("\x1E" . $ref->{'description'} . "\x1C\x79")
923 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
924 $buchungssatz .= "\x00" x $fuellzeichen;
926 $total_bytes = ($blockcount) * 256;
928 $buchungssatz .= "\x1E" . $ref->{'description'} . "\x1C\x79";
929 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
934 print(ED $buchungssatz);
935 $fuellzeichen = 256 - (length($header . $buchungssatz . "z") % 256);
936 $dateiende = "\x00" x $fuellzeichen;
938 print(ED $dateiende);
941 #Make EV Verwaltungsdatei
943 &make_ed_versionset($header, $filename, $blockcount, $fromto);
945 $ev_header = &make_ev_header($form, $fileno);
946 $ev_filename = $export_path . $evfile;
947 push(@filenames, $evfile);
948 open(EV, "> $ev_filename") or die "can't open outputfile: EV01\n";
949 print(EV $ev_header);
951 foreach $file (@ed_versionset) {
952 print(EV $ed_versionset[$file]);
959 print qq|<br>Done. <br>
962 $main::lxdebug->leave_sub();