]> wagnertech.de Git - mfinanz.git/blobdiff - SL/IS.pm
Schalter Lastschrift (Verfahren) für Kunden/Lieferanten
[mfinanz.git] / SL / IS.pm
index c4e2a7fbd04526846b4ed2070d1cf171120fa4aa..b782fef264e972131dbeb04ef1debd17ba1644ab 100644 (file)
--- a/SL/IS.pm
+++ b/SL/IS.pm
@@ -37,6 +37,7 @@ package IS;
 use List::Util qw(max);
 
 use SL::AM;
+use SL::ARAP;
 use SL::CVar;
 use SL::Common;
 use SL::DBUtils;
@@ -129,6 +130,8 @@ sub invoice_details {
   my $subtotal_header = 0;
   my $subposition = 0;
 
+  $form->{discount} = [];
+
   my @arrays =
     qw(runningnumber number description longdescription qty ship unit bin
        deliverydate_oe ordnumber_oe transdate_oe licensenumber validuntil
@@ -209,8 +212,11 @@ sub invoice_details {
       my ($dec)         = ($sellprice =~ /\.(\d+)/);
       my $decimalplaces = max 2, length($dec);
 
-      my $discount             = $form->round_amount($form->{"qty_$i"} * $sellprice * $form->{"discount_$i"} / 100 / $price_factor->{factor}, $decimalplaces);
-      my $linetotal            = $form->round_amount($form->{"qty_$i"} * $sellprice * (100 - $form->{"discount_$i"}) / 100 / $price_factor->{factor}, 2);
+      my $parsed_discount      = $form->parse_amount($myconfig, $form->{"discount_$i"});
+      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);
 
@@ -218,7 +224,7 @@ sub invoice_details {
 
       $linetotal = ($linetotal != 0) ? $linetotal : '';
 
-      push @{ $form->{discount} },   ($discount  != 0) ? $form->format_amount($myconfig, $discount * -1, $decimalplaces) : '';
+      push @{ $form->{discount} },   ($discount  != 0) ? $form->format_amount($myconfig, $discount * -1, 2) : '';
       push @{ $form->{p_discount} }, $form->{"discount_$i"};
 
       $form->{total}            += $linetotal;
@@ -994,6 +1000,11 @@ sub post_invoice {
                               'to_id'      => $form->{id},
       );
   }
+  delete $form->{convert_from_do_ids};
+
+  ARAP->close_orders_if_billed('dbh'     => $dbh,
+                               'arap_id' => $form->{id},
+                               'table'   => 'ar',);
 
   my $rc = 1;
   if (!$provided_dbh) {
@@ -1517,7 +1528,7 @@ sub get_customer {
   # get customer
   $query =
     qq|SELECT
-         c.name AS customer, c.discount, c.creditlimit, c.terms,
+         c.id AS customer_id, c.name AS customer, c.discount, c.creditlimit, c.terms,
          c.email, c.cc, c.bcc, c.language_id, c.payment_id,
          c.street, c.zipcode, c.city, c.country,
          c.notes AS intnotes, c.klass as customer_klass, c.taxzone_id, c.salesman_id,