X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FBuchungsgruppe.pm;h=cad8bb628605d0a6ad2403d0872ff4fc83984b29;hb=9dfd320ff258071e3ad78dd6cf2d76e215efd4f7;hp=bac0f7bcbee6a02d6e70b15dd56478c4948dbea0;hpb=f5c454e3855012bdb1928f3e4c4964403d4d8163;p=kivitendo-erp.git diff --git a/SL/DB/Buchungsgruppe.pm b/SL/DB/Buchungsgruppe.pm index bac0f7bcb..cad8bb628 100644 --- a/SL/DB/Buchungsgruppe.pm +++ b/SL/DB/Buchungsgruppe.pm @@ -6,39 +6,32 @@ 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 => { inventory_accno_id => 'id' }, - }, -); - __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 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) = @_; + + 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; @@ -46,6 +39,9 @@ sub income_accno_id { 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; @@ -53,6 +49,10 @@ sub expense_accno_id { sub income_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 $taxzone_chart = SL::DB::Manager::TaxzoneChart->find_by(taxzone_id => $taxzone_id, buchungsgruppen_id => $self->id); return $taxzone_chart->income_accno if $taxzone_chart; @@ -60,6 +60,10 @@ sub income_account { 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 $taxzone_chart = SL::DB::Manager::TaxzoneChart->find_by(taxzone_id => $taxzone_id, buchungsgruppen_id => $self->id); return $taxzone_chart->expense_accno if $taxzone_chart; @@ -70,6 +74,15 @@ sub taxzonecharts { 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; __END__ @@ -88,26 +101,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