X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FChart.pm;h=40ac530d440718d524c99039d43efcf902df8855;hb=b8ee6b6ed46e55095b955ee1800b8a4b8d8ccc3f;hp=2d865b55daaf25572163470f2e25a437b00e64d1;hpb=82515b2d93dc5632f24d6e0b6f8f05f3fd19fbb0;p=kivitendo-erp.git diff --git a/SL/DB/Chart.pm b/SL/DB/Chart.pm index 2d865b55d..40ac530d4 100644 --- a/SL/DB/Chart.pm +++ b/SL/DB/Chart.pm @@ -3,7 +3,59 @@ package SL::DB::Chart; use strict; use SL::DB::MetaSetup::Chart; +use SL::DB::Manager::Chart; -__PACKAGE__->meta->make_manager_class; +__PACKAGE__->meta->add_relationships(taxkeys => { type => 'one to many', + class => 'SL::DB::TaxKey', + column_map => { id => 'chart_id' }, + }, + ); + +__PACKAGE__->meta->initialize; + +sub get_active_taxkey { + my ($self, $date) = @_; + $date ||= DateTime->today_local; + + my $cache = $::request->cache("get_active_taxkey")->{$date} //= {}; + return $cache->{$self->id} if $cache->{$self->id}; + + require SL::DB::TaxKey; + return $cache->{$self->id} = SL::DB::Manager::TaxKey->get_all( + query => [ and => [ chart_id => $self->id, + startdate => { le => $date } ] ], + sort_by => "startdate DESC")->[0]; +} 1; + +__END__ + +=pod + +=encoding utf8 + +=head1 NAME + +SL::DB::Chart - Rose database model for the "chart" table + +=head1 FUNCTIONS + +=over 4 + +=item C + +Returns the active tax key object for a given date. C<$date> defaults +to the current date if undefined. + +=back + +=head1 BUGS + +Nothing here yet. + +=head1 AUTHOR + +Moritz Bunkus Em.bunkus@linet-services.deE + +=cut