+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_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, $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_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|;
+
+ $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|;
+
+ $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|;
+
+ $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{"taxzones"}) {
+ $self->_get_taxzones($dbh, $params{"taxzones"});
+ }
+
+ if ($params{"employees"}) {
+ $self->_get_employees($dbh, $params{"employees"});
+ }
+
+ 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"});
+ }
+
+ $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
+ $self->get_employee($dbh);
+
+ # setup sales contacts
+ $query = qq|SELECT e.id, e.name
+ FROM employee e
+ WHERE (e.sales = '1') AND (NOT e.id = ?)|;
+ $self->{all_employees} = selectall_hashref_query($self, $dbh, $query, $self->{employee_id});
+
+ # this is for self
+ push(@{ $self->{all_employees} },
+ { id => $self->{employee_id},
+ name => $self->{employee} });
+
+ # sort the whole thing
+ @{ $self->{all_employees} } =
+ sort { $a->{name} cmp $b->{name} } @{ $self->{all_employees} };
+
+ if ($module eq 'AR') {
+
+ # prepare query for departments
+ $query = qq|SELECT id, description
+ FROM department
+ WHERE role = 'P'
+ ORDER BY description|;
+
+ } else {
+ $query = qq|SELECT id, description
+ FROM department
+ ORDER BY description|;
+ }
+
+ $self->{all_departments} = selectall_hashref_query($self, $dbh, $query);