X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=bin%2Fmozilla%2Fap.pl;h=26e397bf705dde650a67e0aaef2e911e84767713;hb=96ab68a31bb2e33769aeccea9b7e51b23b65f59a;hp=dfac71d2f58d5f93f839bff2439b721735a9c08f;hpb=c83c61d255ba54bd5a6c4afa291bc0cfb872297c;p=kivitendo-erp.git diff --git a/bin/mozilla/ap.pl b/bin/mozilla/ap.pl index dfac71d2f..26e397bf7 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,10 +42,10 @@ 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"; -require "bin/mozilla/drafts.pl"; require "bin/mozilla/reportgenerator.pl"; use strict; @@ -89,15 +90,13 @@ sub add { $main::auth->assert('general_ledger'); - return $main::lxdebug->leave_sub() if (load_draft_maybe()); - $form->{title} = "Add"; - $form->{callback} = "ap.pl?action=add&DONT_LOAD_DRAFT=1" unless $form->{callback}; + $form->{callback} = "ap.pl?action=add" unless $form->{callback}; AP->get_transdate(\%myconfig, $form); $form->{initial_transdate} = $form->{transdate}; - &create_links; + create_links(dont_save => 1); $form->{transdate} = $form->{initial_transdate}; &display_form; @@ -113,7 +112,7 @@ sub edit { $form->{title} = "Edit"; - &create_links; + create_links(); &display_form; $main::lxdebug->leave_sub(); @@ -135,18 +134,23 @@ sub display_form { sub create_links { $main::lxdebug->enter_sub(); + my %params = @_; + my $form = $main::form; my %myconfig = %main::myconfig; $main::auth->assert('general_ledger'); $form->create_links("AP", \%myconfig, "vendor"); - my $taxincluded = $form->{taxincluded}; - my $duedate = $form->{duedate}; + my %saved; + if (!$params{dont_save}) { + %saved = map { ($_ => $form->{$_}) } qw(direct_debit taxincluded); + $saved{duedate} = $form->{duedate} if $form->{duedate}; + } IR->get_vendor(\%myconfig, \%$form); - $form->{taxincluded} = $taxincluded; - $form->{duedate} = $duedate if $duedate; + + $form->{$_} = $saved{$_} for keys %saved; $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}"; $form->{rowcount} = 1; @@ -182,6 +186,25 @@ sub create_links { $main::lxdebug->leave_sub(); } +sub _sort_payments { + my @fields = qw(acc_trans_id gldate datepaid source memo paid AP_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(); @@ -192,115 +215,56 @@ sub form_header { $main::auth->assert('general_ledger'); - my $title = $form->{title}; - $form->{title} = $locale->text("$title Accounts Payables Transaction"); + $::form->{invoice_obj} = SL::DB::PurchaseInvoice->new(id => $::form->{id})->load if $::form->{id}; - $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; + $form->{title_} = $form->{title}; + $form->{title} = $form->{title} eq 'Add' ? $locale->text('Add Accounts Payables Transaction') : $locale->text('Edit Accounts Payables Transaction'); # type=submit $locale->text('Add Accounts Payables Transaction') # type=submit $locale->text('Edit Accounts Payables Transaction') - $form->{javascript} = qq||; - # show history button - $form->{javascript} .= qq||; - #/show hhistory button - # set option selected foreach my $item (qw(vendor currency department)) { my $to_replace = H($form->{$item}); $form->{"select$item"} =~ s/ selected//; $form->{"select$item"} =~ s/>\Q${to_replace}\E/ selected>${to_replace}/; } - my $readonly = ($form->{id}) ? "readonly" : ""; + my $readonly = $form->{id} ? "readonly" : ""; $form->{radier} = ($::instance_conf->get_ap_changeable == 2) ? ($form->current_date(\%myconfig) eq $form->{gldate}) : ($::instance_conf->get_ap_changeable == 1); - $readonly = ($form->{radier}) ? "" : $readonly; + $readonly = $form->{radier} ? "" : $readonly; - $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'sell'); - $form->{exchangerate} = $form->{forex} if $form->{forex}; + $form->{readonly} = $readonly; + + $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'sell'); + if ( $form->{forex} ) { + $form->{exchangerate} = $form->{forex}; + } # format amounts $form->{exchangerate} = $form->{exchangerate} ? $form->format_amount(\%myconfig, $form->{exchangerate}) : ''; $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0"); $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0"); - my $exchangerate = qq| -{forex}> -|; - if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) { - if ($form->{forex}) { - $exchangerate .= qq| -