SL::DB::{Chart,Part}: Verwendung von $::request->cache()
[kivitendo-erp.git] / SL / DB / Chart.pm
1 package SL::DB::Chart;
2
3 use strict;
4
5 use SL::DB::MetaSetup::Chart;
6 use SL::DB::Manager::Chart;
7
8 __PACKAGE__->meta->add_relationships(taxkeys => { type         => 'one to many',
9                                                   class        => 'SL::DB::TaxKey',
10                                                   column_map   => { id => 'chart_id' },
11                                                 },
12                                     );
13
14 __PACKAGE__->meta->initialize;
15
16 sub get_active_taxkey {
17   my ($self, $date) = @_;
18   $date ||= DateTime->today_local;
19
20   my $cache = $::request->cache("get_active_taxkey")->{$date} //= {};
21   if ($cache->{$self->id}) {
22     return $cache->{$self->id};
23   }
24
25   require SL::DB::TaxKey;
26   return SL::DB::Manager::TaxKey->get_all(query   => [ and => [ chart_id  => $self->id,
27                                                                 startdate => { le => $date } ] ],
28                                           sort_by => "startdate DESC")->[0];
29 }
30
31 1;
32
33 __END__
34
35 =pod
36
37 =encoding utf8
38
39 =head1 NAME
40
41 SL::DB::Chart - Rose database model for the "chart" table
42
43 =head1 FUNCTIONS
44
45 =over 4
46
47 =item C<get_active_taxkey $date>
48
49 Returns the active tax key object for a given date. C<$date> defaults
50 to the current date if undefined.
51
52 =back
53
54 =head1 BUGS
55
56 Nothing here yet.
57
58 =head1 AUTHOR
59
60 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
61
62 =cut