From 15682dc47316fcc2deab66730045cd38afec001f Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 14 Feb 2007 15:01:49 +0000 Subject: [PATCH] =?utf8?q?Drop-Down-Auswahlboxen=20f=C3=BCr=20Ansprechpart?= =?utf8?q?ner=20und=20Lieferadresse=20bei=20jedem=20Maskenaufbau=20aus=20d?= =?utf8?q?er=20Datenbank=20aufbauen.=20F=C3=BCr=20den=20HTML-Code=20wird?= =?utf8?q?=20jetzt=20das=20CGI-Modul=20verwendet.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Form.pm | 72 ++++++++++++++++++++++++++++--------------- SL/IR.pm | 14 +-------- SL/IS.pm | 25 +-------------- SL/OE.pm | 4 +-- am.pl | 2 ++ bin/mozilla/ir.pl | 32 ++++++++----------- bin/mozilla/is.pl | 78 +++++++++++++++-------------------------------- bin/mozilla/oe.pl | 70 +++++++++++++----------------------------- 8 files changed, 110 insertions(+), 187 deletions(-) diff --git a/SL/Form.pm b/SL/Form.pm index b63e633ab..c4eaf2259 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -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(); } diff --git a/SL/IR.pm b/SL/IR.pm index 8fb9b7775..ae3a3d4e1 100644 --- 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->{$_} } diff --git a/SL/IS.pm b/SL/IS.pm index 12b5b7c2e..e59f2546d 100644 --- 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 diff --git a/SL/OE.pm b/SL/OE.pm index 916d41bda..c1d97a593 100644 --- 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 b8a8b2d1b..7e111f368 100755 --- 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/\\/\//; diff --git a/bin/mozilla/ir.pl b/bin/mozilla/ir.pl index 3736fbe2c..0f9c295a1 100644 --- a/bin/mozilla/ir.pl +++ b/bin/mozilla/ir.pl @@ -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} .= - ""; - foreach $item (@{ $form->{SHIPTO} }) { - if ($item->{shipto_id} == $form->{shipto_id}) { - $form->{selectshipto} .= - ""; - } else { - $form->{selectshipto} .= - ""; - } - - } - } 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| | . $locale->text('Shipping Address') . qq| - |; - $form->{selectshipto} = $form->quote($form->{selectshipto}); - $shipto .= qq| |; - - + | . + $cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, + '-labels' => \%labels, '-default' => $form->{"shipto_id"}) + . qq||; # 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} = ""; - foreach $item (@{ $form->{all_contacts} }) { - my $department = ($item->{cp_abteilung}) ? "--$item->{cp_abteilung}" : ""; - if ($form->{cp_id} == $item->{cp_id}) { - $form->{selectcontact} .= - ""; - } else { - $form->{selectcontact} .= ""; - } - } - } 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|\n| : qq||; - #sk - $contact = - ($form->{selectcontact}) - ? qq|\n| - : qq||; - $department = qq| | . $locale->text('Department') . qq| diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index f7a52e979..bbb90c2d6 100644 --- a/bin/mozilla/oe.pl +++ b/bin/mozilla/oe.pl @@ -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} = ""; - foreach $item (@{ $form->{all_contacts} }) { - my $department = ($item->{cp_abteilung}) ? "--$item->{cp_abteilung}" : ""; - if ($form->{cp_id} == $item->{cp_id}) { - $form->{selectcontact} .= - ""; - } else { - $form->{selectcontact} .= ""; - } - } - } 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} = ""; - foreach $item (@{ $form->{SHIPTO} }) { - if ($item->{shipto_id} == $form->{shipto_id}) { - $form->{selectshipto} .= - ""; - } else { - $form->{selectshipto} .= - ""; - } - - } - } 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| | . $locale->text('Shipping Address') . qq| - |; - $form->{selectshipto} = $form->quote($form->{selectshipto}); - $shipto .= qq| |; - - + | . + $cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values, + '-labels' => \%labels, '-default' => $form->{"shipto_id"}) + . qq||; $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|\n| - : qq||; - $exchangerate = qq| {forex}> |; -- 2.20.1