X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/ff159a4d47b9a2d10744dcfc23da2c63605c8a32..eeb5375ee7727c956cc357cc8f90b19d1bfe80b9:/SL/IO.pm diff --git a/SL/IO.pm b/SL/IO.pm index c0d6987f3..e1374feb3 100644 --- a/SL/IO.pm +++ b/SL/IO.pm @@ -77,5 +77,30 @@ SQL $main::lxdebug->leave_sub(); } +sub get_active_taxes_for_chart { + my ($self, $chart_id, $transdate, $tax_id) = @_; + + my $chart = SL::DB::Chart->new(id => $chart_id)->load; + my $active_taxkey = $chart->get_active_taxkey($transdate); + + my $where = [ chart_categories => { like => '%' . $chart->category . '%' } ]; + + if ( defined $tax_id && $tax_id >= 0 ) { + $where = [ or => [ chart_categories => { like => '%' . $chart->category . '%' }, + id => $tax_id + ] + ]; + } + + my $taxes = SL::DB::Manager::Tax->get_all( + where => $where, + sort_by => 'taxkey, rate', + ); + + my $default_tax = first { $active_taxkey->tax_id == $_->id } @{ $taxes }; + $default_tax->{is_default} = 1 if $default_tax; + + return @{ $taxes }; +} 1;