Merge branch 'f-use-proper-selects-and-pickers'
authorMoritz Bunkus <m.bunkus@linet-services.de>
Mon, 23 Jan 2017 13:57:31 +0000 (14:57 +0100)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Mon, 23 Jan 2017 13:57:31 +0000 (14:57 +0100)
SL/BackgroundJob/CreatePeriodicInvoices.pm
SL/DB/PeriodicInvoicesConfig.pm
SL/LiquidityProjection.pm
doc/changelog
locale/de/all
sql/Pg-upgrade2/periodic_invoices_order_value_periodicity2.sql [new file with mode: 0644]
templates/webpages/oe/edit_periodic_invoices_config.html
templates/webpages/oe/periodic_invoices_email.txt

index 490f21e..1b57cbe 100644 (file)
@@ -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);
index 0d66085..14fa578 100644 (file)
@@ -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<date> 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<sub disable_one_time_config>
+
+Sets the state of the periodic_invoices_configs to inactive
+(active => false) if the periodicity is <Co> (one time).
+Returns undef if the periodicity is not 'one time' otherwise the
+order number of the deactivated periodic order.
 =back
 
 =head1 BUGS
index 710c099..5954e00 100644 (file)
@@ -113,6 +113,7 @@ sub create {
     FROM periodic_invoices pi
     LEFT JOIN periodic_invoices_configs pcfg ON (pi.config_id = pcfg.id)
     WHERE pcfg.active
+      AND NOT pcfg.periodicity = 'o'
       AND (pi.period_start_date >= to_date($q_min_date, 'YYYY-MM-DD'))
 SQL
 
@@ -138,6 +139,7 @@ SQL
     LEFT JOIN buchungsgruppen bg             ON (p.buchungsgruppen_id                     = bg.id)
     LEFT JOIN employee e                     ON (COALESCE(oe.salesman_id, oe.employee_id) = e.id)
     WHERE pcfg.active
+      AND NOT pcfg.periodicity = 'o'
 SQL
 
   # 3. Iterieren über Saldierungsintervalle, vormerken
@@ -180,7 +182,7 @@ SQL
     WHERE (oe.customer_id IS NOT NULL)
       AND NOT COALESCE(oe.quotation, FALSE)
       AND NOT COALESCE(oe.closed,    FALSE)
-      AND (oe.id NOT IN (SELECT oe_id FROM periodic_invoices_configs))
+      AND (oe.id NOT IN (SELECT oe_id FROM periodic_invoices_configs WHERE periodicity <> 'o'))
 SQL
 
   # 5. Initialisierung der Datenstrukturen zum Speichern der
index 37918ec..3c163d2 100644 (file)
@@ -45,6 +45,8 @@ große Features:
 
 kleinere neue Features und Detailverbesserungen:
 
+  - Wiederkehrende Rechnungen können mit der Periode 'einmalig' konfiguriert werden
+
   - Druckvorlagen Mahnungen: Bearbeiter und Verkäufer-Metadaten auch im Ausdruck zu Verfügung stellen
 
   - SEPA Überweisungen zusätzlich Kunden- oder Lieferantennummer im Verwendungszweck vorbelegen
index d0c7855..722eb2a 100755 (executable)
@@ -3691,6 +3691,7 @@ $self->{texts} = {
   'oe.pl::search called with unknown type' => 'oe.pl::search mit unbekanntem Typ aufgerufen',
   'old'                         => 'alt',
   'on the same day'             => 'am selben Tag',
+  'one time'                    => 'einmalig',
   'one-time execution'          => 'einmalige Ausführung',
   'only OB Transactions'        => 'nur EB-Buchungen',
   'open'                        => 'Offen',
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 (file)
index 0000000..6fd38c0
--- /dev/null
@@ -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'));
index 793d21b..ebe5985 100644 (file)
@@ -23,7 +23,7 @@
     <tr>
      <th align="right" valign="top">[%- LxERP.t8('Billing Periodicity') %]</th>
      <td valign="top">
-      [% 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) %]
      </td>
     </tr>
 
index 15d6039..e5fa61f 100644 (file)
@@ -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 %]