--- /dev/null
+package SL::DB::CsvImportProfile;
+
+use strict;
+
+use List::Util qw(first);
+
+use SL::DB::MetaSetup::CsvImportProfile;
+
+__PACKAGE__->meta->add_relationship(
+ settings => {
+ type => 'one to many',
+ class => 'SL::DB::CsvImportProfileSetting',
+ column_map => { id => 'csv_import_profile_id' },
+ },
+);
+
+__PACKAGE__->meta->initialize;
+
+__PACKAGE__->meta->make_manager_class;
+
+__PACKAGE__->before_save('_before_save_unset_default_on_others');
+
+#
+# public functions
+#
+
+sub set {
+ my ($self, %params) = @_;
+
+ while (my ($key, $value) = each %params) {
+ my $setting = $self->_get_setting($key);
+
+ if (!$setting) {
+ $setting = SL::DB::CsvImportProfileSetting->new(key => $key);
+ $self->add_settings($setting);
+ }
+
+ $setting->value($value);
+ }
+
+ return $self;
+}
+
+sub get {
+ my ($self, $key, $default) = @_;
+
+ my $setting = $self->_get_setting($key);
+ return $setting ? $setting->value : $default;
+}
+
+#
+# hooks
+#
+
+sub _before_save_unset_default_on_others {
+ my ($self) = @_;
+
+ if ($self->is_default) {
+ SL::DB::Manager::CsvImportProfile->update_all(set => { is_default => 0 },
+ where => [ type => $self->type,
+ '!id' => $self->id ]);
+ }
+
+ return 1;
+}
+
+#
+# helper functions
+#
+
+sub _get_setting {
+ my ($self, $key) = @_;
+ return first { $_->key eq $key } @{ $self->settings };
+}
+
+1;
--- /dev/null
+# This file has been auto-generated only because it didn't exist.
+# Feel free to modify it at will; it will not be overwritten automatically.
+
+package SL::DB::CsvImportProfileSetting;
+
+use strict;
+
+use SL::DB::MetaSetup::CsvImportProfileSetting;
+
+# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all.
+__PACKAGE__->meta->make_manager_class;
+
+1;
use SL::DB::Business;
use SL::DB::Chart;
use SL::DB::Contact;
+use SL::DB::CsvImportProfile;
+use SL::DB::CsvImportProfileSetting;
use SL::DB::CustomVariable;
use SL::DB::CustomVariableConfig;
use SL::DB::CustomVariableValidity;
bank_accounts => 'bank_account',
buchungsgruppen => 'buchungsgruppe',
contacts => 'contact',
+ csv_import_profiles => 'csv_import_profile',
+ csv_import_profile_settings => 'csv_import_profile_setting',
custom_variable_configs => 'custom_variable_config',
custom_variables => 'custom_variable',
custom_variables_validity => 'custom_variable_validity',
--- /dev/null
+# This file has been auto-generated. Do not modify it; it will be overwritten
+# by rose_auto_create_model.pl automatically.
+package SL::DB::CsvImportProfile;
+
+use strict;
+
+use base qw(SL::DB::Object);
+
+__PACKAGE__->meta->setup(
+ table => 'csv_import_profiles',
+
+ columns => [
+ id => { type => 'serial', not_null => 1 },
+ name => { type => 'text', not_null => 1 },
+ type => { type => 'varchar', length => 20, not_null => 1 },
+ is_default => { type => 'boolean', default => 'false' },
+ ],
+
+ primary_key_columns => [ 'id' ],
+
+ unique_key => [ 'name' ],
+);
+
+1;
+;
--- /dev/null
+# This file has been auto-generated. Do not modify it; it will be overwritten
+# by rose_auto_create_model.pl automatically.
+package SL::DB::CsvImportProfileSetting;
+
+use strict;
+
+use base qw(SL::DB::Object);
+
+__PACKAGE__->meta->setup(
+ table => 'csv_import_profile_settings',
+
+ columns => [
+ id => { type => 'serial', not_null => 1 },
+ csv_import_profile_id => { type => 'integer', not_null => 1 },
+ key => { type => 'text', not_null => 1 },
+ value => { type => 'text' },
+ ],
+
+ primary_key_columns => [ 'id' ],
+
+ unique_key => [ 'csv_import_profile_id', 'key' ],
+
+ foreign_keys => [
+ csv_import_profile => {
+ class => 'SL::DB::CsvImportProfile',
+ key_columns => { csv_import_profile_id => 'id' },
+ },
+ ],
+);
+
+1;
+;
--- /dev/null
+-- @tag: csv_import_profiles
+-- @description: CSV-Import-Profile für Stammdaten
+-- @depends: release_2_6_1
+-- @charset: utf-8
+CREATE TABLE csv_import_profiles (
+ id SERIAL NOT NULL,
+ name text NOT NULL,
+ type varchar(20) NOT NULL,
+ is_default boolean DEFAULT FALSE,
+
+ PRIMARY KEY (id),
+ UNIQUE (name)
+);
+
+CREATE TABLE csv_import_profile_settings (
+ id SERIAL NOT NULL,
+ csv_import_profile_id integer NOT NULL,
+ key text NOT NULL,
+ value text,
+
+ PRIMARY KEY (id),
+ FOREIGN KEY (csv_import_profile_id) REFERENCES csv_import_profiles (id),
+ UNIQUE (csv_import_profile_id, key)
+);