InstanceConfiguration durch Verwendung von AUTOLOAD vereinfacht
[kivitendo-erp.git] / SL / InstanceConfiguration.pm
1 package SL::InstanceConfiguration;
2
3 use strict;
4
5 use Carp;
6 use SL::DB::Currency;
7 use SL::DB::Default;
8
9 use parent qw(Rose::Object);
10 use Rose::Object::MakeMethods::Generic (
11   'scalar --get_set_init' => [ qw(data currencies) ],
12 );
13
14 sub init_data {
15   my $default               = SL::DB::Default->get;
16   my $data                  = { map { $_ => $default->$_ } $default->meta->columns };
17   $data->{default_currency} = $default->currency ? $default->currency->name : undef;
18
19   return $data;
20 }
21
22 sub init_currencies {
23   return [ map { $_->name } @{ SL::DB::Manager::Currency->get_all_sorted } ];
24 }
25
26 sub reload {
27   my ($self)          = @_;
28   $self->{data}       = $self->init_data;
29   $self->{currencies} = $self->init_currencies;
30   return $self;
31 }
32
33 sub get_currencies {
34   my ($self) = @_;
35   return @{ $self->currencies };
36 }
37
38 sub AUTOLOAD {
39   our $AUTOLOAD;
40
41   my $self   =  shift;
42   my $method =  $AUTOLOAD;
43   $method    =~ s/.*:://;
44
45   if ($method =~ m/^get_/) {
46     $method = substr $method, 4;
47     return $self->data->{$method} if exists $self->data->{$method};
48     croak "Invalid method 'get_${method}'";
49   }
50
51   croak "Invalid method '${method}'" if !$self->can($method);
52   return $self->$method(@_);
53 }
54
55 1;
56
57 __END__
58
59 =pod
60
61 =encoding utf8
62
63 =head1 NAME
64
65 SL::InstanceConfiguration - Provide instance-specific configuration data
66
67 =head1 SYNOPSIS
68
69 kivitendo has two configuration levels: installation specific
70 (provided by the global variable C<%::lx_office_conf>) and instance
71 specific. The latter is provided by a global instance of this class,
72 C<$::instance_conf>.
73
74 =head1 FUNCTIONS
75
76 =over 4
77
78 =item C<new>
79
80 Creates a new instance. Does not read the configuration.
81
82 =item C<init>
83
84 Reads the configuration from the database. Returns C<$self>.
85
86 =item C<get_currencies>
87
88 Returns an array of configured currencies.
89
90 =item C<get_default_currency>
91
92 Returns the default currency or undef if no currency has been
93 configured.
94
95 =item C<get_accounting_method>
96
97 Returns the default accounting method, accrual or cash
98
99 =item C<get_inventory_system>
100
101 Returns the default inventory system, perpetual or periodic
102
103 =item C<get_profit_determination>
104
105 Returns the default profit determination method, balance or income
106
107
108 =item C<get_is_changeable>
109
110 =item C<get_ir_changeable>
111
112 =item C<get_ar_changeable>
113
114 =item C<get_ap_changeable>
115
116 =item C<get_gl_changeable>
117
118 Returns if and when these record types are changeable or deleteable after
119 posting. 0 means never, 1 means always and 2 means on the same day.
120
121 =item C<get_datev_check_on_sales_invoice>
122
123 Returns true if datev check should be performed on sales invoices
124
125 =item C<get_datev_check_on_purchase_invoice>
126
127 Returns true if datev check should be performed on purchase invoices
128
129 =item C<get_datev_check_on_ar_transaction>
130
131 Returns true if datev check should be performed on ar transactions
132
133 =item C<get_datev_check_on_ap_transaction>
134
135 Returns true if datev check should be performed on ap transactions
136
137 =item C<get_datev_check_on_gl_transaction>
138
139 Returns true if datev check should be performed on gl transactions
140
141 =item C<get_show_bestbefore>
142
143 Returns the default behavior for showing best before date, true or false
144
145 =item C<get_is_show_mark_as_paid>
146
147 =item C<get_ir_show_mark_as_paid>
148
149 =item C<get_ar_show_mark_as_paid>
150
151 =item C<get_ap_show_mark_as_paid>
152
153 Returns the default behavior for showing the mark as paid button for the
154 corresponding record type (true or false).
155
156 =item C<get_sales_order_show_delete>
157
158 =item C<get_purchase_order_show_delete>
159
160 =item C<get_sales_delivery_order_show_delete>
161
162 =item C<get_purchase_delivery_order_show_delete>
163
164 Returns the default behavior for showing the delete button for the
165 corresponding record type (true or false).
166
167 =item C<get_default_warehouse_id>
168
169 Returns the default warehouse_id
170
171 =item C<get_default_bin_id>
172
173 Returns the default bin_id
174
175 =item C<get_default_warehouse_id_ignore_onhand>
176
177 Returns the default warehouse_id for transfers without checking the
178 current stock quantity
179
180 =item C<get_default_bin_id_ignore_onhand>
181
182 Returns the default bin_id for transfers without checking the.
183 current stock quantity
184
185
186
187 =item C<get_transfer_default>
188
189 =item C<get_transfer_default_use_master_default_bin>
190
191 =item C<get_transfer_default_ignore_onhand>
192
193 Returns the default behavior for the transfer out default feature (true or false)
194
195 =item C<get_max_future_booking_interval>
196
197 Returns the maximum interval value for future bookings
198
199 =item C<get_webdav>
200
201 Returns the configuration for webdav
202
203 =item C<get_webdav_documents>
204
205 Returns the configuration for storing documents in the corresponding webdav folder
206
207 =item C<get_vertreter>
208
209 Returns the configuration for "vertreter"
210
211 =item C<get_parts_show_image>
212
213 Returns the configuarion for show image in parts
214
215 =item C<get_parts_image_css>
216
217 Returns the css format string for images shown in parts
218
219 =item C<get_parts_listing_image>
220
221 Returns the configuartion for showing the picture in the results when you search for parts
222
223 =back
224
225 =head1 BUGS
226
227 Updates to the I<defaults> table require that the instance
228 configuration is re-read. This has not been implemented yet.
229
230 =head1 AUTHOR
231
232 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
233
234 =cut