From 3ccf1a99fce36f76d43c8394b683b88ff14679ff Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 8 Nov 2012 13:50:00 +0100 Subject: [PATCH] Kontaktpersonenfeld von Freitext auf Datum umstelen Basierend auf Patch von Thomas Heck mit Verfeinerungen von mir. Implementiert #2021. --- SL/CT.pm | 13 ++- SL/DB/MetaSetup/Contact.pm | 5 +- locale/de/all | 8 ++ .../contacts_convert_cp_birthday_to_date.pl | 80 +++++++++++++++++++ templates/webpages/ct/_contact.html | 4 +- ...acts_convert_cp_birthday_to_date_form.html | 48 +++++++++++ 6 files changed, 155 insertions(+), 3 deletions(-) create mode 100644 sql/Pg-upgrade2/contacts_convert_cp_birthday_to_date.pl create mode 100644 templates/webpages/dbupgrade/contacts_convert_cp_birthday_to_date_form.html diff --git a/SL/CT.pm b/SL/CT.pm index 93c3fcea2..082afdf25 100644 --- a/SL/CT.pm +++ b/SL/CT.pm @@ -552,7 +552,18 @@ sub _save_contact { my @columns = qw(cp_title cp_givenname cp_name cp_email cp_phone1 cp_phone2 cp_abteilung cp_fax cp_mobile1 cp_mobile2 cp_satphone cp_satfax cp_project cp_privatphone cp_privatemail cp_birthday cp_gender cp_street cp_zipcode cp_city); - my @values = map { $_ eq 'cp_gender' ? ($form->{$_} eq 'f' ? 'f' : 'm') : $form->{$_} } @columns; + my @values = map( + { + if ( $_ eq 'cp_gender' ) { + $form->{$_} eq 'f' ? 'f' : 'm'; + } elsif ( $_ eq 'cp_birthday' && $form->{cp_birthday} eq '' ) { + undef; + } else { + $form->{$_}; + } + } + @columns + ); my ($query, $cp_id); if ($form->{cp_id}) { diff --git a/SL/DB/MetaSetup/Contact.pm b/SL/DB/MetaSetup/Contact.pm index 2eb4fa5e7..322f82647 100644 --- a/SL/DB/MetaSetup/Contact.pm +++ b/SL/DB/MetaSetup/Contact.pm @@ -28,9 +28,12 @@ __PACKAGE__->meta->setup( cp_project => { type => 'text' }, cp_privatphone => { type => 'text' }, cp_privatemail => { type => 'text' }, - cp_birthday => { type => 'text' }, cp_abteilung => { type => 'text' }, cp_gender => { type => 'character', length => 1 }, + cp_street => { type => 'text' }, + cp_zipcode => { type => 'text' }, + cp_city => { type => 'text' }, + cp_birthday => { type => 'date' }, ], primary_key_columns => [ 'cp_id' ], diff --git a/locale/de/all b/locale/de/all index 6ed0ddd6e..3060507a3 100644 --- a/locale/de/all +++ b/locale/de/all @@ -296,6 +296,8 @@ $self->{texts} = { 'Bins saved.' => 'Lagerplätze gespeichert.', 'Bins that have been used in the past cannot be deleted anymore. For these bins there\'s no checkbox in the "Delete" column.' => 'Lagerplätze, die bereits benutzt wurden, können nicht mehr gelöscht werden. Deswegen fehlt bei ihnen die Checkbox in der Spalte "Löschen".', 'Birthday' => 'Geburtstag', + 'Birthday (after conversion)' => 'Geburtstag (nach Umstellung)', + 'Birthday (before conversion)' => 'Geburtstag (vor Umstellung)', 'Bis' => 'bis', 'Bis Konto: ' => 'bis Konto: ', 'Block' => 'Block', @@ -446,6 +448,7 @@ $self->{texts} = { 'Contacts' => 'Ansprechpersonen', 'Continue' => 'Weiter', 'Contra' => 'gegen', + 'Conversion of "birthday" contact person attribute' => 'Umstellung des Kontaktpersonenfeldes "Geburtstag"', 'Copies' => 'Kopien', 'Correct taxkey' => 'Richtiger Steuerschlüssel', 'Corrections' => 'Korrekturen', @@ -562,6 +565,7 @@ $self->{texts} = { 'Database Administration' => 'Datenbankadministration', 'Database Connection Test' => 'Test der Datenbankverbindung', 'Database Host' => 'Datenbankcomputer', + 'Database ID' => 'Datenbank-ID', 'Database User' => 'Datenbankbenutzer', 'Database User missing!' => 'Datenbankbenutzer fehlt!', 'Database backups and restorations are disabled in the configuration.' => 'Datenbanksicherungen und -wiederherstellungen sind in der Konfiguration deaktiviert.', @@ -796,6 +800,8 @@ $self->{texts} = { 'Enter longdescription' => 'Langtext eingeben', 'Enter the abbreviations separated by a colon (i.e CAD:USD:EUR) for your native and foreign currencies' => 'Geben Sie Ihre und weitere Währungen als Abkürzungen durch Doppelpunkte getrennt ein (z.B. EUR:USD:CAD)', 'Enter the requested execution date or leave empty for the quickest possible execution:' => 'Geben Sie das jeweils gewünschte Ausführungsdatum an, oder lassen Sie das Feld leer für die schnellstmögliche Ausführung:', + 'Entries for which automatic conversion failed:' => 'Einträge, für die die automatische Umstellung fehlschlug:', + 'Entries for which automatic conversion succeeded:' => 'Einträge, für die die automatische Umstellung erfolgreich war:', 'Equity' => 'Passiva', 'Error' => 'Fehler', 'Error in database control file \'%s\': %s' => 'Fehler in Datenbankupgradekontrolldatei \'%s\': %s', @@ -1901,6 +1907,7 @@ $self->{texts} = { 'The connection to the database could not be established.' => 'Die Verbindung zur Datenbank konnte nicht hergestellt werden.', 'The connection to the template database failed:' => 'Die Verbindung zur Vorlagendatenbank schlug fehl:', 'The connection was established successfully.' => 'Die Verbindung zur Datenbank wurde erfolgreich hergestellt.', + 'The contact person attribute "birthday" is converted from a free-form text field into a date field.' => 'Das Kontaktpersonenfeld "Geburtstag" wird von einem freien Textfeld auf ein Datumsfeld umgestellt.', 'The creation of the authentication database failed:' => 'Das Anlegen der Authentifizierungsdatenbank schlug fehl:', 'The custom variable has been deleted.' => 'Die benutzerdefinierte Variable wurde gelöscht.', 'The custom variable has been saved.' => 'Die benutzerdefinierte Variable wurde gespeichert.', @@ -2059,6 +2066,7 @@ $self->{texts} = { 'This option controls the method used for profit determination.' => 'Dieser Parameter legt die Berechnungsmethode für die Gewinnermittlung fest.', 'This option controls the posting and calculation behavior for the accounting method.' => 'Dieser Parameter steuert die Buchungs- und Berechnungsmethoden für die Versteuerungsart.', 'This partnumber is not unique. You should change it.' => 'Diese Artikelnummer ist nicht eindeutig. Bitte wählen Sie eine andere.', + 'This requires you to manually correct entries for which an automatic conversion failed and to check those for which it succeeded.' => 'Dies erfordert, dass Sie diejenigen Einträge manuell korrigieren, für die die automatische Umstellung fehlschlug, sowie dass Sie diejenigen überprüfen, für die die Umstellung erfolgreich war.', 'This transaction has to be split into several transactions manually.' => 'Diese Buchung muss manuell in mehrere Buchungen aufgeteilt werden.', 'This update will change the nature the onhand of goods is tracked.' => 'Dieses update ändert die Art und Weise wie Lagermengen gezält werden.', 'This upgrade script tries to map all existing parts in the database to the newly created Buchungsgruppen.' => 'Dieses Upgradescript versucht, bei allen bestehenden Artikeln neu erstellte Buchungsgruppen zuzuordnen.', diff --git a/sql/Pg-upgrade2/contacts_convert_cp_birthday_to_date.pl b/sql/Pg-upgrade2/contacts_convert_cp_birthday_to_date.pl new file mode 100644 index 000000000..2f10670c4 --- /dev/null +++ b/sql/Pg-upgrade2/contacts_convert_cp_birthday_to_date.pl @@ -0,0 +1,80 @@ +# @tag: contacts_convert_cp_birthday_to_date +# @description: Umstellung cp_birthday von Freitext auf Datumsfeld +# @depends: release_2_7_0 +package contacts_convert_cp_birthday_to_date; +use strict; + +die 'This script cannot be run from the command line.' if !$::form; + +sub convert_to_date { + my ($str) = @_; + + return '' if !$str; + + my $sth = $dbh->prepare('SELECT ?::date AS date') or return undef; + $sth->execute($str) or return undef; + + return $sth->fetchrow_hashref->{date}; +} + +sub update { + my @data = (); + my @auto_data = (); + my $sql = <prepare($sql) or die $dbh->errstr; + $sth->execute or die $dbh->errstr; + + my $i = -1; + while (my $row = $sth->fetchrow_hashref) { + $i++; + $row->{cp_birthday} = convert_to_date($::form->{form_submitted} ? $::form->{'cp_birthday_'. $i} : $row->{cp_birthday_old}); + $row->{row_index} = $i; + + if ( defined($row->{cp_birthday}) ) { + push(@auto_data, $row); + } else { + push(@data, $row); + } + } + + $::form->{data} = \@data; + $::form->{auto_data} = \@auto_data; + $::form->{row_length} = $i; + + if (@data) { + print $::form->parse_html_template('dbupgrade/contacts_convert_cp_birthday_to_date_form'); + return 2; + } else { + $sql = <do($sql); + + $sql = <prepare($sql) or die $dbh->errstr; + + foreach (grep { $_->{cp_birthday} ne '' } @auto_data) { + $sth->execute($_->{cp_birthday}, $_->{cp_id}) or die $dbh->errstr; + } + + return 1; + } +} + +return update(); diff --git a/templates/webpages/ct/_contact.html b/templates/webpages/ct/_contact.html index 6b22e4780..2b126c62d 100644 --- a/templates/webpages/ct/_contact.html +++ b/templates/webpages/ct/_contact.html @@ -115,7 +115,9 @@ [% 'Birthday' | $T8 %] - + + [% L.date_tag('cp_birthday', cp_birthday) %] + diff --git a/templates/webpages/dbupgrade/contacts_convert_cp_birthday_to_date_form.html b/templates/webpages/dbupgrade/contacts_convert_cp_birthday_to_date_form.html new file mode 100644 index 000000000..c613264e4 --- /dev/null +++ b/templates/webpages/dbupgrade/contacts_convert_cp_birthday_to_date_form.html @@ -0,0 +1,48 @@ +[%- USE HTML %] +[%- USE L %] +[%- USE LxERP %] + +

[%- LxERP.t8('Conversion of "birthday" contact person attribute') %]

+ +

+ [%- LxERP.t8('The contact person attribute "birthday" is converted from a free-form text field into a date field.') %] + [%- LxERP.t8('This requires you to manually correct entries for which an automatic conversion failed and to check those for which it succeeded.') %] +

+ +[% BLOCK birthday_table %] + + + + + + + + + + + [% FOREACH row IN data %] + + + + + + + + + + [% END %] + +
[%- LxERP.t8('Database ID') %][%- LxERP.t8('Name') %][%- LxERP.t8('Given Name') %][%- LxERP.t8('Birthday (before conversion)') %][%- LxERP.t8('Birthday (after conversion)') %]
[% row.cp_id %][% row.cp_givenname | html %][% row.cp_name | html %][% row.cp_birthday_old | html %][% L.date_tag('cp_birthday_'_ row.row_index, row.cp_birthday) %]
+[% END %] + +
+

[%- LxERP.t8('Entries for which automatic conversion failed:') %]

+ [% PROCESS birthday_table data = data %] + +

[%- LxERP.t8('Entries for which automatic conversion succeeded:') %]

+ [% PROCESS birthday_table data = auto_data %] + + + + +
-- 2.20.1