From 159dd37836728abbb2caca3cb25904428ed99859 Mon Sep 17 00:00:00 2001 From: Thomas Heck Date: Tue, 21 Aug 2012 10:15:38 +0200 Subject: [PATCH] CSV-Import: Projekte implementiert #1907 --- SL/Controller/CsvImport.pm | 5 +- SL/Controller/CsvImport/Project.pm | 76 ++++++++++++++++++++++++++++++ SL/DB/Project.pm | 6 +++ locale/de/all | 7 +-- menu.ini | 4 ++ 5 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 SL/Controller/CsvImport/Project.pm diff --git a/SL/Controller/CsvImport.pm b/SL/Controller/CsvImport.pm index e603faa40..d924f07d9 100644 --- a/SL/Controller/CsvImport.pm +++ b/SL/Controller/CsvImport.pm @@ -11,6 +11,7 @@ use SL::Controller::CsvImport::Contact; use SL::Controller::CsvImport::CustomerVendor; use SL::Controller::CsvImport::Part; use SL::Controller::CsvImport::Shipto; +use SL::Controller::CsvImport::Project; use List::MoreUtils qw(none); @@ -99,7 +100,7 @@ sub check_auth { sub check_type { my ($self) = @_; - die "Invalid CSV import type" if none { $_ eq $::form->{profile}->{type} } qw(parts customers_vendors addresses contacts); + die "Invalid CSV import type" if none { $_ eq $::form->{profile}->{type} } qw(parts customers_vendors addresses contacts projects); $self->type($::form->{profile}->{type}); } @@ -141,6 +142,7 @@ sub render_inputs { : $self->type eq 'addresses' ? $::locale->text('CSV import: shipping addresses') : $self->type eq 'contacts' ? $::locale->text('CSV import: contacts') : $self->type eq 'parts' ? $::locale->text('CSV import: parts and services') + : $self->type eq 'projects' ? $::locale->text('CSV import: projects') : die; if ($self->{type} eq 'parts') { @@ -258,6 +260,7 @@ sub create_worker { : $self->{type} eq 'contacts' ? SL::Controller::CsvImport::Contact->new( controller => $self, file => $file) : $self->{type} eq 'addresses' ? SL::Controller::CsvImport::Shipto->new( controller => $self, file => $file) : $self->{type} eq 'parts' ? SL::Controller::CsvImport::Part->new( controller => $self, file => $file) + : $self->{type} eq 'projects' ? SL::Controller::CsvImport::Project->new( controller => $self, file => $file) : die "Program logic error"; } diff --git a/SL/Controller/CsvImport/Project.pm b/SL/Controller/CsvImport/Project.pm new file mode 100644 index 000000000..8367fbe3a --- /dev/null +++ b/SL/Controller/CsvImport/Project.pm @@ -0,0 +1,76 @@ +package SL::Controller::CsvImport::Project; + +use strict; + +use SL::Helper::Csv; +use SL::DB::CustomVariable; +use SL::DB::CustomVariableConfig; + +use parent qw(SL::Controller::CsvImport::Base); + +use Rose::Object::MakeMethods::Generic +( + scalar => [ qw(table) ], +); + +sub init_class { + my ($self) = @_; + $self->class('SL::DB::Project'); +} + +sub init_all_cvar_configs { + my ($self) = @_; + + return SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'Projects' ]); +} + +sub check_objects { + my ($self) = @_; + + foreach my $entry (@{ $self->controller->data }) { + $self->handle_cvars($entry); + } + + $self->add_cvar_raw_data_columns; +} + +sub check_duplicates { + my $self = shift; + + my %duplicates_by_number; + + if ( $self->controller->profile->get('duplicates') eq 'check_db' ) { + foreach my $object (@{$self->existing_objects}) { + $duplicates_by_number{$object->{projectnumber}} = 'db'; + } + } + + foreach my $entry (@{ $self->controller->data }) { + + my $object = $entry->{object}; + + if ( $duplicates_by_number{$object->projectnumber()} ) + { + push( @{$entry->{errors}}, + $duplicates_by_number{$object->projectnumber()} eq 'db' ? $::locale->text('Duplicate in database') : $::locale->text('Duplicate in CSV file') + ); + } else { + $duplicates_by_number{$object->projectnumber()} = 'csv'; + } + + } +} + +sub setup_displayable_columns { + my ($self) = @_; + + $self->SUPER::setup_displayable_columns; + $self->add_cvar_columns_to_displayable_columns; + + $self->add_displayable_columns({ name => 'projectnumber', description => $::locale->text('number') }, + { name => 'description', description => $::locale->text('Description') }, + { name => 'active', description => $::locale->text('Active') }, + ); +} + +1; diff --git a/SL/DB/Project.pm b/SL/DB/Project.pm index 4b93c5ac7..1d1f1c4a8 100644 --- a/SL/DB/Project.pm +++ b/SL/DB/Project.pm @@ -4,7 +4,13 @@ use strict; use SL::DB::MetaSetup::Project; +use SL::DB::Helper::CustomVariables( + module => 'Project', + cvars_alias => 1, +); + __PACKAGE__->meta->make_manager_class; +__PACKAGE__->meta->initialize; 1; diff --git a/locale/de/all b/locale/de/all index 394de3295..8060572ed 100644 --- a/locale/de/all +++ b/locale/de/all @@ -333,6 +333,7 @@ $self->{texts} = { 'CSV import: contacts' => 'CSV-Import: Ansprechpersonen', 'CSV import: customers and vendors' => 'CSV-Import: Kunden und Lieferanten', 'CSV import: parts and services' => 'CSV-Import: Waren und Dienstleistungen', + 'CSV import: projects' => 'CSV-Import: Projekte', 'CSV import: shipping addresses' => 'CSV-Import: Lieferadressen', 'Calculate' => 'Berechnen', 'Calendar' => 'Kalender', @@ -941,8 +942,6 @@ $self->{texts} = { 'If you select a base unit then you also have to enter a factor.' => 'Wenn Sie eine Basiseinheit auswählen, dann müssen Sie auch einen Faktor eingeben.', 'If you want to change any of these parameters then press the "Back" button, edit the file "config/lx_office.conf" and login into the admin module again.' => 'Wenn Sie einen der Parameter ändern wollen, so drücken Sie auf den "Zurück"-Button, bearbeiten Sie die Datei "config/lx_office.conf", und melden Sie sich erneut im Administrationsbereich an.', 'If you want to delete such a dataset you have to edit the user(s) that are using the dataset in question and have them use another dataset.' => 'Wenn Sie eine solche Datenbank löschen wollen, so müssen Sie zuerst die Benutzer bearbeiten, die die fragliche Datenbank benutzen, und sie so ändern, dass sie eine andere Datenbank benutzen.', - 'If you want to set up the authentication database yourself then log in to the administration panel. kivitendo will then create the database and tables for you.' => 'Wenn Sie die Authentifizierungsdatenbank selber einrichten wollen, so melden Sie sich an der Administrationsoberfläche an. kivitendo wird dann die Datenbank und die Tabellen für Sie anlegen.', - 'If you yourself want to upgrade the installation then please read the file "doc/UPGRADE" and follow the steps outlined in this file.' => 'Wenn Sie selber die Aktualisierung bzw. Einrichtung übernehmen wollen, so lesen Sie bitte die Datei "doc/UPGRADE" und folgen Sie den dort beschriebenen Schritten.', 'Image' => 'Grafik', 'Import' => 'Import', 'Import CSV' => 'CSV-Import', @@ -969,6 +968,7 @@ $self->{texts} = { 'Incoming Payments' => 'Zahlungseingänge', 'Incoming invoice number' => 'Eingangsrechnungsnummer', 'Incorrect Password!' => 'Ungültiges Passwort!', + 'Incorrect password!' => '', 'Incorrect username or password!' => 'Ungültiger Benutzername oder falsches Passwort!', 'Increase' => 'Erhöhen', 'Individual Items' => 'Einzelteile', @@ -1798,8 +1798,6 @@ $self->{texts} = { 'The application "#1" was not found on the system.' => 'Die Anwendung "#1" wurde auf dem System nicht gefunden.', 'The assembly has been created.' => 'Das Erzeugnis wurde hergestellt.', 'The assistant could not find anything wrong with #1. Maybe the problem has been solved in the meantime.' => 'Der Korrekturassistent konnte kein Problem bei #1 feststellen. Eventuell wurde das Problem in der Zwischenzeit bereits behoben.', - 'The authentication configuration file "config/lx_office.conf" does not exist. This kivitendo installation has probably not been updated correctly yet. Please contact your administrator.' => '', - 'The authentication database is not reachable at the moment. Either it hasn\'t been set up yet or the database server might be down. Please contact your administrator.' => 'Die Authentifizierungsdatenbank kann momentan nicht erreicht werden. Entweder wurde sie noch nicht eingerichtet, oder der Datenbankserver antwortet nicht. Bitte wenden Sie sich an Ihren Administrator.', 'The available options depend on the varibale type:' => 'Die verfügbaren Optionen hängen vom Variablentypen ab:', 'The backup you upload here has to be a file created with "pg_dump -o -Ft".' => 'Die von Ihnen hochzuladende Sicherungsdatei muss mit dem Programm und den Parametern "pg_dump -o -Ft" erstellt worden sein.', 'The bank information must not be empty.' => 'Die Bankinformationen müssen vollständig ausgefüllt werden.', @@ -2148,7 +2146,6 @@ $self->{texts} = { 'You cannot continue until all unknown units have been mapped to known ones.' => 'Sie können nicht fortfahren, bis alle unbekannten Einheiten in neue Einheiten umgewandelt wurden.', 'You cannot create an invoice for delivery orders for different customers.' => 'Sie können keine Rechnung zu Lieferscheinen für verschiedene Kunden erstellen.', 'You cannot create an invoice for delivery orders from different vendors.' => 'Sie können keine Rechnung aus Lieferscheinen von verschiedenen Lieferanten erstellen.', - 'You did not enter a name!' => 'Sie haben keinen Namen eingegeben!', 'You do not have the permissions to access this function.' => 'Sie verfügen nicht über die notwendigen Rechte, um auf diese Funktion zuzugreifen.', 'You have entered or selected the following shipping address for this customer:' => 'Sie haben die folgende Lieferadresse eingegeben oder ausgewählt:', 'You have not added bank accounts yet.' => 'Sie haben noch keine Bankkonten angelegt.', diff --git a/menu.ini b/menu.ini index 587376bf3..0f8a3e453 100644 --- a/menu.ini +++ b/menu.ini @@ -758,6 +758,10 @@ module=controller.pl action=CsvImport/new profile.type=parts +[System--Import CSV--Projects] +module=controller.pl +action=CsvImport/new +profile.type=projects [System--Templates] ACCESS=admin -- 2.20.1