X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/3c1ceacd69653915e0b44f1700b198d96681f546..ca12e8dfc4773aabc13818a0398e06e44028e2bc:/SL/IS.pm?ds=inline diff --git a/SL/IS.pm b/SL/IS.pm index ca43fd8ab..b782fef26 100644 --- 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; @@ -970,12 +976,35 @@ sub post_invoice { Common::webdav_folder($form) if ($main::webdav); - my @close_do_ids = map { $_ * 1 } grep { $_ } split m/\s+/, $form->{close_do_ids}; + # 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 @close_do_ids) { + if (scalar @convert_from_do_ids) { DO->close_orders('dbh' => $dbh, - 'ids' => \@close_do_ids); + '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) { @@ -1499,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,