Revision 361a3f88
Von Tamino Steinert vor 6 Tagen hinzugefügt
SL/Controller/Part.pm | ||
---|---|---|
274 | 274 |
} |
275 | 275 |
|
276 | 276 |
SL::DB->client->with_transaction(sub { |
277 |
foreach my $variant (@{$self->part->variants}) { |
|
278 |
$variant->update_attributes( |
|
279 |
description => $variant_id_to_values{$variant->id}->{description}, |
|
280 |
listprice_as_number => $variant_id_to_values{$variant->id}->{listprice_as_number}, |
|
281 |
sellprice_as_number => $variant_id_to_values{$variant->id}->{sellprice_as_number}, |
|
282 |
lastcost_as_number => $variant_id_to_values{$variant->id}->{lastcost_as_number}, |
|
283 |
rop_as_number => $variant_id_to_values{$variant->id}->{rop_as_number}, |
|
284 |
); |
|
285 |
} |
|
277 |
my $new_variant_property; |
|
286 | 278 |
if ($variant_property_id) { |
287 |
SL::DB::VariantPropertyPart->new( |
|
279 |
$new_variant_property = SL::DB::VariantPropertyPart->new(
|
|
288 | 280 |
part_id => $self->part->id, |
289 | 281 |
variant_property_id => $variant_property_id, |
290 | 282 |
)->save; |
291 |
foreach my $variant (@{$self->part->variants}) { |
|
283 |
} |
|
284 |
foreach my $variant (@{$self->part->variants}) { |
|
285 |
my $variant_attributes = $variant_id_to_values{$variant->id}; |
|
286 |
my $variant_property_value_id = delete $variant_attributes->{add_variant_property_value}; |
|
287 |
delete $variant_attributes->{$_} for qw(id position); |
|
288 |
$variant->update_attributes(%$variant_attributes); |
|
289 |
if ($new_variant_property) { |
|
292 | 290 |
SL::DB::VariantPropertyValuePart->new( |
293 | 291 |
part_id => $variant->id, |
294 |
variant_property_value_id => $variant_id_to_values{$variant->id}->{"add_variant_property_value"},
|
|
292 |
variant_property_value_id => $variant_property_value_id,
|
|
295 | 293 |
)->save; |
296 | 294 |
} |
297 | 295 |
} |
298 | 296 |
1; |
299 | 297 |
}) or do { |
300 |
return $self->js->error(t8('Error while adding variant property: ' . @_))->render();
|
|
298 |
return $self->js->error(t8('Error while adding variant property: #1', SL::DB->client->error))->render();
|
|
301 | 299 |
}; |
302 | 300 |
|
303 | 301 |
$self->redirect_to( |
... | ... | |
889 | 887 |
my %sort_keys = ( |
890 | 888 |
partnumber => sub { $_[0]->partnumber }, |
891 | 889 |
description => sub { $_[0]->description }, |
890 |
ean => sub { $_[0]->ean }, |
|
891 |
listprice => sub { $_[0]->listprice }, |
|
892 | 892 |
sellprice => sub { $_[0]->sellprice }, |
893 | 893 |
lastcost => sub { $_[0]->lastcost }, |
894 |
onhand => sub { $_[0]->onhand }, |
|
895 |
rop => sub { $_[0]->rop }, |
|
894 | 896 |
variant_values => sub { $_[0]->variant_values }, |
895 | 897 |
); |
896 | 898 |
foreach my $variant_property (@{$part->variant_properties}) { |
... | ... | |
909 | 911 |
@{$::form->{variants}}; |
910 | 912 |
|
911 | 913 |
my @to_sort = map { { old_pos => $variant_id_to_position{$_->id}, order_by => $method->($_) } } @items; |
912 |
if ($::form->{order_by} =~ /^(sellprice|lastcost)$/ ||
|
|
914 |
if ($::form->{order_by} =~ /^(listpirce|sellprice|lastcost|onhand|rop)$/ ||
|
|
913 | 915 |
$::form->{order_by} =~ /^variant_property_/) { |
914 | 916 |
if ($::form->{sort_dir}) { |
915 | 917 |
@to_sort = sort { $a->{order_by} <=> $b->{order_by} } @to_sort; |
SL/DB/Part.pm | ||
---|---|---|
4 | 4 |
|
5 | 5 |
use Carp; |
6 | 6 |
use List::MoreUtils qw(any uniq pairwise); |
7 |
use List::Util qw(sum max); |
|
7 |
use List::Util qw(sum max first);
|
|
8 | 8 |
use Rose::DB::Object::Helpers qw(as_tree); |
9 | 9 |
|
10 | 10 |
use SL::Locale::String qw(t8); |
... | ... | |
100 | 100 |
map_from => 'part', |
101 | 101 |
map_to => 'variant_property', |
102 | 102 |
type => 'many to many', |
103 |
manager_args => { sort_by => 'sortkey ASC' } |
|
103 | 104 |
}, |
104 | 105 |
variant_property_values => { |
105 | 106 |
map_class => 'SL::DB::VariantPropertyValuePart', |
... | ... | |
107 | 108 |
map_to => 'variant_property_value', |
108 | 109 |
type => 'many to many', |
109 | 110 |
}, |
110 |
parent_variant => {
|
|
111 |
parent_variants => { # access through parent_variant
|
|
111 | 112 |
map_class => 'SL::DB::PartParentVariantPartVariant', |
112 | 113 |
map_from => 'variant', |
113 | 114 |
map_to => 'parent_variant', |
... | ... | |
156 | 157 |
my ($self) = @_; |
157 | 158 |
if ($self->is_variant) { |
158 | 159 |
my @property_value_ids = sort map {$_->id} $self->variant_property_values; |
159 |
my ($parent_variant) = $self->parent_variant;
|
|
160 |
my $parent_variant = $self->parent_variant;
|
|
160 | 161 |
my $other_variants = $parent_variant->variants; |
161 | 162 |
foreach my $variant (@$other_variants) { |
162 | 163 |
next if $variant->id == $self->id; |
... | ... | |
338 | 339 |
shift->buchungsgruppen(@_); |
339 | 340 |
} |
340 | 341 |
|
342 |
sub parent_variant { |
|
343 |
my ($parent_variant) = shift->parent_variants(@_); |
|
344 |
return $parent_variant; |
|
345 |
} |
|
346 |
|
|
341 | 347 |
sub get_variant_property_value_by_unique_name { |
342 | 348 |
my ($self, $variant_property_unique_name) = @_; |
343 | 349 |
|
... | ... | |
687 | 693 |
return unless $self->is_variant; |
688 | 694 |
return "[" .join("|", |
689 | 695 |
map {$_->variant_property->abbreviation . ":" . $_->abbreviation} |
690 |
$self->variant_property_values) . "]"; |
|
696 |
sort {$a->variant_property->sortkey <=> $b->variant_property->sortkey} |
|
697 |
$self->variant_property_values |
|
698 |
) . "]"; |
|
691 | 699 |
} |
692 | 700 |
|
693 | 701 |
sub variant_value { |
... | ... | |
695 | 703 |
die "only callable on parts of type parent_variant" unless $self->is_variant; |
696 | 704 |
die "only callable with SL::DB::VariantProperty object" unless ref $variant_property eq 'SL::DB::VariantProperty'; |
697 | 705 |
|
698 |
my %property_id_to_values =
|
|
699 |
map {$_->variant_property_id => $_}
|
|
706 |
my $property_value =
|
|
707 |
first {$variant_property->id == $_->variant_property_id}
|
|
700 | 708 |
@{$self->variant_property_values}; |
701 | 709 |
|
702 |
my $property_value = $property_id_to_values{$variant_property->id}; |
|
703 |
|
|
704 |
return $property_value && $property_value->displayable_name(); |
|
710 |
return $property_value; |
|
705 | 711 |
} |
706 | 712 |
|
707 | 713 |
sub init_onhandqty { |
templates/design40_webpages/part/_parent_variant.html | ||
---|---|---|
24 | 24 |
[% 'Partnumber' | $T8 %] |
25 | 25 |
</a> |
26 | 26 |
</th> |
27 |
<th id="variant_ean_header_id"> |
|
28 |
<a href='#' onClick='javascript:kivi.Part.reorder_variants("ean")'> |
|
29 |
[% "EAN" | $T8 %] |
|
30 |
</a> |
|
31 |
</th> |
|
27 | 32 |
<th id="variant_description_header_id"> |
28 | 33 |
<a href='#' onClick='javascript:kivi.Part.reorder_variants("description")'> |
29 | 34 |
[% "Description" | $T8 %] |
... | ... | |
41 | 46 |
</a> |
42 | 47 |
</th> |
43 | 48 |
[% END %] |
44 |
<th>[% 'List Price' | $T8 %]</th> |
|
45 |
<th>[% 'Sell Price' | $T8 %]</th> |
|
46 |
<th>[% 'Last Cost' | $T8 %]</th> |
|
47 |
<th>[% 'ROP' | $T8 %]</th> |
|
49 |
<th id="variant_listprice_header_id"> |
|
50 |
<a href='#' onClick='javascript:kivi.Part.reorder_variants("listprice")'> |
|
51 |
[% "List Price" | $T8 %] |
|
52 |
</a> |
|
53 |
</th> |
|
54 |
<th id="variant_sellprice_header_id"> |
|
55 |
<a href='#' onClick='javascript:kivi.Part.reorder_variants("sellprice")'> |
|
56 |
[% "Sell Price" | $T8 %] |
|
57 |
</a> |
|
58 |
</th> |
|
59 |
<th id="variant_lastcost_header_id"> |
|
60 |
<a href='#' onClick='javascript:kivi.Part.reorder_variants("lastcost")'> |
|
61 |
[% "Last Cost" | $T8 %] |
|
62 |
</a> |
|
63 |
</th> |
|
64 |
<th id="variant_onhand_header_id"> |
|
65 |
<a href='#' onClick='javascript:kivi.Part.reorder_variants("onhand")'> |
|
66 |
[% "On Hand" | $T8 %] |
|
67 |
</a> |
|
68 |
</th> |
|
69 |
<th id="variant_rop_header_id"> |
|
70 |
<a href='#' onClick='javascript:kivi.Part.reorder_variants("rop")'> |
|
71 |
[% "ROP" | $T8 %] |
|
72 |
</a> |
|
73 |
</th> |
|
48 | 74 |
<th> |
49 | 75 |
[% L.select_tag("add_variant_property", AVAILABLE_VARIANT_PROPERIES |
50 | 76 |
title_key='displayable_name', value_key='id', |
... | ... | |
54 | 80 |
</th> |
55 | 81 |
</tr> |
56 | 82 |
<tr> |
57 |
<th class="center">
|
|
83 |
<th> |
|
58 | 84 |
[%- L.button_tag('kivi.Part.variant_rows_toggle_selected();', "🔄", |
59 | 85 |
title=LxERP.t8("Toggle selection"), |
60 | 86 |
alt=LxERP.t8("Toggle selection"), |
61 | 87 |
) %] |
62 | 88 |
</th> |
63 |
<th></th> |
|
89 |
<th><!-- partnumber --></th> |
|
90 |
<th><!-- ean --></th> |
|
64 | 91 |
<th> |
65 | 92 |
[% L.input_tag("description_for_selected_variants", SELF.part.description, |
66 | 93 |
class="wi-medium", |
... | ... | |
72 | 99 |
title=LxERP.t8('Apply to selected rows'), |
73 | 100 |
) %] |
74 | 101 |
</th> |
75 |
<th colspan="[% SELF.part.variant_properties.size + 1 %]"></th> |
|
102 |
<th><!-- variant_values --></th> |
|
103 |
[% FOREACH property = SELF.part.variant_properties %] |
|
104 |
<th></th> |
|
105 |
[% END %] |
|
76 | 106 |
<th> |
77 | 107 |
[% L.input_tag( |
78 | 108 |
"listprice_as_number_for_selected_variants", |
... | ... | |
112 | 142 |
title=LxERP.t8('Apply to selected rows'), |
113 | 143 |
) %] |
114 | 144 |
</th> |
145 |
<th><!-- onhand --></th> |
|
115 | 146 |
<th> |
116 | 147 |
[% L.input_tag( |
117 | 148 |
"rop_as_number_for_selected_variants", |
... | ... | |
148 | 179 |
[% L.checkbox_tag('variant_multi_id_' _ loop.count, value=variant.id, checked=0) %] |
149 | 180 |
</td> |
150 | 181 |
<td>[% variant.presenter.part %]</td> |
182 |
<td> |
|
183 |
[% L.input_tag("variants[].ean", variant.ean, class="wi-medium") %] |
|
184 |
</td> |
|
151 | 185 |
<td> |
152 | 186 |
[% L.input_tag("variants[].description", variant.description, class="wi-medium") %] |
153 | 187 |
</td> |
154 | 188 |
<td>[% variant.variant_values | html %]</td> |
155 | 189 |
[% FOREACH variant_property = SELF.part.variant_properties %] |
156 |
<td> [% variant.variant_value(variant_property) %] </td> |
|
190 |
<td> [% variant.variant_value(variant_property).displayable_name %] </td>
|
|
157 | 191 |
[% END %] |
158 | 192 |
<td> |
159 | 193 |
[% L.input_tag( |
... | ... | |
176 | 210 |
class='reformat_number numeric wi-small', |
177 | 211 |
) %] |
178 | 212 |
</td> |
213 |
<td> |
|
214 |
<span class="data wi-small numeric"> |
|
215 |
[% LxERP.format_amount(variant.onhand) %] [% variant.unit | html %] |
|
216 |
</span> |
|
217 |
</td> |
|
179 | 218 |
<td> |
180 | 219 |
[% L.input_tag( |
181 | 220 |
"variants[].rop_as_number", |
Auch abrufbar als: Unified diff
Varianten: Schnellbearbeitung von Varianten (EAN, Auf Lager)