Skip to content

Commit

Permalink
Reclamation Controller: Support für Drucken via internem Kivi parser …
Browse files Browse the repository at this point in the history
…hinzugefügt

Dazu werden die benötigten Druck Variablen aus dem Rose DB objekt
ins template array geschrieben.
  • Loading branch information
rebootl committed Dec 15, 2023
1 parent 6239f95 commit 7e9ab9e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
42 changes: 42 additions & 0 deletions SL/Controller/Reclamation.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2107,6 +2107,44 @@ sub _setup_search_action_bar {
}
}

sub _map_keys_to_arrays {
my ($items, $keys, $array) = @_;

for my $key (@$keys) {
# handle nested keys
if ($key =~ /\./) {
my ($k1, $k2) = split /\./, $key;
$array->{$key} = [ map { $_->{$k1}->{$k2} } @$items ];
} else {
$array->{$key} = [ map { $_->{$key} } @$items ];
}
}
}

sub add_legacy_template_arrays {
my ($print_form) = @_;

# extract loop variables (items and taxes) from the rose db object
# and add them to the form, in the format that the built-in template parser expects
#
# using the keys that are used in the latex template: template/print/marei/sales_reclamation.tex

my $items_sorted = $print_form->{reclamation}->items_sorted;

my @keys = qw( position part.partnumber description longdescription reqdate serialnumber projectnumber reason.description
reason_description_ext qty_as_number unit sellprice_as_number discount_as_number discount_as_percent linetotal );
# (nested keys: part.partnumber, reason.description)

my %template_arrays;
_map_keys_to_arrays($items_sorted, \@keys, \%template_arrays);

my $tax_items = $print_form->{reclamation}->taxes;
my @tax_keys = qw( tax.taxdescription amount );
_map_keys_to_arrays($tax_items, \@tax_keys, \%template_arrays);

$print_form->{TEMPLATE_ARRAYS} = \%template_arrays;
}

sub generate_pdf {
my ($reclamation, $pdf_ref, $params) = @_;

Expand All @@ -2127,6 +2165,10 @@ sub generate_pdf {
# Make reclamation available in template
$print_form->{reclamation} = $reclamation;

# add variables for printing with the built-in parser
$reclamation->flatten_to_form($print_form, format_amounts => 1);
add_legacy_template_arrays($print_form);

my $template_ext;
my $template_type;
if ($print_form->{format} =~ /(opendocument|oasis)/i) {
Expand Down
2 changes: 2 additions & 0 deletions SL/Form.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3164,6 +3164,8 @@ sub prepare_for_printing {
DO->order_details(\%::myconfig, $self);
} elsif ($self->{type} =~ /sales_order|sales_quotation|request_quotation|purchase_order|purchase_quotation_intake/) {
OE->order_details(\%::myconfig, $self);
} elsif ($self->{type} =~ /reclamation/) {
# skip reclamation here, legacy template arrays are added in the reclamation controller
} else {
IS->invoice_details(\%::myconfig, $self, $::locale);
}
Expand Down

0 comments on commit 7e9ab9e

Please sign in to comment.