From af85349024c0d1fc6db899cd84708c7fb6dfb7f4 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 19 Dec 2006 13:28:43 +0000 Subject: [PATCH] =?utf8?q?Verwalten=20von=20Einheitennamen=20f=C3=BCr=20je?= =?utf8?q?de=20angelegte=20Sprache.=20Beim=20Druck=20werden=20die=20Einhei?= =?utf8?q?tennamen=20durch=20diejenigen=20ersetzt,=20die=20f=C3=BCr=20die?= =?utf8?q?=20ausgew=C3=A4hlte=20Ausgabesprache=20gespeichert=20sind.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/AM.pm | 104 ++++++++++++++++-- SL/CT.pm | 9 +- bin/mozilla/am.pl | 56 +++++++++- bin/mozilla/io.pl | 6 +- doc/changelog | 5 + locale/de/all | 3 + locale/de/am | 1 + sql/Pg-upgrade/Pg-upgrade-2.4.0.1-2.4.0.2.sql | 11 ++ templates/webpages/am/edit_units_de.html | 32 +++++- templates/webpages/am/edit_units_master.html | 32 +++++- 10 files changed, 233 insertions(+), 26 deletions(-) create mode 100644 sql/Pg-upgrade/Pg-upgrade-2.4.0.1-2.4.0.2.sql diff --git a/SL/AM.pm b/SL/AM.pm index a3f7f7c27..a159748aa 100644 --- a/SL/AM.pm +++ b/SL/AM.pm @@ -851,7 +851,7 @@ sub delete_business { sub language { $main::lxdebug->enter_sub(); - my ($self, $myconfig, $form) = @_; + my ($self, $myconfig, $form, $return_list) = @_; # connect to database my $dbh = $form->dbconnect($myconfig); @@ -864,14 +864,22 @@ sub language { $sth = $dbh->prepare($query); $sth->execute || $form->dberror($query); + my $ary = []; + while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { - push @{ $form->{ALL} }, $ref; + push(@{ $ary }, $ref); } $sth->finish; $dbh->disconnect; $main::lxdebug->leave_sub(); + + if ($return_list) { + return @{$ary}; + } else { + $form->{ALL} = $ary; + } } sub get_language { @@ -2040,9 +2048,35 @@ sub retrieve_units { } $sth->finish(); - foreach my $unit (keys(%{$units})) { - ($units->{$unit}->{"${prefix}base_unit"}, $units->{$unit}->{"${prefix}factor"}) = AM->get_base_unit($units, $unit); + my $query_lang = "SELECT id, template_code FROM language ORDER BY description"; + $sth = $dbh->prepare($query_lang); + $sth->execute() || $form->dberror($query_lang); + my @languages; + while ($ref = $sth->fetchrow_hashref()) { + push(@languages, $ref); + } + $sth->finish(); + + $query_lang = "SELECT ul.localized, ul.localized_plural, l.id, l.template_code " . + "FROM units_language ul " . + "LEFT JOIN language l ON ul.language_id = l.id " . + "WHERE ul.unit = ?"; + $sth = $dbh->prepare($query_lang); + + foreach my $unit (values(%{$units})) { + ($unit->{"${prefix}base_unit"}, $unit->{"${prefix}factor"}) = AM->get_base_unit($units, $unit->{"name"}); + + $unit->{"LANGUAGES"} = {}; + foreach my $lang (@languages) { + $unit->{"LANGUAGES"}->{$lang->{"template_code"}} = { "template_code" => $lang->{"template_code"} }; + } + + $sth->execute($unit->{"name"}) || $form->dberror($query_lang . " (" . $unit->{"name"} . ")"); + while ($ref = $sth->fetchrow_hashref()) { + map({ $unit->{"LANGUAGES"}->{$ref->{"template_code"}}->{$_} = $ref->{$_} } keys(%{$ref})); + } } + $sth->finish(); $dbh->disconnect(); @@ -2051,6 +2085,29 @@ sub retrieve_units { return $units; } +sub translate_units { + $main::lxdebug->enter_sub(); + + my ($self, $form, $template_code, $unit, $amount) = @_; + + my $units = $self->retrieve_units(\%main::myconfig, $form); + + my $h = $units->{$unit}->{"LANGUAGES"}->{$template_code}; + $main::lxdebug->dump(0, "klaus", $h); + my $new_unit = $unit; + if ($h) { + if (($amount != 1) && $h->{"localized_plural"}) { + $new_unit = $h->{"localized_plural"}; + } elsif ($h->{"localized"}) { + $new_unit = $h->{"localized"}; + } + } + + $main::lxdebug->leave_sub(); + + return $new_unit; +} + sub units_in_use { $main::lxdebug->enter_sub(); @@ -2142,12 +2199,24 @@ sub unit_select_html { sub add_unit { $main::lxdebug->enter_sub(); - my ($self, $myconfig, $form, $name, $base_unit, $factor, $type) = @_; + my ($self, $myconfig, $form, $name, $base_unit, $factor, $type, $languages) = @_; - my $dbh = $form->dbconnect($myconfig); + my $dbh = $form->dbconnect_noauto($myconfig); my $query = "INSERT INTO units (name, base_unit, factor, type) VALUES (?, ?, ?, ?)"; $dbh->do($query, undef, $name, $base_unit, $factor, $type) || $form->dberror($query . " ($name, $base_unit, $factor, $type)"); + + if ($languages) { + $query = "INSERT INTO units_language (unit, language_id, localized, localized_plural) VALUES (?, ?, ?, ?)"; + my $sth = $dbh->prepare($query); + foreach my $lang (@{$languages}) { + my @values = ($name, $lang->{"id"}, $lang->{"localized"}, $lang->{"localized_plural"}); + $sth->execute(@values) || $form->dberror($query . " (" . join(", ", @values) . ")"); + } + $sth->finish(); + } + + $dbh->commit(); $dbh->disconnect(); $main::lxdebug->leave_sub(); @@ -2162,16 +2231,22 @@ sub save_units { my ($base_unit, $unit, $sth, $query); + $query = "DELETE FROM units_language"; + $dbh->do($query) || $form->dberror($query); + if ($delete_units && (0 != scalar(@{$delete_units}))) { - $query = "DELETE FROM units WHERE name = ?"; - $sth = $dbh->prepare($query); - map({ $sth->execute($_) || $form->dberror($query . " ($_)"); } @{$delete_units}); - $sth->finish(); + $query = "DELETE FROM units WHERE name = ("; + map({ $query .= "?," } @{$delete_units}); + substr($query, -1, 1) = ")"; + $dbh->do($query, undef, @{$delete_units}) || $form->dberror($query . " ($_)"); } $query = "UPDATE units SET name = ?, base_unit = ?, factor = ? WHERE name = ?"; $sth = $dbh->prepare($query); + my $query_lang = "INSERT INTO units_language (unit, language_id, localized, localized_plural) VALUES (?, ?, ?, ?)"; + my $sth_lang = $dbh->prepare($query_lang); + foreach $unit (values(%{$units})) { $unit->{"depth"} = 0; my $base_unit = $unit; @@ -2182,6 +2257,14 @@ sub save_units { } foreach $unit (sort({ $a->{"depth"} <=> $b->{"depth"} } values(%{$units}))) { + if ($unit->{"LANGUAGES"}) { + foreach my $lang (@{$unit->{"LANGUAGES"}}) { + next unless ($lang->{"id"} && $lang->{"localized"}); + my @values = ($unit->{"name"}, $lang->{"id"}, $lang->{"localized"}, $lang->{"localized_plural"}); + $sth_lang->execute(@values) || $form->dberror($query_lang . " (" . join(", ", @values) . ")"); + } + } + next if ($unit->{"unchanged_unit"}); my @values = ($unit->{"name"}, $unit->{"base_unit"}, $unit->{"factor"}, $unit->{"old_name"}); @@ -2189,6 +2272,7 @@ sub save_units { } $sth->finish(); + $sth_lang->finish(); $dbh->commit(); $dbh->disconnect(); diff --git a/SL/CT.pm b/SL/CT.pm index f5729927e..3057391e3 100644 --- a/SL/CT.pm +++ b/SL/CT.pm @@ -37,7 +37,7 @@ package CT; use Data::Dumper; - +use SL::DBUtils; sub get_tuple { $main::lxdebug->enter_sub(); @@ -373,7 +373,6 @@ sub save_customer { $form->{obsolete} *= 1; $form->{business} *= 1; $form->{salesman_id} *= 1; - $form->{language_id} *= 1; $form->{payment_id} *= 1; $form->{taxzone_id} *= 1; $form->{creditlimit} = $form->parse_amount($myconfig, $form->{creditlimit}); @@ -472,7 +471,7 @@ sub save_customer { ustid = '$form->{ustid}', username = '$form->{username}', salesman_id = '$form->{salesman_id}', - language_id = '$form->{language_id}', + language_id = | . conv_i($form->{language_id}, "NULL") . qq|, payment_id = '$form->{payment_id}', taxzone_id = '$form->{taxzone_id}', user_password = | . $dbh->quote($form->{user_password}) . qq|, @@ -518,7 +517,6 @@ sub save_customer { $dbh->do($query) || $form->dberror($query); } } - print(STDERR "SHIPTO_ID $form->{shipto_id}\n"); # add shipto $form->add_shipto($dbh, $form->{id}, "CT"); @@ -553,7 +551,6 @@ sub save_vendor { $form->{obsolete} *= 1; $form->{business} *= 1; $form->{payment_id} *= 1; - $form->{language_id} *= 1; $form->{taxzone_id} *= 1; $form->{creditlimit} = $form->parse_amount($myconfig, $form->{creditlimit}); @@ -626,7 +623,7 @@ sub save_vendor { ustid = '$form->{ustid}', payment_id = '$form->{payment_id}', taxzone_id = '$form->{taxzone_id}', - language_id = '$form->{language_id}', + language_id = | . conv_i($form->{language_id}, "NULL") . qq|, username = '$form->{username}', user_password = '$form->{user_password}', v_customer_id = '$form->{v_customer_id}' diff --git a/bin/mozilla/am.pl b/bin/mozilla/am.pl index 4d3a88f33..a86a0afb7 100644 --- a/bin/mozilla/am.pl +++ b/bin/mozilla/am.pl @@ -3531,20 +3531,39 @@ sub edit_units { AM->units_in_use(\%myconfig, $form, $units); map({ $units->{$_}->{"BASE_UNIT_DDBOX"} = AM->unit_select_data($units, $units->{$_}->{"base_unit"}, 1); } keys(%{$units})); + @languages = AM->language(\%myconfig, $form, 1); + @unit_list = (); foreach $name (sort({ lc($a) cmp lc($b) } grep({ !$units->{$_}->{"base_unit"} } keys(%{$units})))) { map({ push(@unit_list, $units->{$_}); } sort({ ($units->{$a}->{"resolved_factor"} * 1) <=> ($units->{$b}->{"resolved_factor"} * 1) } grep({ $units->{$_}->{"resolved_base_unit"} eq $name } keys(%{$units})))); } - map({ $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"}, 5) if ($_->{"factor"}); } @unit_list); + my $i = 1; + foreach (@unit_list) { + $_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"}, 5) if ($_->{"factor"}); + $_->{"UNITLANGUAGES"} = []; + foreach my $lang (@languages) { + push(@{ $_->{"UNITLANGUAGES"} }, + { "idx" => $i, + "unit" => $_->{"name"}, + "language_id" => $lang->{"id"}, + "localized" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized"}, + "localized_plural" => $_->{"LANGUAGES"}->{$lang->{"template_code"}}->{"localized_plural"}, + }); + } + $i++; + } $units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"}); $ddbox = AM->unit_select_data($units, undef, 1); $form->{"title"} = sprintf($locale->text("Add and edit %s"), $form->{"unit_type"} eq "dimension" ? $locale->text("dimension units") : $locale->text("service units")); $form->header(); - print($form->parse_html_template("am/edit_units", { "UNITS" => \@unit_list, "NEW_BASE_UNIT_DDBOX" => $ddbox })); + print($form->parse_html_template("am/edit_units", + { "UNITS" => \@unit_list, + "NEW_BASE_UNIT_DDBOX" => $ddbox, + "LANGUAGES" => \@languages })); $lxdebug->leave_sub(); } @@ -3566,7 +3585,16 @@ sub add_unit { $base_unit = $form->{"new_base_unit"}; } - AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, $form->{"unit_type"}); + my @languages; + foreach my $lang (AM->language(\%myconfig, $form, 1)) { + next unless ($form->{"new_localized_$lang->{id}"} || $form->{"new_localized_plural_$lang->{id}"}); + push(@languages, { "id" => $lang->{"id"}, + "localized" => $form->{"new_localized_$lang->{id}"}, + "localized_plural" => $form->{"new_localized_plural_$lang->{id}"}, + }); + } + + AM->add_unit(\%myconfig, $form, $form->{"new_name"}, $base_unit, $factor, $form->{"unit_type"}, \@languages); $form->{"saved_message"} = $locale->text("The unit has been saved."); @@ -3575,12 +3603,32 @@ sub add_unit { $lxdebug->leave_sub(); } +sub set_unit_languages { + $lxdebug->enter_sub(); + + my ($unit, $languages, $idx) = @_; + + $unit->{"LANGUAGES"} = []; + + foreach my $lang (@{$languages}) { + push(@{ $unit->{"LANGUAGES"} }, + { "id" => $lang->{"id"}, + "localized" => $form->{"localized_${idx}_$lang->{id}"}, + "localized_plural" => $form->{"localized_plural_${idx}_$lang->{id}"}, + }); + } + + $lxdebug->leave_sub(); +} + sub save_unit { $lxdebug->enter_sub(); $old_units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"}, "resolved_"); AM->units_in_use(\%myconfig, $form, $old_units); + @languages = AM->language(\%myconfig, $form, 1); + $new_units = {}; @delete_units = (); foreach $i (1..($form->{"rowcount"} * 1)) { @@ -3592,6 +3640,7 @@ sub save_unit { if ($form->{"unchangeable_$i"}) { $new_units->{$form->{"old_name_$i"}} = $old_units->{$form->{"old_name_$i"}}; $new_units->{$form->{"old_name_$i"}}->{"unchanged_unit"} = 1; + set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i); next; } @@ -3610,6 +3659,7 @@ sub save_unit { my %h = map({ $_ => $form->{"${_}_$i"} } qw(name base_unit factor old_name)); $new_units->{$form->{"name_$i"}} = \%h; $new_units->{$form->{"name_$i"}}->{"row"} = $i; + set_unit_languages($new_units->{$form->{"old_name_$i"}}, \@languages, $i); } foreach $unit (values(%{$new_units})) { diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index 63b2db654..fab0a1ad6 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -1796,7 +1796,7 @@ sub print_form { || $form->{formname} eq 'request_quotation') { $form->{shiptoname} = $myconfig{company}; $form->{shiptostreet} = $myconfig{address}; - } else { + } else { map { $form->{"shipto$_"} = $form->{$_} } @a; } } @@ -1811,6 +1811,10 @@ sub print_form { $form->{printer_code} = $form->get_printer_code(\%myconfig); if ($form->{language} ne "") { + map({ $form->{"unit"}->[$_] = + AM->translate_units($form, $form->{"language"}, + $form->{"unit"}->[$_], $form->{"qty"}->[$_]); } + (0..scalar(@{$form->{"unit"}}) - 1)); $form->{language} = "_" . $form->{language}; } diff --git a/doc/changelog b/doc/changelog index 4b4d028a0..607cdb763 100644 --- a/doc/changelog +++ b/doc/changelog @@ -1,6 +1,11 @@ #################################### # Veraenderungen von Lx-Office ERP # #################################### +????-??-?? - Version 2.4.? + - Ersetzen der Einheitennamen anhand der Vorlagensprache + - Umformartierungen von Zahlen und Datumgsangaben anhand der + Vorlagensprache + 2006-12-12 - Version 2.4.0 - USTVA jetzt mit Taxbird und Winston Anbindung (als Templates verfügbar) - Neues Steuersystem für beliebig viele Steuersätze pro Konto diff --git a/locale/de/all b/locale/de/all index 2ddbf252c..7597d93b6 100644 --- a/locale/de/all +++ b/locale/de/all @@ -736,6 +736,7 @@ gestartet', '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.', + 'Plural' => 'Plural', 'Port' => 'Port', 'Port missing!' => 'Portangabe fehlt!', 'Post' => 'Buchen', @@ -1148,6 +1149,7 @@ gestartet', 'month' => 'monatliche Abgabe', 'none (pricegroup)' => 'keine', 'number' => 'Nummer', + 'plural first char' => 'P', 'posted!' => 'gebucht', 'prices updated!' => ' Preise aktualisiert!', 'quarter' => 'vierteljährliche (quartalsweise) Abgabe', @@ -1158,6 +1160,7 @@ gestartet', 'sent' => 'gesendet', 'sent to printer' => 'an Drucker geschickt', 'service units' => 'Dienstleistungseinheiten', + 'singular first char' => 'S', 'soldtotal' => 'Verkaufte Anzahl', 'successfully created!' => 'wurde erfolgreich erstellt', 'successfully deleted!' => 'wurde erfolgreich gelöscht', diff --git a/locale/de/am b/locale/de/am index 1fa25fe40..6c5829e07 100644 --- a/locale/de/am +++ b/locale/de/am @@ -375,6 +375,7 @@ $self->{subs} = { 'select_part' => 'select_part', 'select_part_internal' => 'select_part_internal', 'set_longdescription' => 'set_longdescription', + 'set_unit_languages' => 'set_unit_languages', 'sic_header' => 'sic_header', 'vendor_selection' => 'vendor_selection', 'warehouse_header' => 'warehouse_header', diff --git a/sql/Pg-upgrade/Pg-upgrade-2.4.0.1-2.4.0.2.sql b/sql/Pg-upgrade/Pg-upgrade-2.4.0.1-2.4.0.2.sql new file mode 100644 index 000000000..ed2c2cd6e --- /dev/null +++ b/sql/Pg-upgrade/Pg-upgrade-2.4.0.1-2.4.0.2.sql @@ -0,0 +1,11 @@ +CREATE TABLE units_language ( + unit varchar (20) NOT NULL, + language_id integer NOT NULL, + localized varchar (20), + localized_plural varchar (20), + + FOREIGN KEY (unit) REFERENCES units (name), + FOREIGN KEY (language_id) REFERENCES language (id) +); +CREATE INDEX units_name_idx ON units (name); +CREATE INDEX units_language_unit_idx ON units_language (unit); diff --git a/templates/webpages/am/edit_units_de.html b/templates/webpages/am/edit_units_de.html index 0f5a2cc28..d36d3c799 100644 --- a/templates/webpages/am/edit_units_de.html +++ b/templates/webpages/am/edit_units_de.html @@ -56,6 +56,15 @@ Faktor + + + + + + Plural + + + @@ -77,6 +86,12 @@ gelöscht.

+

+ Bei den Übersetzungen können Sie unterschiedliche + Varianten für singular und plural angeben (z.B. "day" + und "days"). +

+ @@ -84,6 +99,9 @@ + + + @@ -105,16 +123,24 @@ - - + + + + + diff --git a/templates/webpages/am/edit_units_master.html b/templates/webpages/am/edit_units_master.html index 721b86a54..f873e0fc0 100644 --- a/templates/webpages/am/edit_units_master.html +++ b/templates/webpages/am/edit_units_master.html @@ -56,6 +56,15 @@ + + + + + + + + +
 Einheit Basiseinheit Faktor
- + + S: + + P: + +
Factor
Plural
@@ -77,6 +86,12 @@ gelöscht.

+

+ Bei den Übersetzungen können Sie unterschiedliche + Varianten für singular und plural angeben (z.B. "day" + und "days"). +

+ @@ -84,6 +99,9 @@ + + + @@ -105,16 +123,24 @@ - - + + + + + -- 2.20.1
 Unit Base unit Factor
- + + singular first char: + + plural first char: + +