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