+
+sub _csv_buchungsexport {
+ my %params = @_;
+
+ my @csv_columns = _kivitendo_to_datev();
+ my @csv_headers = _generate_csv_header(
+ from => $params{from}->ymd(''),
+ to => $params{to}->ymd(''),
+ first_day_of_fiscal_year => $params{to}->year . '0101',
+ locked => $params{locked}
+ );
+
+ my @array_of_datev;
+
+ # 2 Headers
+ push @array_of_datev, \@csv_headers;
+ push @array_of_datev, [ map { $_->{csv_header_name} } @csv_columns ];
+
+ my @warnings;
+ foreach my $row (@{ $params{datev_lines} }) {
+ my @current_datev_row;
+
+ # 1. check all datev_lines and see if we have a defined value
+ # 2. if we don't have a defined value set a default if exists
+ # 3. otherwise die
+ foreach my $column (@csv_columns) {
+ if ($column->{kivi_datev_name} eq 'not yet implemented') {
+ push @current_datev_row, '';
+ next;
+ }
+ my $data = $row->{$column->{kivi_datev_name}};
+ if (!defined $data) {
+ if (defined $column->{default}) {
+ $data = $column->{default};
+ } else {
+ die 'No sensible value or a sensible default found for the entry: ' . $column->{kivi_datev_name};
+ }
+ }
+ # checkpoint a: no undefined data. All strict checks now!
+ if (exists $column->{input_check}) {
+ die t8("Wrong field value '#1' for field '#2' for the transaction with amount '#3'",
+ $data, $column->{kivi_datev_name}, $row->{umsatz})
+ unless $column->{input_check}->($data);
+ }
+ # checkpoint b: we can safely format the input
+ if ($column->{formatter}) {
+ $data = $column->{formatter}->($data);
+ }
+ # checkpoint c: all soft checks now, will pop up as a user warning
+ if (exists $column->{valid_check} && !$column->{valid_check}->($data)) {
+ push @warnings, t8("Wrong field value '#1' for field '#2' for the transaction" .
+ " with amount '#3'", $data, $column->{kivi_datev_name}, $row->{umsatz});
+ }
+ push @current_datev_row, $data;
+ }
+ push @array_of_datev, \@current_datev_row;
+ }
+ return (\@array_of_datev, \@warnings);
+}
+
+sub _format_amount {
+ $::form->format_amount({ numberformat => '1000,00' }, @_);
+}
+