Drop-Down-Auswahlboxen für Ansprechpartner und Lieferadresse bei jedem Maskenaufbau...
authorMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 14 Feb 2007 15:01:49 +0000 (15:01 +0000)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 14 Feb 2007 15:01:49 +0000 (15:01 +0000)
SL/Form.pm
SL/IR.pm
SL/IS.pm
SL/OE.pm
am.pl
bin/mozilla/ir.pl
bin/mozilla/is.pl
bin/mozilla/oe.pl

index b63e633..c4eaf22 100644 (file)
@@ -1395,48 +1395,70 @@ sub get_duedate {
   $main::lxdebug->leave_sub();
 }
 
-# get other contact for transaction and form - html/tex
-sub get_contact {
+# get contacts for id, if no contact return {"","","","",""}
+sub get_contacts {
   $main::lxdebug->enter_sub();
 
-  my ($self, $dbh, $id) = @_;
+  my ($self, $dbh, $id, $key) = @_;
 
-  my $query = qq|SELECT c.*
-              FROM contacts c
-              WHERE cp_id=$id|;
-  $sth = $dbh->prepare($query);
-  $sth->execute || $self->dberror($query);
+  $key = "all_contacts" unless ($key);
+  $self->{$key} = [];
 
-  $ref = $sth->fetchrow_hashref(NAME_lc);
+  my $query =
+    qq|SELECT c.cp_id, c.cp_cv_id, c.cp_name, c.cp_givenname, c.cp_abteilung | .
+    qq|FROM contacts c | .
+    qq|WHERE cp_cv_id = ? | .
+    qq|ORDER BY lower(c.cp_name)|;
+  my $sth = $dbh->prepare($query);
+  $sth->execute($id) || $self->dberror($query . " ($id)");
 
-  push @{ $self->{$_} }, $ref;
+  my $i = 0;
+  while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+    push @{ $self->{$key} }, $ref;
+    $i++;
+  }
 
+  if ($i == 0) {
+    push @{ $self->{$key} }, { { "", "", "", "", "", "" } };
+  }
   $sth->finish;
   $main::lxdebug->leave_sub();
 }
 
