Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision fcc8a4a3

Von Tamino Steinert vor 3 Monaten hinzugefügt

  • ID fcc8a4a3970128533b9612b2b4dfc0568d6182a0
  • Vorgänger fa589161
  • Nachfolger 7d0049f9

S:B:CreatePeriodicInvoices: Notizen von Pos. mit richtigen Datum parsen

Unterschiede anzeigen:

SL/BackgroundJob/CreatePeriodicInvoices.pm
23 23
use SL::Util qw(trim);
24 24
use SL::System::Process;
25 25
use SL::Locale::String qw(t8);
26
use SL::DB::Helper::RecordLink qw(RECORD_ITEM_ID RECORD_ITEM_TYPE_REF);
26 27

  
27 28
sub create_job {
28 29
  $_[0]->create_standard_job('0 3 1 * *'); # first day of month at 3:00 am
......
99 100
}
100 101

  
101 102
sub _generate_time_period_variables {
102
  my $config            = shift;
103
  my $period_start_date = shift;
103
  my %params = validate(@_, {
104
      period_start_date => { isa => 'DateTime' },
105
      period_end_date => { type => HASHREF|UNDEF }, # 'DateTime or UNDEF
106
    });
104 107

  
105
  my $period_length   = $config->get_order_value_period_length || $config->get_billing_period_length || 1;
106
  my $period_end_date = $period_start_date->clone->add(months => $period_length)->subtract(days => 1);
108
  my $period_start_date = $params{period_start_date};
109
  my $period_end_date = $params{period_end_date};
107 110

  
108 111
  my @month_names       = ('',
109 112
                           $::locale->text('January'), $::locale->text('February'), $::locale->text('March'),     $::locale->text('April'),   $::locale->text('May'),      $::locale->text('June'),
......
184 187

  
185 188
  my $period_start_date = $order->reqdate;
186 189
  my $config            = $order->periodic_invoices_config;
187
  my $time_period_vars  = _generate_time_period_variables($config, $period_start_date);
188

  
190
  my $time_period_vars  = _generate_time_period_variables(
191
    period_start_date => $order->reqdate,
192
    period_end_date   => $config->add_months(
193
      $order->reqdate, $config->get_billing_period_length || 1
194
    )->subtract(days => 1),
195
  );
189 196
  my $invoice;
190 197
  if (!$self->{db_obj}->db->with_transaction(sub {
191 198
    1;                          # make Emacs happy
......
201 208
      direct_debit => $config->direct_debit,
202 209
    );
203 210

  
204
    _replace_vars(object => $invoice, vars => $time_period_vars, attribute => $_, attribute_format => ($_ eq 'notes' ? 'html' : 'text')) for qw(notes intnotes transaction_description);
211
    _replace_vars(
212
      object => $invoice,
213
      vars => $time_period_vars,
214
      attribute => $_,
215
      attribute_format => ($_ eq 'notes' ? 'html' : 'text')
216
    ) for qw(notes intnotes transaction_description);
205 217

  
206 218
    foreach my $item (@{ $invoice->items }) {
207
      _replace_vars(object => $item, vars => $time_period_vars, attribute => $_, attribute_format => ($_ eq 'longdescription' ? 'html' : 'text')) for qw(description longdescription);
219

  
220
      die "Not created of an order item" if $item->{RECORD_ITEM_TYPE_REF()} ne 'SL::DB::OrderItem';
221
      my $order_item_id = $item->{RECORD_ITEM_ID()};
222
      my $order_item = SL::DB::Manager::OrderItem->find_by(
223
        id => $order_item_id,
224
      ) or die "order item not found with id: $order_item_id";
225
      my $item_count_and_dates = $config->item_count_and_dates_in_period(
226
        invoice_date => $invoice->deliverydate,
227
        item         => $order_item,
228
      );
229
      _replace_vars(
230
        object => $item,
231
        vars => _generate_time_period_variables(
232
          period_start_date => $item_count_and_dates->{start_date},
233
          period_end_date   => $item_count_and_dates->{end_date},
234
        ),
235
        attribute => $_,
236
        attribute_format => ($_ eq 'longdescription' ? 'html' : 'text')
237
      ) for qw(description longdescription);
208 238
    }
209 239

  
210 240
    $invoice->post(ar_id => $config->ar_chart_id) || die;

Auch abrufbar als: Unified diff