+ $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) = @_;
+
+ my $options = ref $key eq 'HASH' ? $key : { key => $key };
+ $options->{key} ||= "all_customers";
+ my $limit_clause = "LIMIT $options->{limit}" if $options->{limit};
+ my $where = $options->{business_is_salesman} ? qq| AND business_id IN (SELECT id FROM business WHERE salesman)| : '';
+
+ my $query = qq|SELECT * FROM customer WHERE NOT obsolete $where ORDER BY name $limit_clause|;
+ $self->{ $options->{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_warehouses {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $param) = @_;
+
+ my ($key, $bins_key);
+
+ if ('' eq ref $param) {
+ $key = $param;
+
+ } else {
+ $key = $param->{key};
+ $bins_key = $param->{bins};
+ }
+
+ my $query = qq|SELECT w.* FROM warehouse w
+ WHERE (NOT w.invalid) AND
+ ((SELECT COUNT(b.*) FROM bin b WHERE b.warehouse_id = w.id) > 0)
+ ORDER BY w.sortkey|;
+
+ $self->{$key} = selectall_hashref_query($self, $dbh, $query);
+
+ if ($bins_key) {
+ $query = qq|SELECT id, description FROM bin WHERE warehouse_id = ?|;
+ my $sth = prepare_query($self, $dbh, $query);
+
+ foreach my $warehouse (@{ $self->{$key} }) {
+ do_statement($self, $sth, $query, $warehouse->{id});
+ $warehouse->{$bins_key} = [];
+
+ while (my $ref = $sth->fetchrow_hashref()) {
+ push @{ $warehouse->{$bins_key} }, $ref;
+ }
+ }
+ $sth->finish();
+ }
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _get_simple {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $table, $key, $sortkey) = @_;
+
+ my $query = qq|SELECT * FROM $table|;
+ $query .= qq| ORDER BY $sortkey| if ($sortkey);
+
+ $self->{$key} = selectall_hashref_query($self, $dbh, $query);
+
+ $main::lxdebug->leave_sub();
+}
+
+#sub _get_groups {
+# $main::lxdebug->enter_sub();
+#
+# my ($self, $dbh, $key) = @_;
+#
+# $key ||= "all_groups";
+#
+# my $groups = $main::auth->read_groups();
+#
+# $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"}) {
+ if (ref $params{"vendors"} eq 'HASH') {
+ $self->_get_vendors($dbh, $params{"vendors"}{key}, $params{"vendors"}{limit});
+ } else {
+ $self->_get_vendors($dbh, $params{"vendors"});
+ }
+ }
+
+ if($params{"payments"}) {
+ $self->_get_payments($dbh, $params{"payments"});
+ }
+
+ if($params{"departments"}) {
+ $self->_get_departments($dbh, $params{"departments"});
+ }
+
+ if ($params{price_factors}) {
+ $self->_get_simple($dbh, 'price_factors', $params{price_factors}, 'sortkey');
+ }
+
+ if ($params{warehouses}) {
+ $self->_get_warehouses($dbh, $params{warehouses});
+ }
+
+# if ($params{groups}) {
+# $self->_get_groups($dbh, $params{groups});
+# }
+
+ if ($params{partsgroup}) {
+ $self->get_partsgroup(\%main::myconfig, { all => 1, target => $params{partsgroup} });
+ }
+
+ $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} });