Merge branch 'master' of ssh://lx-office/~/lx-office-erp
[kivitendo-erp.git] / bin / mozilla / do.pl
index 120606a..8299a1a 100644 (file)
@@ -179,9 +179,9 @@ sub order_links {
   # get customer / vendor
   if ($form->{vc} eq 'vendor') {
     IR->get_vendor(\%myconfig, \%$form);
+    $form->{discount} = $form->{vendor_discount};
   } else {
     IS->get_customer(\%myconfig, \%$form);
-    # OFFEN tritt bug 1284 auch bei vendor auf?
     $form->{discount} = $form->{customer_discount};
   }
 
@@ -733,9 +733,9 @@ sub invoice {
 
   for my $i (1 .. $form->{rowcount}) {
     # für bug 1284
-    if ($form->{discount}){ # Falls wir einen Kundenrabatt haben
+    if ($form->{discount}){ # Falls wir einen Lieferanten-/Kundenrabatt haben
       # und keinen anderen discount wert an $i ...
-      $form->{"discount_$i"} ||= $form->{discount}*100; # ... nehmen wir den kundenrabatt
+      $form->{"discount_$i"} ||= $form->{discount}*100; # ... nehmen wir diesen Rabatt
     }
     map { $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if $form->{"${_}_${i}"} } qw(ship qty sellprice listprice lastcost basefactor);
   }
@@ -846,15 +846,35 @@ sub invoice_multi {
 
   map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued);
 
+  # get vendor or customer discount
+  my $vc_discount;
+  my $saved_form = save_form();
+  if ($form->{vc} eq 'vendor') {
+    IR->get_vendor(\%myconfig, \%$form);
+    $vc_discount = $form->{vendor_discount};
+  } else {
+    IS->get_customer(\%myconfig, \%$form);
+    $vc_discount = $form->parse_amount(\%myconfig, $form->{customer_discount});
+  }
+  restore_form($saved_form);
+
   $form->{rowcount} = 0;
   foreach my $ref (@{ $form->{form_details} }) {
     $form->{rowcount}++;
     $ref->{reqdate} ||= $ref->{dord_transdate}; # copy transdates into each invoice row
     map { $form->{"${_}_$form->{rowcount}"} = $ref->{$_} } keys %{ $ref };
-    map { $form->{"${_}_$form->{rowcount}"} = $form->format_amount(\%myconfig, $ref->{$_}) } qw(qty sellprice discount lastcost);
+    map { $form->{"${_}_$form->{rowcount}"} = $form->format_amount(\%myconfig, $ref->{$_}) } qw(qty sellprice lastcost);
+
+    if ($vc_discount){ # falls wir einen Lieferanten/Kundenrabatt haben 
+      # und keinen anderen discount wert an $i ...
+      $form->{"discount_$form->{rowcount}"} ||= $vc_discount; # ... nehmen wir diesen Rabatt
+    }
+
     $form->{"discount_$form->{rowcount}"}   = $form->{"discount_$form->{rowcount}"}  * 100; #s.a. Bug 1151
     # Anm.: Eine Änderung des discounts in der SL/DO.pm->retrieve (select (doi.discount * 100) as discount) ergibt in psql einen
     # Wert von 10.0000001490116. Ferner ist der Rabatt in der Rechnung dann bei 1.0 (?). Deswegen lasse ich das hier. jb 10.10.09
+
+    $form->{"discount_$form->{rowcount}"} = $form->format_amount(\%myconfig, $form->{"discount_$form->{rowcount}"});
   }
   delete $form->{form_details};