1 package SL::DB::Buchungsgruppe;
 
   5 use SL::DB::MetaSetup::Buchungsgruppe;
 
   6 use SL::DB::Manager::Buchungsgruppe;
 
   7 use SL::DB::Helper::ActsAsList;
 
   9 __PACKAGE__->meta->add_relationship(
 
  10   inventory_account => {
 
  11     type          => 'many to one',
 
  12     class         => 'SL::DB::Chart',
 
  13     column_map    => { inventory_accno_id => 'id' },
 
  17 __PACKAGE__->meta->initialize;
 
  23   push @errors, $::locale->text('The description is missing.') if !$self->description;
 
  24   if( $self->inventory_accno_id ) {
 
  25     require SL::DB::Chart;
 
  26     my $inventory_accno = SL::DB::Manager::Chart->find_by( id => $self->inventory_accno_id );
 
  27     push(@errors, $::locale->text('Buchungsgruppe #1 needs a valid inventory account', $self->description)) unless $inventory_accno;
 
  29     push @errors, $::locale->text('The Buchungsgruppe needs an inventory account.');
 
  36   my ($self, $taxzone) = @_;
 
  38   require SL::DB::TaxZone;
 
  39   require SL::DB::TaxzoneChart;
 
  41   my $taxzone_id = ref $taxzone && $taxzone->isa('SL::DB::TaxZone') ? $taxzone->id : $taxzone;
 
  42   my $taxzone_chart = SL::DB::Manager::TaxzoneChart->find_by(taxzone_id => $taxzone_id, buchungsgruppen_id => $self->id);
 
  43   return $taxzone_chart->income_accno_id if $taxzone_chart;
 
  46 sub expense_accno_id {
 
  47   my ($self, $taxzone) = @_;
 
  48   require SL::DB::TaxZone;
 
  49   require SL::DB::TaxzoneChart;
 
  51   my $taxzone_id = ref $taxzone && $taxzone->isa('SL::DB::TaxZone') ? $taxzone->id : $taxzone;
 
  52   my $taxzone_chart = SL::DB::Manager::TaxzoneChart->find_by(taxzone_id => $taxzone_id, buchungsgruppen_id => $self->id);
 
  53   return $taxzone_chart->expense_accno_id if $taxzone_chart;
 
  57   my ($self, $taxzone) = @_;
 
  59   require SL::DB::TaxZone;
 
  60   require SL::DB::TaxzoneChart;
 
  62   my $taxzone_id       = ref $taxzone && $taxzone->isa('SL::DB::TaxZone') ? $taxzone->id : $taxzone;
 
  63   my $taxzone_chart = SL::DB::Manager::TaxzoneChart->find_by(taxzone_id => $taxzone_id, buchungsgruppen_id => $self->id);
 
  64   return $taxzone_chart->income_accno if $taxzone_chart;
 
  68   my ($self, $taxzone) = @_;
 
  70   require SL::DB::TaxZone;
 
  71   require SL::DB::TaxzoneChart;
 
  73   my $taxzone_id       = ref $taxzone && $taxzone->isa('SL::DB::TaxZone') ? $taxzone->id : $taxzone;
 
  74   my $taxzone_chart = SL::DB::Manager::TaxzoneChart->find_by(taxzone_id => $taxzone_id, buchungsgruppen_id => $self->id);
 
  75   return $taxzone_chart->expense_accno if $taxzone_chart;
 
  80   return SL::DB::Manager::TaxzoneChart->get_all(where => [ buchungsgruppen_id => $self->id ]);
 
  85   die 'not an accessor' if @_ > 1;
 
  88   return 0 if SL::DB::Manager::Part->get_all_count(query => [ buchungsgruppen_id => $self->id ]);
 
 101 SL::DB::Buchungsgruppe - RDBO wrapper for the C<buchungsgruppen> table
 
 107 =item C<expense_accno_id $taxzone>
 
 109 Return the chart ID for the expense account for the given taxzone
 
 110 (either the DB id or an instance of L<SL::DB::TaxZone>).
 
 112 =item C<expense_account>
 
 114 Return the chart (an instance of L<SL::DB::Chart>) for the expense
 
 115 account for the given taxzone (either the DB id or an instance of
 
 118 =item C<income_accno_id>
 
 120 Return the chart ID for the income account for the given taxzone
 
 121 (either the DB id or an instance of L<SL::DB::TaxZone>).
 
 124 =item C<income_account>
 
 126 Return the chart (an instance of L<SL::DB::Chart>) for the income
 
 127 account for the given taxzone (either the DB id or an instance of
 
 132 Checks whether this Buchungsgruppe is assigned to any parts.
 
 142 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>,
 
 143 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>