X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fap.pl;h=1070c673b43cbf957cb530b4262a35da26f6a7a0;hb=14d71a6d1215e4fc67136c060fd21cd6c59602af;hp=b2e5819e81f0834c150107964c61253d85285d3d;hpb=8c204ce48aa9ecc1e3eb6a99ff9e444716633a90;p=kivitendo-erp.git diff --git a/bin/mozilla/ap.pl b/bin/mozilla/ap.pl index b2e5819e8..1070c673b 100644 --- a/bin/mozilla/ap.pl +++ b/bin/mozilla/ap.pl @@ -32,7 +32,8 @@ #====================================================================== use POSIX qw(strftime); -use List::Util qw(sum); +use List::Util qw(max sum); +use List::UtilsBy qw(sort_by); use SL::AP; use SL::FU; @@ -41,6 +42,7 @@ use SL::IS; use SL::PE; use SL::ReportGenerator; use SL::DB::Default; +use SL::DB::PurchaseInvoice; require "bin/mozilla/arap.pl"; require "bin/mozilla/common.pl"; @@ -187,6 +189,25 @@ sub create_links { $main::lxdebug->leave_sub(); } +sub _sort_payments { + my @fields = qw(acc_trans_id gldate datepaid source memo paid AR_paid paid_project_id); + my @payments = + grep { $_->{paid} != 0 } + map { + my $idx = $_; + +{ map { ($_ => delete($::form->{"${_}_${idx}"})) } @fields } + } (1..$::form->{paidaccounts}); + + @payments = sort_by { DateTime->from_kivitendo($_->{datepaid}) } @payments; + + $::form->{paidaccounts} = max scalar(@payments), 1; + + foreach my $idx (1 .. scalar(@payments)) { + my $payment = $payments[$idx - 1]; + $::form->{"${_}_${idx}"} = $payment->{$_} for @fields; + } +} + sub form_header { $main::lxdebug->enter_sub(); @@ -197,6 +218,8 @@ sub form_header { $main::auth->assert('general_ledger'); + $::form->{invoice_obj} = SL::DB::PurchaseInvoice->new(id => $::form->{id})->load if $::form->{id}; + $form->{title_} = $form->{title}; $form->{title} = $form->{title} eq 'Add' ? $locale->text('Add Accounts Payables Transaction') : $locale->text('Edit Accounts Payables Transaction'); @@ -372,6 +395,8 @@ sub form_header { $form->{totalpaid} = 0; + _sort_payments(); + if ( $form->{'paid_'. $form->{paidaccounts}} ) { $form->{paidaccounts}++; } @@ -559,6 +584,7 @@ sub post_payment { my $locale = $main::locale; $main::auth->assert('general_ledger'); + $form->mtime_ischanged('ap'); $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); @@ -607,6 +633,7 @@ sub post { my $locale = $main::locale; $main::auth->assert('general_ledger'); + $form->mtime_ischanged('ap'); my ($inline) = @_;