From: Niclas Zimmermann Date: Fri, 22 Feb 2013 13:58:36 +0000 (+0100) Subject: Merge branch 'tax_festsetzen' X-Git-Tag: release-3.1.0beta1~608^2 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=7ff9fa05e670aa2e5fa76b9d8d0b39ea66a74dd1;hp=1672583af0518aaa1b73d3fb0a7e4a07d5329ffc;p=kivitendo-erp.git Merge branch 'tax_festsetzen' --- diff --git a/locale/de/all b/locale/de/all index 1e8bbdd92..d88e2ec70 100644 --- a/locale/de/all +++ b/locale/de/all @@ -20,9 +20,11 @@ $self->{texts} = { '*) Since version 2.7 these parameters ares set in the client database and not in the configuration file, details in chapter:' => '*) Seit 2.7 werden Gewinnermittlungsart, Versteuerungsart und Warenbuchungsmethode in der Mandanten-DB gesteuert und nicht mehr in der Konfigurationsdatei, Umstellungs-Details:', '*/' => '*/', '---please select---' => '---bitte auswählen---', + '. Automatically generated.' => '. Automatisch erzeugt.', '...after loggin in' => '...nach dem Anmelden', '...done' => '...fertig', '...on the TODO list' => '...auf der Aufgabenliste', + '0% tax with taxkey' => '0% Steuer mit Steuerschlüssel ', '1. Quarter' => '1. Quartal', '2. Quarter' => '2. Quartal', '3. Quarter' => '3. Quartal', @@ -1008,6 +1010,7 @@ $self->{texts} = { 'Income accno' => 'Erlöskonto', 'Incoming Payments' => 'Zahlungseingänge', 'Incoming invoice number' => 'Eingangsrechnungsnummer', + 'Inconsistency in database' => 'Unstimmigkeiten in der Datenbank', 'Incorrect Password!' => 'Ungültiges Passwort!', 'Incorrect password!' => 'Ungültiges Passwort!', 'Incorrect username or password!' => 'Ungültiger Benutzername oder falsches Passwort!', @@ -1417,6 +1420,7 @@ $self->{texts} = { 'Please Check the bank information for each vendor:' => 'Bitte überprüfen Sie die Kontoinformationen der Lieferanten:', 'Please ask your administrator to create warehouses and bins.' => 'Bitten Sie Ihren Administrator, dass er Lager und Lagerplätze anlegt.', 'Please contact your administrator.' => 'Bitte wenden Sie sich an Ihren Administrator.', + 'Please define a taxkey for the following taxes and run the update again:' => 'Bitte definieren Sie einen Steuerschlüssel für die folgenden Steuern und starten Sie dann das Update erneut:', 'Please enter a profile name.' => 'Bitte geben Sie einen Profilnamen an.', 'Please enter the login for the new user.' => 'Bitte geben Sie das Login für den neuen Benutzer ein.', 'Please enter the name of the database that will be used as the template for the new database:' => 'Bitte geben Sie den Namen der Datenbank an, die als Vorlage für die neue Datenbank benutzt wird:', @@ -1440,6 +1444,7 @@ $self->{texts} = { 'Please select the destination bank account for the collections:' => 'Bitte wählen Sie das Bankkonto als Ziel für die Einzüge aus:', 'Please select the source bank account for the transfers:' => 'Bitte wählen Sie das Bankkonto als Quelle für die Überweisungen aus:', 'Please seletct the dataset you want to delete:' => 'Bitte wählen Sie die zu löschende Datenbank aus:', + 'Please set another taxnumber for the following taxes and run the update again:' => 'Bitte wählen Sie ein anderes Steuerautomatik-Konto für die folgenden Steuern aus uns starten Sie dann das Update erneut.', 'Please specify a description for the warehouse designated for these goods.' => 'Bitte geben Sie den Namen des Ziellagers für die übernommenen Daten ein.', 'Plural' => 'Plural', 'Port' => 'Port', @@ -2053,7 +2058,9 @@ $self->{texts} = { 'There are #1 more open invoices from this vendor with other currencies.' => 'Es gibt #1 weitere offene Rechnungen von diesem Lieferanten, die in anderen Währungen ausgestellt wurden.', 'There are #1 unfinished follow-ups of which #2 are due.' => 'Es gibt #1 Wiedervorlage(n), von denen #2 fällig ist/sind.', 'There are bookings to the account 3803 after 01.01.2007. If you didn\'t change this account manually to 19% the bookings are probably incorrect.' => 'Das Konto 3803 wurde nach dem 01.01.2007 bebucht. Falls Sie dieses Konto nicht manuell auf 19% gestellt haben sind die Buchungen wahrscheinlich mit falscher Umsatzsteuer gebucht worden.', + 'There are entries in tax where taxkey is NULL.' => 'In der Datenbank sind Steuern ohne Steuerschlüssel vorhanden (in der Tabelle tax Spalte taxkey).', 'There are four tax zones.' => 'Es gibt vier Steuerzonen.', + 'There are invalid taxnumbers in use.' => 'Es werden ungültige Steuerautomatik-Konten benutzt.', 'There are no entries in the background job history.' => 'Es gibt keine Einträge im Hintergrund-Job-Verlauf.', 'There are no items in stock.' => 'Dieser Artikel ist nicht eingelagert.', 'There are no items on your TODO list at the moment.' => 'Ihre Aufgabenliste enthält momentan keine Einträge.', @@ -2061,6 +2068,7 @@ $self->{texts} = { 'There are still transfers not matching the qty of the delivery order. Stock operations can not be changed later. Do you really want to proceed?' => 'Einige der Lagerbewegungen sind nicht vollständig und Lagerbewegungen können nachträglich nicht mehr verändert werden. Wollen Sie wirklich fortfahren?', 'There are usually three ways to install Perl modules.' => 'Es gibt normalerweise drei Arten, ein Perlmodul zu installieren.', 'There is already a taxkey 0 with tax rate not 0.' => 'Es existiert bereits ein Steuerschlüssel mit Steuersatz ungleich 0%.', + 'There is an inconsistancy in your database.' => 'In Ihrer Datenbank sind Unstimmigkeiten vorhanden.', 'There is at least one sales or purchase invoice for which kivitendo recorded an inventory transaction with taxkeys even though no tax was recorded.' => 'Es gibt mindestens eine Verkaufs- oder Einkaufsrechnung, für die kivitendo eine Warenbestandsbuchung ohne dazugehörige Steuerbuchung durchgeführt hat.', 'There is at least one transaction for which the user has chosen a logically wrong taxkey.' => 'Es gibt mindestens eine Buchung, bei der ein logisch nicht passender Steuerschlüssel ausgewählt wurde.', 'There is not enough available of \'#1\' at warehouse \'#2\', bin \'#3\', #4, #5, for the transfer of #6.' => 'Von \'#1\' ist in Lager \'#2\', Lagerplatz \'#3\', #4, #5, nicht genügend eingelagert, um insgesamt #6 auszulagern.', diff --git a/locale/en/all b/locale/en/all index d39b9aeb1..3424a0158 100644 --- a/locale/en/all +++ b/locale/en/all @@ -20,9 +20,11 @@ $self->{texts} = { '*) Since version 2.7 these parameters ares set in the client database and not in the lx-erp.conf / lx_office.conf file, details in chapter:' => '', '*/' => '', '---please select---' => '', + '. Automatically generated.' => '', '...after loggin in' => '', '...done' => '', '...on the TODO list' => '', + '0% tax with taxkey' => '', '1. Quarter' => '', '2. Quarter' => '', '3. Quarter' => '', @@ -1986,13 +1988,17 @@ $self->{texts} = { 'There are #1 more open invoices from this vendor with other currencies.' => '', 'There are #1 unfinished follow-ups of which #2 are due.' => '', 'There are bookings to the account 3803 after 01.01.2007. If you didn\'t change this account manually to 19% the bookings are probably incorrect.' => '', + 'There are entries in tax where taxkey is NULL.' => '', 'There are four tax zones.' => '', + 'There are invalid taxnumbers in use.' => '', + 'There are no entries in the background job history.' => '', 'There are no items in stock.' => '', 'There are no items on your TODO list at the moment.' => '', 'There are still entries in the database for which no unit has been assigned.' => '', 'There are still transfers not matching the qty of the delivery order. Stock operations can not be changed later. Do you really want to proceed?' => '', 'There are usually three ways to install Perl modules.' => '', 'There is already a taxkey 0 with tax rate not 0.' => '', + 'There is an inconsistancy in your database.' => '', 'There is at least one sales or purchase invoice for which kivitendo recorded an inventory transaction with taxkeys even though no tax was recorded.' => '', 'There is at least one transaction for which the user has chosen a logically wrong taxkey.' => '', 'There is not enough available of \'#1\' at warehouse \'#2\', bin \'#3\', #4, #5, for the transfer of #6.' => '', diff --git a/sql/Pg-upgrade2/add_tax_id_to_acc_trans.sql b/sql/Pg-upgrade2/add_tax_id_to_acc_trans.sql index 7e8b766c7..06047b535 100644 --- a/sql/Pg-upgrade2/add_tax_id_to_acc_trans.sql +++ b/sql/Pg-upgrade2/add_tax_id_to_acc_trans.sql @@ -1,6 +1,6 @@ -- @tag: add_tax_id_to_acc_trans -- @description: Neue Spalte tax_id in der acc_trans --- @depends: release_2_7_0 +-- @depends: release_3_0_0 charts_without_taxkey -- @charset: utf-8 --Neue Spalte tax_id in acc_trans: diff --git a/sql/Pg-upgrade2/tax_constraints.pl b/sql/Pg-upgrade2/tax_constraints.pl new file mode 100644 index 000000000..70fe83d35 --- /dev/null +++ b/sql/Pg-upgrade2/tax_constraints.pl @@ -0,0 +1,304 @@ +# @tag: tax_constraints +# @description: Setzt Fremdschlüssel und andere constraints auf die Tabellen tax und taxkeys +# @depends: release_3_0_0 charts_without_taxkey +# @charset: utf-8 + +use utf8; +use strict; +use SL::Locale; + +die("This script cannot be run from the command line.") unless ($main::form); + +sub mydberror { + my ($msg) = @_; + die($dbup_locale->text("Database update error:") . "
$msg
" . $DBI::errstr); +} + +sub do_query { + my ($query, $may_fail) = @_; + + if (!$dbh->do($query)) { + mydberror($query) unless ($may_fail); + $dbh->rollback(); + $dbh->begin_work(); + } +} + +sub do_update { + #CHECK CONSISTANCY OF tax + #update tax.rate and tax.taxdescription in order to set later NOT NULL constraints + my $query= <selectrow_array($query); + + if ($invalid_tax_account > 0){ + #list all invalid tax accounts + $query = <prepare($query); + $sth->execute || $main::form->dberror($query); + + $main::form->{TAX} = []; + while (my $ref = $sth->fetchrow_hashref("NAME_lc")) { + push @{ $main::form->{TAX} }, $ref; + } + $sth->finish; + + $main::form->{invalid_tax_account} = 1; + print_error_message(); + return 0; + } + + #check entry tax.taxkey of NOT NULL + $query= <selectrow_array($query); + + if ($taxkey_is_null > 0){ + #list all invalid tax accounts + $query = <prepare($query); + $sth->execute || $main::form->dberror($query); + + $main::form->{TAX} = []; + while (my $ref = $sth->fetchrow_hashref("NAME_lc")) { + push @{ $main::form->{TAX} }, $ref; + } + $sth->finish; + + $main::form->{taxkey_is_null} = 1; + print_error_message(); + return 0; + } + #END CHECK OF tax + + #CHECK CONSISTANCY OF taxkeys + #delete invalide entries in taxkeys + $query= <prepare($query); + $sth->execute || $main::form->dberror($query); + + $main::form->{TAXID} = []; + my $rowcount = 0; + while (my $ref = $sth->fetchrow_hashref("NAME_lc")) { + push @{ $main::form->{TAXID} }, $ref; + $rowcount++; + } + $sth->finish; + + my $insertquery; + my $updatequery; + my $tax_id; + for my $i (0 .. $rowcount-1){ + $query= qq| + SELECT id FROM tax WHERE rate = 0 and taxkey=| . $main::form->{TAXID}[$i]->{taxkey_id} . qq| LIMIT 1 +|; + ($tax_id) = $dbh->selectrow_array($query); + if ( not $tax_id ){ + $insertquery=qq| + INSERT INTO tax (rate, taxdescription, taxkey) VALUES (0, '| . $::locale->text('0% tax with taxkey') . $main::form->{TAXID}[$i]->{taxkey_id} . $::locale->text('. Automatically generated.') . + qq|', | . $main::form->{TAXID}[$i]->{taxkey_id} . qq|); +|; + do_query($insertquery); + ($tax_id) = $dbh->selectrow_array($query); + $tax_id || $main::form->dberror($query); + } + $updatequery = qq| + UPDATE taxkeys SET tax_id= | . $tax_id . qq| WHERE taxkey_id = | . $main::form->{TAXID}[$i]->{taxkey_id} . qq| AND tax_id IS NULL +|; + do_query($updatequery); + } + + #The triple taxkey_id, chart_id, startdate in taxkeys has to be unique + #Select these entries: + $query= < 1; +SQL + + $sth = $dbh->prepare($query); + $sth->execute || $main::form->dberror($query); + + $main::form->{TAXKEYS} = []; + $rowcount = 0; + while (my $ref = $sth->fetchrow_hashref("NAME_lc")) { + push @{ $main::form->{TAXKEYS} }, $ref; + $rowcount++; + } + $sth->finish; + + for my $i (0 .. $rowcount-1){ + $query= qq| + DELETE FROM taxkeys tk1 + WHERE (SELECT count(*) + FROM taxkeys tk2 + WHERE tk2.chart_id = tk1.chart_id + AND tk2.startdate = tk1.startdate) > 1 + AND NOT tk1.id = (SELECT id + FROM taxkeys + WHERE chart_id = | . $main::form->{TAXKEYS}[$i]->{chart_id} . qq| + AND startdate = '| . $main::form->{TAXKEYS}[$i]->{startdate} . qq|' + LIMIT 1) +|; + + do_query($query); + } + + #END CHECK OF taxkeys + + #ADD CONSTRAINTS: + #Now the database is consistent, so we can add constraints: + #Crate NOT NULL constraint for tax.rate with default value 0 + $query= <parse_html_template("dbupgrade/tax_constraints"); +} + +return do_update(); diff --git a/templates/webpages/dbupgrade/tax_constraints.html b/templates/webpages/dbupgrade/tax_constraints.html new file mode 100644 index 000000000..085e9fb15 --- /dev/null +++ b/templates/webpages/dbupgrade/tax_constraints.html @@ -0,0 +1,53 @@ +[%- USE T8 %] +[% USE HTML %]
[% 'Inconsistency in database' | $T8 %]
+ +
+ + +

[% 'There is an inconsistancy in your database.' | $T8 %]

+

[% 'Please contact your administrator.' | $T8 %]

+ +[% IF invalid_tax_account %] +

[% 'There are invalid taxnumbers in use.' | $T8 %]

+

[% 'Please set another taxnumber for the following taxes and run the update again:' | $T8 %]

+ + + + + + + + [% SET row_odd = '1' %][% FOREACH row = TAX %] + + + + + + [% END %] +
[% 'tax_taxkey' | $T8 %][% 'tax_taxdescription' | $T8 %][% 'tax_rate' | $T8 %]
[% HTML.escape(row.taxkey) %] [% HTML.escape(row.taxdescription) %][% HTML.escape(row.rate) %] %
+ +[% END %] + +[% IF taxkey_is_null %] +

[% 'There are entries in tax where taxkey is NULL.' | $T8 %]

+

[% 'Please define a taxkey for the following taxes and run the update again:' | $T8 %]

+ + + + + + + + + [% SET row_odd = '1' %][% FOREACH row = TAX %] + + + + + + + [% END %] +
[% 'tax_taxdescription' | $T8 %][% 'tax_rate' | $T8 %][% 'taxnumber' | $T8 %][% 'account_description' | $T8 %]
[% HTML.escape(row.taxdescription) %][% HTML.escape(row.rate) %] %[% HTML.escape(row.taxnumber) %][% HTML.escape(row.account_description) %]
+ +[% END %] +