X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/b103ea259f681f2ca5036e7b0915423c2a8ccc7a..0d37f1e8de798bec9621f6d40e189bf62206de1f:/bin/mozilla/ap.pl diff --git a/bin/mozilla/ap.pl b/bin/mozilla/ap.pl index b2e5819e8..7506693b1 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; @@ -187,6 +188,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(); @@ -372,6 +392,8 @@ sub form_header { $form->{totalpaid} = 0; + _sort_payments(); + if ( $form->{'paid_'. $form->{paidaccounts}} ) { $form->{paidaccounts}++; }