Merge branch 'master' of lx-office.linet-services.de:lx-office-erp
authorMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 19 Jan 2011 09:59:09 +0000 (10:59 +0100)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 19 Jan 2011 09:59:09 +0000 (10:59 +0100)
SL/IS.pm
bin/mozilla/invoice_io.pl
bin/mozilla/io.pl
bin/mozilla/is.pl
bin/mozilla/oe.pl

index 3b031bd..666d8bc 100644 (file)
--- 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"};
index 8c803fb..9527686 100644 (file)
@@ -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"};
index 9260981..3ec65da 100644 (file)
@@ -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|&nbsp;|;
       }
index aeba187..740002b 100644 (file)
@@ -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();
index b7d8653..0e469d8 100644 (file)
@@ -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();