From 1ca98d42a3b628007035e89bb3763fe327b05c39 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 24 Jan 2017 16:19:31 +0100 Subject: [PATCH] Belegvorlagen: Speichern bei Kreditorenbuchungen --- bin/mozilla/ap.pl | 52 +++++++++++++++++++++++++- templates/webpages/ap/form_footer.html | 1 + 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/bin/mozilla/ap.pl b/bin/mozilla/ap.pl index 0766af44d..98f6df750 100644 --- a/bin/mozilla/ap.pl +++ b/bin/mozilla/ap.pl @@ -155,6 +155,56 @@ sub load_record_template { update(); } +sub save_record_template { + $::auth->assert('ap_transactions'); + + my $template = $::form->{record_template_id} ? SL::DB::RecordTemplate->new(id => $::form->{record_template_id})->load : SL::DB::RecordTemplate->new; + my $js = SL::ClientJS->new(controller => SL::Controller::Base->new); + my $new_name = $template->template_name_to_use($::form->{record_template_new_template_name}); + + $js->dialog->close('#record_template_dialog'); + + my @items = grep { + $_->{chart_id} && (($_->{tax_id} // '') ne '') && ($_->{amount1} != 0) + } map { + +{ chart_id => $::form->{"AP_amount_chart_id_${_}"}, + amount1 => $::form->parse_amount(\%::myconfig, $::form->{"amount_${_}"}), + tax_id => (split m{--}, $::form->{"taxchart_${_}"})[0], + project_id => $::form->{"project_id_${_}"} || undef, + } + } (1..($::form->{rowcount} || 1)); + + $template->assign_attributes( + template_type => 'ap_transaction', + template_name => $new_name, + + currency_id => SL::DB::Manager::Currency->find_by(name => $::form->{currency})->id, + ar_ap_chart_id => $::form->{AP_chart_id} || undef, + vendor_id => $::form->{vendor_id} || undef, + department_id => $::form->{department_id} || undef, + project_id => $::form->{globalproject_id} || undef, + taxincluded => $::form->{taxincluded} ? 1 : 0, + direct_debit => $::form->{direct_debit} ? 1 : 0, + ordnumber => $::form->{ordnumber}, + notes => $::form->{notes}, + + items => \@items, + ); + + eval { + $template->save; + 1; + } or do { + return $js + ->flash('error', $::locale->text("Saving the record template '#1' failed.", $new_name)) + ->render; + }; + + return $js + ->flash('info', $::locale->text("The record template '#1' has been saved.", $new_name)) + ->render; +} + sub add { $main::lxdebug->enter_sub(); @@ -380,7 +430,7 @@ sub form_header { my $follow_up_vc = $form->{vendor_id} ? SL::DB::Vendor->load_cached($form->{vendor_id})->name : ''; my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)"; - $::request->layout->add_javascripts("autocomplete_chart.js", "autocomplete_customer.js", "show_vc_details.js", "show_history.js", "follow_up.js", "kivi.Draft.js", "kivi.GL.js"); + $::request->layout->add_javascripts("autocomplete_chart.js", "autocomplete_customer.js", "show_vc_details.js", "show_history.js", "follow_up.js", "kivi.Draft.js", "kivi.GL.js", "kivi.RecordTemplate.js"); my $transdate = $::form->{transdate} ? DateTime->from_kivitendo($::form->{transdate}) : DateTime->today_local; my $first_taxchart; diff --git a/templates/webpages/ap/form_footer.html b/templates/webpages/ap/form_footer.html index 0d948d2a5..ba952ca5d 100644 --- a/templates/webpages/ap/form_footer.html +++ b/templates/webpages/ap/form_footer.html @@ -42,6 +42,7 @@ [% END %] [%- END %] + [% L.button_tag("kivi.RecordTemplate.popup('ap_transaction')", LxERP.t8("Record templates")) %]