kivitendo/SL/DB/Buchungsgruppe.pm @ 7b1da9c3
4fd22b56 | Sven Schöling | package SL::DB::Buchungsgruppe;
|
||
use strict;
|
||||
use SL::DB::MetaSetup::Buchungsgruppe;
|
||||
7b129753 | Moritz Bunkus | use SL::DB::Manager::Buchungsgruppe;
|
||
f5c454e3 | Niclas Zimmermann | use SL::DB::Helper::ActsAsList;
|
||
4fd22b56 | Sven Schöling | |||
04bfdc11 | Moritz Bunkus | __PACKAGE__->meta->initialize;
|
||
09e4a554 | Moritz Bunkus | sub inventory_account { goto &inventory_accno; }
|
||
f5c454e3 | Niclas Zimmermann | sub validate {
|
||
my ($self) = @_;
|
||||
my @errors;
|
||||
push @errors, $::locale->text('The description is missing.') if !$self->description;
|
||||
a28a585e | Geoffrey Richardson | if( $self->inventory_accno_id ) {
|
||
require SL::DB::Chart;
|
||||
my $inventory_accno = SL::DB::Manager::Chart->find_by( id => $self->inventory_accno_id );
|
||||
504fcaf1 | Geoffrey Richardson | push(@errors, $::locale->text('Booking group #1 needs a valid inventory account', $self->description)) unless $inventory_accno;
|
||
a28a585e | Geoffrey Richardson | } else {
|
||
504fcaf1 | Geoffrey Richardson | push @errors, $::locale->text('The booking group needs an inventory account.');
|
||
cff9b88d | Moritz Bunkus | }
|
||
if ($self->id && $self->obsolete) {
|
||||
require SL::DB::Part;
|
||||
my $in_use = SL::DB::Manager::Part->get_first(
|
||||
where => [
|
||||
buchungsgruppen_id => $self->id,
|
||||
obsolete => 0,
|
||||
]);
|
||||
if ($in_use) {
|
||||
push @errors, $::locale->text('The booking group cannot be marked obsolete while still being used by active parts.');
|
||||
}
|
||||
}
|
||||
f5c454e3 | Niclas Zimmermann | |||
return @errors;
|
||||
}
|
||||
7ed8903a | Sven Schöling | sub income_accno_id {
|
||
my ($self, $taxzone) = @_;
|
||||
d7a9026a | Bernd Bleßmann | |||
require SL::DB::TaxZone;
|
||||
require SL::DB::TaxzoneChart;
|
||||
7ed8903a | Sven Schöling | my $taxzone_id = ref $taxzone && $taxzone->isa('SL::DB::TaxZone') ? $taxzone->id : $taxzone;
|
||
b989d7cf | Geoffrey Richardson | 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;
|
||||
7ed8903a | Sven Schöling | }
|
||
sub expense_accno_id {
|
||||
my ($self, $taxzone) = @_;
|
||||
d7a9026a | Bernd Bleßmann | require SL::DB::TaxZone;
|
||
require SL::DB::TaxzoneChart;
|
||||
7ed8903a | Sven Schöling | my $taxzone_id = ref $taxzone && $taxzone->isa('SL::DB::TaxZone') ? $taxzone->id : $taxzone;
|
||
b989d7cf | Geoffrey Richardson | 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;
|
||||
7ed8903a | Sven Schöling | }
|
||
04bfdc11 | Moritz Bunkus | sub income_account {
|
||
my ($self, $taxzone) = @_;
|
||||
d7a9026a | Bernd Bleßmann | |||
require SL::DB::TaxZone;
|
||||
require SL::DB::TaxzoneChart;
|
||||
04bfdc11 | Moritz Bunkus | my $taxzone_id = ref $taxzone && $taxzone->isa('SL::DB::TaxZone') ? $taxzone->id : $taxzone;
|
||
b989d7cf | Geoffrey Richardson | 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;
|
||||
04bfdc11 | Moritz Bunkus | }
|
||
sub expense_account {
|
||||
my ($self, $taxzone) = @_;
|
||||
d7a9026a | Bernd Bleßmann | |||
require SL::DB::TaxZone;
|
||||
require SL::DB::TaxzoneChart;
|
||||
04bfdc11 | Moritz Bunkus | my $taxzone_id = ref $taxzone && $taxzone->isa('SL::DB::TaxZone') ? $taxzone->id : $taxzone;
|
||
b989d7cf | Geoffrey Richardson | 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;
|
||||
04bfdc11 | Moritz Bunkus | }
|
||
f5c454e3 | Niclas Zimmermann | sub taxzonecharts {
|
||
my ($self) = @_;
|
||||
return SL::DB::Manager::TaxzoneChart->get_all(where => [ buchungsgruppen_id => $self->id ]);
|
||||
}
|
||||
2f6a11fb | Bernd Bleßmann | |||
d3801bc9 | Geoffrey Richardson | 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;
|
||||
}
|
||||
f5c454e3 | Niclas Zimmermann | |||
4fd22b56 | Sven Schöling | 1;
|
||
04bfdc11 | Moritz Bunkus | __END__
|
||
=pod
|
||||
=encoding utf8
|
||||
=head1 NAME
|
||||
SL::DB::Buchungsgruppe - RDBO wrapper for the C<buchungsgruppen> table
|
||||
=head1 FUNCTIONS
|
||||
=over 4
|
||||
=item C<expense_accno_id $taxzone>
|
||||
Return the chart ID for the expense account for the given taxzone
|
||||
1c62d23e | Geoffrey Richardson | (either the DB id or an instance of L<SL::DB::TaxZone>).
|
||
04bfdc11 | Moritz Bunkus | |||
=item C<expense_account>
|
||||
Return the chart (an instance of L<SL::DB::Chart>) for the expense
|
||||
1c62d23e | Geoffrey Richardson | account for the given taxzone (either the DB id or an instance of
|
||
L<SL::DB::TaxZone>).
|
||||
04bfdc11 | Moritz Bunkus | |||
=item C<income_accno_id>
|
||||
Return the chart ID for the income account for the given taxzone
|
||||
1c62d23e | Geoffrey Richardson | (either the DB id or an instance of L<SL::DB::TaxZone>).
|
||
04bfdc11 | Moritz Bunkus | L<SL::DB::TaxZone>).
|
||
=item C<income_account>
|
||||
Return the chart (an instance of L<SL::DB::Chart>) for the income
|
||||
1c62d23e | Geoffrey Richardson | account for the given taxzone (either the DB id or an instance of
|
||
L<SL::DB::TaxZone>).
|
||||
04bfdc11 | Moritz Bunkus | |||
d3801bc9 | Geoffrey Richardson | =item C<orphaned>
|
||
Checks whether this Buchungsgruppe is assigned to any parts.
|
||||
04bfdc11 | Moritz Bunkus | =back
|
||
=head1 BUGS
|
||||
Nothing here yet.
|
||||
=head1 AUTHOR
|
||||
Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>,
|
||||
Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
|
||||
=cut
|