From: Bernd Bleßmann Date: Wed, 17 Nov 2021 13:57:32 +0000 (+0100) Subject: Anzahlungs-Rg.: Gegenbuchung bei Schluss-Rg. X-Git-Tag: kivitendo-mebil_0.1-0~10^2~2^2~217^2~37 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=581862258b9fb1d1363d6b95280074f27134b6d5;p=kivitendo-erp.git Anzahlungs-Rg.: Gegenbuchung bei Schluss-Rg. --- diff --git a/SL/IS.pm b/SL/IS.pm index f64d92996..b25423381 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -1054,6 +1054,16 @@ SQL # entsprechend auch beim Bestimmen des Steuerschlüssels in Taxkey.pm berücksichtigen my $taxdate = $form->{tax_point} ||$form->{deliverydate} || $form->{invdate}; + + # reverse booking for invoices for advance payment + my $invoices_for_advance_payment = $self->_get_invoices_for_advance_payment($form->{convert_from_ar_ids} || $form->{id}); + foreach my $invoice_for_advance_payment (@$invoices_for_advance_payment) { + my $transactions = SL::DB::Manager::AccTransaction->get_all(query => [ trans_id => $invoice_for_advance_payment->id ], sort_by => 'acc_trans_id ASC'); + foreach my $transaction (@$transactions) { + $form->{amount}->{$invoice_for_advance_payment->id}->{$transaction->chart->accno} = -1 * $transaction->amount; + } + } + foreach my $trans_id (keys %{ $form->{amount_cogs} }) { foreach my $accno (keys %{ $form->{amount_cogs}{$trans_id} }) { next unless ($form->{expense_inventory} =~ /\Q$accno\E/); @@ -1474,6 +1484,21 @@ SQL return 1; } +sub _get_invoices_for_advance_payment { + my ($self, $id) = @_; + + return [] if !$id; + + my $invoice_obj = SL::DB::Invoice->new(id => $id*1)->load; + my $links = $invoice_obj->linked_records(direction => 'from', from => ['Invoice'], recursive => 1); + my @related_invoices = grep {'SL::DB::Invoice' eq ref $_ && "invoice_for_advance_payment" eq $_->type} @$links; + + push @related_invoices, $invoice_obj if "invoice_for_advance_payment" eq $invoice_obj->type; + + return \@related_invoices; +} + + sub transfer_out { $::lxdebug->enter_sub; diff --git a/bin/mozilla/is.pl b/bin/mozilla/is.pl index 85f335335..2fd82c7b8 100644 --- a/bin/mozilla/is.pl +++ b/bin/mozilla/is.pl @@ -1202,11 +1202,7 @@ sub final_invoice { # (order) -> invoice for adv. payment 1 -> invoice for adv. payment 2 -> invoice for adv. payment 3 -> final invoice # # we are currently in the last invoice for adv. payment (3 in this example) - my $invoice_obj = SL::DB::Invoice->load_cached($form->{id}); - my $links = $invoice_obj->linked_records(direction => 'from', from => ['Invoice'], recursive => 1); - my @related_invoices = grep {'SL::DB::Invoice' eq ref $_ && "invoice_for_advance_payment" eq $_->type} @$links; - - push @related_invoices, $invoice_obj; + my $related_invoices = IS->_get_invoices_for_advance_payment($form->{id}); delete @{ $form }{qw(printed emailed queued invnumber invdate exchangerate forex deliverydate datepaid_1 gldate_1 acc_trans_id_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno locked)}; @@ -1233,7 +1229,7 @@ sub final_invoice { remove_emptied_rows(1); my $i = 0; - foreach my $ri (@related_invoices) { + foreach my $ri (@$related_invoices) { foreach my $item (@{$ri->items_sorted}) { $i++; $form->{"id_$i"} = $item->parts_id;