]> wagnertech.de Git - kivitendo-erp.git/blob - SL/DB/Buchungsgruppe.pm
Nachtrag zu Steuerzonen: benutzte Klassen mit require einbinden.
[kivitendo-erp.git] / SL / DB / Buchungsgruppe.pm
1 package SL::DB::Buchungsgruppe;
2
3 use strict;
4
5 use SL::DB::MetaSetup::Buchungsgruppe;
6 use SL::DB::Manager::Buchungsgruppe;
7 use SL::DB::Helper::ActsAsList;
8
9 __PACKAGE__->meta->add_relationship(
10   inventory_account => {
11     type          => 'many to one',
12     class         => 'SL::DB::Chart',
13     column_map    => { inventory_accno_id => 'id' },
14   },
15 );
16
17 __PACKAGE__->meta->initialize;
18
19 sub validate {
20   my ($self) = @_;
21
22   my @errors;
23   push @errors, $::locale->text('The description is missing.') if !$self->description;
24
25   return @errors;
26 }
27
28 sub inventory_accno {
29   my ($self) = @_;
30   require SL::DB::Manager::Chart;
31   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;
32 }
33
34 sub inventory_accno_description {
35   my ($self) = @_;
36   require SL::DB::Manager::Chart;
37   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;
38 }
39
40 sub income_accno_id {
41   my ($self, $taxzone) = @_;
42
43   require SL::DB::TaxZone;
44   require SL::DB::TaxzoneChart;
45
46   my $taxzone_id = ref $taxzone && $taxzone->isa('SL::DB::TaxZone') ? $taxzone->id : $taxzone;
47   my $taxzone_chart = SL::DB::Manager::TaxzoneChart->find_by(taxzone_id => $taxzone_id, buchungsgruppen_id => $self->id);
48   return $taxzone_chart->income_accno_id if $taxzone_chart;
49 }
50
51 sub expense_accno_id {
52   my ($self, $taxzone) = @_;
53   require SL::DB::TaxZone;
54   require SL::DB::TaxzoneChart;
55
56   my $taxzone_id = ref $taxzone && $taxzone->isa('SL::DB::TaxZone') ? $taxzone->id : $taxzone;
57   my $taxzone_chart = SL::DB::Manager::TaxzoneChart->find_by(taxzone_id => $taxzone_id, buchungsgruppen_id => $self->id);
58   return $taxzone_chart->expense_accno_id if $taxzone_chart;
59 }
60
61 sub income_account {
62   my ($self, $taxzone) = @_;
63
64   require SL::DB::TaxZone;
65   require SL::DB::TaxzoneChart;
66
67   my $taxzone_id       = ref $taxzone && $taxzone->isa('SL::DB::TaxZone') ? $taxzone->id : $taxzone;
68   my $taxzone_chart = SL::DB::Manager::TaxzoneChart->find_by(taxzone_id => $taxzone_id, buchungsgruppen_id => $self->id);
69   return $taxzone_chart->income_accno if $taxzone_chart;
70 }
71
72 sub expense_account {
73   my ($self, $taxzone) = @_;
74
75   require SL::DB::TaxZone;
76   require SL::DB::TaxzoneChart;
77
78   my $taxzone_id       = ref $taxzone && $taxzone->isa('SL::DB::TaxZone') ? $taxzone->id : $taxzone;
79   my $taxzone_chart = SL::DB::Manager::TaxzoneChart->find_by(taxzone_id => $taxzone_id, buchungsgruppen_id => $self->id);
80   return $taxzone_chart->expense_accno if $taxzone_chart;
81 }
82
83 sub taxzonecharts {
84   my ($self) = @_;
85   return SL::DB::Manager::TaxzoneChart->get_all(where => [ buchungsgruppen_id => $self->id ]);
86 }
87
88 1;
89 __END__
90
91 =pod
92
93 =encoding utf8
94
95 =head1 NAME
96
97 SL::DB::Buchungsgruppe - RDBO wrapper for the C<buchungsgruppen> table
98
99 =head1 FUNCTIONS
100
101 =over 4
102
103 =item C<expense_accno_id $taxzone>
104
105 Return the chart ID for the expense account for the given taxzone
106 (either an integer between 0 and 3 inclusively or an instance of
107 L<SL::DB::TaxZone>).
108
109 =item C<expense_account>
110
111 Return the chart (an instance of L<SL::DB::Chart>) for the expense
112 account for the given taxzone (either an integer between 0 and 3
113 inclusively or an instance of L<SL::DB::TaxZone>).
114
115 =item C<income_accno_id>
116
117 Return the chart ID for the income account for the given taxzone
118 (either an integer between 0 and 3 inclusively or an instance of
119 L<SL::DB::TaxZone>).
120
121 =item C<income_account>
122
123 Return the chart (an instance of L<SL::DB::Chart>) for the income
124 account for the given taxzone (either an integer between 0 and 3
125 inclusively or an instance of L<SL::DB::TaxZone>).
126
127 =back
128
129 =head1 BUGS
130
131 Nothing here yet.
132
133 =head1 AUTHOR
134
135 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>,
136 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
137
138 =cut