Revision 522eb5a4
Von Moritz Bunkus vor mehr als 8 Jahren hinzugefügt
SL/DB/Helper/FlattenToForm.pm | ||
---|---|---|
5 | 5 |
use parent qw(Exporter); |
6 | 6 |
our @EXPORT = qw(flatten_to_form); |
7 | 7 |
|
8 |
use List::MoreUtils qw(any); |
|
8 |
use List::MoreUtils qw(uniq any);
|
|
9 | 9 |
|
10 | 10 |
sub flatten_to_form { |
11 | 11 |
my ($self, $form, %params) = @_; |
... | ... | |
61 | 61 |
: ref($self) eq 'SL::DB::Invoice' ? 'invoice' |
62 | 62 |
: ''; |
63 | 63 |
|
64 |
my %cvar_validity = _determine_cvar_validity($self, $vc); |
|
65 |
|
|
64 | 66 |
my $idx = 0; |
65 | 67 |
my $format_amounts = $params{format_amounts} ? 1 : 0; |
66 | 68 |
my $format_notnull = $params{format_amounts} ? 2 : 0; |
... | ... | |
83 | 85 |
_copy($item, $form, '', "_${idx}", $format_percent, qw(discount)); |
84 | 86 |
_copy($item->project, $form, 'project', "_${idx}", 0, qw(number description)) if _has($item, 'project_id'); |
85 | 87 |
|
86 |
_copy_custom_variables($item, $form, 'ic_cvar_', "_${idx}"); |
|
88 |
_copy_custom_variables($item, $form, 'ic_cvar_', "_${idx}", $cvar_validity{items}->{ $item->parts_id });
|
|
87 | 89 |
|
88 | 90 |
if (ref($self) eq 'SL::DB::Invoice') { |
89 | 91 |
my $date = $item->deliverydate ? $item->deliverydate->to_lxoffice : undef; |
... | ... | |
92 | 94 |
} |
93 | 95 |
} |
94 | 96 |
|
95 |
_copy_custom_variables($self, $form, 'vc_cvar_', ''); |
|
97 |
_copy_custom_variables($self, $form, 'vc_cvar_', '', $cvar_validity{vc});
|
|
96 | 98 |
|
97 | 99 |
return $self; |
98 | 100 |
} |
... | ... | |
117 | 119 |
} |
118 | 120 |
|
119 | 121 |
sub _copy_custom_variables { |
120 |
my ($src, $form, $prefix, $postfix, $format_amounts) = @_;
|
|
122 |
my ($src, $form, $prefix, $postfix, $cvar_validity) = @_;
|
|
121 | 123 |
|
122 | 124 |
my $obj = (any { ref($src) eq $_ } qw(SL::DB::OrderItem SL::DB::DeliveryOrderItem SL::DB::InvoiceItem)) |
123 | 125 |
? $src |
124 | 126 |
: $src->customervendor; |
125 | 127 |
|
126 | 128 |
foreach my $cvar (@{ $obj->cvars_by_config }) { |
129 |
next if $cvar_validity && !$cvar_validity->{ $cvar->config_id }; |
|
130 |
|
|
127 | 131 |
my $value = ($cvar->config->type =~ m{^(?:bool|customer|vendor|part)$}) |
128 | 132 |
? $cvar->value |
129 | 133 |
: $cvar->value_as_text; |
... | ... | |
134 | 138 |
return $src; |
135 | 139 |
} |
136 | 140 |
|
141 |
sub _determine_cvar_validity { |
|
142 |
my ($self, $vc) = @_; |
|
143 |
|
|
144 |
my @part_ids = uniq map { $_->parts_id } @{ $self->items }; |
|
145 |
my @parts = map { SL::DB::Part->new(id => $_)->load } @part_ids; |
|
146 |
|
|
147 |
my %item_cvar_validity; |
|
148 |
foreach my $part (@parts) { |
|
149 |
$item_cvar_validity{ $part->id } = { map { ($_->config_id => $_->is_valid) } @{ $part->cvars_by_config } }; |
|
150 |
} |
|
151 |
|
|
152 |
my %vc_cvar_validity = map { ($_->config_id => $_->is_valid) } @{ $self->$vc->cvars_by_config }; |
|
153 |
|
|
154 |
return ( |
|
155 |
items => \%item_cvar_validity, |
|
156 |
vc => \%vc_cvar_validity, |
|
157 |
); |
|
158 |
} |
|
159 |
|
|
137 | 160 |
1; |
Auch abrufbar als: Unified diff
FlattenToForm: nur für Positionsartikel gültige CVars übernehmen
Benutzerdefinierte Variablen, die in den Artikelstammdaten als ungültig
markiert sind, dürfen dem Drucksystem gar nicht erst zur Verfügung
stehen.