X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/ca57b730b7e7936700026e4c18c6ddced11947fe..1cd7aea87cff5ab5a4b51a539e2dc24935f4d8c4:/SL/IS.pm?ds=inline diff --git a/SL/IS.pm b/SL/IS.pm index 8e2514478..7e52b2bea 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -37,9 +37,11 @@ package IS; use List::Util qw(max); use SL::AM; +use SL::ARAP; use SL::CVar; use SL::Common; use SL::DBUtils; +use SL::DO; use SL::MoreCommon; use Data::Dumper; @@ -128,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 @@ -208,8 +212,9 @@ 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 $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 $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); @@ -217,7 +222,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; @@ -969,6 +974,36 @@ sub post_invoice { Common::webdav_folder($form) if ($main::webdav); + # Link this record to the records it was created from. + RecordLinks->create_links('dbh' => $dbh, + 'mode' => 'ids', + 'from_table' => 'oe', + 'from_ids' => $form->{convert_from_oe_ids}, + 'to_table' => 'ar', + 'to_id' => $form->{id}, + ); + delete $form->{convert_from_oe_ids}; + + my @convert_from_do_ids = map { $_ * 1 } grep { $_ } split m/\s+/, $form->{convert_from_do_ids}; + + if (scalar @convert_from_do_ids) { + DO->close_orders('dbh' => $dbh, + 'ids' => \@convert_from_do_ids); + + RecordLinks->create_links('dbh' => $dbh, + 'mode' => 'ids', + 'from_table' => 'delivery_orders', + 'from_ids' => \@convert_from_do_ids, + 'to_table' => 'ar', + '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) { $dbh->commit(); @@ -1491,7 +1526,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,