From 4507456b19be280448043993939fa8657e8a046c Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 18 Jan 2017 12:37:30 +0100 Subject: [PATCH] ActionBar: Verwendung in Kreditorenbuchungen --- bin/mozilla/ap.pl | 168 +++++++++++++++++-------- js/kivi.AP.js | 26 ++++ js/locale/de.js | 2 + locale/de/all | 2 - templates/webpages/ap/form_footer.html | 32 ----- templates/webpages/ap/form_header.html | 4 +- 6 files changed, 148 insertions(+), 86 deletions(-) create mode 100644 js/kivi.AP.js diff --git a/bin/mozilla/ap.pl b/bin/mozilla/ap.pl index b45cb99c5..cc8f4d4b6 100644 --- a/bin/mozilla/ap.pl +++ b/bin/mozilla/ap.pl @@ -316,10 +316,6 @@ sub create_links { AP->setup_form($form); - $form->{locked} = - ($form->datetonum($form->{transdate}, \%myconfig) <= - $form->datetonum($form->{closedto}, \%myconfig)); - $main::lxdebug->leave_sub(); } @@ -436,10 +432,12 @@ 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", "kivi.RecordTemplate.js", "kivi.File.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", "kivi.File.js", "kivi.AP.js"); my $transdate = $::form->{transdate} ? DateTime->from_kivitendo($::form->{transdate}) : DateTime->today_local; my $first_taxchart; + setup_ap_display_form_action_bar(); + $form->header(); for my $i (1 .. $form->{rowcount}) { @@ -568,8 +566,6 @@ sub form_footer { print $::form->parse_html_template('ap/form_footer', { num_due => $num_due, num_follow_ups => $num_follow_ups, - show_post_draft => ($transdate > $closedto) && !$::form->{id}, - show_storno => $storno, }); $::lxdebug->leave_sub; @@ -861,57 +857,25 @@ sub use_as_new { $main::auth->assert('ap_transactions'); - map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 gldate_1 acc_trans_id_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno); + map { delete $form->{$_} } qw(printed emailed queued invnumber deliverydate id datepaid_1 gldate_1 acc_trans_id_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno); $form->{paidaccounts} = 1; $form->{rowcount}--; - $form->{invdate} = $form->current_date(\%myconfig); - &update; - - $main::lxdebug->leave_sub(); -} - -sub delete { - $main::lxdebug->enter_sub(); - - my $form = $main::form; - my $locale = $main::locale; - $main::auth->assert('ap_transactions'); - - $form->{title} = $locale->text('Confirm!'); - - $form->header; + my $today = DateTime->today_local; + $form->{transdate} = $today->to_kivitendo; + $form->{duedate} = $form->{transdate}; - delete $form->{header}; - - print qq| -
{script}> -|; - - foreach my $key (keys %$form) { - next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key})); - $form->{$key} =~ s/\"/"/g; - print qq|\n|; + if ($form->{vendor_id}) { + my $payment_terms = SL::DB::Vendor->load_cached($form->{vendor_id})->payment; + $form->{duedate} = $payment_terms->calc_date(reference_date => $today)->to_kivitendo if $payment_terms; } - print qq| -

$form->{title}

- -

| - . $locale->text('Are you sure you want to delete Transaction') - . qq| $form->{invnumber}

