Revision ff10db79
Von Sven Schöling vor fast 3 Jahren hinzugefügt
SL/Controller/DeliveryOrder.pm | ||
---|---|---|
55 | 55 |
|
56 | 56 |
# safety |
57 | 57 |
__PACKAGE__->run_before('check_auth', |
58 |
except => [ qw(pack_stock_information) ]);
|
|
58 |
except => [ qw(update_stock_information) ]);
|
|
59 | 59 |
|
60 | 60 |
__PACKAGE__->run_before('get_unalterable_data', |
61 | 61 |
only => [ qw(save save_as_new save_and_delivery_order save_and_invoice save_and_ap_transaction |
... | ... | |
920 | 920 |
); |
921 | 921 |
} |
922 | 922 |
|
923 |
# we're using the old YAML based stock packing, but don't want to do this in |
|
924 |
# the frontend so we're doing a tiny roundtrip to the backend, back the info in |
|
925 |
# perl, serve it back to the frontend and store it in the DOM there |
|
926 |
sub action_pack_stock_information { |
|
923 |
sub action_update_stock_information { |
|
927 | 924 |
my ($self) = @_; |
928 | 925 |
|
929 | 926 |
my $stock_info = $::form->{stock_info}; |
927 |
my $unit = $::form->{unit}; |
|
930 | 928 |
my $yaml = SL::YAML::Dump($stock_info); |
929 |
my $stock_qty = $self->calculate_stock_in_out_from_stock_info($unit, $stock_info); |
|
931 | 930 |
|
932 |
$self->render(\$yaml, { layout => 0, process => 0 }); |
|
931 |
my $response = { |
|
932 |
stock_info => $yaml, |
|
933 |
stock_qty => $stock_qty, |
|
934 |
}; |
|
935 |
|
|
936 |
$self->render(\ SL::JSON::to_json($response), { layout => 0, type => 'json', process => 0 }); |
|
933 | 937 |
} |
934 | 938 |
|
935 | 939 |
sub merge_stock_data { |
... | ... | |
2119 | 2123 |
return @errors; |
2120 | 2124 |
} |
2121 | 2125 |
|
2126 |
sub calculate_stock_in_out_from_stock_info { |
|
2127 |
my ($self, $unit, $stock_info) = @_; |
|
2128 |
|
|
2129 |
return "" if !$unit; |
|
2130 |
|
|
2131 |
my %units_by_name = map { $_->name => $_ } @{ SL::DB::Manager::Unit->get_all }; |
|
2132 |
|
|
2133 |
my $sum = sum0 map { |
|
2134 |
$units_by_name{$_->{unit}}->convert_to($_->{qty}, $units_by_name{$unit}) |
|
2135 |
} @$stock_info; |
|
2136 |
|
|
2137 |
my $content = _format_number_units($sum, 2, $units_by_name{$unit}, $units_by_name{$unit}); |
|
2138 |
|
|
2139 |
return $content; |
|
2140 |
} |
|
2141 |
|
|
2122 | 2142 |
sub calculate_stock_in_out { |
2123 |
my ($self, $item) = @_; |
|
2143 |
my ($self, $item, $stock_info) = @_;
|
|
2124 | 2144 |
|
2125 | 2145 |
return "" if !$item->part || !$item->part->unit || !$item->unit; |
2126 | 2146 |
|
2127 |
my $in_out = $self->type_data->transfer; |
|
2128 |
|
|
2129 |
my $do_qty = $item->qty; |
|
2130 | 2147 |
my $sum = sum0 map { |
2131 | 2148 |
$_->unit_obj->convert_to($_->qty, $item->unit_obj) |
2132 | 2149 |
} $item->delivery_order_stock_entries; |
Auch abrufbar als: Unified diff
DeliveryOrder: besseres update nach stock dialog