Ein Bug rausgeholt, einen neuen wieder reingesetzt. Zusatz zu: r3473, der Else-Zweig...
[kivitendo-erp.git] / SL / OE.pm
index 81b9b0a..f700c35 100644 (file)
--- a/SL/OE.pm
+++ b/SL/OE.pm
@@ -39,6 +39,7 @@ use List::Util qw(max);
 use SL::AM;
 use SL::Common;
 use SL::DBUtils;
+use SL::IC;
 
 sub transactions {
   $main::lxdebug->enter_sub();
@@ -436,7 +437,7 @@ sub save {
          globalproject_id = ?, employee_id = ?, salesman_id = ?, cp_id = ?, transaction_description = ?, marge_total = ?, marge_percent = ?
        WHERE id = ?|;
 
-  @values = ($form->{ordnumber}, $form->{quonumber},
+  @values = ($form->{ordnumber} || '', $form->{quonumber},
              $form->{cusordnumber}, conv_date($form->{transdate}),
              conv_i($form->{vendor_id}), conv_i($form->{customer_id}),
              $amount, $netamount, conv_date($reqdate),
@@ -950,6 +951,8 @@ sub order_details {
 
   $form->{discount} = [];
 
+  IC->prepare_parts_for_printing();
+
   my @arrays =
     qw(runningnumber number description longdescription qty ship unit bin
        partnotes serialnumber reqdate sellprice listprice netprice
@@ -1011,8 +1014,10 @@ sub order_details {
       my $decimalplaces = max 2, length($dec);
 
       my $parsed_discount      = $form->parse_amount($myconfig, $form->{"discount_$i"});
-      my $discount             = $form->round_amount($form->{"qty_$i"} * $sellprice * $parsed_discount / 100 / $price_factor->{factor}, $decimalplaces);
-      my $linetotal            = $form->round_amount($form->{"qty_$i"} * $sellprice * (100 - $parsed_discount) / 100 / $price_factor->{factor}, 2);
+      my $linetotal_exact      =                     $form->{"qty_$i"} * $sellprice * (100 - $parsed_discount) / 100 / $price_factor->{factor};
+      my $linetotal            = $form->round_amount($linetotal_exact, 2);
+      my $discount             = $form->round_amount($form->{"qty_$i"} * $sellprice * $parsed_discount / 100 / $price_factor->{factor} - ($linetotal - $linetotal_exact),
+                                                     $decimalplaces);
       my $nodiscount_linetotal = $form->round_amount($form->{"qty_$i"} * $sellprice / $price_factor->{factor}, 2);
       $form->{"netprice_$i"}   = $form->round_amount($form->{"qty_$i"} ? ($linetotal / $form->{"qty_$i"}) : 0, 2);
 
@@ -1070,9 +1075,9 @@ sub order_details {
       }
 
       if ($taxamount != 0) {
-        foreach my $item (split / /, $form->{"taxaccounts_$i"}) {
-          $taxaccounts{$item} += $taxamount * $form->{"${item}_rate"} / $taxrate;
-          $taxbase{$item}     += $taxbase;
+        foreach my $accno (split / /, $form->{"taxaccounts_$i"}) {
+          $taxaccounts{$accno} += $taxamount * $form->{"${accno}_rate"} / $taxrate;
+          $taxbase{$accno}     += $taxbase;
         }
       }