PriceSource: credit_notes auch im Popup unterstützen
[kivitendo-erp.git] / SL / DB / Buchungsgruppe.pm
index bac0f7b..eb467c5 100644 (file)
@@ -25,20 +25,12 @@ sub validate {
   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 +38,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 +48,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 +59,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 +73,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 +100,29 @@ SL::DB::Buchungsgruppe - RDBO wrapper for the C<buchungsgruppen> table
 =item C<expense_accno_id $taxzone>
 
 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<SL::DB::TaxZone>).
+(either the DB id or an instance of L<SL::DB::TaxZone>).
 
 =item C<expense_account>
 
 Return the chart (an instance of L<SL::DB::Chart>) for the expense
-account for the given taxzone (either an integer between 0 and 3
-inclusively or an instance of L<SL::DB::TaxZone>).
+account for the given taxzone (either the DB id or an instance of
+L<SL::DB::TaxZone>).
 
 =item C<income_accno_id>
 
 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<SL::DB::TaxZone>).
 L<SL::DB::TaxZone>).
 
 =item C<income_account>
 
 Return the chart (an instance of L<SL::DB::Chart>) for the income
-account for the given taxzone (either an integer between 0 and 3
-inclusively or an instance of L<SL::DB::TaxZone>).
+account for the given taxzone (either the DB id or an instance of
+L<SL::DB::TaxZone>).
+
+=item C<orphaned>
+
+Checks whether this Buchungsgruppe is assigned to any parts.
 
 =back