From d7d43eb2e00f0609b452e1bea65d50004f2d77e9 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 17 Jan 2017 16:35:52 +0100 Subject: [PATCH] ActionBar: Verwendung bei Debitorenbuchungen --- bin/mozilla/ar.pl | 179 ++++++++++++++++--------- js/kivi.AR.js | 23 ++++ js/locale/de.js | 3 + locale/de/all | 3 + templates/webpages/ar/form_footer.html | 35 ----- 5 files changed, 148 insertions(+), 95 deletions(-) create mode 100644 js/kivi.AR.js diff --git a/bin/mozilla/ar.pl b/bin/mozilla/ar.pl index a4f559034..a1a7635ab 100644 --- a/bin/mozilla/ar.pl +++ b/bin/mozilla/ar.pl @@ -50,6 +50,7 @@ use SL::DB::Invoice; use SL::DB::RecordTemplate; use SL::DB::Tax; use SL::Helper::Flash qw(flash); +use SL::Locale::String qw(t8); use SL::ReportGenerator; require "bin/mozilla/common.pl"; @@ -392,7 +393,7 @@ sub form_header { my $follow_up_vc = $form->{customer_id} ? SL::DB::Customer->load_cached($form->{customer_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.File.js", "kivi.RecordTemplate.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.File.js", "kivi.RecordTemplate.js", "kivi.AR.js"); my $transdate = $::form->{transdate} ? DateTime->from_kivitendo($::form->{transdate}) : DateTime->today_local; my $first_taxchart; @@ -502,6 +503,8 @@ sub form_header { ], ); + setup_ar_form_header_action_bar(); + $form->header; print $::form->parse_html_template('ar/form_header', { paid_missing => $::form->{invtotal} - $::form->{totalpaid}, @@ -539,20 +542,6 @@ sub form_footer { } } - my $transdate = $form->datetonum($form->{transdate}, \%myconfig); - my $closedto = $form->datetonum($form->{closedto}, \%myconfig); - - $form->{is_closed} = $transdate <= $closedto; - - # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it - $form->{show_storno_button} = - $form->{id} && - !IS->has_storno(\%myconfig, $form, 'ar') && - !IS->is_storno(\%myconfig, $form, 'ar') && - ($form->{totalpaid} == 0 || $form->{totalpaid} eq ""); - - $form->{show_mark_as_paid_button} = $form->{id} && $::instance_conf->get_ar_show_mark_as_paid(); - print $::form->parse_html_template('ar/form_footer'); $main::lxdebug->leave_sub(); @@ -562,7 +551,6 @@ sub mark_as_paid { $::auth->assert('ar_transactions'); SL::DB::Invoice->new(id => $::form->{id})->load->mark_as_paid; - $::form->redirect($::locale->text("Marked as paid")); } @@ -836,58 +824,26 @@ sub use_as_new { my $form = $main::form; my %myconfig = %main::myconfig; - 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(); - - $main::auth->assert('ar_transactions'); - - my $form = $main::form; - my $locale = $main::locale; + my $today = DateTime->today_local; + $form->{transdate} = $today->to_kivitendo; + $form->{duedate} = $form->{transdate}; - $form->{title} = $locale->text('Confirm!'); - - $form->header; - - 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->{customer_id}) { + my $payment_terms = SL::DB::Customer->load_cached($form->{customer_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(); - - $main::auth->assert('ar_transactions'); +sub delete { + $::auth->assert('ar_transactions'); my $form = $main::form; my %myconfig = %main::myconfig; @@ -905,8 +861,6 @@ sub yes { $form->redirect($locale->text('Transaction deleted!')); } $form->error($locale->text('Cannot delete transaction!')); - - $main::lxdebug->leave_sub(); } sub setup_ar_search_action_bar { @@ -1283,4 +1237,109 @@ sub storno { $main::lxdebug->leave_sub(); } +sub setup_ar_form_header_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, 'ar', $::form->{id}); + my $has_storno = IS->has_storno(\%::myconfig, $::form, 'ar'); + + 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.AR.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.AR.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.') + : $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', 'ar_transaction' ], + ], + action => [ + t8('Drafts'), + call => [ 'kivi.Draft.popup', 'ar', '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" + ); + } +} + 1; diff --git a/js/kivi.AR.js b/js/kivi.AR.js new file mode 100644 index 000000000..40b297b5e --- /dev/null +++ b/js/kivi.AR.js @@ -0,0 +1,23 @@ +namespace('kivi.AR', 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 ($('#customer').val() === '') + errors.push(kivi.t8('Customer 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 6ba3771af..59aadf35a 100644 --- a/js/locale/de.js +++ b/js/locale/de.js @@ -29,6 +29,7 @@ namespace("kivi").setupLocale({ "Create new quotation/order":"Neues Angebot/neuen Auftrag anlegen", "Create new qutoation/order":"Neues Angebot/neuen Auftrag anlegen", "Create new version":"Neue Version anlegen", +"Customer missing!":"Kundenname fehlt!", "Database Connection Test":"Test der Datenbankverbindung", "Delete":"Löschen", "Delete picture":"Bild löschen", @@ -46,6 +47,7 @@ namespace("kivi").setupLocale({ "Do you really want to unimport the selected documents?":"Wollen Sie wirklich diese Dateien an die Quelle zurückgeben?", "Do you want to set the account number \"#1\" to \"#2\" and the name \"#3\" to \"#4\"?":"Soll die Kontonummer \"#1\" zu \"#2\" und den Name \"#3\" zu \"#4\" geändert werden?", "Download picture":"Bild herunterladen", +"Due Date missing!":"Fälligkeitsdatum fehlt!", "Edit":"Bearbeiten", "Edit article/section assignments":"Zuweisung Artikel/Abschnitte bearbeiten", "Edit custom shipto":"Individuelle Lieferadresse bearbeiten", @@ -61,6 +63,7 @@ namespace("kivi").setupLocale({ "History":"Historie", "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!", "Map":"Karte", "More than one file selected, please set only one checkbox!":"Mehr als ein Element selektiert, bitte nur eine Box anklicken", "No":"Nein", diff --git a/locale/de/all b/locale/de/all index fb92910b0..d3c96016c 100755 --- a/locale/de/all +++ b/locale/de/all @@ -1593,6 +1593,7 @@ $self->{texts} = { 'Invoice with Storno (abbreviation)' => 'R(S)', 'Invoices' => 'Rechnungen', 'Invoices can only be changed on the day they are posted.' => 'Rechnungen können nur am Buchungstag geändert werden.', + 'Invoices with payments cannot be canceled.' => 'Rechnungen mit Zahlungen können nicht storniert werden.', 'Invoices, Credit Notes & AR Transactions' => 'Rechnungen, Gutschriften & Debitorenbuchungen', 'Is Searchable' => 'Durchsuchbar', 'Is this a summary account to record' => 'Sammelkonto für', @@ -2431,6 +2432,7 @@ $self->{texts} = { 'Result' => 'Ergebnis', 'Revenue' => 'Erlöskonto', 'Revenue Account' => 'Erlöskonto', + 'Reversal invoices cannot be canceled.' => 'Stornorechnungen können nicht storniert werden.', 'Revert to version' => 'Auf Version zurücksetzen', 'Review of Aging list' => 'Altersstrukturliste', 'Right' => 'Rechts', @@ -3213,6 +3215,7 @@ $self->{texts} = { 'This has been changed in this version, therefore please change the "old" bins to some real warehouse bins.' => 'Das wurde in dieser Version umgestellt, bitte ändern Sie die Freitext-Lagerplätze auf vorhandene Lagerplätze.', 'This has been changed in this version.' => 'Ab dieser Version ist dies nicht mehr so.', 'This invoice has already been posted.' => 'Die Rechnung wurde bereits gebucht.', + 'This invoice has been canceled already.' => 'Die Rechnung wurde bereits storniert.', 'This invoice has not been posted yet.' => 'Die Rechnung wurde noch nicht gebucht.', 'This invoice\'s dunning level: #1' => 'Mahnstufe dieser Rechnung: #1', 'This is a very critical problem.' => 'Dieses Problem ist sehr schwerwiegend.', diff --git a/templates/webpages/ar/form_footer.html b/templates/webpages/ar/form_footer.html index 7672e52f7..3fedfe185 100644 --- a/templates/webpages/ar/form_footer.html +++ b/templates/webpages/ar/form_footer.html @@ -10,41 +10,6 @@ [% P.hidden_tag('draft_id', draft_id) %] [% P.hidden_tag('draft_description', draft_description) %] - -
- - - - [% IF ( show_storno_button ) %] - - [% END %] - - [% IF ( id ) %] - [% IF ( radier ) %] - - - [% END %] - - [% IF ( !is_closed ) %] - - [% END %] - - - - - [% ELSE %] - [% IF ( !is_closed ) %] - - [% L.button_tag('kivi.Draft.popup("ar", "invoice", "' _ draft_id _ '", "' _ draft_description _ '")', LxERP.t8('Drafts')) %] - [% END %] - [% END %] - - [% IF ( show_mark_as_paid_button ) %] - [% 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 %] - - [% L.button_tag("kivi.RecordTemplate.popup('ar_transaction')", LxERP.t8("Record templates")) %] -