X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FBuchungsgruppe.pm;h=eb467c541b5791ed5aca4c235fd52b0a16d09e2a;hb=17384c044b465c262772eb9737ea298069c4d826;hp=1045ac1905f21f6672da1cbcb38d8b3f59396993;hpb=04bfdc112567932e056aad505b79b4bf7dc6b4b4;p=kivitendo-erp.git diff --git a/SL/DB/Buchungsgruppe.pm b/SL/DB/Buchungsgruppe.pm index 1045ac190..eb467c541 100644 --- a/SL/DB/Buchungsgruppe.pm +++ b/SL/DB/Buchungsgruppe.pm @@ -4,88 +4,82 @@ use strict; use SL::DB::MetaSetup::Buchungsgruppe; use SL::DB::Manager::Buchungsgruppe; +use SL::DB::Helper::ActsAsList; __PACKAGE__->meta->add_relationship( inventory_account => { type => 'many to one', class => 'SL::DB::Chart', - column_map => { income_accno_id_0 => 'id' }, - }, - income_account_0 => { - type => 'many to one', - class => 'SL::DB::Chart', - column_map => { income_accno_id_0 => 'id' }, - }, - income_account_1 => { - type => 'many to one', - class => 'SL::DB::Chart', - column_map => { income_accno_id_1 => 'id' }, - }, - income_account_2 => { - type => 'many to one', - class => 'SL::DB::Chart', - column_map => { income_accno_id_2 => 'id' }, - }, - income_account_3 => { - type => 'many to one', - class => 'SL::DB::Chart', - column_map => { income_accno_id_3 => 'id' }, - }, - expense_account_0 => { - type => 'many to one', - class => 'SL::DB::Chart', - column_map => { expense_accno_id_0 => 'id' }, - }, - expense_account_1 => { - type => 'many to one', - class => 'SL::DB::Chart', - column_map => { expense_accno_id_1 => 'id' }, - }, - expense_account_2 => { - type => 'many to one', - class => 'SL::DB::Chart', - column_map => { expense_accno_id_2 => 'id' }, - }, - expense_account_3 => { - type => 'many to one', - class => 'SL::DB::Chart', - column_map => { expense_accno_id_3 => 'id' }, + column_map => { inventory_accno_id => 'id' }, }, ); __PACKAGE__->meta->initialize; +sub validate { + my ($self) = @_; + + my @errors; + push @errors, $::locale->text('The description is missing.') if !$self->description; + + return @errors; +} sub income_accno_id { my ($self, $taxzone) = @_; - my $taxzone_id = ref $taxzone && $taxzone->isa('SL::DB::TaxZone') ? $taxzone->id : $taxzone; - my $method = 'income_accno_id_' . $taxzone_id; - return $self->$method; + 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) = @_; - my $taxzone_id = ref $taxzone && $taxzone->isa('SL::DB::TaxZone') ? $taxzone->id : $taxzone; - my $method = 'expense_accno_id_' . $taxzone_id; + require SL::DB::TaxZone; + require SL::DB::TaxzoneChart; - return $self->$method; + 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; } sub income_account { my ($self, $taxzone) = @_; - my $taxzone_id = ref $taxzone && $taxzone->isa('SL::DB::TaxZone') ? $taxzone->id : $taxzone; - my $method = 'income_account_' . $taxzone_id; - return $self->$method; + 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 if $taxzone_chart; } sub expense_account { 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 $method = 'expense_account_' . $taxzone_id; + my $taxzone_chart = SL::DB::Manager::TaxzoneChart->find_by(taxzone_id => $taxzone_id, buchungsgruppen_id => $self->id); + return $taxzone_chart->expense_accno if $taxzone_chart; +} - return $self->$method; +sub taxzonecharts { + my ($self) = @_; + return SL::DB::Manager::TaxzoneChart->get_all(where => [ buchungsgruppen_id => $self->id ]); +} + +sub orphaned { + my ($self) = @_; + die 'not an accessor' if @_ > 1; + + require SL::DB::Part; + return 0 if SL::DB::Manager::Part->get_all_count(query => [ buchungsgruppen_id => $self->id ]); + return 1; } 1; @@ -106,26 +100,29 @@ SL::DB::Buchungsgruppe - RDBO wrapper for the C table =item C Return the chart ID for the expense account for the given taxzone -(either an integer between 0 and 3 inclusively or an instance of -L). +(either the DB id or an instance of L). =item C Return the chart (an instance of L) for the expense -account for the given taxzone (either an integer between 0 and 3 -inclusively or an instance of L). +account for the given taxzone (either the DB id or an instance of +L). =item C Return the chart ID for the income account for the given taxzone -(either an integer between 0 and 3 inclusively or an instance of +(either the DB id or an instance of L). L). =item C Return the chart (an instance of L) for the income -account for the given taxzone (either an integer between 0 and 3 -inclusively or an instance of L). +account for the given taxzone (either the DB id or an instance of +L). + +=item C + +Checks whether this Buchungsgruppe is assigned to any parts. =back