+ $dbh->disconnect();
+
+ $main::lxdebug->leave_sub();
+}
+
+sub get_duedate {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig) = @_;
+
+ my $dbh = $self->dbconnect($myconfig);
+ my $query = qq|SELECT current_date + terms_netto FROM payment_terms WHERE id = ?|;
+ ($self->{duedate}) = selectrow_query($self, $dbh, $query, $self->{payment_id});
+ $dbh->disconnect();
+
+ $main::lxdebug->leave_sub();
+}
+
+sub _get_contacts {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $id, $key) = @_;
+
+ $key = "all_contacts" unless ($key);
+
+ my $query =
+ qq|SELECT cp_id, cp_cv_id, cp_name, cp_givenname, cp_abteilung | .
+ qq|FROM contacts | .
+ qq|WHERE cp_cv_id = ? | .
+ qq|ORDER BY lower(cp_name)|;
+
+ $self->{$key} = selectall_hashref_query($self, $dbh, $query, $id);
+
+ $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)|;
+
+ $self->{$key} = selectall_hashref_query($self, $dbh, $query, @values);
+
+ $main::lxdebug->leave_sub();
+}
+
+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 shipto_id, shiptoname, shiptodepartment_1 | .
+ qq|FROM shipto | .
+ qq|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.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_employees {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $dbh, $key) = @_;
+
+ $key = "all_employees" unless ($key);
+ $self->{$key} =
+ selectall_hashref_query($self, $dbh, qq|SELECT * FROM employee|);
+
+ $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_lists {
+ $main::lxdebug->enter_sub();
+
+ my $self = shift;
+ my %params = @_;
+
+ my $dbh = $self->dbconnect(\%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{"employees"}) {
+ $self->_get_employees($dbh, $params{"employees"});
+ }
+
+ if ($params{"business_types"}) {
+ $self->_get_business_types($dbh, $params{"business_types"});
+ }
+
+ $dbh->disconnect();
+
+ $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->dbconnect($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
+#
+sub all_vc {
+ $main::lxdebug->enter_sub();
+
+ my ($self, $myconfig, $table, $module) = @_;
+
+ my $ref;
+ my $dbh = $self->dbconnect($myconfig);
+
+ $table = $table eq "customer" ? "customer" : "vendor";
+
+ my $query = qq|SELECT count(*) FROM $table|;
+ my ($count) = selectrow_query($self, $dbh, $query);
+
+ # build selection list
+ if ($count < $myconfig->{vclimit}) {
+ $query = qq|SELECT id, name, salesman_id
+ FROM $table WHERE NOT obsolete
+ ORDER BY name|;
+ $self->{"all_$table"} = selectall_hashref_query($self, $dbh, $query);
+ }
+
+ # get self