Revision 1ad7929f
Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt
SL/BackgroundJob/CreatePeriodicInvoices.pm | ||
---|---|---|
5 | 5 |
use parent qw(SL::BackgroundJob::Base); |
6 | 6 |
|
7 | 7 |
use Config::Std; |
8 |
use DateTime::Format::Strptime; |
|
8 | 9 |
use English qw(-no_match_vars); |
9 | 10 |
|
10 | 11 |
use SL::DB::AuthUser; |
... | ... | |
79 | 80 |
$::locale->text('January'), $::locale->text('February'), $::locale->text('March'), $::locale->text('April'), $::locale->text('May'), $::locale->text('June'), |
80 | 81 |
$::locale->text('July'), $::locale->text('August'), $::locale->text('September'), $::locale->text('October'), $::locale->text('November'), $::locale->text('December')); |
81 | 82 |
|
82 |
my $vars = { current_quarter => $period_start_date->quarter, |
|
83 |
previous_quarter => $period_start_date->clone->subtract(months => 3)->quarter, |
|
84 |
next_quarter => $period_start_date->clone->add( months => 3)->quarter, |
|
83 |
my $vars = { |
|
84 |
current_quarter => [ $period_start_date->clone->truncate(to => 'month'), sub { $_[0]->quarter } ], |
|
85 |
previous_quarter => [ $period_start_date->clone->truncate(to => 'month')->subtract(months => 3), sub { $_[0]->quarter } ], |
|
86 |
next_quarter => [ $period_start_date->clone->truncate(to => 'month')->add( months => 3), sub { $_[0]->quarter } ], |
|
85 | 87 |
|
86 |
current_month => $period_start_date->month,
|
|
87 |
previous_month => $period_start_date->clone->subtract(months => 1)->month,
|
|
88 |
next_month => $period_start_date->clone->add( months => 1)->month,
|
|
88 |
current_month => [ $period_start_date->clone->truncate(to => 'month'), sub { $_[0]->month } ],
|
|
89 |
previous_month => [ $period_start_date->clone->truncate(to => 'month')->subtract(months => 1), sub { $_[0]->month } ],
|
|
90 |
next_month => [ $period_start_date->clone->truncate(to => 'month')->add( months => 1), sub { $_[0]->month } ],
|
|
89 | 91 |
|
90 |
current_year => $period_start_date->year,
|
|
91 |
previous_year => $period_start_date->year - 1,
|
|
92 |
next_year => $period_start_date->year + 1,
|
|
92 |
current_year => [ $period_start_date->clone->truncate(to => 'year'), sub { $_[0]->year } ],
|
|
93 |
previous_year => [ $period_start_date->clone->truncate(to => 'year')->subtract(years => 1), sub { $_[0]->year } ],
|
|
94 |
next_year => [ $period_start_date->clone->truncate(to => 'year')->add( years => 1), sub { $_[0]->year } ],
|
|
93 | 95 |
|
94 |
period_start_date => $::locale->format_date(\%::myconfig, $period_start_date),
|
|
95 |
period_end_date => $::locale->format_date(\%::myconfig, $period_end_date),
|
|
96 |
};
|
|
96 |
period_start_date => [ $period_start_date->clone->truncate(to => 'month'), sub { $::locale->format_date(\%::myconfig, $_[0]) } ],
|
|
97 |
period_end_date => [ $period_end_date ->clone->truncate(to => 'month'), sub { $::locale->format_date(\%::myconfig, $_[0]) } ],
|
|
98 |
}; |
|
97 | 99 |
|
98 | 100 |
map { $vars->{"${_}_month_long"} = $month_names[ $vars->{"${_}_month"} ] } qw(current previous next); |
99 | 101 |
|
... | ... | |
106 | 108 |
my $sub = shift; |
107 | 109 |
my $str = $object->$sub; |
108 | 110 |
|
109 |
my ($key, $value); |
|
110 |
$str =~ s|<\%${key}\%>|$value|g while ($key, $value) = each %{ $vars }; |
|
111 |
$str =~ s{ <\% ([a-z0-9_]+) ( \s+ format \s*=\s* (.*?) \s* )? \%>}{ |
|
112 |
my ($key, $format) = ($1, $3); |
|
113 |
if (!$vars->{$key}) { |
|
114 |
''; |
|
115 |
|
|
116 |
} elsif ($format) { |
|
117 |
DateTime::Format::Strptime->new( |
|
118 |
pattern => $format, |
|
119 |
locale => 'de_DE', |
|
120 |
time_zone => 'local', |
|
121 |
)->format_datetime($vars->{$key}->[0]); |
|
122 |
|
|
123 |
} else { |
|
124 |
$vars->{$1}->[1]->($vars->{$1}->[0]); |
|
125 |
} |
|
126 |
}eigx; |
|
127 |
|
|
111 | 128 |
$object->$sub($str); |
112 | 129 |
} |
113 | 130 |
|
Auch abrufbar als: Unified diff
Wiederkehrende Rechnungen: Formatierung von Datumsdruckvariablen über freie Formatstrings