$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();
}
$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);
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);
}
$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->{$_} }
$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;
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);
}
$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->{$_} }
}
$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
$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;
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);
use SL::LXDebug;
$lxdebug = LXDebug->new();
+use CGI;
use SL::Form;
use SL::Locale;
}
$form = new Form;
+$cgi = new CGI('');
# name of this script
$0 =~ tr/\\/\//;
$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}/;
$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}) {
<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} = "";
? 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>
<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)) {
#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});
? 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>
#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});
$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}>
|;