From: Moritz Bunkus Date: Tue, 12 Jun 2018 07:00:00 +0000 (+0200) Subject: Debitorenbuchungen: Flag »cleared« beim Zahlungsbuchen beibehalten X-Git-Tag: release-3.5.4~395 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=2d4626f98c3ef03c52cadde9e7bcee2330b02cd9;p=kivitendo-erp.git Debitorenbuchungen: Flag »cleared« beim Zahlungsbuchen beibehalten Existierende Zahlungen werden aus acc_trans komplett gelöscht und neu eingefügt. Dabei geht der Status des Flags »cleared« verloren, der anzeigt, dass eine Zahlung mit dem Konto abgeglichen wurde. Das Flag einer Zahlung wird nun beibehalten, sofern: • die Zahlung bereits vorher existiert hat (Präsenz der `acc_trans_id`) • Wert und Konto gleich geblieben sind --- diff --git a/SL/AR.pm b/SL/AR.pm index 4f150673b..e227eb6e1 100644 --- a/SL/AR.pm +++ b/SL/AR.pm @@ -49,17 +49,19 @@ use SL::DB; use strict; sub post_transaction { - my ($self, $myconfig, $form, $provided_dbh, $payments_only) = @_; + my ($self, $myconfig, $form, $provided_dbh, %params) = @_; $main::lxdebug->enter_sub(); - my $rc = SL::DB->client->with_transaction(\&_post_transaction, $self, $myconfig, $form, $provided_dbh, $payments_only); + my $rc = SL::DB->client->with_transaction(\&_post_transaction, $self, $myconfig, $form, $provided_dbh, %params); $::lxdebug->leave_sub; return $rc; } sub _post_transaction { - my ($self, $myconfig, $form, $provided_dbh, $payments_only) = @_; + my ($self, $myconfig, $form, $provided_dbh, %params) = @_; + + my $payments_only = $params{payments_only}; my ($query, $sth, $null, $taxrate, $amount, $tax); my $exchangerate = 0; @@ -190,6 +192,8 @@ sub _post_transaction { $form->new_lastmtime('ar'); + my %already_cleared = %{ $params{already_cleared} // {} }; + # add paid transactions for my $i (1 .. $form->{paidaccounts}) { @@ -213,20 +217,28 @@ sub _post_transaction { $form->{exchangerate} = $form->{"exchangerate_$i"} if ($form->{amount} == 0 && $form->{netamount} == 0); + my $new_cleared = !$form->{"acc_trans_id_$i"} ? 'f' + : !$already_cleared{$form->{"acc_trans_id_$i"}} ? 'f' + : $already_cleared{$form->{"acc_trans_id_$i"}}->{amount} != $form->{"paid_$i"} * -1 ? 'f' + : $already_cleared{$form->{"acc_trans_id_$i"}}->{accno} != $form->{AR}{"paid_$i"} ? 'f' + : $already_cleared{$form->{"acc_trans_id_$i"}}->{cleared} ? 't' + : 'f'; + # receivables amount $amount = $form->round_amount($form->{"paid_$i"} * $form->{exchangerate}, 2); if ($amount != 0) { # add receivable - $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id, chart_link) - VALUES (?, ?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE id = ?), + $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, cleared, taxkey, tax_id, chart_link) + VALUES (?, ?, ?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE id = ?), (SELECT tax_id FROM taxkeys WHERE chart_id = ? AND startdate <= ? ORDER BY startdate DESC LIMIT 1), (SELECT c.link FROM chart c WHERE c.id = ?))|; - @values = (conv_i($form->{id}), $form->{AR_chart_id}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AR_chart_id}, $form->{AR_chart_id}, conv_date($form->{"datepaid_$i"}), $form->{AR_chart_id}); + @values = (conv_i($form->{id}), $form->{AR_chart_id}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $new_cleared, + $form->{AR_chart_id}, $form->{AR_chart_id}, conv_date($form->{"datepaid_$i"}), $form->{AR_chart_id}); do_query($form, $dbh, $query, @values); } @@ -236,8 +248,8 @@ sub _post_transaction { my $project_id = conv_i($form->{"paid_project_id_$i"}); my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->current_date($myconfig)); $amount = $form->{"paid_$i"} * -1; - $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, project_id, taxkey, tax_id, chart_link) - VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?), + $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, project_id, cleared, taxkey, tax_id, chart_link) + VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?), (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id @@ -246,7 +258,7 @@ sub _post_transaction { AND startdate <= ? ORDER BY startdate DESC LIMIT 1), (SELECT c.link FROM chart c WHERE c.accno = ?))|; - @values = (conv_i($form->{id}), $form->{AR}{"paid_$i"}, $amount, conv_date($form->{"datepaid_$i"}), $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $form->{AR}{"paid_$i"}, + @values = (conv_i($form->{id}), $form->{AR}{"paid_$i"}, $amount, conv_date($form->{"datepaid_$i"}), $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $new_cleared, $form->{AR}{"paid_$i"}, $form->{AR}{"paid_$i"}, conv_date($form->{"datepaid_$i"}), $form->{AR}{"paid_$i"}); do_query($form, $dbh, $query, @values); @@ -385,6 +397,15 @@ sub _post_payment { $old_form = save_form(); + $query = <{id}); + # Delete all entries in acc_trans from prior payments. if (SL::DB::Default->get->payments_changeable != 0) { $self->_delete_payments($form, $dbh); @@ -424,7 +445,7 @@ sub _post_payment { ($form->{AR_chart_id}) = selectfirst_array_query($form, $dbh, $query, conv_i($form->{id})); # Post the new payments. - $self->post_transaction($myconfig, $form, $dbh, 1); + $self->post_transaction($myconfig, $form, $dbh, payments_only => 1, already_cleared => \%already_cleared); restore_form($old_form);