X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/eebe8e90991eacadb6fbd20a648c152017a620c7..89b2668811eac6023ad58322e2f9970ddb6a27c9:/bin/mozilla/oe.pl diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index b9abb0f16..860d722d4 100644 --- a/bin/mozilla/oe.pl +++ b/bin/mozilla/oe.pl @@ -465,7 +465,7 @@ sub form_header { } } - $::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.SalesPurchase show_form_details show_history show_vc_details ckeditor/ckeditor ckeditor/adapters/jquery)); + $::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.SalesPurchase show_form_details show_history show_vc_details ckeditor/ckeditor ckeditor/adapters/jquery kivi.io)); $form->header; if ($form->{CFDD_shipto} && $form->{CFDD_shipto_id} ) { @@ -594,8 +594,6 @@ sub update { check_oe_access(); - my $order = _make_record(); - set_headings($form->{"id"} ? "edit" : "add"); $form->{update} = 1; @@ -680,7 +678,20 @@ sub update { if ($sellprice) { $form->{"sellprice_$i"} = $sellprice; } else { - $form->{"sellprice_$i"} *= (1 - $form->{tradediscount}); + my $record = _make_record(); + my $price_source = SL::PriceSource->new(record_item => $record->items->[$i-1], record => $record); + my $best_price = $price_source->best_price; + my $best_discount = $price_source->best_discount; + + if ($best_price) { + $::form->{"sellprice_$i"} = $best_price->price; + $::form->{"active_price_source_$i"} = $best_price->source; + } + if ($best_discount) { + $::form->{"discount_$i"} = $best_discount->discount; + $::form->{"active_discount_source_$i"} = $best_discount->source; + } + $form->{"sellprice_$i"} /= $exchangerate; # if there is an exchange rate adjust sellprice } @@ -2111,28 +2122,3 @@ sub dispatcher { $::form->error($::locale->text('No action defined.')); } -sub _make_record { - my $obj = SL::DB::Order->new; - - for my $method (keys %$::form) { - next unless $obj->can($method); - next unless $obj->meta->column($method); - - if ($obj->meta->column($method)->isa('Rose::DB::Object::Metadata::Column::Date')) { - $obj->${\"$method\_as_date"}($::form->{$method}); - } elsif ((ref $obj->meta->column($method)) =~ /^Rose::DB::Object::Metadata::Column::(?:Integer|Numeric|Float|DoublePrecsion)$/) { - $obj->$method($::form->{$method}); - } - } - - my @items; - for my $i (1 .. $::form->{rowcount}) { - next unless $::form->{"id_$i"}; - push @items, _make_record_item($i) - } - - $obj->orderitems(@items); - - return $obj; -} -