From: Moritz Bunkus Date: Fri, 2 Feb 2007 14:37:30 +0000 (+0000) Subject: Für alle Zahlungskonditionen kann jetzt für jede Sprache eine Übersetzung speichern. X-Git-Tag: release-2.4.2~166 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=dcef6ec7d98eb0f1d05bd3ac251a0b4bc607b4c3;p=kivitendo-erp.git Für alle Zahlungskonditionen kann jetzt für jede Sprache eine Übersetzung speichern. --- diff --git a/SL/AM.pm b/SL/AM.pm index 77a5955d2..162f54fac 100644 --- a/SL/AM.pm +++ b/SL/AM.pm @@ -974,13 +974,13 @@ sub delete_language { # connect to database my $dbh = $form->dbconnect_noauto($myconfig); - my $query = "DELETE FROM units_language WHERE language_id = ?"; - $dbh->do($query, undef, $form->{"id"}) || - $form->dberror($query . " ($form->{id})"); + foreach my $table (qw(translation_payment_terms units_language)) { + my $query = qq|DELETE FROM $table WHERE language_id = ?|; + do_query($form, $dbh, $query, $form->{"id"}); + } $query = "DELETE FROM language WHERE id = ?"; - $dbh->do($query, undef, $form->{"id"}) || - $form->dberror($query . " ($form->{id})"); + do_query($form, $dbh, $query, $form->{"id"}); $dbh->commit(); $dbh->disconnect; @@ -1360,9 +1360,30 @@ sub get_payment { my $ref = $sth->fetchrow_hashref(NAME_lc); map { $form->{$_} = $ref->{$_} } keys %$ref; + $sth->finish(); + + $query = + qq|SELECT t.language_id, t.description_long, l.description AS language | . + qq|FROM translation_payment_terms t | . + qq|LEFT JOIN language l ON t.language_id = l.id | . + qq|WHERE t.payment_terms_id = ? | . + qq|UNION | . + qq|SELECT l.id AS language_id, NULL AS description_long, | . + qq|l.description AS language | . + qq|FROM language l|; + $sth = $dbh->prepare($query); + $sth->execute($form->{"id"}) || $form->dberror($query . " ($form->{id})"); + my %mapping; + while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { + $mapping{ $ref->{"language_id"} } = $ref + unless (defined($mapping{ $ref->{"language_id"} })); + } $sth->finish; + $form->{"TRANSLATION"} = [sort({ $a->{"language"} cmp $b->{"language"} } + values(%mapping))]; + $dbh->disconnect; $main::lxdebug->leave_sub(); @@ -1374,34 +1395,61 @@ sub save_payment { my ($self, $myconfig, $form) = @_; # connect to database - my $dbh = $form->dbconnect($myconfig); + my $dbh = $form->dbconnect_noauto($myconfig); + my $query; + + if (!$form->{id}) { + $query = qq|SELECT nextval('id'), MAX(sortkey) + 1 FROM payment_terms|; + my $sortkey; + ($form->{id}, $sortkey) = selectrow_query($form, $dbh, $query); + + $query = qq|INSERT INTO payment_terms (id, sortkey) VALUES (?, ?)|; + do_query($form, $dbh, $query, $form->{id}, $sortkey); + + } else { + $query = + qq|DELETE FROM translation_payment_terms | . + qq|WHERE payment_terms_id = ?|; + do_query($form, $dbh, $query, $form->{"id"}); + } + + $query = qq|UPDATE payment_terms SET + description = ?, description_long = ?, + ranking = ?, + terms_netto = ?, terms_skonto = ?, + percent_skonto = ? + WHERE id = ?|; my @values = ($form->{description}, $form->{description_long}, $form->{ranking} * 1, $form->{terms_netto} * 1, $form->{terms_skonto} * 1, - $form->{percent_skonto} * 1); + $form->{percent_skonto} * 1, + $form->{id}); + do_query($form, $dbh, $query, @values); - my $query; - # id is the old record - if ($form->{id}) { - $query = qq|UPDATE payment_terms SET - description = ?, description_long = ?, - ranking = ?, - terms_netto = ?, terms_skonto = ?, - percent_skonto = ? - WHERE id = ?|; - push(@values, $form->{"id"}); - } else { - $query = qq|SELECT MAX(sortkey) + 1 FROM payment_terms|; - my ($sortkey) = selectrow_query($form, $dbh, $query); - $query = qq|INSERT INTO payment_terms - (description, description_long, ranking, - terms_netto, terms_skonto, percent_skonto, sortkey) - VALUES (?, ?, ?, ?, ?, ?, ?)|; - push(@values, $sortkey); + $query = qq|SELECT id FROM language|; + my @language_ids; + my $sth = $dbh->prepare($query); + $sth->execute() || $form->dberror($query); + + while (my ($id) = $sth->fetchrow_array()) { + push(@language_ids, $id); } - do_query($form, $dbh, $query, @values); + $sth->finish(); + $query = + qq|INSERT INTO translation_payment_terms | . + qq|(language_id, payment_terms_id, description_long) | . + qq|VALUES (?, ?, ?)|; + $sth = $dbh->prepare($query); + + foreach my $language_id (@language_ids) { + do_statement($form, $sth, $query, $language_id, $form->{"id"}, + $form->{"description_long_${language_id}"}); + } + $sth->finish(); + + $dbh->commit(); $dbh->disconnect; $main::lxdebug->leave_sub(); @@ -1413,11 +1461,16 @@ sub delete_payment { my ($self, $myconfig, $form) = @_; # connect to database - my $dbh = $form->dbconnect($myconfig); + my $dbh = $form->dbconnect_noauto($myconfig); my $query = qq|DELETE FROM payment_terms WHERE id = ?|; do_query($form, $dbh, $query, $form->{"id"}); + $query = + qq|DELETE FROM translation_payment_terms WHERE payment_terms_id = ?|; + do_query($form, $dbh, $query, $form->{"id"}); + + $dbh->commit(); $dbh->disconnect; $main::lxdebug->leave_sub(); diff --git a/SL/DBUtils.pm b/SL/DBUtils.pm index 996add880..38acf12af 100644 --- a/SL/DBUtils.pm +++ b/SL/DBUtils.pm @@ -3,7 +3,7 @@ package SL::DBUtils; require Exporter; @ISA = qw(Exporter); -@EXPORT = qw(conv_i conv_date do_query selectrow_query dump_query); +@EXPORT = qw(conv_i conv_date do_query selectrow_query do_statement dump_query); sub conv_i { my ($value, $default) = @_; @@ -40,6 +40,17 @@ sub selectrow_query { } } +sub do_statement { + my ($form, $sth, $query) = splice(@_, 0, 3); + + if (0 == scalar(@_)) { + $sth->execute() || $form->dberror($query); + } else { + $sth->execute(@_) || + $form->dberror($query . " (" . join(", ", @_) . ")"); + } +} + sub dump_query { my ($level, $msg, $query) = splice(@_, 0, 3); while ($query =~ /\?/) { diff --git a/bin/mozilla/am.pl b/bin/mozilla/am.pl index c9b5f549f..f8ea6fa37 100644 --- a/bin/mozilla/am.pl +++ b/bin/mozilla/am.pl @@ -2326,6 +2326,10 @@ sub add_payment { $form->{terms_netto} = 0; $form->{terms_skonto} = 0; $form->{percent_skonto} = 0; + my @languages = AM->language(\%myconfig, $form, 1); + map({ $_->{"language"} = $_->{"description"}; + $_->{"language_id"} = $_->{"id"}; } @languages); + $form->{"TRANSLATION"} = \@languages; &payment_header; &form_footer; @@ -2337,7 +2341,7 @@ sub edit_payment { $form->{title} = "Edit"; - AM->get_payment(\%myconfig, \%$form); + AM->get_payment(\%myconfig, $form); $form->{percent_skonto} = $form->format_amount(\%myconfig, $form->{percent_skonto} * 100); @@ -2537,6 +2541,22 @@ sub payment_header { | . $locale->text('Long Description') . qq| +|; + + foreach my $language (@{ $form->{"TRANSLATION"} }) { + print qq| + + | . + sprintf($locale->text('Translation (%s)'), + $language->{"language"}) + . qq| + + +|; + } + + print qq| | . $locale->text('Netto Terms') . qq| diff --git a/locale/de/all b/locale/de/all index 14a203859..ca7ca69a3 100644 --- a/locale/de/all +++ b/locale/de/all @@ -1049,6 +1049,7 @@ gestartet', 'Transfer' => 'Umlagerung', 'Transfer Inventory' => 'Ware umlagern', 'Transfer to' => 'umlagern nach', + 'Translation (%s)' => 'Übersetzung (%s)', 'Trial Balance' => 'Saldenbilanz', 'Type' => 'Typ', 'Type of Business' => 'Kundentyp', diff --git a/locale/de/am b/locale/de/am index 63cdef2f8..b5eed17cc 100644 --- a/locale/de/am +++ b/locale/de/am @@ -255,6 +255,7 @@ $self->{texts} = { 'Top (Javascript)' => 'Oben (mit Javascript)', 'Transaction reversal enforced for all dates' => 'Fehleintragungen müssen für jeden Zeitraum mit einer Kontraeintragung ausgebessert werden', 'Transaction reversal enforced up to' => 'Fehleintragungen können bis zu dem angegebenen Zeitraum nur mit einer Kontraeintragung ausgebessert werden!', + 'Translation (%s)' => 'Übersetzung (%s)', 'Type of Business' => 'Kundentyp', 'UStVA-Nr. 35' => 'Kz. 35', 'UStVA-Nr. 36' => 'Kz. 36', diff --git a/sql/Pg-upgrade2/payment_terms_translation.sql b/sql/Pg-upgrade2/payment_terms_translation.sql new file mode 100644 index 000000000..a8d7ff7cf --- /dev/null +++ b/sql/Pg-upgrade2/payment_terms_translation.sql @@ -0,0 +1,11 @@ +-- @tag: payment_terms_translation +-- @description: Übersetzungen von Zahlungskonditionen +-- @depends: release_2_4_1 +CREATE TABLE translation_payment_terms ( + payment_terms_id integer NOT NULL, + language_id integer NOT NULL, + description_long text, + + FOREIGN KEY (payment_terms_id) REFERENCES payment_terms (id), + FOREIGN KEY (language_id) REFERENCES language (id) +);