sub language {
$main::lxdebug->enter_sub();
- my ($self, $myconfig, $form) = @_;
+ my ($self, $myconfig, $form, $return_list) = @_;
# connect to database
my $dbh = $form->dbconnect($myconfig);
$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 {
}
$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();
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();
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();
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;
}
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"});
}
$sth->finish();
+ $sth_lang->finish();
$dbh->commit();
$dbh->disconnect();
package CT;
use Data::Dumper;
-
+use SL::DBUtils;
sub get_tuple {
$main::lxdebug->enter_sub();
$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});
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|,
$dbh->do($query) || $form->dberror($query);
}
}
- print(STDERR "SHIPTO_ID $form->{shipto_id}\n");
# add shipto
$form->add_shipto($dbh, $form->{id}, "CT");
$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});
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}'
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();
}
$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.");
$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)) {
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;
}
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})) {
|| $form->{formname} eq 'request_quotation') {
$form->{shiptoname} = $myconfig{company};
$form->{shiptostreet} = $myconfig{address};
- } else {
+ } else {
map { $form->{"shipto$_"} = $form->{$_} } @a;
}
}
$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};
}
####################################\r
# Veraenderungen von Lx-Office ERP #\r
####################################\r
+????-??-?? - Version 2.4.?\r
+ - Ersetzen der Einheitennamen anhand der Vorlagensprache\r
+ - Umformartierungen von Zahlen und Datumgsangaben anhand der\r
+ Vorlagensprache\r
+\r
2006-12-12 - Version 2.4.0\r
- USTVA jetzt mit Taxbird und Winston Anbindung (als Templates verfügbar)\r
- Neues Steuersystem für beliebig viele Steuersätze pro Konto\r
'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',
'month' => 'monatliche Abgabe',
'none (pricegroup)' => 'keine',
'number' => 'Nummer',
+ 'plural first char' => 'P',
'posted!' => 'gebucht',
'prices updated!' => ' Preise aktualisiert!',
'quarter' => 'vierteljährliche (quartalsweise) Abgabe',
'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',
'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',
--- /dev/null
+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);
<th align="right">Faktor</th>
<td><input name="new_factor"></td>
</tr>
+
+ <TMPL_LOOP LANGUAGES>
+ <tr>
+ <th align="right"><TMPL_VAR description></th>
+ <td><input name="new_localized_<TMPL_VAR id>" size="20" maxlength="20"></td>
+ <th align="right">Plural</th>
+ <td><input name="new_localized_plural_<TMPL_VAR id>" size="20" maxlength="20"></td>
+ </tr>
+ </TMPL_LOOP>
</table>
<input type="submit" class="submit" name="action" value="Erfassen">
gelöscht.
</p>
+ <p>
+ Bei den Übersetzungen können Sie unterschiedliche
+ Varianten für singular und plural angeben (z.B. "day"
+ und "days").
+ </p>
+
<table>
<tr>
<th class="listheading"> </th>
<th class="listheading">Einheit</th>
<th class="listheading">Basiseinheit</th>
<th class="listheading">Faktor</th>
+ <TMPL_LOOP LANGUAGES>
+ <th class="listheading"><TMPL_VAR description></th>
+ </TMPL_LOOP>
</tr>
<TMPL_LOOP NAME=UNITS>
<td align="center"><input type="checkbox" name="delete_<TMPL_VAR NAME=__counter__>"></td>
<td>
<input type="hidden" name="old_name_<TMPL_VAR NAME=__counter__>" value="<TMPL_VAR NAME=name>">
- <input name="name_<TMPL_VAR NAME=__counter__>" size="20" maxlength="20" value="<TMPL_VAR NAME=name>">
+ <input name="name_<TMPL_VAR NAME=__counter__>" size="10" maxlength="20" value="<TMPL_VAR NAME=name>">
</td>
<td>
<select name="base_unit_<TMPL_VAR NAME=__counter__>">
<TMPL_LOOP NAME=BASE_UNIT_DDBOX><option <TMPL_VAR NAME=selected>><TMPL_VAR NAME=name></option></TMPL_LOOP>
</select>
</td>
- <td><input name="factor_<TMPL_VAR NAME=__counter__>" value="<TMPL_VAR NAME=factor>"></td>
-
+ <td><input name="factor_<TMPL_VAR NAME=__counter__>" size="8" value="<TMPL_VAR NAME=factor>"></td>
</TMPL_IF>
+
+ <TMPL_LOOP UNITLANGUAGES>
+ <td>
+ S:
+ <input name="localized_<TMPL_VAR idx>_<TMPL_VAR language_id>" value="<TMPL_VAR localized>" size="6" maxlength="20">
+ P:
+ <input name="localized_plural_<TMPL_VAR idx>_<TMPL_VAR language_id>" value="<TMPL_VAR localized_plural>" size="6" maxlength="20">
+ </td>
+ </TMPL_LOOP>
</tr>
<TMPL_IF NAME=__last__><input type="hidden" name="rowcount" value="<TMPL_VAR NAME=__counter__>"></TMPL_IF>
<th align="right"><translate>Factor</translate></th>
<td><input name="new_factor"></td>
</tr>
+
+ <TMPL_LOOP LANGUAGES>
+ <tr>
+ <th align="right"><TMPL_VAR description></th>
+ <td><input name="new_localized_<TMPL_VAR id>" size="20" maxlength="20"></td>
+ <th align="right"><translate>Plural</translate></th>
+ <td><input name="new_localized_plural_<TMPL_VAR id>" size="20" maxlength="20"></td>
+ </tr>
+ </TMPL_LOOP>
</table>
<input type="submit" class="submit" name="action" value="<translate>Add</translate>">
gelöscht.
</p>
+ <p>
+ Bei den Übersetzungen können Sie unterschiedliche
+ Varianten für singular und plural angeben (z.B. "day"
+ und "days").
+ </p>
+
<table>
<tr>
<th class="listheading"> </th>
<th class="listheading"><translate>Unit</translate></th>
<th class="listheading"><translate>Base unit</translate></th>
<th class="listheading"><translate>Factor</translate></th>
+ <TMPL_LOOP LANGUAGES>
+ <th class="listheading"><TMPL_VAR description></th>
+ </TMPL_LOOP>
</tr>
<TMPL_LOOP NAME=UNITS>
<td align="center"><input type="checkbox" name="delete_<TMPL_VAR NAME=__counter__>"></td>
<td>
<input type="hidden" name="old_name_<TMPL_VAR NAME=__counter__>" value="<TMPL_VAR NAME=name>">
- <input name="name_<TMPL_VAR NAME=__counter__>" size="20" maxlength="20" value="<TMPL_VAR NAME=name>">
+ <input name="name_<TMPL_VAR NAME=__counter__>" size="10" maxlength="20" value="<TMPL_VAR NAME=name>">
</td>
<td>
<select name="base_unit_<TMPL_VAR NAME=__counter__>">
<TMPL_LOOP NAME=BASE_UNIT_DDBOX><option <TMPL_VAR NAME=selected>><TMPL_VAR NAME=name></option></TMPL_LOOP>
</select>
</td>
- <td><input name="factor_<TMPL_VAR NAME=__counter__>" value="<TMPL_VAR NAME=factor>"></td>
-
+ <td><input name="factor_<TMPL_VAR NAME=__counter__>" size="8" value="<TMPL_VAR NAME=factor>"></td>
</TMPL_IF>
+
+ <TMPL_LOOP UNITLANGUAGES>
+ <td>
+ <translate>singular first char</translate>:
+ <input name="localized_<TMPL_VAR idx>_<TMPL_VAR language_id>" value="<TMPL_VAR localized>" size="6" maxlength="20">
+ <translate>plural first char</translate>:
+ <input name="localized_plural_<TMPL_VAR idx>_<TMPL_VAR language_id>" value="<TMPL_VAR localized_plural>" size="6" maxlength="20">
+ </td>
+ </TMPL_LOOP>
</tr>
<TMPL_IF NAME=__last__><input type="hidden" name="rowcount" value="<TMPL_VAR NAME=__counter__>"></TMPL_IF>