From ef92528c3f875dee2b456418adb214ccebb97361 Mon Sep 17 00:00:00 2001 From: "G. Richardson" Date: Wed, 19 Jan 2011 10:47:17 +0100 Subject: [PATCH] Preisgruppen verbessert MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Bei Hinzufügen neuer Artikel wird die Preisgruppe des Kunden berücksichtigt Bei Wechseln von Preisgruppen wird der Preisgruppenpreis gesetzt Laden von alten Angeboten/Aufträgen/Rechnungen funktioniert, Preisgruppen werden korrekt in DB gespeichert Workflow getestet: Angebot -> Auftrag -> Rechnung Angebot -> Rechnung Workflow mit Lieferschein dazwischen funktioniert nicht Das Verhalten, ob direkt nach Laden/Speichern/Workflow alle Preisgruppenoptionen im Dropdownmenü angezeigt werden, oder nur die gewählte, ist nicht in allen Masken einheitlich. Spätestens nach einem Erneuern stehen aber alle Preisgruppen wieder zur Verfügung. Ändert sich der Preisgruppenpreis einer Ware wird beim Aufrufen alter Rechnungen nicht mehr der neue Preisgruppenpreis, sondern der korrekte Wert aus der DB angezeigt. (Bug 1426) Bug 1206 trifft auch nicht mehr zu. --- SL/IS.pm | 46 ++++++++++++++++++++++++++++++--------- bin/mozilla/invoice_io.pl | 3 ++- bin/mozilla/io.pl | 4 +++- bin/mozilla/is.pl | 13 ++++++++++- bin/mozilla/oe.pl | 4 ++++ 5 files changed, 57 insertions(+), 13 deletions(-) diff --git a/SL/IS.pm b/SL/IS.pm index 3b031bd96..666d8bc04 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -1997,6 +1997,10 @@ sub get_pricegroups_for_parts { my ($price, $selectedpricegroup_id) = split(/--/, $form->{"sellprice_pg_$i"}); my $pricegroup_old = $form->{"pricegroup_old_$i"}; + + # sellprice has format 13,0000 or 0,00000, can't check for 0 numerically + my $sellprice = $form->{"sellprice_$i"}; + my $pricegroup_id = $form->{"pricegroup_id_$i"}; $form->{"new_pricegroup_$i"} = $selectedpricegroup_id; $form->{"old_pricegroup_$i"} = $pricegroup_old; @@ -2075,10 +2079,27 @@ sub get_pricegroups_for_parts { $pkr->{price} = $form->format_amount($myconfig, $pkr->{price}, 5); if ($selectedpricegroup_id eq undef) { - if ($pkr->{pricegroup_id} eq $form->{customer_klass}) { - + # new entries in article list, either old invoice was loaded (edit) or a new article was added + # Case A: open old invoice, no pricegroup selected + # Case B: add new article to invoice, no pricegroup selected + + # to distinguish case A and B the variable pricegroup_id_$i is used + # for new articles this variable isn't defined, for loaded articles it is + # sellprice can't be used, as it already has 0,00 set + + if ($pkr->{pricegroup_id} eq $form->{"pricegroup_id_$i"} and defined $form->{"pricegroup_id_$i"}) { + # Case A $pkr->{selected} = ' selected'; + } elsif ($pkr->{pricegroup_id} eq $form->{customer_klass} + and not defined $form->{"pricegroup_id_$i"} + and $pkr->{price} != 0 # only use customer pricegroup price if it has a value, else use default_sellprice + # for the case where pricegroup prices haven't been set + ) { + # Case B: use default pricegroup of customer + + $pkr->{selected} = ' selected'; # unless $form->{selected}; + # no customer pricesgroup set if ($pkr->{price} == $pkr->{default_sellprice}) { @@ -2087,29 +2108,34 @@ sub get_pricegroups_for_parts { } else { # this sub should not set anything and only return. --sschoeling, 20090506 -# $form->{"sellprice_$i"} = $pkr->{price}; +# is this correct? put in again... -- grichardson 20110119 + $form->{"sellprice_$i"} = $pkr->{price}; } - } elsif ($pkr->{price} == $pkr->{default_sellprice}) { + } elsif ($pkr->{price} == $pkr->{default_sellprice} and $pkr->{default_sellprice} != 0) { $pkr->{price} = $form->{"sellprice_$i"}; $pkr->{selected} = ' selected'; } - } else { + } + + # existing article: pricegroup or price changed + if ($selectedpricegroup_id or $selectedpricegroup_id == 0) { if ($selectedpricegroup_id ne $pricegroup_old) { + # pricegroup has changed if ($pkr->{pricegroup_id} eq $selectedpricegroup_id) { $pkr->{selected} = ' selected'; } - } elsif ( ( $form->parse_amount($myconfig, $price_new) - != $form->parse_amount($myconfig, $form->{"sellprice_$i"})) - and ($price_new ne 0)) { + } elsif (($price_new != $form->{"sellprice_$i"}) and ($price_new ne 0) and defined $price_new) { + # sellprice has changed + # when loading existing invoices $price_new is NULL if ($pkr->{pricegroup_id} == 0) { $pkr->{price} = $form->{"sellprice_$i"}; $pkr->{selected} = ' selected'; } } elsif ($pkr->{pricegroup_id} eq $selectedpricegroup_id) { + # neither sellprice nor pricegroup changed $pkr->{selected} = ' selected'; - if ( ($pkr->{pricegroup_id} == 0) - and ($pkr->{price} == $form->{"sellprice_$i"})) { + if ( ($pkr->{pricegroup_id} == 0) and ($pkr->{price} == $form->{"sellprice_$i"})) { # $pkr->{price} = $form->{"sellprice_$i"}; } else { $pkr->{price} = $form->{"sellprice_$i"}; diff --git a/bin/mozilla/invoice_io.pl b/bin/mozilla/invoice_io.pl index 8c803fb4d..952768611 100644 --- a/bin/mozilla/invoice_io.pl +++ b/bin/mozilla/invoice_io.pl @@ -126,7 +126,8 @@ sub set_pricegroup { if ($item->{selected} && ($pricegroup_id != 0)) { $form->{"pricegroup_old_$j"} = $pricegroup_id; $form->{"price_new_$j"} = $price; - $form->{"sellprice_$j"} = $price; + # edit: don't change the sellprice here + # $form->{"sellprice_$j"} = $price; # this must only be updated for existing articles, not new ones } if ($pricegroup_id == 0) { $form->{"price_new_$j"} = $form->{"sellprice_$j"}; diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index 926098188..3ec65da21 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -288,9 +288,11 @@ sub display_row { # for last row and report # set pricegroup drop down list from report menu if ($form->{"sellprice_$i"} != 0) { + # remember the pricegroup_id in pricegroup_old + # but don't overwrite it $form->{"pricegroup_old_$i"} = $form->{"pricegroup_id_$i"}; my $default_option = $form->{"sellprice_$i"}.'--'.$form->{"pricegroup_id_$i"}; - $column_data{sellprice_pg} = NTI($cgi->popup_menu("sellpricepg_$i", [ $default_option ], $default_option, { $default_option => $form->{"pricegroup_$i"} || '' })); + $column_data{sellprice_pg} = NTI($cgi->popup_menu("sellprice_pg_$i", [ $default_option ], $default_option, { $default_option => $form->{"pricegroup_$i"} || '' })); } else { $column_data{sellprice_pg} = qq| |; } diff --git a/bin/mozilla/is.pl b/bin/mozilla/is.pl index aeba18777..740002bee 100644 --- a/bin/mozilla/is.pl +++ b/bin/mozilla/is.pl @@ -266,7 +266,13 @@ sub prepare_invoice { # get pricegroups for parts IS->get_pricegroups_for_parts(\%myconfig, \%$form); - set_pricegroup($_) for 1 .. $form->{rowcount}; + + # Problem: set_pricegroup resets the sellprice of old invoices to the price + # currently defined in the pricegroup, which is a problem if the price has + # changed, as the old invoice gets the new price + # set_pricegroup must never be called, when an old invoice is initially loaded + + # set_pricegroup($_) for 1 .. $form->{rowcount}; } $main::lxdebug->leave_sub(); } @@ -780,6 +786,11 @@ sub use_as_template { $form->{paidaccounts} = 1; $form->{rowcount}--; $form->{invdate} = $form->current_date(\%myconfig); + + # remember pricegroups for "use as template" + IS->get_pricegroups_for_parts(\%myconfig, \%$form); + set_pricegroup($_) for 1 .. $form->{rowcount}; + &display_form; $main::lxdebug->leave_sub(); diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index b7d86538c..0e469d8d3 100644 --- a/bin/mozilla/oe.pl +++ b/bin/mozilla/oe.pl @@ -1419,6 +1419,10 @@ sub invoice { } + # show pricegroup in newly loaded invoice when creating invoice from quotation/order + IS->get_pricegroups_for_parts(\%myconfig, \%$form); + set_pricegroup($_) for 1 .. $form->{rowcount}; + &display_form; $main::lxdebug->leave_sub(); -- 2.20.1