From 26dfef7da64e9712db783fb666bb6af80b89675e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20B=C3=BCren?= Date: Mon, 1 Aug 2016 15:50:15 +0200 Subject: [PATCH] do.pl sort Funktion verbessert MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit parse_amount/format_amount Problem bei Nachkommastellen. Hintergrund: Ein save mit no_redirect wird benötigt, damit ein erneutes Update die Reihenfolge auch an der Oberfläche anzeigt. Leider wird save somit zweimal aufgerufen und damit auch 2x parse_amount Entsprechend zwischendrin einmal mit format_amount wieder ausgeglichen. --- bin/mozilla/do.pl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bin/mozilla/do.pl b/bin/mozilla/do.pl index c43acce32..a583f8d14 100644 --- a/bin/mozilla/do.pl +++ b/bin/mozilla/do.pl @@ -1796,6 +1796,11 @@ sub sort { # hashify partnumbers, positions. key is delivery_order_items_id for my $i (1 .. ($form->{rowcount}) ) { $temp_hash{$form->{"delivery_order_items_id_$i"}} = { runningnumber => $form->{"runningnumber_$i"}, partnumber => $form->{"partnumber_$i"} }; + if ($form->{id} && $form->{"discount_$i"}) { + # prepare_order assumes a db value if there is a form->id and multiplies *100 + # We hope for new controller code (no more format_amount/parse_amount distinction) + $form->{"discount_$i"} /=100; + } } # naturally sort partnumbers and get a sorted array of doi_ids my @sorted_doi_ids = sort { Sort::Naturally::ncmp($temp_hash{$a}->{"partnumber"}, $temp_hash{$b}->{"partnumber"}) } keys %temp_hash; @@ -1807,6 +1812,12 @@ sub sort { $form->{"runningnumber_$temp_hash{$_}->{runningnumber}"} = $new_number; $new_number++; } + # all parse_amounts changes are in form (i.e. , to .) therefore we need + # another format_amount to change it back, for the next save ;-( + # works great except for row discounts (see above comment) + prepare_order(); + + $main::lxdebug->leave_sub(); save(); } -- 2.20.1