+use SL::DB::Manager::Buchungsgruppe;
+use SL::DB::Helper::ActsAsList;
+
+__PACKAGE__->meta->initialize;
+
+sub inventory_account { goto &inventory_accno; }
+
+sub validate {
+ my ($self) = @_;
+
+ my @errors;
+ push @errors, $::locale->text('The description is missing.') if !$self->description;
+ if( $self->inventory_accno_id ) {
+ require SL::DB::Chart;
+ my $inventory_accno = SL::DB::Manager::Chart->find_by( id => $self->inventory_accno_id );
+ push(@errors, $::locale->text('Booking group #1 needs a valid inventory account', $self->description)) unless $inventory_accno;
+ } else {
+ push @errors, $::locale->text('The booking group needs an inventory account.');
+ };
+
+ return @errors;
+}
+
+sub income_accno_id {
+ my ($self, $taxzone) = @_;
+
+ require SL::DB::TaxZone;
+ require SL::DB::TaxzoneChart;
+
+ my $taxzone_id = ref $taxzone && $taxzone->isa('SL::DB::TaxZone') ? $taxzone->id : $taxzone;
+ my $taxzone_chart = SL::DB::Manager::TaxzoneChart->find_by(taxzone_id => $taxzone_id, buchungsgruppen_id => $self->id);
+ return $taxzone_chart->income_accno_id if $taxzone_chart;
+}
+
+sub expense_accno_id {
+ my ($self, $taxzone) = @_;
+ require SL::DB::TaxZone;
+ require SL::DB::TaxzoneChart;
+
+ my $taxzone_id = ref $taxzone && $taxzone->isa('SL::DB::TaxZone') ? $taxzone->id : $taxzone;
+ my $taxzone_chart = SL::DB::Manager::TaxzoneChart->find_by(taxzone_id => $taxzone_id, buchungsgruppen_id => $self->id);
+ return $taxzone_chart->expense_accno_id if $taxzone_chart;
+}