+sub get_chart_balances {
+ my ($self, @chart_ids) = @_;
+
+ return () unless @chart_ids;
+
+ my $placeholders = join ', ', ('?') x scalar(@chart_ids);
+ my $query = qq|SELECT chart_id, SUM(amount) AS sum
+ FROM acc_trans
+ WHERE chart_id IN (${placeholders})
+ GROUP BY chart_id|;
+
+ my %balances = selectall_as_map($::form, $::form->get_standard_dbh(\%::myconfig), $query, 'chart_id', 'sum', @chart_ids);
+
+ return %balances;
+}
+
+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 };