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