Revision f01ed5d1
Von Bernd Bleßmann vor mehr als 3 Jahren hinzugefügt
SL/Controller/Part.pm | ||
---|---|---|
284 | 284 |
my $part_type = $::form->{part_type}; |
285 | 285 |
die unless $part_type =~ /^(assortment|assembly)$/; |
286 | 286 |
|
287 |
my $sellprice_sum = $self->recalc_item_totals(part_type => $part_type, price_type => 'sellcost'); |
|
288 |
my $lastcost_sum = $self->recalc_item_totals(part_type => $part_type, price_type => 'lastcost'); |
|
287 |
my $sellprice_sum = $self->recalc_item_totals(part_type => $part_type, price_type => 'sellcost'); |
|
288 |
my $lastcost_sum = $self->recalc_item_totals(part_type => $part_type, price_type => 'lastcost'); |
|
289 |
my $items_weight_sum = $self->recalc_item_totals(part_type => $part_type, price_type => 'weight'); |
|
289 | 290 |
|
290 | 291 |
my $sum_diff = $sellprice_sum-$lastcost_sum; |
291 | 292 |
|
... | ... | |
295 | 296 |
->html('#items_sum_diff', $::form->format_amount(\%::myconfig, $sum_diff, 2, 0)) |
296 | 297 |
->html('#items_sellprice_sum_basic', $::form->format_amount(\%::myconfig, $sellprice_sum, 2, 0)) |
297 | 298 |
->html('#items_lastcost_sum_basic', $::form->format_amount(\%::myconfig, $lastcost_sum, 2, 0)) |
299 |
->html('#items_weight_sum_basic' , $::form->format_amount(\%::myconfig, $items_weight_sum)) |
|
298 | 300 |
->no_flash_clear->render(); |
299 | 301 |
} |
300 | 302 |
|
... | ... | |
400 | 402 |
my $items_sellprice_sum = $part->items_sellprice_sum; |
401 | 403 |
my $items_lastcost_sum = $part->items_lastcost_sum; |
402 | 404 |
my $items_sum_diff = $items_sellprice_sum - $items_lastcost_sum; |
405 |
my $items_weight_sum = $part->items_weight_sum; |
|
403 | 406 |
|
404 | 407 |
$self->js |
405 | 408 |
->append('#assembly_rows', $html) # append in tbody |
... | ... | |
410 | 413 |
->html('#items_sum_diff', $::form->format_amount(\%::myconfig, $items_sum_diff , 2, 0)) |
411 | 414 |
->html('#items_sellprice_sum_basic', $::form->format_amount(\%::myconfig, $items_sellprice_sum, 2, 0)) |
412 | 415 |
->html('#items_lastcost_sum_basic' , $::form->format_amount(\%::myconfig, $items_lastcost_sum , 2, 0)) |
416 |
->html('#items_weight_sum_basic' , $::form->format_amount(\%::myconfig, $items_weight_sum)) |
|
413 | 417 |
->render; |
414 | 418 |
} |
415 | 419 |
|
... | ... | |
734 | 738 |
} |
735 | 739 |
} elsif ( $part->is_assembly ) { |
736 | 740 |
$part->assemblies( @{$self->assembly_items} ); |
737 |
if ( $params{price_type} eq 'lastcost' ) { |
|
741 |
if ( $params{price_type} eq 'weight' ) { |
|
742 |
return $part->items_weight_sum; |
|
743 |
} elsif ( $params{price_type} eq 'lastcost' ) { |
|
738 | 744 |
return $part->items_lastcost_sum; |
739 | 745 |
} else { |
740 | 746 |
return $part->items_sellprice_sum; |
SL/DB/Assembly.pm | ||
---|---|---|
23 | 23 |
return $self->qty * $self->part->lastcost / ( $self->part->price_factor_id ? $self->part->price_factor->factor : 1 ); |
24 | 24 |
} |
25 | 25 |
|
26 |
sub linetotal_weight { |
|
27 |
my ($self) = @_; |
|
28 |
|
|
29 |
return 0 unless $self->qty > 0 and ($self->part->weight||0) > 0; |
|
30 |
return $self->qty * $self->part->weight; |
|
31 |
} |
|
32 |
|
|
26 | 33 |
1; |
SL/DB/Part.pm | ||
---|---|---|
4 | 4 |
|
5 | 5 |
use Carp; |
6 | 6 |
use List::MoreUtils qw(any uniq); |
7 |
use List::Util qw(sum); |
|
7 | 8 |
use Rose::DB::Object::Helpers qw(as_tree); |
8 | 9 |
|
9 | 10 |
use SL::Locale::String qw(t8); |
... | ... | |
26 | 27 |
{name => 'ean', title => t8('EAN') }, ], |
27 | 28 |
); |
28 | 29 |
|
29 |
use List::Util qw(sum); |
|
30 | 30 |
|
31 | 31 |
__PACKAGE__->meta->add_relationships( |
32 | 32 |
assemblies => { |
... | ... | |
91 | 91 |
__PACKAGE__->attr_sorted({ unsorted => 'customerprices', position => 'sortorder' }); |
92 | 92 |
|
93 | 93 |
__PACKAGE__->before_save('_before_save_set_partnumber'); |
94 |
__PACKAGE__->before_save('_before_save_set_assembly_weight'); |
|
94 | 95 |
|
95 | 96 |
sub _before_save_set_partnumber { |
96 | 97 |
my ($self) = @_; |
... | ... | |
99 | 100 |
return 1; |
100 | 101 |
} |
101 | 102 |
|
103 |
sub _before_save_set_assembly_weight { |
|
104 |
my ($self) = @_; |
|
105 |
|
|
106 |
if ( $self->part_type eq 'assembly' ) { |
|
107 |
my $weight_sum = $self->items_weight_sum; |
|
108 |
$self->weight($self->items_weight_sum) if $weight_sum; |
|
109 |
} |
|
110 |
return 1; |
|
111 |
} |
|
112 |
|
|
102 | 113 |
sub items { |
103 | 114 |
my ($self) = @_; |
104 | 115 |
|
... | ... | |
425 | 436 |
SQL |
426 | 437 |
|
427 | 438 |
my $objs = SL::DB::Manager::Inventory->get_all( |
428 |
query => [ id => [ \"$query" ] ], |
|
439 |
query => [ id => [ \"$query" ] ], # make emacs happy "
|
|
429 | 440 |
with_objects => [ 'parts', 'trans_type', 'bin', 'bin.warehouse' ], # prevent lazy loading in template |
430 | 441 |
sort_by => 'itime DESC', |
431 | 442 |
); |
... | ... | |
519 | 530 |
sum map { $_->linetotal_lastcost } @{$self->items}; |
520 | 531 |
}; |
521 | 532 |
|
533 |
sub items_weight_sum { |
|
534 |
my ($self) = @_; |
|
535 |
|
|
536 |
return unless $self->is_assembly; |
|
537 |
return unless $self->items; |
|
538 |
sum map { $_->linetotal_weight} @{$self->items}; |
|
539 |
}; |
|
540 |
|
|
522 | 541 |
1; |
523 | 542 |
|
524 | 543 |
__END__ |
templates/webpages/part/_basic_data.html | ||
---|---|---|
145 | 145 |
<th align="right" nowrap="true">[% 'Weight' | $T8 %]</th> |
146 | 146 |
<td> |
147 | 147 |
[%- IF SELF.part.is_assembly %] |
148 |
[% LxERP.format_amount(SELF.part.weight) %]
|
|
148 |
<span id="items_weight_sum_basic">[% LxERP.format_amount(SELF.part.weight) %]</span>
|
|
149 | 149 |
[% ELSE %] |
150 | 150 |
[% L.input_tag('part.weight_as_number', SELF.part.weight_as_number, size=10, class='reformat_number numeric') %] |
151 | 151 |
[% END %] |
Auch abrufbar als: Unified diff
Erzeugnisse: Gewicht aus einzelnen Bestandteilen ermitteln und speichern.