1 #====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #====================================================================
12 $main::lxdebug->enter_sub();
14 my ($self, $myconfig, $form, $order_by, $order_dir) = @_;
16 my $dbh = $form->dbconnect($myconfig);
18 my (@filter_values, $filter);
19 if ($form->{"partnumber"}) {
20 $filter .= " AND (partnumber ILIKE ?)";
21 push(@filter_values, '%' . $form->{"partnumber"} . '%');
23 if ($form->{"description"}) {
24 $filter .= " AND (description ILIKE ?)";
25 push(@filter_values, '%' . $form->{"description"} . '%');
27 substr($filter, 1, 3) = "WHERE" if ($filter);
29 $order_by =~ s/[^a-zA-Z_]//g;
30 $order_dir = $order_dir ? "ASC" : "DESC";
32 my $query = "SELECT id, partnumber, description FROM parts $filter ORDER BY $order_by $order_dir";
33 my $sth = $dbh->prepare($query);
34 $sth->execute(@filter_values) || $form->dberror($query . " (" . join(", ", @filter_values) . ")");
36 while (my $ref = $sth->fetchrow_hashref()) {
37 push(@{$parts}, $ref);
42 $main::lxdebug->leave_sub();
47 sub retrieve_projects {
48 $main::lxdebug->enter_sub();
50 my ($self, $myconfig, $form, $order_by, $order_dir) = @_;
52 my $dbh = $form->dbconnect($myconfig);
54 my (@filter_values, $filter);
55 if ($form->{"projectnumber"}) {
56 $filter .= " AND (projectnumber ILIKE ?)";
57 push(@filter_values, '%' . $form->{"projectnumber"} . '%');
59 if ($form->{"description"}) {
60 $filter .= " AND (description ILIKE ?)";
61 push(@filter_values, '%' . $form->{"description"} . '%');
63 substr($filter, 1, 3) = "WHERE" if ($filter);
65 $order_by =~ s/[^a-zA-Z_]//g;
66 $order_dir = $order_dir ? "ASC" : "DESC";
68 my $query = "SELECT id, projectnumber, description FROM project $filter ORDER BY $order_by $order_dir";
69 my $sth = $dbh->prepare($query);
70 $sth->execute(@filter_values) || $form->dberror($query . " (" . join(", ", @filter_values) . ")");
72 while (my $ref = $sth->fetchrow_hashref()) {
73 push(@{$projects}, $ref);
78 $main::lxdebug->leave_sub();
83 sub retrieve_employees {
84 $main::lxdebug->enter_sub();
86 my ($self, $myconfig, $form, $order_by, $order_dir) = @_;
88 my $dbh = $form->dbconnect($myconfig);
90 my (@filter_values, $filter);
91 if ($form->{"name"}) {
92 $filter .= " AND (name ILIKE ?)";
93 push(@filter_values, '%' . $form->{"name"} . '%');
95 substr($filter, 1, 3) = "WHERE" if ($filter);
97 $order_by =~ s/[^a-zA-Z_]//g;
98 $order_dir = $order_dir ? "ASC" : "DESC";
100 my $query = "SELECT id, name FROM employee $filter ORDER BY $order_by $order_dir";
101 my $sth = $dbh->prepare($query);
102 $sth->execute(@filter_values) || $form->dberror($query . " (" . join(", ", @filter_values) . ")");
104 while (my $ref = $sth->fetchrow_hashref()) {
105 push(@{$employees}, $ref);
110 $main::lxdebug->leave_sub();
115 sub retrieve_delivery_customer {
116 $main::lxdebug->enter_sub();
118 my ($self, $myconfig, $form, $order_by, $order_dir) = @_;
120 my $dbh = $form->dbconnect($myconfig);
122 my (@filter_values, $filter);
123 if ($form->{"name"}) {
124 $filter .= " (name ILIKE '%$form->{name}%') AND";
125 push(@filter_values, '%' . $form->{"name"} . '%');
127 #substr($filter, 1, 3) = "WHERE" if ($filter);
129 $order_by =~ s/[^a-zA-Z_]//g;
130 $order_dir = $order_dir ? "ASC" : "DESC";
132 my $query = "SELECT id, name, customernumber, (street || ', ' || zipcode || city) as address FROM customer WHERE $filter business_id=(SELECT id from business WHERE description='Endkunde') ORDER BY $order_by $order_dir";
133 my $sth = $dbh->prepare($query);
134 $sth->execute() || $form->dberror($query . " (" . join(", ", @filter_values) . ")");
135 my $delivery_customers = [];
136 while (my $ref = $sth->fetchrow_hashref()) {
137 push(@{$delivery_customers}, $ref);
142 $main::lxdebug->leave_sub();
144 return $delivery_customers;
147 sub retrieve_vendor {
148 $main::lxdebug->enter_sub();
150 my ($self, $myconfig, $form, $order_by, $order_dir) = @_;
152 my $dbh = $form->dbconnect($myconfig);
154 my (@filter_values, $filter);
155 if ($form->{"name"}) {
156 $filter .= " (name ILIKE '%$form->{name}%') AND";
157 push(@filter_values, '%' . $form->{"name"} . '%');
159 #substr($filter, 1, 3) = "WHERE" if ($filter);
161 $order_by =~ s/[^a-zA-Z_]//g;
162 $order_dir = $order_dir ? "ASC" : "DESC";
164 my $query = "SELECT id, name, customernumber, (street || ', ' || zipcode || city) as address FROM customer WHERE $filter business_id=(SELECT id from business WHERE description='Händler') ORDER BY $order_by $order_dir";
165 my $sth = $dbh->prepare($query);
166 $sth->execute() || $form->dberror($query . " (" . join(", ", @filter_values) . ")");
168 while (my $ref = $sth->fetchrow_hashref()) {
169 push(@{$vendors}, $ref);
174 $main::lxdebug->leave_sub();