- - -
-|; + &update; $main::lxdebug->leave_sub(); } -sub yes { - $main::lxdebug->enter_sub(); - +sub delete { my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; @@ -930,8 +894,6 @@ sub yes { $form->redirect($locale->text('Transaction deleted!')); } $form->error($locale->text('Cannot delete transaction!')); - - $main::lxdebug->leave_sub(); } sub search { @@ -1180,3 +1142,109 @@ sub storno { $main::lxdebug->leave_sub(); } + +sub setup_ap_display_form_action_bar { + my $transdate = $::form->datetonum($::form->{transdate}, \%::myconfig); + my $closedto = $::form->datetonum($::form->{closedto}, \%::myconfig); + my $is_closed = $transdate <= $closedto; + + my $change_never = $::instance_conf->get_ar_changeable == 0; + my $change_on_same_day_only = $::instance_conf->get_ar_changeable == 2 && ($::form->current_date(\%::myconfig) ne $::form->{gldate}); + + my $is_storno = IS->is_storno(\%::myconfig, $::form, 'ap', $::form->{id}); + my $has_storno = IS->has_storno(\%::myconfig, $::form, 'ap'); + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + action => [ + t8('Update'), + submit => [ '#form', { action => "update" } ], + id => 'update_button', + accesskey => 'enter', + ], + + combobox => [ + action => [ + t8('Post'), + submit => [ '#form', { action => "post" } ], + checks => [ 'kivi.AP.check_fields_before_posting' ], + disabled => $is_closed ? t8('The billing period has already been locked.') + : $is_storno ? t8('A canceled invoice cannot be posted.') + : ($::form->{id} && $change_never) ? t8('Changing invoices has been disabled in the configuration.') + : ($::form->{id} && $change_on_same_day_only) ? t8('Invoices can only be changed on the day they are posted.') + : undef, + ], + action => [ + t8('Post Payment'), + submit => [ '#form', { action => "post_payment" } ], + disabled => !$::form->{id} ? t8('This invoice has not been posted yet.') : undef, + ], + action => [ t8('Mark as paid'), + submit => [ '#form', { action => "mark_as_paid" } ], + confirm => t8('This will remove the invoice from showing as unpaid even if the unpaid amount does not match the amount. Proceed?'), + disabled => !$::form->{id} ? t8('This invoice has not been posted yet.') : undef, + only_if => $::instance_conf->get_is_show_mark_as_paid, + ], + ], # end of combobox "Post" + + combobox => [ + action => [ t8('Storno'), + submit => [ '#form', { action => "storno" } ], + checks => [ 'kivi.AP.check_fields_before_posting' ], + confirm => t8('Do you really want to cancel this invoice?'), + disabled => !$::form->{id} ? t8('This invoice has not been posted yet.') + : $has_storno ? t8('This invoice has been canceled already.') + : $is_storno ? t8('Reversal invoices cannot be canceled.') + : $::form->{totalpaid} ? t8('Invoices with payments cannot be canceled.') + : undef, + ], + action => [ t8('Delete'), + submit => [ '#form', { action => "delete" } ], + confirm => t8('Do you really want to delete this object?'), + disabled => !$::form->{id} ? t8('This invoice has not been posted yet.') + : $change_never ? t8('Changing invoices has been disabled in the configuration.') + : $change_on_same_day_only ? t8('Invoices can only be changed on the day they are posted.') + : $has_storno ? t8('This invoice has been canceled already.') + : $is_closed ? t8('The billing period has already been locked.') + : undef, + ], + ], # end of combobox "Storno" + + 'separator', + + combobox => [ + action => [ t8('Workflow') ], + action => [ + t8('Use As New'), + submit => [ '#form', { action => "use_as_new" } ], + disabled => !$::form->{id} ? t8('This invoice has not been posted yet.') : undef, + ], + ], # end of combobox "Workflow" + + combobox => [ + action => [ t8('more') ], + action => [ + t8('History'), + call => [ 'set_history_window', $::form->{id} * 1, 'glid' ], + disabled => !$::form->{id} ? t8('This invoice has not been posted yet.') : undef, + ], + action => [ + t8('Follow-Up'), + call => [ 'follow_up_window' ], + disabled => !$::form->{id} ? t8('This invoice has not been posted yet.') : undef, + ], + action => [ + t8('Record templates'), + call => [ 'kivi.RecordTemplate.popup', 'ap_transaction' ], + ], + action => [ + t8('Drafts'), + call => [ 'kivi.Draft.popup', 'ap', 'invoice', $::form->{draft_id}, $::form->{draft_description} ], + disabled => $::form->{id} ? t8('This invoice has already been posted.') + : $is_closed ? t8('The billing period has already been locked.') + : undef, + ], + ], # end of combobox "more" + ); + } +} diff --git a/js/kivi.AP.js b/js/kivi.AP.js new file mode 100644 index 000000000..55c164fd9 --- /dev/null +++ b/js/kivi.AP.js @@ -0,0 +1,26 @@ +namespace('kivi.AP', function(ns){ + 'use strict'; + + ns.check_fields_before_posting = function() { + var errors = []; + + if ($('#transdate').val() === '') + errors.push(kivi.t8('Invoice Date missing!')); + + if ($('#duedate').val() === '') + errors.push(kivi.t8('Due Date missing!')); + + if ($('#invnumber').val() === '') + errors.push(kivi.t8('Invoice Number missing!')); + + if ($('#vendor').val() === '') + errors.push(kivi.t8('Vendor missing!')); + + if (errors.length === 0) + return true; + + alert(errors.join(' ')); + + return false; + }; +}); diff --git a/js/locale/de.js b/js/locale/de.js index 59aadf35a..2bdd17e3f 100644 --- a/js/locale/de.js +++ b/js/locale/de.js @@ -64,6 +64,7 @@ namespace("kivi").setupLocale({ "If you switch to a different tab without saving you will lose the data you've entered in the current tab.":"Wenn Sie auf einen anderen Tab wechseln, ohne vorher zu speichern, so gehen die im aktuellen Tab eingegebenen Daten verloren.", "Import documents from #1":"Importiere Dateien von Quelle '#1'", "Invoice Date missing!":"Rechnungsdatum fehlt!", +"Invoice Number missing!":"Rechnungsnummer fehlt!", "Map":"Karte", "More than one file selected, please set only one checkbox!":"Mehr als ein Element selektiert, bitte nur eine Box anklicken", "No":"Nein", @@ -123,6 +124,7 @@ namespace("kivi").setupLocale({ "Transaction description":"Vorgangsbezeichnung", "Update":"Erneuern", "Update quotation/order":"Auftrag/Angebot aktualisieren", +"Vendor missing!":"Lieferant fehlt!", "Version actions":"Aktionen für Versionen", "Yes":"Ja", "filename has not uploadable characters ":"Bitte Dateinamen ändern. Er hat für den Upload nicht verwendbare Sonderzeichen ", diff --git a/locale/de/all b/locale/de/all index d3c96016c..7f22f7b2a 100755 --- a/locale/de/all +++ b/locale/de/all @@ -300,7 +300,6 @@ $self->{texts} = { 'Ar aging on %s' => 'Offene Forderungen zum %s', 'Are you sure to generate cb/ob transactions?' => 'Sollen die EB/SB Buchungen wirklich erzeugt werden?', 'Are you sure you want to delete Invoice Number' => 'Soll die Rechnung mit folgender Nummer wirklich gelöscht werden:', - 'Are you sure you want to delete Transaction' => 'Buchung wirklich löschen?', 'Are you sure you want to delete this background job?' => 'Sind Sie sicher, dass Sie diesen Hintergrund-Job löschen möchten?', 'Are you sure you want to delete this delivery term?' => 'Wollen Sie diese Lieferbedingungen wirklich löschen?', 'Are you sure you want to delete this letter?' => 'Sind Sie sicher, dass Sie diesen Brief löschen wollen?', @@ -3691,7 +3690,6 @@ $self->{texts} = { 'generated Files' => 'Erzeugte Dokumente', 'gobd-#1-#2.zip' => 'gobd-#1-#2.zip', 'h' => 'h', - 'history' => 'Historie', 'history search engine' => 'Historien Suchmaschine', 'imported' => 'Importiert', 'inactive' => 'inaktiv', diff --git a/templates/webpages/ap/form_footer.html b/templates/webpages/ap/form_footer.html index df58faa13..8f02e0c2d 100644 --- a/templates/webpages/ap/form_footer.html +++ b/templates/webpages/ap/form_footer.html @@ -11,38 +11,6 @@ [% P.hidden_tag('draft_id', draft_id) %] [% P.hidden_tag('draft_description', draft_description) %] - -
- - - -[%- IF id %] - [%- IF radier %] - - - [%- END %] - - [%- IF show_storno %] - - [%- END %] - - - - - -[%- ELSIF show_post_draft %] - - [% L.button_tag('kivi.Draft.popup("ap", "invoice", "' _ draft_id _ '", "' _ draft_description _ '")', LxERP.t8('Drafts')) %] -[%- END %] - -[%- IF id %] - - [% IF INSTANCE_CONF.get_ap_show_mark_as_paid %] - [% L.submit_tag("action", LxERP.t8('Mark as paid'), confirm=LxERP.t8('This will remove the invoice from showing as unpaid even if the unpaid amount does not match the amount. Proceed?')) %] - [% END %] -[%- END %] - - [% L.button_tag("kivi.RecordTemplate.popup('ap_transaction')", LxERP.t8("Record templates")) %]