]> wagnertech.de Git - mfinanz.git/blob - SL/InstanceConfiguration.pm
kivitendo 3.9.2-0.2
[mfinanz.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 get_layout_style {
66   return $_[0]->data->{layout_style} if exists $_[0]->data->{layout_style};
67   return '';
68 }
69
70 sub AUTOLOAD {
71   our $AUTOLOAD;
72
73   my $self   =  shift;
74   my $method =  $AUTOLOAD;
75   $method    =~ s/.*:://;
76
77   return if $method eq 'DESTROY';
78
79   if ($method =~ m/^get_/) {
80     $method = substr $method, 4;
81     return $self->data->{$method} if exists $self->data->{$method};
82     croak "Invalid method 'get_${method}'";
83   }
84
85   croak "Invalid method '${method}'" if !$self->can($method);
86   return $self->$method(@_);
87 }
88
89 1;
90
91 __END__
92
93 =pod
94
95 =encoding utf8
96
97 =head1 NAME
98
99 SL::InstanceConfiguration - Provide instance-specific configuration data
100
101 =head1 SYNOPSIS
102
103 kivitendo has two configuration levels: installation specific
104 (provided by the global variable C<%::lx_office_conf>) and instance
105 specific. The latter is provided by a global instance of this class,
106 C<$::instance_conf>.
107
108 =head1 FUNCTIONS
109
110 =over 4
111
112 =item C<new>
113
114 Creates a new instance. Does not read the configuration.
115
116 =item C<crm_installed>
117
118 Returns trueish if the CRM component is installed.
119
120 =item C<get_currencies>
121
122 Returns an array of configured currencies.
123
124 =item C<get_default_currency>
125
126 Returns the default currency or undef if no currency has been
127 configured.
128
129 =item C<get_layout_style>
130
131 Returns the forced default layout style or '' if the database column
132 does not exist yet.
133
134 =item C<get_accounting_method>
135
136 Returns the default accounting method, accrual or cash
137
138 =item C<get_inventory_system>
139
140 Returns the default inventory system, perpetual or periodic
141
142 =item C<get_profit_determination>
143
144 Returns the default profit determination method, balance or income
145
146 =item C<get_balance_startdate_method>
147
148 Returns the default method for determining the startdate for the balance
149 report.
150
151 Valid options:
152 closed_to start_of_year all_transactions last_ob_or_all_transactions last_ob_or_start_of_year
153
154 =item C<get_is_changeable>
155
156 =item C<get_ir_changeable>
157
158 =item C<get_ar_changeable>
159
160 =item C<get_ap_changeable>
161
162 =item C<get_gl_changeable>
163
164 Returns if and when these record types are changeable or deleteable after
165 posting. 0 means never, 1 means always and 2 means on the same day.
166
167 =item C<get_datev_check_on_sales_invoice>
168
169 Returns true if datev check should be performed on sales invoices
170
171 =item C<get_datev_check_on_purchase_invoice>
172
173 Returns true if datev check should be performed on purchase invoices
174
175 =item C<get_datev_check_on_ar_transaction>
176
177 Returns true if datev check should be performed on ar transactions
178
179 =item C<get_datev_check_on_ap_transaction>
180
181 Returns true if datev check should be performed on ap transactions
182
183 =item C<get_datev_check_on_gl_transaction>
184
185 Returns true if datev check should be performed on gl transactions
186
187 =item C<get_show_bestbefore>
188
189 Returns the default behavior for showing best before date, true or false
190
191 =item C<get_is_show_mark_as_paid>
192
193 =item C<get_ir_show_mark_as_paid>
194
195 =item C<get_ar_show_mark_as_paid>
196
197 =item C<get_ap_show_mark_as_paid>
198
199 Returns the default behavior for showing the "mark as paid" button for the
200 corresponding record type (true or false).
201
202 =item C<get_sales_order_show_delete>
203
204 =item C<get_purchase_order_show_delete>
205
206 =item C<get_sales_delivery_order_show_delete>
207
208 =item C<get_purchase_delivery_order_show_delete>
209
210 Returns the default behavior for showing the delete button for the
211 corresponding record type (true or false).
212
213 =item C<get_warehouse_id>
214
215 Returns the default warehouse_id
216
217 =item C<get_bin_id>
218
219 Returns the default bin_id
220
221 =item C<get_warehouse_id_ignore_onhand>
222
223 Returns the default warehouse_id for transfers without checking the
224 current stock quantity
225
226 =item C<get_bin_id_ignore_onhand>
227
228 Returns the default bin_id for transfers without checking the
229 current stock quantity
230
231 =item C<get_transfer_default>
232
233 =item C<get_transfer_default_use_master_default_bin>
234
235 =item C<get_transfer_default_ignore_onhand>
236
237 Returns the default behavior for the transfer out default feature (true or false)
238
239 =item C<get_max_future_booking_interval>
240
241 Returns the maximum interval value for future bookings
242
243 =item C<get_webdav>
244
245 Returns the configuration for WebDAV
246
247 =item C<get_webdav_documents>
248
249 Returns the configuration for storing documents in the corresponding WebDAV folder
250
251 =item C<get_vertreter>
252
253 Returns the configuration for "vertreter"
254
255 =item C<get_parts_show_image>
256
257 Returns the configuarion for show image in parts
258
259 =item C<get_parts_image_css>
260
261 Returns the css format string for images shown in parts
262
263 =item C<get_parts_listing_image>
264
265 Returns the configuration for showing the picture in the results when you search for parts
266
267 =back
268
269 =head1 BUGS
270
271 Updates to the I<defaults> table require that the instance
272 configuration is re-read. This has not been implemented yet.
273
274 =head1 AUTHOR
275
276 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
277
278 =cut