X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FBuchungsgruppe.pm;h=cad8bb628605d0a6ad2403d0872ff4fc83984b29;hb=c5057972d03f3546494fabe72224785e5a0a1714;hp=26f446b33ceef602a3c40f9959f5d60ad8795c2f;hpb=7cf894f137fa5e4a2679b8a6e1aa00566041f9e4;p=kivitendo-erp.git diff --git a/SL/DB/Buchungsgruppe.pm b/SL/DB/Buchungsgruppe.pm index 26f446b33..cad8bb628 100644 --- a/SL/DB/Buchungsgruppe.pm +++ b/SL/DB/Buchungsgruppe.pm @@ -1,29 +1,139 @@ -# This file has been auto-generated only because it didn't exist. -# Feel free to modify it at will; it will not be overwritten automatically. - package SL::DB::Buchungsgruppe; use strict; use SL::DB::MetaSetup::Buchungsgruppe; +use SL::DB::Manager::Buchungsgruppe; +use SL::DB::Helper::ActsAsList; + +__PACKAGE__->meta->initialize; + +sub inventory_account { goto &inventory_accno; } -# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. -__PACKAGE__->meta->make_manager_class; +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) = @_; - 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) = @_; + require SL::DB::TaxZone; + require SL::DB::TaxzoneChart; + my $taxzone_id = ref $taxzone && $taxzone->isa('SL::DB::TaxZone') ? $taxzone->id : $taxzone; - my $method = 'expense_accno_id_' . $taxzone_id; + 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) = @_; + + 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 $taxzone_chart = SL::DB::Manager::TaxzoneChart->find_by(taxzone_id => $taxzone_id, buchungsgruppen_id => $self->id); + return $taxzone_chart->expense_accno if $taxzone_chart; +} + +sub taxzonecharts { + my ($self) = @_; + return SL::DB::Manager::TaxzoneChart->get_all(where => [ buchungsgruppen_id => $self->id ]); +} - return $self->$method; +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__ + +=pod + +=encoding utf8 + +=head1 NAME + +SL::DB::Buchungsgruppe - RDBO wrapper for the C table + +=head1 FUNCTIONS + +=over 4 + +=item C + +Return the chart ID for the expense account for the given taxzone +(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 the DB id or an instance of +L). + +=item C + +Return the chart ID for the income account for the given taxzone +(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 the DB id or an instance of +L). + +=item C + +Checks whether this Buchungsgruppe is assigned to any parts. + +=back + +=head1 BUGS + +Nothing here yet. + +=head1 AUTHOR + +Sven Schöling Es.schoeling@linet-services.deE, +Moritz Bunkus Em.bunkus@linet-services.deE + +=cut