+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;
+ push @where, qq|business_id IN (SELECT id FROM business WHERE salesman)| if $options->{business_is_salesman};
+ push @where, qq|NOT obsolete| if !$options->{with_obsolete};
+ my $where_str = @where ? "WHERE " . join(" AND ", map { "($_)" } @where) : '';
+
+ my $query = qq|SELECT * FROM customer $where_str 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();
+#}
+