Revision c20a734c
Von Jan Büren vor etwa 6 Jahren hinzugefügt
SL/BackgroundJob/CreatePeriodicInvoices.pm | ||
---|---|---|
31 | 31 |
if (!$self->{db_obj}->db->with_transaction(sub { |
32 | 32 |
1; # make Emacs happy |
33 | 33 |
|
34 |
my $configs = SL::DB::Manager::PeriodicInvoicesConfig->get_all(query => [ active => 1 ]); |
|
34 |
my $configs = SL::DB::Manager::PeriodicInvoicesConfig->get_all(query => [ active => 1 ]);
|
|
35 | 35 |
|
36 |
foreach my $config (@{ $configs }) { |
|
37 |
my $new_end_date = $config->handle_automatic_extension; |
|
38 |
_log_msg("Periodic invoice configuration ID " . $config->id . " extended through " . $new_end_date->strftime('%d.%m.%Y') . "\n") if $new_end_date; |
|
39 |
} |
|
36 |
foreach my $config (@{ $configs }) {
|
|
37 |
my $new_end_date = $config->handle_automatic_extension;
|
|
38 |
_log_msg("Periodic invoice configuration ID " . $config->id . " extended through " . $new_end_date->strftime('%d.%m.%Y') . "\n") if $new_end_date;
|
|
39 |
}
|
|
40 | 40 |
|
41 |
my (@new_invoices, @invoices_to_print, @invoices_to_email, @disabled_orders); |
|
41 |
my (@new_invoices, @invoices_to_print, @invoices_to_email, @disabled_orders);
|
|
42 | 42 |
|
43 |
_log_msg("Number of configs: " . scalar(@{ $configs})); |
|
43 |
_log_msg("Number of configs: " . scalar(@{ $configs}));
|
|
44 | 44 |
|
45 |
foreach my $config (@{ $configs }) { |
|
46 |
# A configuration can be set to inactive by |
|
47 |
# $config->handle_automatic_extension. Therefore the check in |
|
48 |
# ...->get_all() does not suffice. |
|
49 |
_log_msg("Config " . $config->id . " active " . $config->active); |
|
50 |
next unless $config->active; |
|
45 |
foreach my $config (@{ $configs }) {
|
|
46 |
# A configuration can be set to inactive by
|
|
47 |
# $config->handle_automatic_extension. Therefore the check in
|
|
48 |
# ...->get_all() does not suffice.
|
|
49 |
_log_msg("Config " . $config->id . " active " . $config->active);
|
|
50 |
next unless $config->active;
|
|
51 | 51 |
|
52 |
my @dates = _calculate_dates($config); |
|
52 |
my @dates = _calculate_dates($config);
|
|
53 | 53 |
|
54 |
_log_msg("Dates: " . join(' ', map { $_->to_lxoffice } @dates)); |
|
54 |
_log_msg("Dates: " . join(' ', map { $_->to_lxoffice } @dates));
|
|
55 | 55 |
|
56 |
foreach my $date (@dates) { |
|
57 |
my $data = $self->_create_periodic_invoice($config, $date); |
|
58 |
next unless $data; |
|
56 |
foreach my $date (@dates) {
|
|
57 |
my $data = $self->_create_periodic_invoice($config, $date);
|
|
58 |
next unless $data;
|
|
59 | 59 |
|
60 |
_log_msg("Invoice " . $data->{invoice}->invnumber . " posted for config ID " . $config->id . ", period start date " . $::locale->format_date(\%::myconfig, $date) . "\n"); |
|
60 |
_log_msg("Invoice " . $data->{invoice}->invnumber . " posted for config ID " . $config->id . ", period start date " . $::locale->format_date(\%::myconfig, $date) . "\n");
|
|
61 | 61 |
|
62 |
push @new_invoices, $data; |
|
63 |
push @invoices_to_print, $data if $config->print; |
|
64 |
push @invoices_to_email, $data if $config->send_email; |
|
62 |
push @new_invoices, $data;
|
|
63 |
push @invoices_to_print, $data if $config->print;
|
|
64 |
push @invoices_to_email, $data if $config->send_email;
|
|
65 | 65 |
|
66 |
my $inactive_ordnumber = $config->disable_one_time_config; |
|
67 |
if ($inactive_ordnumber) { |
|
68 |
# disable one time configs and skip eventual invoices |
|
69 |
_log_msg("Order " . $inactive_ordnumber . " deavtivated \n"); |
|
70 |
push @disabled_orders, $inactive_ordnumber; |
|
71 |
last; |
|
66 |
my $inactive_ordnumber = $config->disable_one_time_config; |
|
67 |
if ($inactive_ordnumber) { |
|
68 |
# disable one time configs and skip eventual invoices |
|
69 |
_log_msg("Order " . $inactive_ordnumber . " deavtivated \n"); |
|
70 |
push @disabled_orders, $inactive_ordnumber; |
|
71 |
last; |
|
72 |
} |
|
72 | 73 |
} |
73 | 74 |
} |
74 |
} |
|
75 | 75 |
|
76 |
foreach my $inv ( @invoices_to_print ) { $self->_print_invoice($inv); } |
|
77 |
foreach my $inv ( @invoices_to_email ) { $self->_email_invoice($inv); } |
|
76 |
foreach my $inv ( @invoices_to_print ) { $self->_print_invoice($inv); }
|
|
77 |
foreach my $inv ( @invoices_to_email ) { $self->_email_invoice($inv); }
|
|
78 | 78 |
|
79 |
$self->_send_summary_email( |
|
80 |
[ map { $_->{invoice} } @new_invoices ], |
|
81 |
[ map { $_->{invoice} } @invoices_to_print ], |
|
82 |
[ map { $_->{invoice} } @invoices_to_email ], |
|
83 |
\@disabled_orders , |
|
84 |
); |
|
79 |
$self->_send_summary_email(
|
|
80 |
[ map { $_->{invoice} } @new_invoices ],
|
|
81 |
[ map { $_->{invoice} } @invoices_to_print ],
|
|
82 |
[ map { $_->{invoice} } @invoices_to_email ],
|
|
83 |
\@disabled_orders ,
|
|
84 |
);
|
|
85 | 85 |
|
86 |
1; |
|
87 |
})) { |
|
88 |
$::lxdebug->message(LXDebug->WARN(), "_create_invoice failed: " . join("\n", (split(/\n/, $self->{db_obj}->db->error))[0..2])); |
|
89 |
return undef; |
|
90 |
} |
|
86 |
1;
|
|
87 |
})) {
|
|
88 |
$::lxdebug->message(LXDebug->WARN(), "_create_invoice failed: " . join("\n", (split(/\n/, $self->{db_obj}->db->error))[0..2]));
|
|
89 |
return undef;
|
|
90 |
}
|
|
91 | 91 |
|
92 |
if (@{ $self->{job_errors} }) { |
|
93 |
my $msg = join "\n", @{ $self->{job_errors} }; |
|
94 |
_log_msg("Errors: $msg"); |
|
95 |
die $msg; |
|
96 |
} |
|
92 |
if (@{ $self->{job_errors} }) {
|
|
93 |
my $msg = join "\n", @{ $self->{job_errors} };
|
|
94 |
_log_msg("Errors: $msg");
|
|
95 |
die $msg;
|
|
96 |
}
|
|
97 | 97 |
|
98 | 98 |
return 1; |
99 | 99 |
} |
Auch abrufbar als: Unified diff
Kosmetik (Einrückungen) zum Commit von gerade