Die Zahlungskonditionen sortierbar gemacht.
authorMoritz Bunkus <m.bunkus@linet-services.de>
Fri, 2 Feb 2007 13:48:23 +0000 (13:48 +0000)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Fri, 2 Feb 2007 13:48:23 +0000 (13:48 +0000)
16 files changed:
SL/AM.pm
SL/CT.pm
SL/Form.pm
SL/IC.pm
bin/mozilla/am.pl
bin/mozilla/common.pl
locale/de/am
locale/de/cn
locale/de/common
locale/de/dn
locale/de/ic
locale/de/io
locale/de/ir
locale/de/is
locale/de/oe
sql/Pg-upgrade2/payment_terms_sortkey.sql [new file with mode: 0644]

index dd59725..77a5955 100644 (file)
--- 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;
 
index a4eb0b2..4578224 100644 (file)
--- 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);
 
index b12cb9e..444bfdc 100644 (file)
@@ -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);
 
index 56bc2ee..933b801 100644 (file)
--- 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);
 
index c336f3a..1571e24 100644 (file)
@@ -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|<th class="listheading" align="center" valign="center">|
+    . qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">|
+    . qq|</th>|;
+  $column_header{down} =
+      qq|<th class="listheading" align="center" valign="center">|
+    . qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">|
+    . qq|</th>|;
   $column_header{description} =
       qq|<th class=listheading>|
     . $locale->text('Description')
@@ -2414,6 +2424,9 @@ sub list_payment {
         </tr>
 |;
 
+  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 {
         <tr valign=top class=listrow$i>
 |;
 
+    if ($row) {
+      my $pref = $form->{ALL}->[$row - 1];
+      $column_data{up} =
+        qq|<td align="center" valign="center">| .
+        qq|<a href="${swap_link}&id1=$ref->{id}&id2=$pref->{id}">| .
+        qq|<img src="image/up.png" alt="| . $locale->text("up") . qq|">| .
+        qq|</a></td>|;
+    } else {
+      $column_data{up} = qq|<td>&nbsp;</td>|;
+    }
+
+    if ($row == (scalar(@{ $form->{ALL} }) - 1)) {
+      $column_data{down} = qq|<td>&nbsp;</td>|;
+    } else {
+      my $nref = $form->{ALL}->[$row + 1];
+      $column_data{down} =
+        qq|<td align="center" valign="center">| .
+        qq|<a href="${swap_link}&id1=$ref->{id}&id2=$nref->{id}">| .
+        qq|<img src="image/down.png" alt="| . $locale->text("down") . qq|">| .
+        qq|</a></td>|;
+    }
 
     $column_data{description} =
-      qq|<td><a href=$form->{script}?action=edit_payment&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{description}</td>|;
-    $column_data{description_long}           = qq|<td align=right>$ref->{description_long}</td>|;
+      qq|<td><a href="| .
+      build_std_url("action=edit_payment", "id=$ref->{id}", "callback=$callback") .
+      qq|">| . H($ref->{description}) . qq|</a></td>|;
+    $column_data{description_long} =
+      qq|<td align=right>| . H($ref->{description_long}) . qq|</td>|;
     $column_data{terms_netto} =
       qq|<td align=right>$ref->{terms_netto}</td>|;
     $column_data{terms_skonto} =
       qq|<td align=right>$ref->{terms_skonto}</td>|;
     $column_data{percent_skonto} =
-      qq|<td align=right>$ref->{percent_skonto} %</td>|;
+      qq|<td align=right>| .
+      $form->format_amount(\%myconfig, $ref->{percent_skonto} * 100) .
+      qq|%</td>|;
     map { print "$column_data{$_}\n" } @column_index;
 
     print qq|
        </tr>
 |;
+    $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();
 
index 18cb890..ea34189 100644 (file)
@@ -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();
 
index 051d201..e39eb6f 100644 (file)
@@ -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',
index dddb115..402c50c 100644 (file)
@@ -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',
index f9f38b6..551e135 100644 (file)
@@ -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',
index 7a1ac1c..07d6afc 100644 (file)
@@ -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',
index 7ab20fb..18d1b1d 100644 (file)
@@ -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',
index 18dc07d..e8fc49d 100644 (file)
@@ -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',
index 536a5b3..b521636 100644 (file)
@@ -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',
index afd668d..2b4da0f 100644 (file)
@@ -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',
index 0581717..8523d12 100644 (file)
@@ -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 (file)
index 0000000..0c92e99
--- /dev/null
@@ -0,0 +1,8 @@
+-- @tag: payment_terms_sortkey
+-- @description: Neue Spalte f&uuml;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;