]> wagnertech.de Git - mfinanz.git/blobdiff - SL/InstanceConfiguration.pm
POD-Dokumentation aktualisiert
[mfinanz.git] / SL / InstanceConfiguration.pm
index 58025ce5792257fb20ccb5b090d498e5b9c2fc85..084f0ac94bfdfd72c7de09b07bce4187223921a2 100644 (file)
@@ -2,81 +2,73 @@ package SL::InstanceConfiguration;
 
 use strict;
 
-use SL::DBUtils;
-
-sub new {
-  my ($class) = @_;
-
-  return bless {}, $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|);
 }
 
-sub init {
-  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;
+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 get_default_currency {
+sub init_currencies {
   my ($self) = @_;
 
-  return ($self->get_currencies)[0];
+  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_currencies {
+sub init_default_currency {
   my ($self) = @_;
 
-  return $self->{currencies} ? @{ $self->{currencies} } : ();
+  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_accounting_method {
-  my ($self) = @_;
-  return $self->{data}->{accounting_method};
+sub init_crm_installed {
+  return -f (SL::System::Process->exe_dir . '/crm/Changelog');
 }
 
-sub get_inventory_system {
+sub reload {
   my ($self) = @_;
-  return $self->{data}->{inventory_system};
-}
 
-sub get_profit_determination {
-  my ($self) = @_;
-  return $self->{data}->{profit_determination};
-}
+  delete @{ $self }{qw(data currencies default_currency)};
 
-sub get_datev_check_on_sales_invoice {
-  my ($self) = @_;
-  return $self->{data}->{datev_check_on_sales_invoice};
+  return $self;
 }
 
-sub get_datev_check_on_purchase_invoice {
+sub get_currencies {
   my ($self) = @_;
-  return $self->{data}->{datev_check_on_purchase_invoice};
+  return @{ $self->currencies };
 }
 
-sub get_datev_check_on_ar_transaction {
-  my ($self) = @_;
-  return $self->{data}->{datev_check_on_ar_transaction};
-}
+sub AUTOLOAD {
+  our $AUTOLOAD;
 
-sub get_datev_check_on_ap_transaction {
-  my ($self) = @_;
-  return $self->{data}->{datev_check_on_ap_transaction};
-}
+  my $self   =  shift;
+  my $method =  $AUTOLOAD;
+  $method    =~ s/.*:://;
 
-sub get_datev_check_on_gl_transaction {
-  my ($self) = @_;
-  return $self->{data}->{datev_check_on_gl_transaction};
-}
+  return if $method eq 'DESTROY';
 
-sub get_show_bestbefore {
-  my ($self) = @_;
-  return $self->{data}->{show_bestbefore};
+  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;
@@ -93,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>.
@@ -102,59 +94,10 @@ C<$::instance_conf>.
 
 =over 4
 
-=item C<new>
-
-Creates a new instance. Does not read the configuration.
-
-=item C<init>
-
-Reads the configuration from the database. Returns C<$self>.
-
 =item C<get_currencies>
 
 Returns an array of configured currencies.
 
-=item C<get_default_currency>
-
-Returns the default currency or undef if no currency has been
-configured.
-
-=item C<get_accounting_method>
-
-Returns the default accounting method, accrual or cash
-
-=item C<get_inventory_system>
-
-Returns the default inventory system, perpetual or periodic
-
-=item C<get_profit_determination>
-
-Returns the default profit determination method, balance or income
-
-=item C<get_datev_check_on_sales_invoice>
-
-Returns true if datev check should be performed on sales invoices
-
-=item C<get_datev_check_on_purchase_invoice>
-
-Returns true if datev check should be performed on purchase invoices
-
-=item C<get_datev_check_on_ar_transaction>
-
-Returns true if datev check should be performed on ar transactions
-
-=item C<get_datev_check_on_ap_transaction>
-
-Returns true if datev check should be performed on ap transactions
-
-=item C<get_datev_check_on_gl_transaction>
-
-Returns true if datev check should be performed on gl transactions
-
-=item C<get_show_bestbefore>
-
-Returns the default behavior for showing best before date, true or false
-
 =back
 
 =head1 BUGS