+ push @{ $self->{$key} }, { { "", "", "", "", "", "" } };
+ }
+ $sth->finish;
+ $main::lxdebug->leave_sub();
+}
+
+sub _get_projects {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $key) = @_;
+
+ my ($all, $old_id, $where, @values);
+
+ if (ref($key) eq "HASH") {
+ my $params = $key;
+
+ $key = "ALL_PROJECTS";
+
+ foreach my $p (keys(%{$params})) {
+ if ($p eq "all") {
+ $all = $params->{$p};
+ } elsif ($p eq "old_id") {
+ $old_id = $params->{$p};
+ } elsif ($p eq "key") {
+ $key = $params->{$p};
+ }
+ }
+ }
+
+ if (!$all) {
+ $where = "WHERE active ";
+ if ($old_id) {
+ if (ref($old_id) eq "ARRAY") {
+ my @ids = grep({ $_ } @{$old_id});
+ if (@ids) {
+ $where .= " OR id IN (" . join(",", map({ "?" } @ids)) . ") ";
+ push(@values, @ids);
+ }
+ } else {
+ $where .= " OR (id = ?) ";
+ push(@values, $old_id);
+ }
+ }
+ }
+
+ my $query =
+ qq|SELECT id, projectnumber, description, active | .
+ qq|FROM project | .
+ $where .
+ qq|ORDER BY lower(projectnumber)|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute(@values) ||
+ $self->dberror($query . " (" . join(", ", @values) . ")");
+
+ $self->{$key} = [];
+ while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+ push(@{ $self->{$key} }, $ref);
+ }
+
+ $sth->finish;
+ $main::lxdebug->leave_sub();
+}
+
+sub _get_shipto {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $vc_id, $key) = @_;
+
+ $key = "all_shipto" unless ($key);
+ $self->{$key} = [];
+
+ # get shipping addresses
+ my $query =
+ qq|SELECT s.shipto_id,s.shiptoname,s.shiptodepartment_1 | .
+ qq|FROM shipto s | .
+ qq|WHERE s.trans_id = ?|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute($vc_id) || $self->dberror($query . " ($vc_id)");
+
+ while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
+ push(@{ $self->{$key} }, $ref);
+ }
+ $sth->finish;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _get_printers {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $key) = @_;
+
+ $key = "all_printers" unless ($key);
+ $self->{$key} = [];
+
+ my $query = qq|SELECT id, printer_description, printer_command FROM printers|;
+ my $sth = $dbh->prepare($query);
+ $sth->execute() || $self->dberror($query);
+
+ while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
+ push(@{ $self->{$key} }, $ref);
+ }
+ $sth->finish;
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _get_charts {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $params) = @_;
+
+ $key = $params->{key};
+ $key = "all_charts" unless ($key);
+ $self->{$key} = [];
+
+ my $transdate = quote_db_date($params->{transdate});
+
+ my $query =
+ qq|SELECT c.accno, c.description, c.link, tk.taxkey_id, tk.tax_id | .
+ qq|FROM chart c | .
+ qq|LEFT JOIN taxkeys tk ON | .
+ qq|(tk.id = (SELECT id FROM taxkeys | .
+ qq| WHERE taxkeys.chart_id = c.id AND startdate <= $transdate | .
+ qq| ORDER BY startdate DESC LIMIT 1)) | .
+ qq|ORDER BY c.accno|;
+
+ my $sth = $dbh->prepare($query);
+ $sth->execute() || $self->dberror($query);
+
+ while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
+ push(@{ $self->{$key} }, $ref);