f7728aef18d4ac2d4e2f08da421ac44704bea4b4
[kivitendo-erp.git] / SL / DB / Manager / Chart.pm
1 package SL::DB::Manager::Chart;
2
3 use strict;
4
5 use SL::DB::Helper::Manager;
6 use base qw(SL::DB::Helper::Manager);
7
8 use SL::DB::Helper::Sorted;
9 use DateTime;
10 use SL::DBUtils;
11
12 sub object_class { 'SL::DB::Chart' }
13
14 __PACKAGE__->make_manager_methods;
15
16 sub link_filter {
17   my ($class, $link) = @_;
18
19   return (or => [ link => $link,
20                   link => { like => "${link}:\%"    },
21                   link => { like => "\%:${link}"    },
22                   link => { like => "\%:${link}:\%" } ]);
23 }
24
25 sub cache_taxkeys {
26   my ($self, %params) = @_;
27
28   my $date  = $params{date} || DateTime->today;
29   my $cache = $::request->cache('::SL::DB::Chart::get_active_taxkey')->{$date} //= {};
30
31   require SL::DB::TaxKey;
32   my $tks = SL::DB::Manager::TaxKey->get_all;
33   my %tks_by_id = map { $_->id => $_ } @$tks;
34
35   my $rows = selectall_hashref_query($::form, $::form->get_standard_dbh, <<"", $date);
36     SELECT DISTINCT ON (chart_id) chart_id, startdate, id
37     FROM taxkeys
38     WHERE startdate < ?
39     ORDER BY chart_id, startdate DESC;
40
41   for (@$rows) {
42     $cache->{$_->{chart_id}} = $tks_by_id{$_->{id}};
43   }
44 }
45
46 1;
47
48 __END__
49
50 =pod
51
52 =encoding utf8
53
54 =head1 NAME
55
56 SL::DB::Manager::Chart - Manager class for the model for the C<chart> table
57
58 =head1 FUNCTIONS
59
60 =over 4
61
62 =item C<link_filter $link>
63
64 Returns a query builder filter that matches charts whose 'C<link>'
65 field contains C<$link>. Matching is done so that the exact value of
66 C<$link> matches but not if C<$link> is only a substring of a
67 match. Therefore C<$link = 'AR'> will match the column content 'C<AR>'
68 or 'C<AR_paid:AR>' but not 'C<AR_amount>'.
69
70 =back
71
72 =head1 BUGS
73
74 Nothing here yet.
75
76 =head1 AUTHOR
77
78 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
79
80 =cut