+sub get_contact {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+ my $dbh = $form->dbconnect($myconfig);
+ my $query = qq|SELECT c.*
+ FROM contacts c
+ WHERE c.cp_id = $form->{cp_id} order by c.cp_id limit 1|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ my $ref = $sth->fetchrow_hashref(NAME_lc);
+
+ map { $form->{$_} = $ref->{$_} } keys %$ref;
+
+ $sth->finish;
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}
+
+
+sub get_shipto {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+ my $dbh = $form->dbconnect($myconfig);
+ my $query = qq|SELECT s.*
+ FROM shipto s
+ WHERE s.shipto_id = $form->{shipto_id}|;
+ #WHERE s.shipto_id = $form->{shipto_id} order by s.shipto_id limit 1|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+ my $ref = $sth->fetchrow_hashref(NAME_lc);
+
+ map { $form->{$_} = $ref->{$_} } keys %$ref;
+
+ $sth->finish;
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub get_delivery {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+ my $dbh = $form->dbconnect($myconfig);
+ $tabelle = ($form->{db} eq "vendor") ? "ap" : "ar";
+
+ $where = " WHERE 1=1 ";
+ if ($form->{shipto_id} && $tabelle eq "ar") {
+ $where .= "AND $tabelle.shipto_id=$form->{shipto_id} ";
+ } else {
+ $where .="AND $tabelle.$form->{db}_id=$form->{id} ";
+ }
+ if ($form->{from}) {
+ $where .= "AND $tabelle.transdate >= '$form->{from}' ";
+ }
+ if ($form->{to}) {
+ $where .= "AND $tabelle.transdate <= '$form->{to}' ";
+ }
+ my $query = qq|select shiptoname, $tabelle.transdate, $tabelle.invnumber, $tabelle.ordnumber, invoice.description, qty, invoice.unit FROM $tabelle LEFT JOIN shipto ON |;
+ $query .= ($tabelle eq "ar") ? qq|($tabelle.shipto_id=shipto.shipto_id) |:qq|($tabelle.id=shipto.trans_id) |;
+ $query .=qq|LEFT join invoice on ($tabelle.id=invoice.trans_id) LEFT join parts ON (parts.id=invoice.parts_id) $where ORDER BY $tabelle.transdate DESC LIMIT 15|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+
+ while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+ push @{ $form->{DELIVERY} }, $ref;
+ }
+ $sth->finish;
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}