From: Moritz Bunkus Date: Mon, 4 Dec 2006 11:35:18 +0000 (+0000) Subject: Datenbankupgrade: In der Tabelle defaults wird jetzt auch der verwendete Kontenrahmen... X-Git-Tag: release-2.4.0^2~128 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=89c9d0aafa8b2a1ae33bc590c8dafb0edc9a428c;p=kivitendo-erp.git Datenbankupgrade: In der Tabelle defaults wird jetzt auch der verwendete Kontenrahmen gespeichert. Dieser wird beim Anlegen der Datenbank eingetragen. Das Datenbankupgrade versucht, den Kontenrahmen zu erraten und fragt im Zweifelsfall beim Benutzer nach. --- diff --git a/SL/User.pm b/SL/User.pm index 24774db20..62bc94f6d 100644 --- a/SL/User.pm +++ b/SL/User.pm @@ -388,6 +388,9 @@ sub dbcreate { $filename = qq|sql/$form->{chart}-chart.sql|; $self->process_query($form, $dbh, $filename); + $query = "UPDATE defaults SET coa = " . $dbh->quote($form->{"chart"}); + $dbh->do($query) || $form->dberror($query); + $dbh->disconnect; $main::lxdebug->leave_sub(); diff --git a/locale/de/Pg-upgrade-2.2.0.27-2.2.0.28 b/locale/de/Pg-upgrade-2.2.0.27-2.2.0.28 new file mode 100644 index 000000000..4375fec51 --- /dev/null +++ b/locale/de/Pg-upgrade-2.2.0.27-2.2.0.28 @@ -0,0 +1,15 @@ +$self{texts} = { + 'Database update error:' => 'Database update error:', +}; + +$self{subs} = { + 'look_for_accno' => 'look_for_accno', + 'mydberror' => 'mydberror', + 'myshowerror' => 'myshowerror', + 'update_defaults_add_coa' => 'update_defaults_add_coa', + 'update_defaults_set_coa' => 'update_defaults_set_coa', + 'update_guess_chart_of_accounts' => 'update_guess_chart_of_accounts', + 'weiter' => 'continue', +}; + +1; diff --git a/locale/de/all b/locale/de/all index 0be3e02d3..0029a37f1 100644 --- a/locale/de/all +++ b/locale/de/all @@ -212,6 +212,7 @@ aktualisieren wollen?', 'Change Password' => 'Passwort ändern', 'Character Set' => 'Zeichensatz', 'Chart of Accounts' => 'Kontenübersicht', + 'Chart of accounts' => 'Kontenrahmen', 'Check' => 'Scheck', 'Checks' => 'Schecks', 'Choose Customer' => 'Endkunde wählen:', @@ -711,6 +712,7 @@ gestartet', 'Please insert your longdescription below' => 'Bitte den Langtext eingeben', 'Please select a customer from the list below.' => 'Bitte einen Endkunden aus der Liste auswählen', 'Please select a vendor from the list below.' => 'Bitte einen Händler aus der Liste auswählen', + 'Please select the chart of accounts this installation is using from the list below.' => 'Bitte wählen Sie den Kontenrahmen aus, der bei dieser Installation verwendet wird.', 'Port' => 'Port', 'Port missing!' => 'Portangabe fehlt!', 'Post' => 'Buchen', @@ -836,6 +838,7 @@ gestartet', 'Select from one of the names below' => 'Wählen Sie einen der untenstehenden Namen', 'Select from one of the projects below' => 'Wählen Sie eines der untenstehenden Projekte', 'Select postscript or PDF!' => 'Postscript oder PDF auswählen!', + 'Select the chart of accounts in use' => 'Benutzten Kontenrahmen auswählen', 'Sell Price' => 'Verkaufspreis', 'Sep' => 'Sep', 'September' => 'September', diff --git a/sql/Pg-upgrade/Pg-upgrade-2.2.0.27-2.2.0.28.pl b/sql/Pg-upgrade/Pg-upgrade-2.2.0.27-2.2.0.28.pl new file mode 100644 index 000000000..473186707 --- /dev/null +++ b/sql/Pg-upgrade/Pg-upgrade-2.2.0.27-2.2.0.28.pl @@ -0,0 +1,86 @@ +#!/usr/bin/perl + +die("This script cannot be run from the command line.") unless ($main::form); + +sub mydberror { + my ($dbup_locale, $msg) = @_; + die($dbup_locale->text("Database update error:") . + "
$msg
" . $DBI::errstr); +} + +sub myshowerror { + my ($msg) = @_; + + print($main::form->parse_html_template("dbupgrade/units_error", + { "message" => $msg })); + return 2; +} + +sub update_defaults_add_coa { + if ($dbh->do("ALTER TABLE defaults ADD COLUMN coa text")) { + $dbh->commit(); + } else { + $dbh->rollback(); + } + $dbh->begin_work(); +} + +sub update_defaults_set_coa { + my ($coa) = @_; + + $dbh->do("UPDATE defaults SET coa = " . $dbh->quote($coa)); + + return 1; +} + +sub look_for_accno { + my ($accno) = @_; + + my ($result) = + $dbh->selectrow_array("SELECT COUNT(*) FROM chart WHERE accno = " . + $dbh->quote($accno)); + + return $result; +} + +sub update_guess_chart_of_accounts { + update_defaults_add_coa(); + + my $form = $main::form; + + my @valid_coas = map({ s/^sql\///; s/-chart.sql//; $_; } ); + $main::lxdebug->dump(0, "mufti", \@valid_coas); + + my $query = "SELECT coa FROM defaults"; + my ($coa) = $dbh->selectrow_array($query); + + return 1 if (grep({ $coa eq $_ } @valid_coas)); + + return update_defaults_set_coa("Germany-DATEV-SKR04EU") + if (look_for_accno("0135")); + + return update_defaults_set_coa("Germany-DATEV-SKR03EU") + if (look_for_accno("0027")); + + return update_defaults_set_coa("Austria") + if (look_for_accno("0625")); + + return update_defaults_set_coa("France") + if (look_for_accno("131800")); + + return update_defaults_set_coa("Swiss-German") + if (look_for_accno("21235")); + + return update_defaults_set_coa($form->{"coa"}) + if (($form->{"action2"} eq "set_coa") && + grep({ $form->{"coa"} eq $_ } @valid_coas)); + + my @coas = map(+{ "name" => $_ }, @valid_coas); + + print($form->parse_html_template("dbupgrade/coa_guess", + { "COAS" => \@coas })); + + return 2; +} + +return update_guess_chart_of_accounts(); diff --git a/sql/lx-office.sql b/sql/lx-office.sql index 6807f217f..b4f956bbc 100644 --- a/sql/lx-office.sql +++ b/sql/lx-office.sql @@ -112,6 +112,7 @@ CREATE TABLE "defaults" ( "audittrail" bool default 'f', "articlenumber" text, "servicenumber" text, + "coa" text, "itime" timestamp DEFAULT now(), "mtime" timestamp ); diff --git a/templates/webpages/dbupgrade/coa_guess_de.html b/templates/webpages/dbupgrade/coa_guess_de.html new file mode 100644 index 000000000..a7f48bc6d --- /dev/null +++ b/templates/webpages/dbupgrade/coa_guess_de.html @@ -0,0 +1,27 @@ +
Benutzten Kontenrahmen auswählen
+ +
+ + + + + + + + +

+
+ +

+ Bitte wählen Sie den Kontenrahmen aus, der bei dieser Installation verwendet wird. +

+ +

+ Kontenrahmen: + +

+ + + +
+ diff --git a/templates/webpages/dbupgrade/coa_guess_master.html b/templates/webpages/dbupgrade/coa_guess_master.html new file mode 100644 index 000000000..61eabac9e --- /dev/null +++ b/templates/webpages/dbupgrade/coa_guess_master.html @@ -0,0 +1,28 @@ +
Select the chart of accounts in use
+ +
+ + + + + + + + +

+
+ +

+ Please select the chart of accounts this installation + is using from the list below. +

+ +

+ Chart of accounts: + +

+ + + +
+