From 3ff5da55d203a1ac5dbd269737577f0abeb424e0 Mon Sep 17 00:00:00 2001 From: Niclas Zimmermann Date: Thu, 20 Sep 2012 15:42:57 +0200 Subject: [PATCH] Bilanzfehler bei Wechselkursbuchungen MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Wenn man Rechnungen (die Fremdwährungen nutzen) bezahlt hat, wurden Gewinne/Verluste durch mögliche Kurswechsel bei Zahlungsbuchungen nicht weiter berücksichtigt. Dadurch kam es zu Bilanzfehlern im Buchungsjournal. Das return bei payments_only wird jetzt erst nach den Wechselkurs- buchungen ausgeführt. Project_id wurde durch ein conv_i gekapselt. --- SL/IS.pm | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/SL/IS.pm b/SL/IS.pm index 22080c7e6..82226ee52 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -933,18 +933,16 @@ sub post_invoice { # exchangerate difference $form->{fx}{$accno}{ $form->{"datepaid_$i"} } += - $form->{"paid_$i"} * ($form->{"exchangerate_$i"} - 1) + $diff; + $form->{"paid_$i"} * ($form->{"exchangerate_$i"} - 1) + $diff; # gain/loss $amount = - $form->{"paid_$i"} * $form->{exchangerate} - $form->{"paid_$i"} * - $form->{"exchangerate_$i"}; + $form->{"paid_$i"} * $form->{exchangerate} - $form->{"paid_$i"} * + $form->{"exchangerate_$i"}; if ($amount > 0) { - $form->{fx}{ $form->{fxgain_accno} }{ $form->{"datepaid_$i"} } += - $amount; + $form->{fx}{ $form->{fxgain_accno} }{ $form->{"datepaid_$i"} } += $amount; } else { - $form->{fx}{ $form->{fxloss_accno} }{ $form->{"datepaid_$i"} } += - $amount; + $form->{fx}{ $form->{fxloss_accno} }{ $form->{"datepaid_$i"} } += $amount; } $diff = 0; @@ -963,35 +961,32 @@ sub post_invoice { IO->set_datepaid(table => 'ar', id => $form->{id}, dbh => $dbh); - if ($payments_only) { - $query = qq|UPDATE ar SET paid = ? WHERE id = ?|; - do_query($form, $dbh, $query, $form->{paid}, conv_i($form->{id})); - - $dbh->commit if !$provided_dbh; - - $main::lxdebug->leave_sub(); - return; - } - # record exchange rate differences and gains/losses foreach my $accno (keys %{ $form->{fx} }) { foreach my $transdate (keys %{ $form->{fx}{$accno} }) { - if ( - ($form->{fx}{$accno}{$transdate} = - $form->round_amount($form->{fx}{$accno}{$transdate}, 2) - ) != 0 - ) { + $form->{fx}{$accno}{$transdate} = $form->round_amount($form->{fx}{$accno}{$transdate}, 2); + if ( $form->{fx}{$accno}{$transdate} != 0 ) { $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction, taxkey, project_id) VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, '0', '1', (SELECT taxkey_id FROM chart WHERE accno = ?), ?)|; - @values = (conv_i($form->{"id"}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $accno, $project_id); + @values = (conv_i($form->{"id"}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $accno, conv_i($project_id)); do_query($form, $dbh, $query, @values); } } } + if ($payments_only) { + $query = qq|UPDATE ar SET paid = ? WHERE id = ?|; + do_query($form, $dbh, $query, $form->{paid}, conv_i($form->{id})); + + $dbh->commit if !$provided_dbh; + + $main::lxdebug->leave_sub(); + return; + } + $amount = $netamount + $tax; # save AR record -- 2.20.1