From 923610728cc212616c8e2fd0b50ad0f555ce3cc5 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 20 Feb 2007 14:56:32 +0000 Subject: [PATCH] "Zahlung buchen" bei Kreditoren- und Debitorenrechnungen: Konten richtig zuordnen und das richtige Datumsfeld benutzen. --- SL/AP.pm | 13 +++++++------ SL/AR.pm | 12 +++++++----- SL/Form.pm | 4 ++-- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/SL/AP.pm b/SL/AP.pm index f6478d39d..cb5f65b17 100644 --- a/SL/AP.pm +++ b/SL/AP.pm @@ -516,7 +516,7 @@ sub post_payment { # connect to database, turn off autocommit my $dbh = $form->dbconnect_noauto($myconfig); - $form->{datepaid} = $form->{invdate}; + $form->{datepaid} = $form->{transdate}; # total payments, don't move we need it here for my $i (1 .. $form->{paidaccounts}) { @@ -526,17 +526,19 @@ sub post_payment { } $form->{exchangerate} = - $form->get_exchangerate($dbh, $form->{currency}, $form->{invdate}, + $form->get_exchangerate($dbh, $form->{currency}, $form->{transdate}, "buy"); my (@values, $query); + my ($accno_ap) = split(/--/, $form->{APselected}); + # record payments and offsetting AP for my $i (1 .. $form->{paidaccounts}) { if ($form->{"paid_$i"} != 0) { my ($accno) = split /--/, $form->{"AP_paid_$i"}; - $form->{"datepaid_$i"} = $form->{invdate} + $form->{"datepaid_$i"} = $form->{transdate} unless ($form->{"datepaid_$i"}); $form->{datepaid} = $form->{"datepaid_$i"}; @@ -559,20 +561,19 @@ sub post_payment { $form->round_amount($form->{"paid_$i"} * $form->{"exchangerate"}, 2) * -1; - $query = qq|DELETE FROM acc_trans | . qq|WHERE trans_id = ? | . qq| AND chart_id = (SELECT c.id FROM chart c WHERE c.accno = ?) | . qq| AND amount = ? AND transdate = ?|; - @values = ($form->{id}, $form->{AP}, $amount, + @values = ($form->{id}, $accno_ap, $amount, conv_date($form->{"datepaid_$i"})); do_query($form, $dbh, $query, @values); $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id) | . qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?)|; - @values = ($form->{id}, $form->{AP}, $amount, + @values = ($form->{id}, $accno_ap, $amount, conv_date($form->{"datepaid_$i"}), conv_i($form->{"paid_project_id_$i"})); do_query($form, $dbh, $query, @values); diff --git a/SL/AR.pm b/SL/AR.pm index 049229f55..ddd67b429 100644 --- a/SL/AR.pm +++ b/SL/AR.pm @@ -383,7 +383,7 @@ sub post_payment { # connect to database, turn off autocommit my $dbh = $form->dbconnect_noauto($myconfig); - $form->{datepaid} = $form->{invdate}; + $form->{datepaid} = $form->{transdate}; # total payments, don't move we need it here for my $i (1 .. $form->{paidaccounts}) { @@ -397,9 +397,11 @@ sub post_payment { } $form->{exchangerate} = - $form->get_exchangerate($dbh, $form->{currency}, $form->{invdate}, + $form->get_exchangerate($dbh, $form->{currency}, $form->{transdate}, "buy"); + my ($accno_ar) = split(/--/, $form->{ARselected}); + # record payments and offsetting AR for my $i (1 .. $form->{paidaccounts}) { @@ -407,7 +409,7 @@ sub post_payment { my $project_id = conv_i($form->{"paid_project_id_$i"}); my ($accno) = split /--/, $form->{"AR_paid_$i"}; - $form->{"datepaid_$i"} = $form->{invdate} + $form->{"datepaid_$i"} = $form->{transdate} unless ($form->{"datepaid_$i"}); $form->{datepaid} = $form->{"datepaid_$i"}; @@ -432,13 +434,13 @@ sub post_payment { $query = qq|DELETE FROM acc_trans WHERE trans_id=$form->{id} AND chart_id=(SELECT c.id FROM chart c - WHERE c.accno = '$form->{AR}') AND amount=$amount AND transdate='$form->{"datepaid_$i"}'|; + WHERE c.accno = '$accno_ar') AND amount=$amount AND transdate='$form->{"datepaid_$i"}'|; $dbh->do($query) || $form->dberror($query); $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id) VALUES ($form->{id}, (SELECT c.id FROM chart c - WHERE c.accno = '$form->{AR}'), + WHERE c.accno = '$accno_ar'), $amount, '$form->{"datepaid_$i"}', ?)|; do_query($form, $dbh, $query, $project_id); diff --git a/SL/Form.pm b/SL/Form.pm index 90ac919ef..b6e0d8365 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -1092,7 +1092,7 @@ sub get_exchangerate { unless ($transdate) { $main::lxdebug->leave_sub(); - return ""; + return 1; } my $query = qq|SELECT e.$fld FROM exchangerate e @@ -1104,7 +1104,7 @@ sub get_exchangerate { my ($exchangerate) = $sth->fetchrow_array; $sth->finish; - if ($exchangerate == 0) { + if (!$exchangerate) { $exchangerate = 1; } -- 2.20.1