Revision a2a0b82c
Von Cem Aydin vor 3 Monaten hinzugefügt
SL/Controller/Reclamation.pm | ||
---|---|---|
2147 | 2147 |
if ($print_form->{format} =~ /(opendocument|oasis)/i) { |
2148 | 2148 |
$template_ext = 'odt'; |
2149 | 2149 |
$template_type = 'OpenDocument'; |
2150 |
|
|
2151 |
# add variables for printing with the built-in parser |
|
2152 |
$reclamation->flatten_to_form($print_form, format_amounts => 1); |
|
2153 |
$reclamation->add_legacy_template_arrays($print_form); |
|
2150 | 2154 |
} |
2151 | 2155 |
|
2152 | 2156 |
# search for the template |
SL/DB/Helper/LegacyPrinting.pm | ||
---|---|---|
1 |
package SL::DB::Helper::LegacyPrinting; |
|
2 |
|
|
3 |
use strict; |
|
4 |
|
|
5 |
use parent qw(Exporter); |
|
6 |
our @EXPORT = qw(map_keys_to_arrays format_as_number); |
|
7 |
|
|
8 |
sub map_keys_to_arrays { |
|
9 |
my ($items, $keys, $template_arrays) = @_; |
|
10 |
|
|
11 |
for my $key (@$keys) { |
|
12 |
# handle nested keys |
|
13 |
if ($key =~ /\./) { |
|
14 |
my ($k1, $k2) = split /\./, $key; |
|
15 |
$template_arrays->{$k1} = [ map { { $k2 => $_->{$k1}->{$k2} } } @$items ]; |
|
16 |
} else { |
|
17 |
$template_arrays->{$key} = [ map { |
|
18 |
$_->can($key) ? $_->$key |
|
19 |
: $_->{$key} |
|
20 |
} @$items ]; |
|
21 |
} |
|
22 |
} |
|
23 |
} |
|
24 |
|
|
25 |
sub format_as_number { |
|
26 |
my ($keys, $template_arrays) = @_; |
|
27 |
|
|
28 |
for my $key (@$keys) { |
|
29 |
$template_arrays->{$key} = [ map { |
|
30 |
$::form->format_amount(\%::myconfig, $_, 2, 0), |
|
31 |
} @{ $template_arrays->{$key} } ]; |
|
32 |
} |
|
33 |
} |
|
34 |
|
|
35 |
1; |
|
36 |
|
|
37 |
__END__ |
|
38 |
|
|
39 |
=pod |
|
40 |
|
|
41 |
=encoding utf8 |
|
42 |
|
|
43 |
=head1 NAME |
|
44 |
|
|
45 |
SL::DB::Helper::LegacyPrinting - Helper functions to support printing using the built-it template parser |
|
46 |
|
|
47 |
=head1 DESCRIPTION |
|
48 |
|
|
49 |
The new Reclamation controller, and possibly other future controllers, only support printing using Template Toolkit (TT) |
|
50 |
for parsing the templates. For OpenDocument templates however, template toolkit cannot be used. |
|
51 |
|
|
52 |
Template Toolkit (TT) can access Rose DB objects directly, which is a feature not available in the built-in parser. |
|
53 |
For positions in a loop, such as positions in a table, the built-in parser expects the data in a specific format. |
|
54 |
Therefore, we need to prepare the data accordingly before it can be processed by the built-in parser. |
|
55 |
|
|
56 |
In the past this was done in the respective modules, e.g. SL/OE.pm. The idea would be to extract the data from the Rose |
|
57 |
DB objects. That should hopefully result in less and simpler code. |
|
58 |
|
|
59 |
=head1 FUNCTIONS |
|
60 |
|
|
61 |
=head2 C<map_keys_to_arrays ($items, $keys, $template_arrays)> |
|
62 |
|
|
63 |
Extracts the given keys from the given list of Rose DB objects and adds them to the given hash reference, |
|
64 |
in the format that the built in template parser expects. |
|
65 |
|
|
66 |
The expected format looks like the following, e.g.: |
|
67 |
|
|
68 |
# 'qty_as_number' => [ |
|
69 |
# '1.00', |
|
70 |
# '3.00' |
|
71 |
# ], |
|
72 |
# 'part' => [ |
|
73 |
# { |
|
74 |
# 'partnumber' => '000013' |
|
75 |
# }, |
|
76 |
# { |
|
77 |
# 'partnumber' => '000004' |
|
78 |
# } |
|
79 |
# ], |
|
80 |
# 'position' => [ |
|
81 |
# 1, |
|
82 |
# 2 |
|
83 |
# ], |
|
84 |
# 'unit' => [ |
|
85 |
# 'Stck', |
|
86 |
# 'Stck' |
|
87 |
# ], |
|
88 |
|
|
89 |
=over 4 |
|
90 |
|
|
91 |
=item C<$items> |
|
92 |
|
|
93 |
A reference to a list of Rose DB objects from which the keys should be extracted. |
|
94 |
|
|
95 |
=item C<$keys> |
|
96 |
|
|
97 |
A reference to a list of keys that should be extracted from the Rose DB object. |
|
98 |
Nested keys should be denoted by a dot. E.g.: |
|
99 |
|
|
100 |
qw( qty_as_number part.partnumber position unit ) |
|
101 |
|
|
102 |
=item C<$template_arrays> |
|
103 |
|
|
104 |
A reference to a hash to which the extracted keys should be added. |
|
105 |
|
|
106 |
=back |
|
107 |
|
|
108 |
=head2 C<format_as_number ($keys, $template_arrays)> |
|
109 |
|
|
110 |
Formats the given keys in the given hash reference as numbers. |
|
111 |
|
|
112 |
=head1 AUTHOR |
|
113 |
|
|
114 |
Cem Aydin E<lt>cem.aydin@revamp-it.chE<gt> |
SL/DB/Reclamation.pm | ||
---|---|---|
26 | 26 |
use SL::Locale::String qw(t8); |
27 | 27 |
use SL::RecordLinks; |
28 | 28 |
use Rose::DB::Object::Helpers qw(as_tree strip); |
29 |
use SL::DB::Helper::LegacyPrinting qw(map_keys_to_arrays format_as_number); |
|
29 | 30 |
|
30 | 31 |
__PACKAGE__->meta->add_relationship( |
31 | 32 |
|
... | ... | |
233 | 234 |
return $delivery_order; |
234 | 235 |
} |
235 | 236 |
|
237 |
sub add_legacy_template_arrays { |
|
238 |
my ($self, $print_form) = @_; |
|
239 |
|
|
240 |
# for now using the keys that are used in the latex template: template/print/marei/sales_reclamation.tex |
|
241 |
# (nested keys: part.partnumber, reason.description) |
|
242 |
my @keys = qw( position part.partnumber description longdescription reqdate serialnumber projectnumber reason.description |
|
243 |
reason_description_ext qty_as_number unit sellprice_as_number discount_as_number discount_as_percent linetotal ); |
|
244 |
|
|
245 |
my @tax_keys = qw( tax.taxdescription amount ); |
|
246 |
|
|
247 |
my %template_arrays; |
|
248 |
map_keys_to_arrays($self->items_sorted, \@keys, \%template_arrays); |
|
249 |
map_keys_to_arrays($self->taxes, \@tax_keys, \%template_arrays); |
|
250 |
|
|
251 |
format_as_number([ qw(linetotal) ], \%template_arrays); |
|
252 |
$print_form->{TEMPLATE_ARRAYS} = \%template_arrays; |
|
253 |
} |
|
254 |
|
|
236 | 255 |
#TODO(Werner): überprüfen ob alle Felder richtig gestetzt werden |
237 | 256 |
sub new_from { |
238 | 257 |
my ($class, $source, %params) = @_; |
... | ... | |
571 | 590 |
|
572 | 591 |
At the moment only sales quotations and sales reclamations can be converted. |
573 | 592 |
|
593 |
=head2 C<add_legacy_template_arrays $print_form> |
|
594 |
|
|
595 |
For printing OpenDocument documents we need to extract loop variables (items and |
|
596 |
taxes) from the Rose DB object and add them to the form, in the format that the |
|
597 |
built-in template parser expects. |
|
598 |
|
|
599 |
<$print_form> Print form used in the controller. |
|
600 |
|
|
574 | 601 |
=head2 C<new_from $source, %params> |
575 | 602 |
|
576 | 603 |
Creates a new C<SL::DB::Reclamation> instance and copies as much |
SL/Form.pm | ||
---|---|---|
3206 | 3206 |
DO->order_details(\%::myconfig, $self); |
3207 | 3207 |
} elsif ($self->{type} =~ /sales_order|sales_quotation|request_quotation|purchase_order|purchase_quotation_intake/) { |
3208 | 3208 |
OE->order_details(\%::myconfig, $self); |
3209 |
} elsif ($self->{type} =~ /reclamation/) { |
|
3210 |
# skip reclamation here, legacy template arrays are added in the reclamation controller |
|
3209 | 3211 |
} else { |
3210 | 3212 |
IS->invoice_details(\%::myconfig, $self, $::locale); |
3211 | 3213 |
} |
Auch abrufbar als: Unified diff
Reclamation Controller: Support für Drucken via internem Kivi parser hinzugefügt
Dazu werden die benötigten Druck Variablen aus dem Rose DB objekt
ins template array geschrieben.
Helfer Funktionen unter SL/DB/Helper/LegacyPrinting.pm erstellt.
Siehe auch perldoc in dieser Datei.