-# get contacts for id, if no contact return {"","","","",""}
-sub get_contacts {
+sub get_lists {
   $main::lxdebug->enter_sub();
 
-  my ($self, $dbh, $id) = @_;
+  my $self = shift;
+  my %params = @_;
+
+  my $dbh = $self->dbconnect(\%main::myconfig);
+  my ($sth, $query, $ref);
 
-  my $query = qq|SELECT c.cp_id, c.cp_cv_id, c.cp_name, c.cp_givenname, c.cp_abteilung
-              FROM contacts c
-              WHERE cp_cv_id=$id|;
-  my $sth = $dbh->prepare($query);
-  $sth->execute || $self->dberror($query);
+  my $vc = $self->{"vc"} eq "customer" ? "customer" : "vendor";
+  my $vc_id = $self->{"${vc}_id"};
 
-  my $i = 0;
-  while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
-    push @{ $self->{all_contacts} }, $ref;
-    $i++;
+  if ($params{"contacts"}) {
+    $self->get_contacts($dbh, $vc_id, $params{"contacts"});
   }
 
-  if ($i == 0) {
-    push @{ $self->{all_contacts} }, { { "", "", "", "", "", "" } };
+  if ($params{"shipto"}) {
+    # get shipping addresses
+    $query =
+      qq|SELECT s.shipto_id,s.shiptoname,s.shiptodepartment_1 | .
+      qq|FROM shipto s | .
+      qq|WHERE s.trans_id = ?|;
+    $sth = $dbh->prepare($query);
+    $sth->execute($vc_id) || $self->dberror($query . " ($vc_id)");
+
+    $self->{$params{"shipto"}} = [];
+    while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
+      push(@{ $self->{$params{"shipto"}} }, $ref);
+    }
+    $sth->finish;
   }
-  $sth->finish;
+
+  $dbh->disconnect();
+
   $main::lxdebug->leave_sub();
 }
 
index 8fb9b77..ae3a3d4 100644 (file)
--- a/SL/IR.pm
+++ b/SL/IR.pm
@@ -81,9 +81,6 @@ sub post_invoice {
     $sth->finish;
   }
 
-  ($null, $form->{contact_id}) = split /--/, $form->{contact};
-  $form->{contact_id} *= 1;
-
   map { $form->{$_} =~ s/\'/\'\'/g } qw(invnumber ordnumber quonumber);
 
   my ($amount, $linetotal, $lastinventoryaccno, $lastexpenseaccno);
@@ -641,7 +638,7 @@ sub post_invoice {
              curr = '$form->{currency}',
              department_id = $form->{department_id},
               storno = '$form->{storno}',
-              cp_id = $form->{contact_id}
+              cp_id = | . conv_i($form->{cp_id}, 'NULL') . qq|
               WHERE id = $form->{id}|;
   $dbh->do($query) || $form->dberror($query);
 
@@ -1042,15 +1039,6 @@ sub get_vendor {
   }
   $sth->finish;
 
-  $form->get_contacts($dbh, $form->{vendor_id});
-
-  ($null, $form->{cp_id}) = split /--/, $form->{contact};
-
-  # get contact if selected
-  if ($form->{contact} ne "--" && $form->{contact} ne "") {
-    $form->get_contact($dbh, $form->{cp_id});
-  }
-
   # get shipto if we do not convert an order or invoice
   if (!$form->{shipto}) {
     map { delete $form->{$_} }
index 12b5b7c..e59f254 100644 (file)
--- a/SL/IS.pm
+++ b/SL/IS.pm
@@ -475,8 +475,6 @@ sub post_invoice {
     $form->get_employee($dbh);
   }
 
-  $form->{contact_id} = $form->{cp_id};
-  $form->{contact_id} *= 1;
   $form->{payment_id} *= 1;
   $form->{language_id} *= 1;
   $form->{taxzone_id} *= 1;
@@ -1010,7 +1008,7 @@ Message: $form->{message}\r| if $form->{message};
               delivery_vendor_id = $form->{delivery_vendor_id},
               employee_id = $form->{employee_id},
               storno = '$form->{storno}',
-              cp_id = $form->{contact_id}
+              cp_id = | . conv_i($form->{"cp_id"}, 'NULL') . qq|
               WHERE id = $form->{id}
              |;
   $dbh->do($query) || $form->dberror($query);
@@ -1775,14 +1773,6 @@ sub get_customer {
   }
   $sth->finish;
 
-  $form->get_contacts($dbh, $form->{customer_id});
-  $form->{cp_id} *= 1;
-
-  # get contact if selected
-  if ($form->{cp_id}) {
-    $form->get_contact($dbh, $form->{cp_id});
-  }
-
   # get shipto if we did not converted an order or invoice
   if (!$form->{shipto}) {
     map { delete $form->{$_} }
@@ -1813,19 +1803,6 @@ sub get_customer {
   }
   $sth->finish;
 
-  # get shipping addresses
-  $query = qq|SELECT s.shipto_id,s.shiptoname,s.shiptodepartment_1
-              FROM shipto s
-             WHERE s.trans_id = $form->{customer_id}|;
-  $sth = $dbh->prepare($query);
-  $sth->execute || $form->dberror($query);
-
-  my $customertax = ();
-  while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
-    push(@{ $form->{SHIPTO} }, $ref);
-  }
-  $sth->finish;
-
   # setup last accounts used for this customer
   if (!$form->{id} && $form->{type} !~ /_(order|quotation)/) {
     $query = qq|SELECT c.accno, c.description, c.link, c.category
index 916d41b..c1d97a5 100644 (file)
--- a/SL/OE.pm
+++ b/SL/OE.pm
@@ -180,8 +180,6 @@ sub save {
     $form->get_employee($dbh);
   }
 
-  $form->{contact_id} = $form->{cp_id};
-  $form->{contact_id} *= 1;
   $form->{payment_id} *= 1;
   $form->{language_id} *= 1;
   $form->{shipto_id} *= 1;
@@ -477,7 +475,7 @@ Message: $form->{message}\r| if $form->{message};
              delivery_vendor_id = $form->{delivery_vendor_id},
              delivery_customer_id = $form->{delivery_customer_id},
              employee_id = $form->{employee_id},
-              cp_id = $form->{contact_id}
+              cp_id = | . conv_i($form->{cp_id}, 'NULL') . qq|
               WHERE id = $form->{id}|;
   $dbh->do($query) || $form->dberror($query);
 
diff --git a/am.pl b/am.pl
index b8a8b2d..7e111f3 100755 (executable)
--- a/am.pl
+++ b/am.pl
@@ -42,6 +42,7 @@ $| = 1;
 use SL::LXDebug;
 $lxdebug = LXDebug->new();
 
+use CGI;
 use SL::Form;
 use SL::Locale;
 
@@ -53,6 +54,7 @@ if (defined($latex) && !defined($latex_templates)) {
 }
 
 $form = new Form;
+$cgi = new CGI('');
 
 # name of this script
 $0 =~ tr/\\/\//;
index 3736fbe..0f9c295 100644 (file)
@@ -219,7 +219,7 @@ sub form_header {
   $lxdebug->enter_sub();
 
   # set option selected
-  foreach $item (qw(AP vendor currency department contact)) {
+  foreach $item (qw(AP vendor currency department)) {
     $form->{"select$item"} =~ s/ selected//;
     $form->{"select$item"} =~
       s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
@@ -239,20 +239,6 @@ sub form_header {
   $form->{creditremaining} =
     $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
 
-  #build contacts
-  if ($form->{all_contacts}) {
-
-    $form->{selectcontact} = "";
-    foreach $item (@{ $form->{all_contacts} }) {
-      if ($form->{cp_id} == $item->{cp_id}) {
-        $form->{selectcontact} .=
-          "<option selected>$item->{cp_name}--$item->{cp_id}";
-      } else {
-        $form->{selectcontact} .= "<option>$item->{cp_name}--$item->{cp_id}";
-      }
-    }
-  }
-
   $exchangerate = "";
   if ($form->{currency} ne $form->{defaultcurrency}) {
     if ($form->{forex}) {
@@ -273,6 +259,17 @@ sub form_header {
 <input type=hidden name=forex value=$form->{forex}>
 |;
 
+  $form->get_lists("contacts" => "ALL_CONTACTS");
+
+  my (%labels, @values);
+  foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
+    push(@values, $item->{"cp_id"});
+    $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
+      ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
+  }
+  my $contact =
+    $cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
+                     '-labels' => \%labels, '-default' => $form->{"cp_id"});
 
   if (@{ $form->{TAXZONE} }) {
     $form->{selecttaxzone} = "";
@@ -308,11 +305,6 @@ sub form_header {
     ? qq|<select name=vendor>$form->{selectvendor}</select>\n<input type=hidden name="selectvendor" value="$form->{selectvendor}">|
     : qq|<input name=vendor value="$form->{vendor}" size=35>|;
 
-  $contact =
-    ($form->{selectcontact})
-    ? qq|<select name=contact>$form->{selectcontact}</select>\n<input type=hidden name="selectcontact" value="$form->{selectcontact}">|
-    : qq|<input name=contact value="$form->{contact}" size=35>|;
-
   $department = qq|
               <tr>
              <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
index 4637f6b..e29ca4c 100644 (file)
@@ -353,34 +353,33 @@ sub form_header {
                <input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
              </tr>|;
 
-
-  if (@{ $form->{SHIPTO} }) {
-    $form->{selectshipto} = "<option value=0></option>";
-    foreach $item (@{ $form->{SHIPTO} }) {
-      if ($item->{shipto_id} == $form->{shipto_id}) {
-        $form->{selectshipto} .=
-          "<option value=$item->{shipto_id} selected>$item->{shiptoname} $item->{shiptodepartment_1}</option>";
-      } else {
-        $form->{selectshipto} .=
-          "<option value=$item->{shipto_id}>$item->{shiptoname} $item->{shiptodepartment}</option>";
-      }
-
-    }
-  } else {
-    $form->{selectshipto} = $form->unquote($form->{selectshipto});
-    $form->{selectshipto} =~ s/ selected//g;
-    if ($form->{shipto_id} ne "") {
-      $form->{selectshipto} =~ s/value=$form->{shipto_id}/value=$form->{shipto_id} selected/;
-    }
+  $form->get_lists("contacts" => "ALL_CONTACTS",
+                   "shipto" => "ALL_SHIPTO");
+
+  my (%labels, @values);
+  foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
+    push(@values, $item->{"cp_id"});
+    $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
+      ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
+  }
+  my $contact =
+    $cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
+                     '-labels' => \%labels, '-default' => $form->{"cp_id"});
+
+  %labels = ();
+  @values = ("");
+  foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
+    push(@values, $item->{"shipto_id"});
+    $labels{$item->{"shipto_id"}} =
+      $item->{"shiptoname"} . " " . $item->{"shiptodepartment_1"};
   }
 
-  $shipto = qq|
+  my $shipto = qq|
                <th align=right>| . $locale->text('Shipping Address') . qq|</th>
-               <td><select name=shipto_id style="width:200px;">$form->{selectshipto}</select></td>|;
-  $form->{selectshipto} = $form->quote($form->{selectshipto});
-  $shipto .= qq| <input type=hidden name=selectshipto value="$form->{selectshipto}">|;
-
-
+               <td>| .
+    $cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values,
+                     '-labels' => \%labels, '-default' => $form->{"shipto_id"})
+    . qq|</td>|;
 
   # set option selected
   foreach $item (qw(AR customer currency department employee)) {
@@ -392,35 +391,12 @@ sub form_header {
   #quote customer Bug 133
   $form->{selectcustomer} = $form->quote($form->{selectcustomer});
   
-  #build contacts
-  if ($form->{all_contacts}) {
-
-    $form->{selectcontact} = "<option></option>";
-    foreach $item (@{ $form->{all_contacts} }) {
-      my $department = ($item->{cp_abteilung}) ? "--$item->{cp_abteilung}" : "";
-      if ($form->{cp_id} == $item->{cp_id}) {
-        $form->{selectcontact} .=
-          "<option value=$item->{cp_id} selected>$item->{cp_name}$department</option>";
-      } else {
-        $form->{selectcontact} .= "<option value=$item->{cp_id}>$item->{cp_name}$department</option>";
-      }
-    }
-  } else {
-    $form->{selectcontact} =~ s/ selected//g;
-    if ($form->{cp_id} ne "") {
-      $form->{selectcontact} =~ s/value=$form->{cp_id}/value=$form->{cp_id} selected/;
-    }
-  }
-
-
   if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
     $creditwarning = 1;
   } else {
     $creditwarning = 0;
   }
 
-  #else {$form->{all_contacts} = 0;}
-
   $form->{exchangerate} =
     $form->format_amount(\%myconfig, $form->{exchangerate});
 
@@ -452,12 +428,6 @@ sub form_header {
     ? qq|<select name=customer>$form->{selectcustomer}</select>\n<input type=hidden name="selectcustomer" value="$form->{selectcustomer}">|
     : qq|<input name=customer value="$form->{customer}" size=35>|;
 
-  #sk
-  $contact =
-    ($form->{selectcontact})
-    ? qq|<select name=cp_id>$form->{selectcontact}</select>\n<input type=hidden name="selectcontact" value="$form->{selectcontact}">|
-    : qq|<input name=contact value="$form->{contact}" size=35>|;
-
   $department = qq|
               <tr>
                <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
index f7a52e9..bbb90c2 100644 (file)
@@ -407,54 +407,33 @@ sub form_header {
   #quote select[customer|vendor] Bug 133
   $form->{"select$form->{vc}"} = $form->quote($form->{"select$form->{vc}"});
 
-  #build contacts
-  if ($form->{all_contacts}) {
-
-    $form->{selectcontact} = "<option></option>";
-    foreach $item (@{ $form->{all_contacts} }) {
-      my $department = ($item->{cp_abteilung}) ? "--$item->{cp_abteilung}" : "";
-      if ($form->{cp_id} == $item->{cp_id}) {
-        $form->{selectcontact} .=
-          "<option value=$item->{cp_id} selected>$item->{cp_name}$department</option>";
-      } else {
-        $form->{selectcontact} .= "<option value=$item->{cp_id}>$item->{cp_name}$department</option>";
-      }
-    }
-  } else {
-    $form->{selectcontact} =~ s/ selected//g;
-    if ($form->{cp_id} ne "") {
-      $form->{selectcontact} =~ s/value=$form->{cp_id}/value=$form->{cp_id} selected/;
-    }
-  }
+  $form->get_lists("contacts" => "ALL_CONTACTS",
+                   "shipto" => "ALL_SHIPTO");
 
+  my (%labels, @values);
+  foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
+    push(@values, $item->{"cp_id"});
+    $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
+      ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
+  }
+  my $contact =
+    $cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
+                     '-labels' => \%labels, '-default' => $form->{"cp_id"});
 
-  if (@{ $form->{SHIPTO} }) {
-    $form->{selectshipto} = "<option value=0></option>";
-    foreach $item (@{ $form->{SHIPTO} }) {
-      if ($item->{shipto_id} == $form->{shipto_id}) {
-        $form->{selectshipto} .=
-          "<option value=$item->{shipto_id} selected>$item->{shiptoname} $item->{shiptodepartment_1}</option>";
-      } else {
-        $form->{selectshipto} .=
-          "<option value=$item->{shipto_id}>$item->{shiptoname} $item->{shiptodepartment}</option>";
-      }
-
-    }
-  } else {
-    $form->{selectshipto} = $form->unquote($form->{selectshipto});
-    $form->{selectshipto} =~ s/ selected//g;
-    if ($form->{shipto_id} ne "") {
-      $form->{selectshipto} =~ s/value=$form->{shipto_id}/value=$form->{shipto_id} selected/;
-    }
+  %labels = ();
+  @values = ("");
+  foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
+    push(@values, $item->{"shipto_id"});
+    $labels{$item->{"shipto_id"}} =
+      $item->{"shiptoname"} . " " . $item->{"shiptodepartment_1"};
   }
 
-  $shipto = qq|
+  my $shipto = qq|
                <th align=right>| . $locale->text('Shipping Address') . qq|</th>
-               <td><select name=shipto_id style="width:200px;">$form->{selectshipto}</select></td>|;
-  $form->{selectshipto} = $form->quote($form->{selectshipto});
-  $shipto .= qq| <input type=hidden name=selectshipto value="$form->{selectshipto}">|;
-
-
+               <td>| .
+    $cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values,
+                     '-labels' => \%labels, '-default' => $form->{"shipto_id"})
+    . qq|</td>|;
 
   $form->{exchangerate} =
     $form->format_amount(\%myconfig, $form->{exchangerate});
@@ -470,11 +449,6 @@ sub form_header {
   $form->{creditremaining} =
     $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
 
-  $contact =
-    ($form->{selectcontact})
-    ? qq|<select name=cp_id>$form->{selectcontact}</select>\n<input type=hidden name="selectcontact" value="$form->{selectcontact}">|
-    : qq|<input name=contact value="$form->{contact}" size=35>|;
-
   $exchangerate = qq|
 <input type=hidden name=forex value=$form->{forex}>
 |;