SL::DB::Buchungsgruppen: Verknüpfungen und Hilfsmethoden
[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
8 __PACKAGE__->meta->add_relationship(
9   inventory_account => {
10     type          => 'many to one',
11     class         => 'SL::DB::Chart',
12     column_map    => { income_accno_id_0 => 'id' },
13   },
14   income_account_0 => {
15     type         => 'many to one',
16     class        => 'SL::DB::Chart',
17     column_map   => { income_accno_id_0 => 'id' },
18   },
19   income_account_1 => {
20     type         => 'many to one',
21     class        => 'SL::DB::Chart',
22     column_map   => { income_accno_id_1 => 'id' },
23   },
24   income_account_2 => {
25     type         => 'many to one',
26     class        => 'SL::DB::Chart',
27     column_map   => { income_accno_id_2 => 'id' },
28   },
29   income_account_3 => {
30     type         => 'many to one',
31     class        => 'SL::DB::Chart',
32     column_map   => { income_accno_id_3 => 'id' },
33   },
34   expense_account_0 => {
35     type         => 'many to one',
36     class        => 'SL::DB::Chart',
37     column_map   => { expense_accno_id_0 => 'id' },
38   },
39   expense_account_1 => {
40     type         => 'many to one',
41     class        => 'SL::DB::Chart',
42     column_map   => { expense_accno_id_1 => 'id' },
43   },
44   expense_account_2 => {
45     type         => 'many to one',
46     class        => 'SL::DB::Chart',
47     column_map   => { expense_accno_id_2 => 'id' },
48   },
49   expense_account_3 => {
50     type         => 'many to one',
51     class        => 'SL::DB::Chart',
52     column_map   => { expense_accno_id_3 => 'id' },
53   },
54 );
55
56 __PACKAGE__->meta->initialize;
57
58
59 sub income_accno_id {
60   my ($self, $taxzone) = @_;
61   my $taxzone_id = ref $taxzone && $taxzone->isa('SL::DB::TaxZone') ? $taxzone->id : $taxzone;
62   my $method = 'income_accno_id_' . $taxzone_id;
63
64   return $self->$method;
65 }
66
67 sub expense_accno_id {
68   my ($self, $taxzone) = @_;
69   my $taxzone_id = ref $taxzone && $taxzone->isa('SL::DB::TaxZone') ? $taxzone->id : $taxzone;
70   my $method = 'expense_accno_id_' . $taxzone_id;
71
72   return $self->$method;
73 }
74
75 sub income_account {
76   my ($self, $taxzone) = @_;
77   my $taxzone_id       = ref $taxzone && $taxzone->isa('SL::DB::TaxZone') ? $taxzone->id : $taxzone;
78   my $method           = 'income_account_' . $taxzone_id;
79
80   return $self->$method;
81 }
82
83 sub expense_account {
84   my ($self, $taxzone) = @_;
85   my $taxzone_id       = ref $taxzone && $taxzone->isa('SL::DB::TaxZone') ? $taxzone->id : $taxzone;
86   my $method           = 'expense_account_' . $taxzone_id;
87
88   return $self->$method;
89 }
90
91 1;
92 __END__
93
94 =pod
95
96 =encoding utf8
97
98 =head1 NAME
99
100 SL::DB::Buchungsgruppe - RDBO wrapper for the C<buchungsgruppen> table
101
102 =head1 FUNCTIONS
103
104 =over 4
105
106 =item C<expense_accno_id $taxzone>
107
108 Return the chart ID for the expense account for the given taxzone
109 (either an integer between 0 and 3 inclusively or an instance of
110 L<SL::DB::TaxZone>).
111
112 =item C<expense_account>
113
114 Return the chart (an instance of L<SL::DB::Chart>) for the expense
115 account for the given taxzone (either an integer between 0 and 3
116 inclusively or an instance of L<SL::DB::TaxZone>).
117
118 =item C<income_accno_id>
119
120 Return the chart ID for the income account for the given taxzone
121 (either an integer between 0 and 3 inclusively or an instance of
122 L<SL::DB::TaxZone>).
123
124 =item C<income_account>
125
126 Return the chart (an instance of L<SL::DB::Chart>) for the income
127 account for the given taxzone (either an integer between 0 and 3
128 inclusively or an instance of L<SL::DB::TaxZone>).
129
130 =back
131
132 =head1 BUGS
133
134 Nothing here yet.
135
136 =head1 AUTHOR
137
138 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>,
139 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
140
141 =cut