From 828bd68326ee5bd732d3d01e9f166dacb7424657 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 2 Feb 2007 13:48:23 +0000 Subject: [PATCH] Die Zahlungskonditionen sortierbar gemacht. --- SL/AM.pm | 59 +++++++++----------- SL/CT.pm | 4 +- SL/Form.pm | 4 +- SL/IC.pm | 2 +- bin/mozilla/am.pl | 65 ++++++++++++++++++++--- bin/mozilla/common.pl | 26 +++++++++ locale/de/am | 3 ++ locale/de/cn | 2 + locale/de/common | 2 + locale/de/dn | 2 + locale/de/ic | 2 + locale/de/io | 2 + locale/de/ir | 2 + locale/de/is | 2 + locale/de/oe | 2 + sql/Pg-upgrade2/payment_terms_sortkey.sql | 8 +++ 16 files changed, 142 insertions(+), 45 deletions(-) create mode 100644 sql/Pg-upgrade2/payment_terms_sortkey.sql diff --git a/SL/AM.pm b/SL/AM.pm index dd59725da..77a5955d2 100644 --- a/SL/AM.pm +++ b/SL/AM.pm @@ -1204,6 +1204,8 @@ sub swap_sortkeys { (SELECT sortkey FROM $table WHERE id = ?) AS sortkey2|; my @values = ($form->{"id1"}, $form->{"id2"}); my @sortkeys = selectrow_query($form, $dbh, $query, @values); + $main::lxdebug->dump(0, "v", \@values); + $main::lxdebug->dump(0, "s", \@sortkeys); $query = qq|UPDATE $table SET sortkey = ? WHERE id = ?|; my $sth = $dbh->prepare($query); @@ -1328,15 +1330,13 @@ sub payment { # connect to database my $dbh = $form->dbconnect($myconfig); - my $query = qq|SELECT * - FROM payment_terms - ORDER BY id|; + my $query = qq|SELECT * FROM payment_terms ORDER BY sortkey|; $sth = $dbh->prepare($query); $sth->execute || $form->dberror($query); + $form->{ALL} = []; while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { - $ref->{percent_skonto} = $form->format_amount($myconfig,($ref->{percent_skonto} * 100)); push @{ $form->{ALL} }, $ref; } @@ -1354,16 +1354,11 @@ sub get_payment { # connect to database my $dbh = $form->dbconnect($myconfig); - my $query = - qq|SELECT * - FROM payment_terms - WHERE id = $form->{id}|; + my $query = qq|SELECT * FROM payment_terms WHERE id = ?|; my $sth = $dbh->prepare($query); - $sth->execute || $form->dberror($query); + $sth->execute($form->{"id"}) || $form->dberror($query . " ($form->{id})"); my $ref = $sth->fetchrow_hashref(NAME_lc); - $ref->{percent_skonto} = $form->format_amount($myconfig,($ref->{percent_skonto} * 100)); - map { $form->{$_} = $ref->{$_} } keys %$ref; $sth->finish; @@ -1381,32 +1376,31 @@ sub save_payment { # connect to database my $dbh = $form->dbconnect($myconfig); - $form->{description} =~ s/\'/\'\'/g; - $form->{description_long} =~ s/\'/\'\'/g; - $percentskonto = $form->parse_amount($myconfig, $form->{percent_skonto}) /100; - $form->{ranking} *= 1; - $form->{terms_netto} *= 1; - $form->{terms_skonto} *= 1; - $form->{percent_skonto} *= 1; - - + my @values = ($form->{description}, $form->{description_long}, + $form->{ranking} * 1, + $form->{terms_netto} * 1, $form->{terms_skonto} * 1, + $form->{percent_skonto} * 1); + my $query; # id is the old record if ($form->{id}) { $query = qq|UPDATE payment_terms SET - description = '$form->{description}', - ranking = $form->{ranking}, - description_long = '$form->{description_long}', - terms_netto = $form->{terms_netto}, - terms_skonto = $form->{terms_skonto}, - percent_skonto = $percentskonto - WHERE id = $form->{id}|; + 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, ranking, description_long, terms_netto, terms_skonto, percent_skonto) - VALUES ('$form->{description}', $form->{ranking}, '$form->{description_long}', $form->{terms_netto}, $form->{terms_skonto}, $percentskonto)|; + (description, description_long, ranking, + terms_netto, terms_skonto, percent_skonto, sortkey) + VALUES (?, ?, ?, ?, ?, ?, ?)|; + push(@values, $sortkey); } - $dbh->do($query) || $form->dberror($query); + do_query($form, $dbh, $query, @values); $dbh->disconnect; @@ -1421,9 +1415,8 @@ sub delete_payment { # connect to database my $dbh = $form->dbconnect($myconfig); - $query = qq|DELETE FROM payment_terms - WHERE id = $form->{id}|; - $dbh->do($query) || $form->dberror($query); + my $query = qq|DELETE FROM payment_terms WHERE id = ?|; + do_query($form, $dbh, $query, $form->{"id"}); $dbh->disconnect; diff --git a/SL/CT.pm b/SL/CT.pm index a4eb0b216..4578224bf 100644 --- a/SL/CT.pm +++ b/SL/CT.pm @@ -185,7 +185,7 @@ sub get_tuple { # get payment terms $query = qq|SELECT id, description FROM payment_terms - ORDER BY 1|; + ORDER BY sortkey|; $sth = $dbh->prepare($query); $sth->execute || $form->dberror($query); @@ -315,7 +315,7 @@ sub taxaccounts { # get payment terms $query = qq|SELECT id, description FROM payment_terms - ORDER BY 1|; + ORDER BY sortkey|; $sth = $dbh->prepare($query); $sth->execute || $form->dberror($query); diff --git a/SL/Form.pm b/SL/Form.pm index b12cb9e11..444bfdcaa 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -1562,7 +1562,7 @@ sub all_vc { # get payment terms $query = qq|SELECT id, description FROM payment_terms - ORDER BY 1|; + ORDER BY sortkey|; $sth = $dbh->prepare($query); $sth->execute || $self->dberror($query); @@ -1612,7 +1612,7 @@ sub language_payment { # get payment terms $query = qq|SELECT id, description FROM payment_terms - ORDER BY 1|; + ORDER BY sortkey|; $sth = $dbh->prepare($query); $sth->execute || $self->dberror($query); diff --git a/SL/IC.pm b/SL/IC.pm index 56bc2eeeb..933b80173 100644 --- a/SL/IC.pm +++ b/SL/IC.pm @@ -1517,7 +1517,7 @@ sub create_links { # get payment terms $query = qq|SELECT id, description FROM payment_terms - ORDER BY 1|; + ORDER BY sortkey|; $sth = $dbh->prepare($query); $sth->execute || $form->dberror($query); diff --git a/bin/mozilla/am.pl b/bin/mozilla/am.pl index c336f3a70..1571e24c0 100644 --- a/bin/mozilla/am.pl +++ b/bin/mozilla/am.pl @@ -2348,6 +2348,8 @@ sub edit_payment { $form->{title} = "Edit"; AM->get_payment(\%myconfig, \%$form); + $form->{percent_skonto} = + $form->format_amount(\%myconfig, $form->{percent_skonto} * 100); &payment_header; @@ -2362,15 +2364,23 @@ sub list_payment { AM->payment(\%myconfig, \%$form); - $form->{callback} = - "$form->{script}?action=list_payment&path=$form->{path}&login=$form->{login}&password=$form->{password}"; + $form->{callback} = build_std_url("action=list_payment"); $callback = $form->escape($form->{callback}); $form->{title} = $locale->text('Payment Terms'); - @column_index = qw(description description_long terms_netto terms_skonto percent_skonto); + @column_index = qw(up down description description_long terms_netto + terms_skonto percent_skonto); + $column_header{up} = + qq|| + . qq|| . $locale->text(| + . qq||; + $column_header{down} = + qq|| + . qq|| . $locale->text(| + . qq||; $column_header{description} = qq|| . $locale->text('Description') @@ -2414,6 +2424,9 @@ sub list_payment { |; + my $swap_link = build_std_url("action=swap_payment_terms"); + + my $row = 0; foreach $ref (@{ $form->{ALL} }) { $i++; @@ -2423,21 +2436,48 @@ sub list_payment { |; + if ($row) { + my $pref = $form->{ALL}->[$row - 1]; + $column_data{up} = + qq|| . + qq|| . + qq|| . $locale->text(| . + qq||; + } else { + $column_data{up} = qq| |; + } + + if ($row == (scalar(@{ $form->{ALL} }) - 1)) { + $column_data{down} = qq| |; + } else { + my $nref = $form->{ALL}->[$row + 1]; + $column_data{down} = + qq|| . + qq|| . + qq|| . $locale->text(| . + qq||; + } $column_data{description} = - qq|{script}?action=edit_payment&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{description}|; - $column_data{description_long} = qq|$ref->{description_long}|; + qq|{id}", "callback=$callback") . + qq|">| . H($ref->{description}) . qq||; + $column_data{description_long} = + qq|| . H($ref->{description_long}) . qq||; $column_data{terms_netto} = qq|$ref->{terms_netto}|; $column_data{terms_skonto} = qq|$ref->{terms_skonto}|; $column_data{percent_skonto} = - qq|$ref->{percent_skonto} %|; + qq|| . + $form->format_amount(\%myconfig, $ref->{percent_skonto} * 100) . + qq|%|; map { print "$column_data{$_}\n" } @column_index; print qq| |; + $row++; } print qq| @@ -2530,7 +2570,9 @@ sub payment_header { sub save_payment { $lxdebug->enter_sub(); - $form->isblank("description", $locale->text('Language missing!')); + $form->isblank("description", $locale->text('Description missing!')); + $form->{"percent_skonto"} = + $form->parse_amount(\%myconfig, $form->{percent_skonto}) / 100; AM->save_payment(\%myconfig, \%$form); $form->redirect($locale->text('Payment Terms saved!')); @@ -2546,6 +2588,15 @@ sub delete_payment { $lxdebug->leave_sub(); } +sub swap_payment_terms { + $lxdebug->enter_sub(); + + AM->swap_sortkeys(\%myconfig, $form, "payment_terms"); + list_payment(); + + $lxdebug->leave_sub(); +} + sub add_sic { $lxdebug->enter_sub(); diff --git a/bin/mozilla/common.pl b/bin/mozilla/common.pl index 18cb89074..ea34189db 100644 --- a/bin/mozilla/common.pl +++ b/bin/mozilla/common.pl @@ -41,6 +41,28 @@ sub restore_form { $lxdebug->leave_sub(); } +sub build_std_url { + $lxdebug->enter_sub(); + + my $url = "$form->{script}?"; + my $first = 1; + foreach my $key ((qw(login password path), @_)) { + next unless ($key); + $url .= "&" unless ($first); + $first = 0; + + if ($key =~ /=/) { + $url .= $key; + } else { + $url .= "${key}=" . E($form->{$key}); + } + } + + $lxdebug->leave_sub(); + + return $url; +} + sub select_employee { $lxdebug->enter_sub(); @@ -424,6 +446,10 @@ sub Q { return $form->quote($_[0]); } +sub E { + return $form->escape($_[0]); +} + sub format_dates { $lxdebug->enter_sub(); diff --git a/locale/de/am b/locale/de/am index 051d201bd..e39eb6fd5 100644 --- a/locale/de/am +++ b/locale/de/am @@ -298,6 +298,7 @@ $self->{texts} = { }; $self->{subs} = { + 'E' => 'E', 'H' => 'H', 'Q' => 'Q', 'account_header' => 'account_header', @@ -317,6 +318,7 @@ $self->{subs} = { 'audit_control' => 'audit_control', 'backup' => 'backup', 'buchungsgruppe_header' => 'buchungsgruppe_header', + 'build_std_url' => 'build_std_url', 'business_header' => 'business_header', 'calculate_qty' => 'calculate_qty', 'config' => 'config', @@ -401,6 +403,7 @@ $self->{subs} = { 'set_unit_languages' => 'set_unit_languages', 'sic_header' => 'sic_header', 'swap_buchungsgruppen' => 'swap_buchungsgruppen', + 'swap_payment_terms' => 'swap_payment_terms', 'vendor_selection' => 'vendor_selection', 'warehouse_header' => 'warehouse_header', 'erfassen' => 'add', diff --git a/locale/de/cn b/locale/de/cn index dddb11505..402c50cec 100644 --- a/locale/de/cn +++ b/locale/de/cn @@ -205,12 +205,14 @@ $self->{texts} = { }; $self->{subs} = { + 'E' => 'E', 'H' => 'H', 'Q' => 'Q', 'add' => 'add', 'add_transaction' => 'add_transaction', 'ap_transaction' => 'ap_transaction', 'ar_transaction' => 'ar_transaction', + 'build_std_url' => 'build_std_url', 'calculate_qty' => 'calculate_qty', 'check_form' => 'check_form', 'check_name' => 'check_name', diff --git a/locale/de/common b/locale/de/common index f9f38b6b4..551e13532 100644 --- a/locale/de/common +++ b/locale/de/common @@ -23,8 +23,10 @@ $self->{texts} = { }; $self->{subs} = { + 'E' => 'E', 'H' => 'H', 'Q' => 'Q', + 'build_std_url' => 'build_std_url', 'calculate_qty' => 'calculate_qty', 'delivery_customer_selection' => 'delivery_customer_selection', 'employee_selection_internal' => 'employee_selection_internal', diff --git a/locale/de/dn b/locale/de/dn index 7a1ac1ce5..07d6afc86 100644 --- a/locale/de/dn +++ b/locale/de/dn @@ -197,12 +197,14 @@ gestartet', }; $self->{subs} = { + 'E' => 'E', 'H' => 'H', 'Q' => 'Q', 'add' => 'add', 'add_transaction' => 'add_transaction', 'ap_transaction' => 'ap_transaction', 'ar_transaction' => 'ar_transaction', + 'build_std_url' => 'build_std_url', 'calculate_qty' => 'calculate_qty', 'check_form' => 'check_form', 'check_name' => 'check_name', diff --git a/locale/de/ic b/locale/de/ic index 7ab20fb7a..18d1b1dd3 100644 --- a/locale/de/ic +++ b/locale/de/ic @@ -246,11 +246,13 @@ aktualisieren wollen?', }; $self->{subs} = { + 'E' => 'E', 'H' => 'H', 'Q' => 'Q', 'add' => 'add', 'addtop100' => 'addtop100', 'assembly_row' => 'assembly_row', + 'build_std_url' => 'build_std_url', 'calculate_qty' => 'calculate_qty', 'check_form' => 'check_form', 'choice' => 'choice', diff --git a/locale/de/io b/locale/de/io index 18dc07d35..e8fc49d04 100644 --- a/locale/de/io +++ b/locale/de/io @@ -142,8 +142,10 @@ $self->{texts} = { }; $self->{subs} = { + 'E' => 'E', 'H' => 'H', 'Q' => 'Q', + 'build_std_url' => 'build_std_url', 'calculate_qty' => 'calculate_qty', 'check_form' => 'check_form', 'customer_details' => 'customer_details', diff --git a/locale/de/ir b/locale/de/ir index 536a5b36c..b52163649 100644 --- a/locale/de/ir +++ b/locale/de/ir @@ -197,12 +197,14 @@ $self->{texts} = { }; $self->{subs} = { + 'E' => 'E', 'H' => 'H', 'Q' => 'Q', 'add' => 'add', 'add_transaction' => 'add_transaction', 'ap_transaction' => 'ap_transaction', 'ar_transaction' => 'ar_transaction', + 'build_std_url' => 'build_std_url', 'calculate_qty' => 'calculate_qty', 'check_form' => 'check_form', 'check_name' => 'check_name', diff --git a/locale/de/is b/locale/de/is index afd668df9..2b4da0fc5 100644 --- a/locale/de/is +++ b/locale/de/is @@ -222,12 +222,14 @@ $self->{texts} = { }; $self->{subs} = { + 'E' => 'E', 'H' => 'H', 'Q' => 'Q', 'add' => 'add', 'add_transaction' => 'add_transaction', 'ap_transaction' => 'ap_transaction', 'ar_transaction' => 'ar_transaction', + 'build_std_url' => 'build_std_url', 'calculate_qty' => 'calculate_qty', 'check_form' => 'check_form', 'check_name' => 'check_name', diff --git a/locale/de/oe b/locale/de/oe index 05817170b..8523d1218 100644 --- a/locale/de/oe +++ b/locale/de/oe @@ -258,6 +258,7 @@ $self->{texts} = { }; $self->{subs} = { + 'E' => 'E', 'H' => 'H', 'Q' => 'Q', 'add' => 'add', @@ -265,6 +266,7 @@ $self->{subs} = { 'ap_transaction' => 'ap_transaction', 'ar_transaction' => 'ar_transaction', 'backorder_exchangerate' => 'backorder_exchangerate', + 'build_std_url' => 'build_std_url', 'calculate_qty' => 'calculate_qty', 'check_form' => 'check_form', 'check_name' => 'check_name', diff --git a/sql/Pg-upgrade2/payment_terms_sortkey.sql b/sql/Pg-upgrade2/payment_terms_sortkey.sql new file mode 100644 index 000000000..0c92e995c --- /dev/null +++ b/sql/Pg-upgrade2/payment_terms_sortkey.sql @@ -0,0 +1,8 @@ +-- @tag: payment_terms_sortkey +-- @description: Neue Spalte für Sortierreihenfolge der Zahlungskonditionen +-- @depends: release_2_4_1 +ALTER TABLE payment_terms ADD COLUMN sortkey integer; +CREATE SEQUENCE tmp_counter; +UPDATE payment_terms SET sortkey = nextval('tmp_counter'); +DROP SEQUENCE tmp_counter; +ALTER TABLE payment_terms ALTER COLUMN sortkey SET NOT NULL; -- 2.20.1