X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FDB%2FBuchungsgruppe.pm;h=bac0f7bcbee6a02d6e70b15dd56478c4948dbea0;hb=f5c454e3855012bdb1928f3e4c4964403d4d8163;hp=1045ac1905f21f6672da1cbcb38d8b3f59396993;hpb=04bfdc112567932e056aad505b79b4bf7dc6b4b4;p=kivitendo-erp.git diff --git a/SL/DB/Buchungsgruppe.pm b/SL/DB/Buchungsgruppe.pm index 1045ac190..bac0f7bcb 100644 --- a/SL/DB/Buchungsgruppe.pm +++ b/SL/DB/Buchungsgruppe.pm @@ -4,88 +4,70 @@ 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 inventory_accno { + my ($self) = @_; + require SL::DB::Manager::Chart; + return SL::DB::Manager::Chart->find_by(id => $self->inventory_accno_id) ? SL::DB::Manager::Chart->find_by(id => $self->inventory_accno_id)->accno() : undef; +} + +sub inventory_accno_description { + my ($self) = @_; + require SL::DB::Manager::Chart; + return SL::DB::Manager::Chart->find_by(id => $self->inventory_accno_id) ? SL::DB::Manager::Chart->find_by(id => $self->inventory_accno_id)->description() : undef; +} 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; + 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; - - return $self->$method; + 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; + 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) = @_; 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 ]); } 1;