X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fir.pl;h=6bcba9bdfae55a19f008cf76e4b9957bbe1702a1;hb=refs%2Fheads%2Forder_controller;hp=86f78a80719d12244108401a6ff773176381b1b2;hpb=01678c873dfa6fcbe5003789e79d8b7ad7c93551;p=kivitendo-erp.git diff --git a/bin/mozilla/ir.pl b/bin/mozilla/ir.pl index 86f78a807..6bcba9bdf 100644 --- a/bin/mozilla/ir.pl +++ b/bin/mozilla/ir.pl @@ -36,7 +36,9 @@ use SL::IR; use SL::IS; use SL::PE; use SL::DB::Default; +use SL::DB::PurchaseInvoice; use List::Util qw(max sum); +use List::UtilsBy qw(sort_by); require "bin/mozilla/io.pl"; require "bin/mozilla/invoice_io.pl"; @@ -258,6 +260,7 @@ sub form_header { my %TMPL_VAR = (); my @custom_hiddens; + $TMPL_VAR{invoice_obj} = SL::DB::PurchaseInvoice->new(id => $form->{id})->load if $form->{id}; $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id}; $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id}; @@ -349,6 +352,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 +413,8 @@ sub form_footer { } # payments + _sort_payments(); + my $totalpaid = 0; $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); $form->{paid_indices} = [ 1 .. $form->{paidaccounts} ]; @@ -648,6 +672,7 @@ sub post_payment { $main::auth->assert('vendor_invoice_edit'); + $form->mtime_ischanged('ap') ; $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); for my $i (1 .. $form->{paidaccounts}) { if ($form->{"paid_$i"}) { @@ -707,6 +732,7 @@ sub post { $main::auth->assert('vendor_invoice_edit'); + $form->mtime_ischanged('ap'); $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); $form->isblank("invdate", $locale->text('Invoice Date missing!'));