+sub _get_shipto {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $vc_id, $key) = @_;
+
+ $key = "all_shipto" unless ($key);
+
+ # get shipping addresses
+ my $query = qq|SELECT * FROM shipto WHERE trans_id = ?|;
+
+ $self->{$key} = selectall_hashref_query($self, $dbh, $query, $vc_id);
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _get_printers {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $key) = @_;
+
+ $key = "all_printers" unless ($key);
+
+ my $query = qq|SELECT id, printer_description, printer_command, template_code FROM printers|;
+
+ $self->{$key} = selectall_hashref_query($self, $dbh, $query);
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _get_charts {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $params) = @_;
+
+ $key = $params->{key};
+ $key = "all_charts" unless ($key);
+
+ my $transdate = quote_db_date($params->{transdate});
+
+ my $query =
+ qq|SELECT c.id, 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|;
+
+ $self->{$key} = selectall_hashref_query($self, $dbh, $query);
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _get_taxcharts {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $key) = @_;
+
+ $key = "all_taxcharts" unless ($key);
+
+ my $query = qq|SELECT * FROM tax ORDER BY taxkey|;
+
+ $self->{$key} = selectall_hashref_query($self, $dbh, $query);
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _get_taxzones {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $key) = @_;
+
+ $key = "all_taxzones" unless ($key);
+
+ my $query = qq|SELECT * FROM tax_zones ORDER BY id|;
+
+ $self->{$key} = selectall_hashref_query($self, $dbh, $query);
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _get_employees {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $default_key, $key) = @_;
+
+ $key = $default_key unless ($key);
+ $self->{$key} = selectall_hashref_query($self, $dbh, qq|SELECT * FROM employee ORDER BY name|);
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _get_business_types {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $key) = @_;
+
+ $key = "all_business_types" unless ($key);
+ $self->{$key} =
+ selectall_hashref_query($self, $dbh, qq|SELECT * FROM business|);
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _get_languages {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $key) = @_;
+
+ $key = "all_languages" unless ($key);
+
+ my $query = qq|SELECT * FROM language ORDER BY id|;
+
+ $self->{$key} = selectall_hashref_query($self, $dbh, $query);
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _get_dunning_configs {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $key) = @_;
+
+ $key = "all_dunning_configs" unless ($key);
+
+ my $query = qq|SELECT * FROM dunning_config ORDER BY dunning_level|;
+
+ $self->{$key} = selectall_hashref_query($self, $dbh, $query);
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _get_currencies {
+$main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $key) = @_;
+
+ $key = "all_currencies" unless ($key);
+
+ my $query = qq|SELECT curr AS currency FROM defaults|;
+
+ $self->{$key} = [split(/\:/ , selectfirst_hashref_query($self, $dbh, $query)->{currency})];
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _get_payments {
+$main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $key) = @_;
+
+ $key = "all_payments" unless ($key);
+
+ my $query = qq|SELECT * FROM payment_terms ORDER BY id|;
+
+ $self->{$key} = selectall_hashref_query($self, $dbh, $query);
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _get_customers {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $key) = @_;
+
+ $key = "all_customers" unless ($key);
+
+ my $query = qq|SELECT * FROM customer WHERE NOT obsolete ORDER BY name|;
+
+ $self->{$key} = selectall_hashref_query($self, $dbh, $query);
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _get_vendors {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $key) = @_;
+
+ $key = "all_vendors" unless ($key);
+
+ my $query = qq|SELECT * FROM vendor WHERE NOT obsolete ORDER BY name|;
+
+ $self->{$key} = selectall_hashref_query($self, $dbh, $query);
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _get_departments {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $key) = @_;
+
+ $key = "all_departments" unless ($key);
+
+ my $query = qq|SELECT * FROM department ORDER BY description|;
+
+ $self->{$key} = selectall_hashref_query($self, $dbh, $query);
+
+ $main::lxdebug->leave_sub();
+}
+
+sub get_lists {
+ $main::lxdebug->enter_sub();
+
+ my $self = shift;
+ my %params = @_;
+
+ my $dbh = $self->get_standard_dbh(\%main::myconfig);
+ my ($sth, $query, $ref);
+
+ my $vc = $self->{"vc"} eq "customer" ? "customer" : "vendor";
+ my $vc_id = $self->{"${vc}_id"};
+
+ if ($params{"contacts"}) {
+ $self->_get_contacts($dbh, $vc_id, $params{"contacts"});
+ }
+
+ if ($params{"shipto"}) {
+ $self->_get_shipto($dbh, $vc_id, $params{"shipto"});
+ }
+
+ if ($params{"projects"} || $params{"all_projects"}) {
+ $self->_get_projects($dbh, $params{"all_projects"} ?
+ $params{"all_projects"} : $params{"projects"},
+ $params{"all_projects"} ? 1 : 0);
+ }
+
+ if ($params{"printers"}) {
+ $self->_get_printers($dbh, $params{"printers"});
+ }
+
+ if ($params{"languages"}) {
+ $self->_get_languages($dbh, $params{"languages"});
+ }
+
+ if ($params{"charts"}) {
+ $self->_get_charts($dbh, $params{"charts"});
+ }
+
+ if ($params{"taxcharts"}) {
+ $self->_get_taxcharts($dbh, $params{"taxcharts"});
+ }
+
+ if ($params{"taxzones"}) {
+ $self->_get_taxzones($dbh, $params{"taxzones"});
+ }
+
+ if ($params{"employees"}) {
+ $self->_get_employees($dbh, "all_employees", $params{"employees"});
+ }
+
+ if ($params{"salesmen"}) {
+ $self->_get_employees($dbh, "all_salesmen", $params{"salesmen"});
+ }
+
+ if ($params{"business_types"}) {
+ $self->_get_business_types($dbh, $params{"business_types"});
+ }
+
+ if ($params{"dunning_configs"}) {
+ $self->_get_dunning_configs($dbh, $params{"dunning_configs"});
+ }
+
+ if($params{"currencies"}) {
+ $self->_get_currencies($dbh, $params{"currencies"});
+ }
+
+ if($params{"customers"}) {
+ $self->_get_customers($dbh, $params{"customers"});
+ }
+
+ if($params{"vendors"}) {
+ $self->_get_vendors($dbh, $params{"vendors"});
+ }
+
+ if($params{"payments"}) {
+ $self->_get_payments($dbh, $params{"payments"});
+ }
+
+ if($params{"departments"}) {
+ $self->_get_departments($dbh, $params{"departments"});
+ }
+
+ $main::lxdebug->leave_sub();
+}
+
+# this sub gets the id and name from $table
+sub get_name {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $table) = @_;
+
+ # connect to database
+ my $dbh = $self->get_standard_dbh($myconfig);
+
+ $table = $table eq "customer" ? "customer" : "vendor";
+ my $arap = $self->{arap} eq "ar" ? "ar" : "ap";
+
+ my ($query, @values);
+
+ if (!$self->{openinvoices}) {
+ my $where;
+ if ($self->{customernumber} ne "") {
+ $where = qq|(vc.customernumber ILIKE ?)|;
+ push(@values, '%' . $self->{customernumber} . '%');
+ } else {
+ $where = qq|(vc.name ILIKE ?)|;
+ push(@values, '%' . $self->{$table} . '%');
+ }
+
+ $query =
+ qq~SELECT vc.id, vc.name,
+ vc.street || ' ' || vc.zipcode || ' ' || vc.city || ' ' || vc.country AS address
+ FROM $table vc
+ WHERE $where AND (NOT vc.obsolete)
+ ORDER BY vc.name~;
+ } else {
+ $query =
+ qq~SELECT DISTINCT vc.id, vc.name,
+ vc.street || ' ' || vc.zipcode || ' ' || vc.city || ' ' || vc.country AS address
+ FROM $arap a
+ JOIN $table vc ON (a.${table}_id = vc.id)
+ WHERE NOT (a.amount = a.paid) AND (vc.name ILIKE ?)
+ ORDER BY vc.name~;
+ push(@values, '%' . $self->{$table} . '%');
+ }
+
+ $self->{name_list} = selectall_hashref_query($self, $dbh, $query, @values);
+
+ $main::lxdebug->leave_sub();
+
+ return scalar(@{ $self->{name_list} });
+}
+
+# the selection sub is used in the AR, AP, IS, IR and OE module