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