Revision eaf4d483
Von Moritz Bunkus vor fast 18 Jahren hinzugefügt
SL/AM.pm | ||
---|---|---|
2284 | 2284 |
push(@{$select}, { "name" => "", "base_unit" => "", "factor" => "", "selected" => "" }); |
2285 | 2285 |
} |
2286 | 2286 |
|
2287 |
foreach my $unit (sort({ lc($a) cmp lc($b) } keys(%{$units}))) {
|
|
2287 |
foreach my $unit (sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } keys(%{$units}))) {
|
|
2288 | 2288 |
push(@{$select}, { "name" => $unit, |
2289 | 2289 |
"base_unit" => $units->{$unit}->{"base_unit"}, |
2290 | 2290 |
"factor" => $units->{$unit}->{"factor"}, |
... | ... | |
2303 | 2303 |
|
2304 | 2304 |
my $select = "<select name=${name}>"; |
2305 | 2305 |
|
2306 |
foreach my $unit (sort({ lc($a) cmp lc($b) } keys(%{$units}))) {
|
|
2306 |
foreach my $unit (sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } keys(%{$units}))) {
|
|
2307 | 2307 |
if (!$convertible_into || |
2308 | 2308 |
($units->{$convertible_into} && |
2309 | 2309 |
($units->{$convertible_into}->{"base_unit"} eq $units->{$unit}->{"base_unit"}))) { |
... | ... | |
2324 | 2324 |
|
2325 | 2325 |
my $dbh = $form->dbconnect_noauto($myconfig); |
2326 | 2326 |
|
2327 |
my $query = "INSERT INTO units (name, base_unit, factor, type) VALUES (?, ?, ?, ?)"; |
|
2328 |
$dbh->do($query, undef, $name, $base_unit, $factor, $type) || $form->dberror($query . " ($name, $base_unit, $factor, $type)"); |
|
2327 |
my $query = qq|SELECT COALESCE(MAX(sortkey), 0) + 1 FROM units|; |
|
2328 |
my ($sortkey) = selectrow_query($form, $dbh, $query); |
|
2329 |
|
|
2330 |
$query = "INSERT INTO units (name, base_unit, factor, type, sortkey) " . |
|
2331 |
"VALUES (?, ?, ?, ?, ?)"; |
|
2332 |
do_query($form, $dbh, $query, $name, $base_unit, $factor, $type, $sortkey); |
|
2329 | 2333 |
|
2330 | 2334 |
if ($languages) { |
2331 | 2335 |
$query = "INSERT INTO units_language (unit, language_id, localized, localized_plural) VALUES (?, ?, ?, ?)"; |
... | ... | |
2401 | 2405 |
$main::lxdebug->leave_sub(); |
2402 | 2406 |
} |
2403 | 2407 |
|
2408 |
sub swap_units { |
|
2409 |
$main::lxdebug->enter_sub(); |
|
2410 |
|
|
2411 |
my ($self, $myconfig, $form, $dir, $name_1, $unit_type) = @_; |
|
2412 |
|
|
2413 |
my $dbh = $form->dbconnect_noauto($myconfig); |
|
2414 |
|
|
2415 |
my $query; |
|
2416 |
|
|
2417 |
$query = qq|SELECT sortkey FROM units WHERE name = ?|; |
|
2418 |
my ($sortkey_1) = selectrow_query($form, $dbh, $query, $name_1); |
|
2419 |
|
|
2420 |
$query = |
|
2421 |
qq|SELECT sortkey FROM units | . |
|
2422 |
qq|WHERE sortkey | . ($dir eq "down" ? ">" : "<") . qq| ? AND type = ? | . |
|
2423 |
qq|ORDER BY sortkey | . ($dir eq "down" ? "ASC" : "DESC") . qq| LIMIT 1|; |
|
2424 |
my ($sortkey_2) = selectrow_query($form, $dbh, $query, $sortkey_1, $unit_type); |
|
2425 |
|
|
2426 |
$main::lxdebug->message(0, "name1 $name_1 dir $dir sk1 $sortkey_1 sk2 $sortkey_2"); |
|
2427 |
|
|
2428 |
if (defined($sortkey_1)) { |
|
2429 |
$query = qq|SELECT name FROM units WHERE sortkey = ${sortkey_2}|; |
|
2430 |
my ($name_2) = selectrow_query($form, $dbh, $query); |
|
2431 |
|
|
2432 |
if (defined($name_2)) { |
|
2433 |
$query = qq|UPDATE units SET sortkey = ? WHERE name = ?|; |
|
2434 |
my $sth = $dbh->prepare($query); |
|
2435 |
|
|
2436 |
do_statement($form, $sth, $query, $sortkey_1, $name_2); |
|
2437 |
do_statement($form, $sth, $query, $sortkey_2, $name_1); |
|
2438 |
} |
|
2439 |
} |
|
2440 |
|
|
2441 |
$dbh->commit(); |
|
2442 |
$dbh->disconnect(); |
|
2443 |
|
|
2444 |
$main::lxdebug->leave_sub(); |
|
2445 |
} |
|
2446 |
|
|
2404 | 2447 |
1; |
bin/mozilla/am.pl | ||
---|---|---|
3665 | 3665 |
|
3666 | 3666 |
@languages = AM->language(\%myconfig, $form, 1); |
3667 | 3667 |
|
3668 |
@unit_list = (); |
|
3669 |
foreach $name (sort({ lc($a) cmp lc($b) } grep({ !$units->{$_}->{"base_unit"} } keys(%{$units})))) { |
|
3670 |
map({ push(@unit_list, $units->{$_}); } |
|
3671 |
sort({ ($units->{$a}->{"resolved_factor"} * 1) <=> ($units->{$b}->{"resolved_factor"} * 1) } |
|
3672 |
grep({ $units->{$_}->{"resolved_base_unit"} eq $name } keys(%{$units})))); |
|
3673 |
} |
|
3668 |
@unit_list = sort({ $a->{"sortkey"} <=> $b->{"sortkey"} } values(%{$units})); |
|
3669 |
|
|
3674 | 3670 |
my $i = 1; |
3675 | 3671 |
foreach (@unit_list) { |
3676 | 3672 |
$_->{"factor"} = $form->format_amount(\%myconfig, $_->{"factor"} * 1) if ($_->{"factor"}); |
... | ... | |
3690 | 3686 |
$units = AM->retrieve_units(\%myconfig, $form, $form->{"unit_type"}); |
3691 | 3687 |
$ddbox = AM->unit_select_data($units, undef, 1); |
3692 | 3688 |
|
3689 |
my $updownlink = build_std_url("action=swap_units", "unit_type"); |
|
3690 |
|
|
3693 | 3691 |
$form->{"title"} = sprintf($locale->text("Add and edit %s"), $form->{"unit_type"} eq "dimension" ? $locale->text("dimension units") : $locale->text("service units")); |
3694 | 3692 |
$form->header(); |
3695 | 3693 |
print($form->parse_html_template("am/edit_units", |
3696 | 3694 |
{ "UNITS" => \@unit_list, |
3697 | 3695 |
"NEW_BASE_UNIT_DDBOX" => $ddbox, |
3698 |
"LANGUAGES" => \@languages })); |
|
3696 |
"LANGUAGES" => \@languages, |
|
3697 |
"updownlink" => $updownlink })); |
|
3699 | 3698 |
|
3700 | 3699 |
$lxdebug->leave_sub(); |
3701 | 3700 |
} |
... | ... | |
3831 | 3830 |
|
3832 | 3831 |
$lxdebug->leave_sub(); |
3833 | 3832 |
} |
3833 |
|
|
3834 |
sub swap_units { |
|
3835 |
$lxdebug->enter_sub(); |
|
3836 |
|
|
3837 |
my $dir = $form->{"dir"} eq "down" ? "down" : "up"; |
|
3838 |
my $unit_type = $form->{"unit_type"} eq "dimension" ? |
|
3839 |
"dimension" : "service"; |
|
3840 |
AM->swap_units(\%myconfig, $form, $dir, $form->{"name"}, $unit_type); |
|
3841 |
|
|
3842 |
edit_units(); |
|
3843 |
|
|
3844 |
$lxdebug->leave_sub(); |
|
3845 |
} |
locale/de/am | ||
---|---|---|
440 | 440 |
'sic_header' => 'sic_header', |
441 | 441 |
'swap_buchungsgruppen' => 'swap_buchungsgruppen', |
442 | 442 |
'swap_payment_terms' => 'swap_payment_terms', |
443 |
'swap_units' => 'swap_units', |
|
443 | 444 |
'vendor_selection' => 'vendor_selection', |
444 | 445 |
'warehouse_header' => 'warehouse_header', |
445 | 446 |
'erfassen' => 'add', |
sql/Pg-upgrade2/units_sortkey.sql | ||
---|---|---|
1 |
-- @tag: units_sortkey |
|
2 |
-- @description: Neue Spalte für Sortierreihenfolge der Einheiten |
|
3 |
-- @depends: release_2_4_1 |
|
4 |
ALTER TABLE units ADD COLUMN sortkey integer; |
|
5 |
CREATE SEQUENCE tmp_counter; |
|
6 |
UPDATE units SET sortkey = nextval('tmp_counter'); |
|
7 |
DROP SEQUENCE tmp_counter; |
|
8 |
ALTER TABLE units ALTER COLUMN sortkey SET NOT NULL; |
templates/webpages/am/edit_units_de.html | ||
---|---|---|
94 | 94 |
|
95 | 95 |
<table> |
96 | 96 |
<tr> |
97 |
<th class="listheading"> </th>
|
|
97 |
<th class="listheading" width="32" align="center" valign="center"><img alt="hoch" src="image/up.png"><img alt="runter" src="image/down.png"></th>
|
|
98 | 98 |
<th class="listheading">L?schen</th> |
99 | 99 |
<th class="listheading">Einheit</th> |
100 | 100 |
<th class="listheading">Basiseinheit</th> |
... | ... | |
106 | 106 |
|
107 | 107 |
<TMPL_LOOP NAME=UNITS> |
108 | 108 |
<tr> |
109 |
<td width="32" align="center" valign="center"><TMPL_IF __first__><img src="image/transparent16x16.gif"><TMPL_ELSE><a href="<TMPL_VAR updownlink>&dir=up&name=<TMPL_VAR name ESCAPE=URL>"><img alt="hoch" src="image/up.png"></a></TMPL_IF><TMPL_IF __last__><img src="image/transparent16x16.gif"><TMPL_ELSE><a href="<TMPL_VAR updownlink>&dir=down&name=<TMPL_VAR name ESCAPE=URL>"><img alt="runter" src="image/down.png"></a></TMPL_IF></td> |
|
109 | 110 |
<TMPL_IF NAME=in_use> |
110 |
<td><TMPL_VAR NAME=__counter__></td> |
|
111 | 111 |
<td> |
112 | 112 |
<input type="hidden" name="unchangeable_<TMPL_VAR NAME=__counter__>" value="1"> |
113 | 113 |
<input type="hidden" name="old_name_<TMPL_VAR NAME=__counter__>" value="<TMPL_VAR NAME=name>"> |
... | ... | |
119 | 119 |
|
120 | 120 |
<TMPL_ELSE> |
121 | 121 |
|
122 |
<td><TMPL_VAR NAME=__counter__></td> |
|
123 | 122 |
<td align="center"><input type="checkbox" name="delete_<TMPL_VAR NAME=__counter__>"></td> |
124 | 123 |
<td> |
125 | 124 |
<input type="hidden" name="old_name_<TMPL_VAR NAME=__counter__>" value="<TMPL_VAR NAME=name>"> |
templates/webpages/am/edit_units_master.html | ||
---|---|---|
94 | 94 |
|
95 | 95 |
<table> |
96 | 96 |
<tr> |
97 |
<th class="listheading"> </th>
|
|
97 |
<th class="listheading" width="32" align="center" valign="center"><img alt="<translate>up</translate>" src="image/up.png"><img alt="<translate>down</translate>" src="image/down.png"></th>
|
|
98 | 98 |
<th class="listheading"><translate>Delete</translate></th> |
99 | 99 |
<th class="listheading"><translate>Unit</translate></th> |
100 | 100 |
<th class="listheading"><translate>Base unit</translate></th> |
... | ... | |
106 | 106 |
|
107 | 107 |
<TMPL_LOOP NAME=UNITS> |
108 | 108 |
<tr> |
109 |
<td width="32" align="center" valign="center"><TMPL_IF __first__><img src="image/transparent16x16.gif"><TMPL_ELSE><a href="<TMPL_VAR updownlink>&dir=up&name=<TMPL_VAR name ESCAPE=URL>"><img alt="<translate>up</translate>" src="image/up.png"></a></TMPL_IF><TMPL_IF __last__><img src="image/transparent16x16.gif"><TMPL_ELSE><a href="<TMPL_VAR updownlink>&dir=down&name=<TMPL_VAR name ESCAPE=URL>"><img alt="<translate>down</translate>" src="image/down.png"></a></TMPL_IF></td> |
|
109 | 110 |
<TMPL_IF NAME=in_use> |
110 |
<td><TMPL_VAR NAME=__counter__></td> |
|
111 | 111 |
<td> |
112 | 112 |
<input type="hidden" name="unchangeable_<TMPL_VAR NAME=__counter__>" value="1"> |
113 | 113 |
<input type="hidden" name="old_name_<TMPL_VAR NAME=__counter__>" value="<TMPL_VAR NAME=name>"> |
... | ... | |
119 | 119 |
|
120 | 120 |
<TMPL_ELSE> |
121 | 121 |
|
122 |
<td><TMPL_VAR NAME=__counter__></td> |
|
123 | 122 |
<td align="center"><input type="checkbox" name="delete_<TMPL_VAR NAME=__counter__>"></td> |
124 | 123 |
<td> |
125 | 124 |
<input type="hidden" name="old_name_<TMPL_VAR NAME=__counter__>" value="<TMPL_VAR NAME=name>"> |
Auch abrufbar als: Unified diff
Einheiten sortierbar gemacht.