+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.id = $form->{shipto_id} order by s.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);
+ $where = " WHERE 1=1 ";
+ if ($form->{shipto_id}) {
+ $where .= "AND ar.shipto_id=$form->{shipto_id} ";
+ }
+ if ($form->{from}) {
+ $where .= "AND ar.transdate >= '$form->{from}' ";
+ }
+ if ($form->{to}) {
+ $where .= "AND ar.transdate <= '$form->{to}' ";
+ }
+
+ my $query = qq|select shiptoname, adr_code, ar.transdate, ar.invnumber, ar.ordnumber, invoice.description, qty, invoice.unit FROM ar LEFT join shipto ON (ar.shipto_id=shipto.id) LEFT join invoice on (ar.id=invoice.trans_id) LEFT join parts ON (parts.id=invoice.parts_id) LEFT join adr ON (parts.adr_id=adr.id) $where ORDER BY ar.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();
+}
+
+sub adr {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $form) = @_;
+ my $dbh = $form->dbconnect($myconfig);
+ $where = " WHERE 1=1 ";
+ if ($form->{from}) {
+ $where .= "AND ar.transdate >= '$form->{from}' ";
+ }
+ if ($form->{to}) {
+ $where .= "AND ar.transdate <= '$form->{to}' ";
+ }
+ if ($form->{year}) {
+ $where = " WHERE ar.transdate >= '$form->{year}-01-01' AND ar.transdate <= '$form->{year}-12-31' ";
+ }
+
+ my $query = qq|select adr_code, adr_description, sum(base_qty), parts.unit from ar LEFT join invoice on (ar.id=invoice.trans_id) LEFT join parts ON (invoice.parts_id=parts.id) LEFT join adr ON (adr.id=parts.adr_id) $where GROUP BY adr_code,adr_description,parts.unit|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+
+
+ while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+ push @{ $form->{ADR} }, $ref;
+ }
+ $sth->finish;
+ $dbh->disconnect;
+
+ $main::lxdebug->leave_sub();
+}
+