X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/faada7386844d5b45d03721f8ff5ce6ab61efe55..b04128a335772d4cb9a30b0fde52413796981de0:/SL/InstanceConfiguration.pm diff --git a/SL/InstanceConfiguration.pm b/SL/InstanceConfiguration.pm index 24fd3be28..084f0ac94 100644 --- a/SL/InstanceConfiguration.pm +++ b/SL/InstanceConfiguration.pm @@ -2,51 +2,73 @@ package SL::InstanceConfiguration; use strict; -use SL::DBUtils; - -sub new { - my ($class) = @_; +use Carp; +use SL::DBUtils (); +use SL::System::Process; + +use parent qw(Rose::Object); +use Rose::Object::MakeMethods::Generic ( + 'scalar --get_set_init' => [ qw(data currencies default_currency _table_currencies_exists crm_installed) ], +); + +sub init_data { + return {} if !$::auth->client; + return SL::DBUtils::selectfirst_hashref_query($::form, $::form->get_standard_dbh, qq|SELECT * FROM defaults|); +} - return bless {}, $class; +sub init__table_currencies_exists { + return 0 if !$::auth->client; + return !!(SL::DBUtils::selectall_hashref_query($::form, $::form->get_standard_dbh, qq|SELECT tablename FROM pg_tables WHERE (schemaname = 'public') AND (tablename = 'currencies')|))[0]; } -sub init { +sub init_currencies { my ($self) = @_; - $self->{data} = selectfirst_hashref_query($::form, $::form->get_standard_dbh, qq|SELECT * FROM defaults|); - - my $curr = $self->{data}->{curr} || ''; - $curr =~ s/\s+//g; - $self->{currencies} = [ split m/:/, $curr ]; - - return $self; + return [] if !$self->_table_currencies_exists; + return [ map { $_->{name} } SL::DBUtils::selectall_hashref_query($::form, $::form->get_standard_dbh, qq|SELECT name FROM currencies ORDER BY id ASC|) ]; } -sub get_default_currency { +sub init_default_currency { my ($self) = @_; - return ($self->get_currencies)[0]; + return undef if !$self->_table_currencies_exists || !$self->data->{currency_id}; + return (SL::DBUtils::selectfirst_array_query($::form, $::form->get_standard_dbh, qq|SELECT name FROM currencies WHERE id = ?|, $self->data->{currency_id}))[0]; } -sub get_currencies { - my ($self) = @_; - - return $self->{currencies} ? @{ $self->{currencies} } : (); +sub init_crm_installed { + return -f (SL::System::Process->exe_dir . '/crm/Changelog'); } -sub get_accounting_method { +sub reload { my ($self) = @_; - return $self->{data}->{accounting_method}; + + delete @{ $self }{qw(data currencies default_currency)}; + + return $self; } -sub get_inventory_system { +sub get_currencies { my ($self) = @_; - return $self->{data}->{inventory_system}; + return @{ $self->currencies }; } -sub get_profit_determination { - my ($self) = @_; - return $self->{data}->{profit_determination}; +sub AUTOLOAD { + our $AUTOLOAD; + + my $self = shift; + my $method = $AUTOLOAD; + $method =~ s/.*:://; + + return if $method eq 'DESTROY'; + + if ($method =~ m/^get_/) { + $method = substr $method, 4; + return $self->data->{$method} if exists $self->data->{$method}; + croak "Invalid method 'get_${method}'"; + } + + croak "Invalid method '${method}'" if !$self->can($method); + return $self->$method(@_); } 1; @@ -63,7 +85,7 @@ SL::InstanceConfiguration - Provide instance-specific configuration data =head1 SYNOPSIS -Lx-Office has two configuration levels: installation specific +kivitendo has two configuration levels: installation specific (provided by the global variable C<%::lx_office_conf>) and instance specific. The latter is provided by a global instance of this class, C<$::instance_conf>. @@ -72,35 +94,10 @@ C<$::instance_conf>. =over 4 -=item C - -Creates a new instance. Does not read the configuration. - -=item C - -Reads the configuration from the database. Returns C<$self>. - =item C Returns an array of configured currencies. -=item C - -Returns the default currency or undef if no currency has been -configured. - -=item C - -Returns the default accounting method, accrual or cash - -=item C - -Returns the default inventory system, perpetual or periodic - -=item C - -Returns the default profit determination method, balance or income - =back =head1 BUGS