#======================================================================
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;
$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();
$form->{totalpaid} = 0;
+ _sort_payments();
+
if ( $form->{'paid_'. $form->{paidaccounts}} ) {
$form->{paidaccounts}++;
}
use POSIX qw(strftime);
use List::Util qw(sum first max);
+use List::UtilsBy qw(sort_by);
use SL::AR;
use SL::FU;
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",
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;
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";
$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();
}
# payments
+ _sort_payments();
+
my $totalpaid = 0;
$form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
$form->{paid_indices} = [ 1 .. $form->{paidaccounts} ];
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;
$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();
}
# payments
+ _sort_payments();
+
my $totalpaid = 0;
$form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
$form->{paid_indices} = [ 1 .. $form->{paidaccounts} ];