- my $form = $::form;
-
- $self->get_datev_stamm->{abrechnungsnr} = "99";
-
- my @filenames;
-
- my $filename = "ED00000";
- my $evfile = "EV01";
- my @ed_versionset;
- my $fileno = 1;
- my $i = 0;
- my $blockcount = 1;
- my $remaining_bytes = 256;
- my $total_bytes = 256;
- my $buchungssatz = "";
- $filename++;
- my $ed_filename = $self->export_path . $filename;
- push(@filenames, $filename);
- open(ED, ">", $ed_filename) or die "can't open outputfile: $!\n";
- my $header = $self->make_kne_data_header($form);
- $remaining_bytes -= length($header);
-
- my $fuellzeichen;
-
- my (@where, @values) = ((), ());
- if ($self->accnofrom) {
- push @where, 'c.accno >= ?';
- push @values, $self->accnofrom;
- }
- if ($self->accnoto) {
- push @where, 'c.accno <= ?';
- push @values, $self->accnoto;
- }
-
- my $where_str = @where ? ' WHERE ' . join(' AND ', map { "($_)" } @where) : '';
-
- my $query = qq|SELECT c.accno, c.description
- FROM chart c
- $where_str
- ORDER BY c.accno|;
-
- my $sth = $self->dbh->prepare($query);
- $sth->execute(@values) || $form->dberror($query);
-
- while (my $ref = $sth->fetchrow_hashref("NAME_lc")) {
- if (($remaining_bytes - length("t" . $ref->{'accno'})) <= 6) {
- $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
- $buchungssatz .= "\x00" x $fuellzeichen;
- $blockcount++;
- $total_bytes = ($blockcount) * 256;
- }
- $buchungssatz .= "t" . $ref->{'accno'};
- $remaining_bytes = $total_bytes - length($buchungssatz . $header);
- $ref->{'description'} =~ s/[^0-9A-Za-z\$\%\&\*\+\-\/]//g;
- $ref->{'description'} = substr($ref->{'description'}, 0, 40);
- $ref->{'description'} =~ s/\ *$//;
-
- if (
- ($remaining_bytes - length("\x1E" . $ref->{'description'} . "\x1C\x79")
- ) <= 6
- ) {
- $fuellzeichen = ($blockcount * 256 - length($buchungssatz . $header));
- $buchungssatz .= "\x00" x $fuellzeichen;
- $blockcount++;
- $total_bytes = ($blockcount) * 256;
- }
- $buchungssatz .= "\x1E" . $ref->{'description'} . "\x1C\x79";
- $remaining_bytes = $total_bytes - length($buchungssatz . $header);
- }
-
- $sth->finish;
- print(ED $header);
- print(ED $buchungssatz);
- $fuellzeichen = 256 - (length($header . $buchungssatz . "z") % 256);
- my $dateiende = "\x00" x $fuellzeichen;
- print(ED "z");
- print(ED $dateiende);
- close(ED);
-
- #Make EV Verwaltungsdatei
- $ed_versionset[0] =
- $self->make_ed_versionset($header, $filename, $blockcount);
-
- my $ev_header = $self->make_ev_header($form, $fileno);
- my $ev_filename = $self->export_path . $evfile;
- push(@filenames, $evfile);
- open(EV, ">", $ev_filename) or die "can't open outputfile: EV01\n";
- print(EV $ev_header);
-
- foreach my $file (@ed_versionset) {
- print(EV $ed_versionset[$file]);
- }
- close(EV);
-
- $self->add_filenames(@filenames);
-
- $main::lxdebug->leave_sub();
-
- return { 'download_token' => $self->download_token, 'filenames' => \@filenames };
-}
-
-sub _format_accno {
- my ($accno) = @_;
- return $accno . ('0' x (6 - min(length($accno), 6)));
-}
-
-sub csv_export_for_tax_accountant {
- my ($self) = @_;
-
- $self->generate_datev_data(from_to => $self->fromto);
-
- foreach my $transaction (@{ $self->{DATEV} }) {
- foreach my $entry (@{ $transaction }) {
- $entry->{sortkey} = join '-', map { lc } (DateTime->from_kivitendo($entry->{transdate})->strftime('%Y%m%d'), $entry->{name}, $entry->{reference});
- }
- }
-
- my %transactions =
- partition_by { $_->[0]->{table} }
- sort_by { $_->[0]->{sortkey} }
- grep { 2 == scalar(@{ $_ }) }
- @{ $self->{DATEV} };
-
- my %column_defs = (
- acc_trans_id => { 'text' => $::locale->text('ID'), },
- amount => { 'text' => $::locale->text('Amount'), },
- credit_accname => { 'text' => $::locale->text('Credit Account Name'), },
- credit_accno => { 'text' => $::locale->text('Credit Account'), },
- debit_accname => { 'text' => $::locale->text('Debit Account Name'), },
- debit_accno => { 'text' => $::locale->text('Debit Account'), },
- invnumber => { 'text' => $::locale->text('Reference'), },
- name => { 'text' => $::locale->text('Name'), },
- notes => { 'text' => $::locale->text('Notes'), },
- tax => { 'text' => $::locale->text('Tax'), },
- taxkey => { 'text' => $::locale->text('Taxkey'), },
- tax_accname => { 'text' => $::locale->text('Tax Account Name'), },
- tax_accno => { 'text' => $::locale->text('Tax Account'), },
- transdate => { 'text' => $::locale->text('Transdate'), },
- vcnumber => { 'text' => $::locale->text('Customer/Vendor Number'), },
- );
-
- my @columns = qw(
- acc_trans_id name vcnumber
- transdate invnumber amount
- debit_accno debit_accname
- credit_accno credit_accname
- tax
- tax_accno tax_accname taxkey
- notes
- );
-
- my %filenames_by_type = (
- ar => $::locale->text('AR Transactions'),
- ap => $::locale->text('AP Transactions'),
- gl => $::locale->text('GL Transactions'),
- );