From: Moritz Bunkus Date: Wed, 30 Sep 2015 10:52:49 +0000 (+0200) Subject: Rechnungen: Zahlungsein-/-ausgänge nach Datum sortieren X-Git-Tag: release-3.4.1~690 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=0d37f1e8de798bec9621f6d40e189bf62206de1f;p=kivitendo-erp.git Rechnungen: Zahlungsein-/-ausgänge nach Datum sortieren --- 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}++; } diff --git a/bin/mozilla/ar.pl b/bin/mozilla/ar.pl index 38a667e95..b1421d6ad 100644 --- a/bin/mozilla/ar.pl +++ b/bin/mozilla/ar.pl @@ -33,6 +33,7 @@ use POSIX qw(strftime); use List::Util qw(sum first max); +use List::UtilsBy qw(sort_by); use SL::AR; use SL::FU; @@ -409,8 +410,8 @@ sub form_header { gldate => $form->{"gldate_$i"}, }; - # default account for current assets (i.e. 1801 - SKR04) if no account is selected - $form->{accno_arap} = IS->get_standard_accno_current_assets(\%myconfig, \%$form); + # default account for current assets (i.e. 1801 - SKR04) if no account is selected + $form->{accno_arap} = IS->get_standard_accno_current_assets(\%myconfig, \%$form); $payment->{selectAR_paid} = NTI($cgi->popup_menu('-name' => "AR_paid_$i", @@ -429,6 +430,12 @@ sub form_header { push @payments, $payment; } + my @empty = grep { $_->{paid} eq '' } @payments; + @payments = ( + (sort_by { DateTime->from_kivitendo($_->{datepaid}) } grep { $_->{paid} ne '' } @payments), + @empty, + ); + $form->{totalpaid} = sum map { $_->{paid} } @payments; $form->header; diff --git a/bin/mozilla/ir.pl b/bin/mozilla/ir.pl index 86f78a807..843230212 100644 --- a/bin/mozilla/ir.pl +++ b/bin/mozilla/ir.pl @@ -37,6 +37,7 @@ use SL::IS; use SL::PE; use SL::DB::Default; use List::Util qw(max sum); +use List::UtilsBy qw(sort_by); require "bin/mozilla/io.pl"; require "bin/mozilla/invoice_io.pl"; @@ -349,6 +350,25 @@ sub form_header { $main::lxdebug->leave_sub(); } +sub _sort_payments { + my @fields = qw(acc_trans_id gldate datepaid source memo paid AR_paid); + 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_footer { $main::lxdebug->enter_sub(); @@ -391,6 +411,8 @@ sub form_footer { } # payments + _sort_payments(); + my $totalpaid = 0; $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); $form->{paid_indices} = [ 1 .. $form->{paidaccounts} ]; diff --git a/bin/mozilla/is.pl b/bin/mozilla/is.pl index 84109cdd6..4b3177105 100644 --- a/bin/mozilla/is.pl +++ b/bin/mozilla/is.pl @@ -39,6 +39,7 @@ use Data::Dumper; use DateTime; use List::MoreUtils qw(uniq); use List::Util qw(max sum); +use List::UtilsBy qw(sort_by); use English qw(-no_match_vars); use SL::DB::Default; @@ -400,6 +401,25 @@ sub form_header { $main::lxdebug->leave_sub(); } +sub _sort_payments { + my @fields = qw(acc_trans_id gldate datepaid source memo paid AR_paid); + 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_footer { $main::lxdebug->enter_sub(); @@ -446,6 +466,8 @@ sub form_footer { } # payments + _sort_payments(); + my $totalpaid = 0; $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); $form->{paid_indices} = [ 1 .. $form->{paidaccounts} ];