From: Jan Büren Date: Sat, 21 Jan 2017 13:20:18 +0000 (+0100) Subject: Wiederkehrende Rechnungen, um neue Periode 'einmalig' erweitert. X-Git-Tag: release-3.5.4~1670 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=efeb61e04032ded4fdc9719a4bf5a031c4a042d1;p=kivitendo-erp.git Wiederkehrende Rechnungen, um neue Periode 'einmalig' erweitert. Wiederkehrenden Rechnungen die aus einem Auftrag automatisch generiert werden können jetzt die Periode 'einmalig' (engl. 'one time') mit dem Zeitwert 0 haben. Falls diese Periode angewählt wird, wird die Konfiguration des Auftrags nach Erzeugen der einmaligen Rechnung auf inaktiv gesetzt (s.a. perldoc SL/DB/PeriodicInvoicesConfigs.pm). Der Empfänger der Rechnungslauf-Mail bekommt in diesem Fall zusätzlich die Auftragsnummer, bei welchem die wiederkehrenden Rechnungen deaktiviert wurden mitgeteilt. Zusätzlich ist diese Benachrichtigung per Mail erweitert, sodass jetzt auch eine Liste der versandten Rechnungen per E-Mail mitgeteilt wird. --- diff --git a/SL/BackgroundJob/CreatePeriodicInvoices.pm b/SL/BackgroundJob/CreatePeriodicInvoices.pm index 490f21ea3..1b57cbeaf 100644 --- a/SL/BackgroundJob/CreatePeriodicInvoices.pm +++ b/SL/BackgroundJob/CreatePeriodicInvoices.pm @@ -36,7 +36,7 @@ sub run { _log_msg("Periodic invoice configuration ID " . $config->id . " extended through " . $new_end_date->strftime('%d.%m.%Y') . "\n") if $new_end_date; } - my (@new_invoices, @invoices_to_print, @invoices_to_email); + my (@new_invoices, @invoices_to_print, @invoices_to_email, @disabled_orders); _log_msg("Number of configs: " . scalar(@{ $configs})); @@ -63,6 +63,9 @@ sub run { # last; } + # disable one time configs (periodicity is only one time). + my $inactive_ordnumber = $config->disable_one_time_config; + push @disabled_orders, $inactive_ordnumber if $inactive_ordnumber; } foreach my $inv ( @invoices_to_print ) { $self->_print_invoice($inv); } @@ -72,6 +75,7 @@ sub run { [ map { $_->{invoice} } @new_invoices ], [ map { $_->{invoice} } @invoices_to_print ], [ map { $_->{invoice} } @invoices_to_email ], + \@disabled_orders , ); if (@{ $self->{job_errors} }) { @@ -275,8 +279,8 @@ sub _calculate_dates { } sub _send_summary_email { - my ($self, $posted_invoices, $printed_invoices, $emailed_invoices) = @_; - + my ($self, $posted_invoices, $printed_invoices, $emailed_invoices, + $disabled_orders) = @_; my %config = %::lx_office_conf; return if !$config{periodic_invoices} || !$config{periodic_invoices}->{send_email_to} || !scalar @{ $posted_invoices }; @@ -298,7 +302,8 @@ sub _send_summary_email { my $filename = $email_template || ( (SL::DB::Default->get->templates || "templates/webpages") . "/oe/periodic_invoices_email.txt" ); my %params = ( POSTED_INVOICES => $posted_invoices, PRINTED_INVOICES => $printed_invoices, - EMAILED_INVOICES => $emailed_invoices ); + EMAILED_INVOICES => $emailed_invoices, + DISABLED_ORDERS => $disabled_orders ); my $output; $template->process($filename, \%params, \$output); diff --git a/SL/DB/PeriodicInvoicesConfig.pm b/SL/DB/PeriodicInvoicesConfig.pm index 0d6608565..14fa5786a 100644 --- a/SL/DB/PeriodicInvoicesConfig.pm +++ b/SL/DB/PeriodicInvoicesConfig.pm @@ -11,7 +11,7 @@ __PACKAGE__->meta->initialize; # Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. __PACKAGE__->meta->make_manager_class; -our %PERIOD_LENGTHS = ( m => 1, q => 3, b => 6, y => 12 ); +our %PERIOD_LENGTHS = ( o => 0, m => 1, q => 3, b => 6, y => 12 ); our %ORDER_VALUE_PERIOD_LENGTHS = ( %PERIOD_LENGTHS, 2 => 24, 3 => 36, 4 => 48, 5 => 60 ); our @PERIODICITIES = keys %PERIOD_LENGTHS; our @ORDER_VALUE_PERIODICITIES = keys %ORDER_VALUE_PERIOD_LENGTHS; @@ -128,6 +128,20 @@ sub is_last_bill_date_in_order_value_cycle { return $date_itr == $next_billing_date; } +sub disable_one_time_config { + my $self = shift; + + _log_msg("check one time for " . $self->id . "\n"); + + # A periodicity of one time was set. Deactivate this config now. + if ($self->periodicity eq 'o') { + _log_msg("setting inactive\n"); + $self->active(0); + $self->save; + return $self->order->ordnumber; + } + return undef; +} 1; __END__ @@ -235,6 +249,12 @@ date given by the C parameter plus the billing period length equals one of those dates then the given date is indeed the date of the last invoice in that particular order value cycle. +=item C + +Sets the state of the periodic_invoices_configs to inactive +(active => false) if the periodicity is (one time). +Returns undef if the periodicity is not 'one time' otherwise the +order number of the deactivated periodic order. =back =head1 BUGS diff --git a/sql/Pg-upgrade2/periodic_invoices_order_value_periodicity2.sql b/sql/Pg-upgrade2/periodic_invoices_order_value_periodicity2.sql new file mode 100644 index 000000000..6fd38c09d --- /dev/null +++ b/sql/Pg-upgrade2/periodic_invoices_order_value_periodicity2.sql @@ -0,0 +1,11 @@ +-- @tag: periodic_invoices_order_value_periodicity2 +-- @description:periodic_invoices_configs_valid_periodicity Wiederkehrende Rechnungen: Einstellung für Periode, auf die sich der Auftragswert bezieht +-- @depends: release_3_4_1 periodic_invoices_order_value_periodicity + +-- Spalte »periodicity«: Erweiterung um Periode o (one time). Einmalige Ausführung +ALTER TABLE periodic_invoices_configs +DROP CONSTRAINT periodic_invoices_configs_valid_periodicity; + +ALTER TABLE periodic_invoices_configs +ADD CONSTRAINT periodic_invoices_configs_valid_periodicity +CHECK (periodicity IN ('o', 'm', 'q', 'b', 'y')); diff --git a/templates/webpages/oe/edit_periodic_invoices_config.html b/templates/webpages/oe/edit_periodic_invoices_config.html index 793d21b76..ebe5985bd 100644 --- a/templates/webpages/oe/edit_periodic_invoices_config.html +++ b/templates/webpages/oe/edit_periodic_invoices_config.html @@ -23,7 +23,7 @@ [%- LxERP.t8('Billing Periodicity') %] - [% L.select_tag("periodicity", [ [ "m", LxERP.t8("monthly") ], [ "q", LxERP.t8("every third month") ], [ "b", LxERP.t8("semiannually") ], [ "y", LxERP.t8("yearly") ] ], default=periodicity, style=style) %] + [% L.select_tag("periodicity", [ [ "o", LxERP.t8("one time") ], [ "m", LxERP.t8("monthly") ], [ "q", LxERP.t8("every third month") ], [ "b", LxERP.t8("semiannually") ], [ "y", LxERP.t8("yearly") ] ], default=periodicity, style=style) %] diff --git a/templates/webpages/oe/periodic_invoices_email.txt b/templates/webpages/oe/periodic_invoices_email.txt index 15d6039a8..e5fa61f29 100644 --- a/templates/webpages/oe/periodic_invoices_email.txt +++ b/templates/webpages/oe/periodic_invoices_email.txt @@ -9,3 +9,15 @@ Davon wurden die folgenden Rechnungen automatisch ausgedruckt: [% FOREACH inv = PRINTED_INVOICES %][% inv.invnumber %] [% END %] [%- END %] + +[% IF EMAILED_INVOICES.size -%] +Davon wurden die folgenden Rechnungen automatisch per E-Mail versand: + +[% FOREACH inv = EMAILED_INVOICES %][% inv.invnumber %] [% END %] +[%- END %] + +[% IF DISABLED_ORDERS.size -%] +Bei folgenden Auftragsnummern, wurde die Konfiguration auf inaktiv (Periodenwahl 'einmalig') gesetzt. + +[% FOREACH disabled_order = DISABLED_ORDERS %][% disabled_order %] [% END %] +[%- END %]