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 #======================================================================
32 $main::lxdebug->enter_sub();
34 my ($self, $myconfig, $form) = @_;
37 my $dbh = $form->dbconnect($myconfig);
39 $query = qq|SELECT * FROM datev|;
40 $sth = $dbh->prepare($query);
41 $sth->execute || $form->dberror($query);
43 my $ref = $sth->fetchrow_hashref(NAME_lc);
45 map { $form->{$_} = $ref->{$_} } keys %$ref;
49 $main::lxdebug->leave_sub();
52 sub save_datev_stamm {
53 $main::lxdebug->enter_sub();
55 my ($self, $myconfig, $form) = @_;
58 my $dbh = $form->dbconnect_noauto($myconfig);
60 $query = qq|DELETE FROM datev|;
61 $dbh->do($query) || $form->dberror($query);
63 $query = qq|INSERT INTO datev
64 (beraternr, beratername, dfvkz, mandantennr, datentraegernr, abrechnungsnr) VALUES
66 . $dbh->quote($form->{beraternr}) . qq|,|
67 . $dbh->quote($form->{beratername}) . qq|,|
68 . $dbh->quote($form->{dfvkz}) . qq|,
70 . $dbh->quote($form->{mandantennr}) . qq|,|
71 . $dbh->quote($form->{datentraegernr}) . qq|,|
72 . $dbh->quote($form->{abrechnungsnr}) . qq|)|;
73 $sth = $dbh->prepare($query);
74 $sth->execute || $form->dberror($query);
79 $main::lxdebug->leave_sub();
83 $main::lxdebug->enter_sub();
85 my ($self, $myconfig, $form) = @_;
88 if ($form->{exporttype} == 0) {
89 @rc = &kne_buchungsexport($myconfig, $form);
91 @rc = &kne_stammdatenexport($myconfig, $form);
94 $main::lxdebug->leave_sub();
100 $main::lxdebug->enter_sub();
102 my ($self, $myconfig, $form) = @_;
104 # connect to database
105 my $dbh = $form->dbconnect_noauto($myconfig);
108 $main::lxdebug->leave_sub();
112 $main::lxdebug->enter_sub();
114 my ($zeitraum, $monat, $quartal, $transdatefrom, $transdateto) = @_;
116 $fromto = "transdate >= ";
121 if ($zeitraum eq "monat") {
123 $monat eq "1" && do {
124 $form->{fromdate} = "1.1.$jahr";
125 $form->{todate} = "31.1.$jahr";
128 $monat eq "2" && do {
129 $form->{fromdate} = "1.2.$jahr";
131 #this works from 1901 to 2099, 1900 and 2100 fail.
132 $leap = ($jahr % 4 == 0) ? "29" : "28";
133 $form->{todate} = "$leap.2.$jahr";
136 $monat eq "3" && do {
137 $form->{fromdate} = "1.3.$jahr";
138 $form->{todate} = "31.3.$jahr";
141 $monat eq "4" && do {
142 $form->{fromdate} = "1.4.$jahr";
143 $form->{todate} = "30.4.$jahr";
146 $monat eq "5" && do {
147 $form->{fromdate} = "1.5.$jahr";
148 $form->{todate} = "31.5.$jahr";
151 $monat eq "6" && do {
152 $form->{fromdate} = "1.6.$jahr";
153 $form->{todate} = "30.6.$jahr";
156 $monat eq "7" && do {
157 $form->{fromdate} = "1.7.$jahr";
158 $form->{todate} = "31.7.$jahr";
161 $monat eq "8" && do {
162 $form->{fromdate} = "1.8.$jahr";
163 $form->{todate} = "31.8.$jahr";
166 $monat eq "9" && do {
167 $form->{fromdate} = "1.9.$jahr";
168 $form->{todate} = "30.9.$jahr";
171 $monat eq "10" && do {
172 $form->{fromdate} = "1.10.$jahr";
173 $form->{todate} = "31.10.$jahr";
176 $monat eq "11" && do {
177 $form->{fromdate} = "1.11.$jahr";
178 $form->{todate} = "30.11.$jahr";
181 $monat eq "12" && do {
182 $form->{fromdate} = "1.12.$jahr";
183 $form->{todate} = "31.12.$jahr";
188 "'" . $form->{fromdate} . "' and transdate <= '" . $form->{todate} . "'";
191 elsif ($zeitraum eq "quartal") {
194 "'01.01." . $jahr . "' and transdate <= '31.03." . $jahr . "'";
195 } elsif ($quartal == 2) {
197 "'01.04." . $jahr . "' and transdate <= '30.06." . $jahr . "'";
198 } elsif ($quartal == 3) {
200 "'01.07." . $jahr . "' and transdate <= '30.09." . $jahr . "'";
201 } elsif ($quartal == 4) {
203 "'01.10." . $jahr . "' and transdate <= '31.12." . $jahr . "'";
207 elsif ($zeitraum eq "zeit") {
209 "'" . $transdatefrom . "' and transdate <= '" . $transdateto . "'";
212 $main::lxdebug->leave_sub();
217 sub get_transactions {
218 $main::lxdebug->enter_sub();
220 my ($myconfig, $form, $fromto) = @_;
222 # connect to database
223 my $dbh = $form->dbconnect($myconfig);
225 $fromto =~ s/transdate/ac\.transdate/g;
227 $query = qq|SELECT id, taxkey, rate FROM tax|;
228 $sth = $dbh->prepare($query);
229 $sth->execute || $form->dberror($query);
231 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
232 $taxes{ $ref->{id} } = $ref->{rate};
238 qq|SELECT ac.oid, ac.transdate, ac.trans_id,ar.id, ac.amount, ac.taxkey, ar.invnumber, ar.duedate, ar.amount as umsatz,
239 ct.name, c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id, t.chart_id, t.rate, t.id AS taxid, t.taxkey AS taxtaxkey FROM acc_trans ac,ar ar, customer ct,
240 chart c LEFT JOIN tax t ON
241 (t.chart_id=c.id)WHERE $fromto AND ac.trans_id=ar.id AND ac.trans_id=ar.id
242 AND ar.customer_id=ct.id AND ac.chart_id=c.id
244 SELECT ac.oid, ac.transdate, ac.trans_id,ap.id, ac.amount, ac.taxkey, ap.invnumber, ap.duedate, ap.amount as umsatz,
245 ct.name, c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id, t.chart_id, t.rate, t.id AS taxid, t.taxkey AS taxtaxkey FROM acc_trans ac, ap ap, vendor ct, chart c LEFT JOIN tax t ON
247 WHERE $fromto AND ac.trans_id=ap.id AND ap.vendor_id=ct.id AND ac.chart_id=c.id
249 SELECT ac.oid, ac.transdate, ac.trans_id,gl.id, ac.amount, ac.taxkey, gl.reference AS invnumber, gl.transdate AS duedate, ac.amount as umsatz,
250 gl.description AS name, c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id, t.chart_id, t.rate, t.id AS taxid, t.taxkey AS taxtaxkey FROM acc_trans ac, gl gl,
251 chart c LEFT JOIN tax t ON
252 (t.chart_id=c.id) WHERE $fromto AND ac.trans_id=gl.id AND ac.chart_id=c.id
253 ORDER BY trans_id, oid|;
255 $sth = $dbh->prepare($query);
256 $sth->execute || $form->dberror($query);
261 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
265 if (($counter % 500) == 0) {
269 $count += $ref->{amount};
271 while (abs($count) > 0.01 || $firstrun) {
272 $ref2 = $sth->fetchrow_hashref(NAME_lc);
274 $count += $ref2->{amount};
278 my %taxid_taxkeys = ();
280 if (scalar(@{$i}) > 2) {
281 for my $j (0 .. (scalar(@{$i}) - 1)) {
282 if (abs($i->[$j]->{'amount'}) > abs($absumsatz)) {
283 $absumsatz = $i->[$j]->{'amount'};
286 if (($i->[$j]->{'taxtaxkey'}) && ($i->[$j]->{'taxid'})) {
287 $taxid_taxkeys{$i->[$j]->{'taxtaxkey'}} = $i->[$j]->{'taxid'};
290 $ml = ($i->[0]->{'umsatz'} > 0) ? 1 : -1;
291 for my $j (0 .. (scalar(@{$i}) - 1)) {
292 if ( ($j != $notsplitindex)
293 && ($i->[$j]->{'chart_id'} eq "")
294 && ( $i->[$j]->{'taxkey'} eq ""
295 || $i->[$j]->{'taxkey'} eq "0"
296 || $i->[$j]->{'taxkey'} eq "1"
297 || $i->[$j]->{'taxkey'} eq "10"
298 || $i->[$j]->{'taxkey'} eq "11")) {
300 map({ $blubb{$_} = $i->[$notsplitindex]->{$_}; } keys(%{ $i->[$notsplitindex] }));
302 $absumsatz += $i->[$j]->{'amount'};
303 $blubb{'amount'} = $i->[$j]->{'amount'} * (-1);
304 $blubb{'umsatz'} = abs($i->[$j]->{'amount'}) * $ml;
305 $i->[$j]->{'umsatz'} = abs($i->[$j]->{'amount'}) * $ml;
307 push @{ $splits[$g] }, \%blubb; #$i->[$notsplitindex];
308 push @{ $splits[$g] }, $i->[$j];
309 push @{ $form->{DATEV} }, \@{ $splits[$g] };
313 } elsif (($j != $notsplitindex) && ($i->[$j]->{'chart_id'} eq "")) {
314 $absumsatz += ($i->[$j]->{'amount'} * (1 + $taxes{ $taxid_taxkeys{$i->[$j]->{'taxkey'}} }));
317 map({ $blubb{$_} = $i->[$notsplitindex]->{$_}; } keys(%{ $i->[$notsplitindex] }));
319 $test = 1 + $taxes{ $taxid_taxkeys{$i->[$j]->{'taxkey'}} };
320 $blubb{'amount'} = $form->round_amount(($i->[$j]->{'amount'} * $test * -1), 2);
321 $blubb{'umsatz'} = abs($form->round_amount(($i->[$j]->{'amount'} * $test), 2)) * $ml;
322 $i->[$j]->{'umsatz'} = abs($form->round_amount(($i->[$j]->{'amount'} * $test), 2)) * $ml;
324 push @{ $splits[$g] }, \%blubb;
325 push @{ $splits[$g] }, $i->[$j];
326 push @{ $form->{DATEV} }, \@{ $splits[$g] };
333 if (abs($absumsatz) > 0.01) {
334 $form->error("Datev-Export fehlgeschlagen! Bei Transaktion $i->[0]->{trans_id} $absumsatz\n");
337 push @{ $form->{DATEV} }, \@{$i};
344 $main::lxdebug->leave_sub();
347 sub make_kne_data_header {
348 $main::lxdebug->enter_sub();
350 my ($myconfig, $form, $fromto) = @_;
352 # connect to database
353 my $dbh = $form->dbconnect($myconfig);
359 $anwendungsnr = ($fromto) ? "\x31\x31" : "\x31\x33";
360 while (length($form->{datentraegernr}) < 3) {
361 $form->{datentraegernr} = "\x30" . $form->{datentraegernr};
364 $header = "\x1D\x18\x31" . $form->{datentraegernr} . $anwendungsnr;
366 $dfvkz = $form->{dfvkz};
367 while (length($dfvkz) < 2) {
368 $dfvkz = "\x30" . $dfvkz;
372 $beraternr = $form->{beraternr};
373 while (length($beraternr) < 7) {
374 $beraternr = "\x30" . $beraternr;
376 $header .= $beraternr;
378 $mandantennr = $form->{mandantennr};
379 while (length($mandantennr) < 5) {
380 $mandantennr = "\x30" . $mandantennr;
382 $header .= $mandantennr;
384 $abrechnungsnr = $form->{abrechnungsnr} . $jahr;
385 while (length($abrechnungsnr) < 6) {
386 $abrechnungsnr = "\x30" . $abrechnungsnr;
388 $header .= $abrechnungsnr;
390 $fromto =~ s/transdate|>=|and|\'|<=//g;
391 my ($from, $to) = split / /, $fromto;
396 my ($fday, $fmonth, $fyear) = split(/\./, $from);
397 if (length($fmonth) < 2) {
398 $fmonth = "0" . $fmonth;
400 if (length($fday) < 2) {
403 $from = $fday . $fmonth . substr($fyear, -2, 2);
411 my ($tday, $tmonth, $tyear) = split(/\./, $to);
412 if (length($tmonth) < 2) {
413 $tmonth = "0" . $tmonth;
415 if (length($tday) < 2) {
418 $to = $tday . $tmonth . substr($tyear, -2, 2);
424 $primanota = "\x30\x30\x31";
425 $header .= $primanota;
428 $passwort = $form->{passwort};
429 while (length($passwort) < 4) {
430 $passwort = "\x30" . $passwort;
432 $header .= $passwort;
434 $anwendungsinfo = "\x20" x 16;
435 $header .= $anwendungsinfo;
436 $inputinfo = "\x20" x 16;
437 $header .= $inputinfo;
442 if ($form->{exporttype} == 0) {
443 $versionssatz = "\xB5" . "1,";
445 $versionssatz = "\xB6" . "1,";
448 $query = qq| select accno from chart limit 1|;
449 $sth = $dbh->prepare($query);
450 $sth->execute || $form->dberror($query);
451 my $ref = $sth->fetchrow_hashref(NAME_lc);
453 $accnolength = $ref->{accno};
456 $versionssatz .= length($accnolength);
457 $versionssatz .= ",";
458 $versionssatz .= length($accnolength);
459 $versionssatz .= ",SELF" . "\x1C\x79";
463 $header .= $versionssatz;
465 $main::lxdebug->leave_sub();
471 $main::lxdebug->enter_sub();
473 my ($date, $six) = @_;
475 ($day, $month, $year) = split(/\./, $date);
478 $day = substr($day, 1, 1);
480 if (length($month) < 2) {
481 $month = "0" . $month;
483 if (length($year) > 2) {
484 $year = substr($year, -2, 2);
488 $date = $day . $month . $year;
490 $date = $day . $month;
493 $main::lxdebug->leave_sub();
499 $main::lxdebug->enter_sub();
501 my ($umsatz, $stellen) = @_;
504 ($vorkomma, $nachkomma) = split(/\./, $umsatz);
507 for ($i = $stellen; $i >= $stellen + 2 - length($vorkomma); $i--) {
511 for ($i = 3; $i > length($nachkomma); $i--) {
514 $umsatz = $vorkomma . substr($nachkomma, 0, 2);
516 $main::lxdebug->leave_sub();
521 sub make_ed_versionset {
522 $main::lxdebug->enter_sub();
524 my ($header, $filename, $blockcount, $fromto) = @_;
526 $versionset = "V" . substr($filename, 2, 5);
527 $versionset .= substr($header, 6, 22);
529 $versionset .= "0000" . substr($header, 28, 19);
531 $datum = "\x20" x 16;
532 $versionset .= $datum . "001" . substr($header, 28, 4);
534 while (length($blockcount) < 5) {
535 $blockcount = "0" . $blockcount;
537 $versionset .= $blockcount;
538 $versionset .= "001";
539 $versionset .= "\x20\x31";
540 $versionset .= substr($header, -12, 10) . " ";
541 $versionset .= "\x20" x 53;
543 $main::lxdebug->leave_sub();
549 $main::lxdebug->enter_sub();
551 my ($form, $fileno) = @_;
552 $datentraegernr = $form->{datentraegernr};
553 $beraternummer = $form->{beraternr};
554 $beratername = $form->{beratername};
555 $anzahl_dateien = $fileno;
557 while (length($datentraegernr) < 3) {
558 $datentraegernr .= " ";
561 while (length($beraternummer) < 7) {
562 $beraternummer .= " ";
565 while (length($beratername) < 9) {
569 while (length($anzahl_dateien) < 5) {
570 $anzahl_dateien = "0" . $anzahl_dateien;
574 $datentraegernr . "\x20\x20\x20" . $beraternummer . $beratername . "\x20";
575 $ev_header .= $anzahl_dateien . $anzahl_dateien;
576 $ev_header .= "\x20" x 95;
578 $main::lxdebug->leave_sub();
583 sub kne_buchungsexport {
584 $main::lxdebug->enter_sub();
586 my ($myconfig, $form) = @_;
590 my $export_path = $main::userspath . "/";
591 my $filename = "ED00000";
599 <body>Export in Bearbeitung<br>
600 Buchungssätze verarbeitet:
604 &get_dates($form->{zeitraum}, $form->{monat},
605 $form->{quartal}, $form->{transdatefrom},
606 $form->{transdateto});
607 &get_transactions($myconfig, $form, $fromto);
609 print qq|<br>2. Durchlauf:|;
610 while (scalar(@{ $form->{DATEV} })) {
612 my $remaining_bytes = 256;
613 my $total_bytes = 256;
615 my $buchungssatz = "";
617 my $ed_filename = $export_path . $filename;
618 push(@filenames, $filename);
619 open(ED, "> $ed_filename") or die "can't open outputfile: $!\n";
620 $header = &make_kne_data_header($myconfig, $form, $fromto);
621 $remaining_bytes -= length($header);
623 while (scalar(@{ $form->{DATEV} }) > 0) {
624 $transaction = shift @{ $form->{DATEV} };
625 $trans_lines = scalar(@{$transaction});
627 if (($counter % 500) == 0) {
642 %umlaute = ('ä' => 'ae',
650 for (my $i = 0; $i < $trans_lines; $i++) {
651 if ($trans_lines == 2) {
652 if (abs($transaction->[$i]->{'amount'}) > abs($umsatz)) {
653 $umsatz = $transaction->[$i]->{'amount'};
656 if (abs($transaction->[$i]->{'umsatz'}) > abs($umsatz)) {
657 $umsatz = $transaction->[$i]->{'umsatz'};
660 if ($transaction->[$i]->{'datevautomatik'}) {
663 if ($transaction->[$i]->{'taxkey'}) {
664 $taxkey = $transaction->[$i]->{'taxkey'};
666 if ($transaction->[$i]->{'charttax'}) {
667 $charttax = $transaction->[$i]->{'charttax'};
669 if ( ($transaction->[$i]->{'id'} eq $transaction->[$i]->{'chart_id'})
670 && ($trans_lines > 2)) {
671 undef($transaction->[$i]);
672 } elsif ($transaction->[$i]->{'amount'} > 0) {
679 $umsatzsumme += abs($umsatz);
681 # Umwandlung von Umlauten und Sonderzeichen in erlaubte Zeichen bei Textfeldern
682 foreach $umlaut (keys(%umlaute)) {
683 $transaction->[$haben]->{'invnumber'} =~
684 s/${umlaut}/${umlaute{$umlaut}}/g;
685 $transaction->[$haben]->{'name'} =~ s/${umlaut}/${umlaute{$umlaut}}/g;
688 $transaction->[$haben]->{'invnumber'} =~ s/[^0-9A-Za-z\$\%\&\*\+\-\/]//g;
689 $transaction->[$haben]->{'name'} =~ s/[^0-9A-Za-z\$\%\&\*\+\-\ \/]//g;
691 $transaction->[$haben]->{'invnumber'} =
692 substr($transaction->[$haben]->{'invnumber'}, 0, 12);
693 $transaction->[$haben]->{'name'} =
694 substr($transaction->[$haben]->{'name'}, 0, 30);
695 $transaction->[$haben]->{'invnumber'} =~ s/\ *$//;
696 $transaction->[$haben]->{'name'} =~ s/\ *$//;
698 if ($trans_lines >= 2) {
700 $gegenkonto = "a" . $transaction->[$haben]->{'accno'};
701 $konto = "e" . $transaction->[$soll]->{'accno'};
702 if ($transaction->[$haben]->{'invnumber'} ne "") {
704 "\xBD" . $transaction->[$haben]->{'invnumber'} . "\x1C";
707 $datum .= &datetofour($transaction->[$haben]->{'transdate'}, 0);
708 $waehrung = "\xB3" . "EUR" . "\x1C";
709 if ($transaction->[$haben]->{'name'} ne "") {
710 $buchungstext = "\x1E" . $transaction->[$haben]->{'name'} . "\x1C";
712 if ($transaction->[$haben]->{'duedate'} ne "") {
714 . &datetofour($transaction->[$haben]->{'duedate'}, 1) . "\x1C";
718 if (($remaining_bytes - length("+" . &formatumsatz($umsatz, 0))) <= 6) {
719 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
720 $buchungssatz .= "\x00" x $fuellzeichen;
722 $total_bytes = ($blockcount) * 256;
724 $umsatz = abs($umsatz);
725 $vorzeichen = ($umsatz > 0) ? "+" : "-";
726 $buchungssatz .= $vorzeichen . &formatumsatz($umsatz, 0);
727 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
729 if ( ($taxkey || $datevautomatik)
730 && (!$datevautomatik || ($datevautomatik && ($charttax ne $taxkey)))) {
731 if (($remaining_bytes - length("\x6C" . "11")) <= 6) {
733 ($blockcount * 256 - length($buchungssatz . $header));
734 $buchungssatz .= "\x00" x $fuellzeichen;
736 $total_bytes = ($blockcount) * 256;
738 if (!$datevautomatik) {
739 $buchungssatz .= "\x6C" . $taxkey;
741 $buchungssatz .= "\x6C" . "4";
743 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
746 if (($remaining_bytes - length($gegenkonto)) <= 6) {
747 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
748 $buchungssatz .= "\x00" x $fuellzeichen;
750 $total_bytes = ($blockcount) * 256;
752 $buchungssatz .= $gegenkonto;
753 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
755 if (($remaining_bytes - length($belegfeld1)) <= 6) {
756 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
757 $buchungssatz .= "\x00" x $fuellzeichen;
759 $total_bytes = ($blockcount) * 256;
761 $buchungssatz .= $belegfeld1;
762 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
764 if (($remaining_bytes - length($belegfeld2)) <= 6) {
765 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
766 $buchungssatz .= "\x00" x $fuellzeichen;
768 $total_bytes = ($blockcount) * 256;
770 $buchungssatz .= $belegfeld2;
771 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
773 if (($remaining_bytes - length($datum)) <= 6) {
774 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
775 $buchungssatz .= "\x00" x $fuellzeichen;
777 $total_bytes = ($blockcount) * 256;
779 $buchungssatz .= $datum;
780 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
782 if (($remaining_bytes - length($konto)) <= 6) {
783 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
784 $buchungssatz .= "\x00" x $fuellzeichen;
786 $total_bytes = ($blockcount) * 256;
788 $buchungssatz .= $konto;
789 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
791 if (($remaining_bytes - length($buchungstext)) <= 6) {
792 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
793 $buchungssatz .= "\x00" x $fuellzeichen;
795 $total_bytes = ($blockcount) * 256;
797 $buchungssatz .= $buchungstext;
798 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
800 if (($remaining_bytes - (length($waehrung . "\x79"))) <= 6) {
801 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
802 $buchungssatz .= "\x00" x $fuellzeichen;
804 $total_bytes = ($blockcount) * 256;
806 $buchungssatz .= $waehrung . "\x79";
807 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
812 "x" . &formatumsatz($umsatzsumme, 14) . "\x79" . "\x7a";
814 256 - (length($header . $buchungssatz . $mandantenendsumme) % 256);
815 $dateiende = "\x00" x $fuellzeichen;
817 print(ED $buchungssatz);
818 print(ED $mandantenendsumme);
819 print(ED $dateiende);
822 $ed_versionset[$fileno] =
823 &make_ed_versionset($header, $filename, $blockcount, $fromto);
827 #Make EV Verwaltungsdatei
828 $ev_header = &make_ev_header($form, $fileno);
829 $ev_filename = $export_path . $evfile;
830 push(@filenames, $evfile);
831 open(EV, "> $ev_filename") or die "can't open outputfile: EV01\n";
832 print(EV $ev_header);
834 foreach $file (@ed_versionset) {
835 print(EV $ed_versionset[$file]);
838 print qq|<br>Done. <br>
841 $main::lxdebug->leave_sub();
846 sub kne_stammdatenexport {
847 $main::lxdebug->enter_sub();
849 my ($myconfig, $form) = @_;
850 $form->{abrechnungsnr} = "99";
855 <body>Export in Bearbeitung<br>
860 my $export_path = $main::userspath . "/";
861 my $filename = "ED00000";
867 my $remaining_bytes = 256;
868 my $total_bytes = 256;
869 my $buchungssatz = "";
871 my $ed_filename = $export_path . $filename;
872 push(@filenames, $filename);
873 open(ED, "> $ed_filename") or die "can't open outputfile: $!\n";
874 $header = &make_kne_data_header($myconfig, $form, "");
875 $remaining_bytes -= length($header);
877 # connect to database
878 my $dbh = $form->dbconnect($myconfig);
881 qq|SELECT c.accno, c.description FROM chart c WHERE c.accno >=|
882 . $dbh->quote($form->{accnofrom}) . qq|
884 . $dbh->quote($form->{accnoto}) . qq| ORDER BY c.accno|;
886 $sth = $dbh->prepare($query);
887 $sth->execute || $form->dberror($query);
889 while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
890 if (($remaining_bytes - length("t" . $ref->{'accno'})) <= 6) {
891 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
892 $buchungssatz .= "\x00" x $fuellzeichen;
894 $total_bytes = ($blockcount) * 256;
896 $buchungssatz .= "t" . $ref->{'accno'};
897 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
898 $ref->{'description'} =~ s/[^0-9A-Za-z\$\%\&\*\+\-\/]//g;
899 $ref->{'description'} = substr($ref->{'description'}, 0, 40);
900 $ref->{'description'} =~ s/\ *$//;
903 ($remaining_bytes - length("\x1E" . $ref->{'description'} . "\x1C\x79")
906 $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
907 $buchungssatz .= "\x00" x $fuellzeichen;
909 $total_bytes = ($blockcount) * 256;
911 $buchungssatz .= "\x1E" . $ref->{'description'} . "\x1C\x79";
912 $remaining_bytes = $total_bytes - length($buchungssatz . $header);
917 print(ED $buchungssatz);
918 $fuellzeichen = 256 - (length($header . $buchungssatz . "z") % 256);
919 $dateiende = "\x00" x $fuellzeichen;
921 print(ED $dateiende);
924 #Make EV Verwaltungsdatei
926 &make_ed_versionset($header, $filename, $blockcount, $fromto);
928 $ev_header = &make_ev_header($form, $fileno);
929 $ev_filename = $export_path . $evfile;
930 push(@filenames, $evfile);
931 open(EV, "> $ev_filename") or die "can't open outputfile: EV01\n";
932 print(EV $ev_header);
934 foreach $file (@ed_versionset) {
935 print(EV $ed_versionset[$file]);
942 print qq|<br>Done. <br>
945 $main::lxdebug->leave_sub();