$self->{action} = lc $self->{action};
$self->{action} =~ s/( |-|,|\#)/_/g;
- $self->{version} = "2.4.1";
+ $self->{version} = "2.4.2";
$main::lxdebug->leave_sub();
}
my $neg = ($amount =~ s/-//);
- if (defined($places)) {
+ if (defined($places) && ($places ne '')) {
if ($places < 0) {
$amount *= 1;
$places *= -1;
$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();
}