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