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