X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fap.pl;h=1070c673b43cbf957cb530b4262a35da26f6a7a0;hb=c01d62c4a634f27fc4560d88cf98b84af9a85d95;hp=04604831e5a6e6d59cd76dec441dc400bb22dc67;hpb=281696eb5e8c1a2ca203907cbff7d18052037b2f;p=kivitendo-erp.git diff --git a/bin/mozilla/ap.pl b/bin/mozilla/ap.pl index 04604831e..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}++; } @@ -410,7 +435,9 @@ sub form_header { $form->{paid_missing} = $form->{invtotal_unformatted} - $form->{totalpaid}; - print $form->parse_html_template('ap/form_header'); + print $form->parse_html_template('ap/form_header', { + today => DateTime->today, + }); $main::lxdebug->leave_sub(); } @@ -557,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); @@ -605,6 +633,7 @@ sub post { my $locale = $main::locale; $main::auth->assert('general_ledger'); + $form->mtime_ischanged('ap'); my ($inline) = @_; @@ -871,7 +900,7 @@ sub ap_transactions { my @columns = qw(transdate id type invnumber ordnumber name netamount tax amount paid datepaid due duedate transaction_description notes employee globalprojectnumber - vendornumber country ustid taxzone payment_terms charts); + vendornumber country ustid taxzone payment_terms charts direct_debit); my @hidden_variables = map { "l_${_}" } @columns; push @hidden_variables, "l_subtotal", qw(open closed vendor invnumber ordnumber transaction_description notes project_id transdatefrom transdateto department); @@ -902,9 +931,10 @@ sub ap_transactions { 'taxzone' => { 'text' => $locale->text('Steuersatz'), }, 'payment_terms' => { 'text' => $locale->text('Payment Terms'), }, 'charts' => { 'text' => $locale->text('Buchungskonto'), }, + 'direct_debit' => { 'text' => $locale->text('direct debit'), }, ); - foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid employee shippingpoint shipvia transaction_description)) { + foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid employee shippingpoint shipvia transaction_description direct_debit)) { my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir}; $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir"; } @@ -980,6 +1010,8 @@ sub ap_transactions { : $locale->text("AP Transaction (abbreviation)"); } + $ap->{direct_debit} = $ap->{direct_debit} ? $::locale->text('yes') : $::locale->text('no'); + my $row = { }; foreach my $column (@columns) {