1 #====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #====================================================================
11 use Time::HiRes qw(gettimeofday);
14 my ($a, $b) = gettimeofday();
15 return "${a}-${b}-${$}";
19 return "/tmp/lx-office-tmp-" . unique_id();
23 $main::lxdebug->enter_sub();
25 my ($self, $myconfig, $form, $order_by, $order_dir) = @_;
27 my $dbh = $form->dbconnect($myconfig);
29 my (@filter_values, $filter);
30 if ($form->{"partnumber"}) {
31 $filter .= " AND (partnumber ILIKE ?)";
32 push(@filter_values, '%' . $form->{"partnumber"} . '%');
34 if ($form->{"description"}) {
35 $filter .= " AND (description ILIKE ?)";
36 push(@filter_values, '%' . $form->{"description"} . '%');
38 substr($filter, 1, 3) = "WHERE" if ($filter);
40 $order_by =~ s/[^a-zA-Z_]//g;
41 $order_dir = $order_dir ? "ASC" : "DESC";
43 my $query = "SELECT id, partnumber, description FROM parts $filter ORDER BY $order_by $order_dir";
44 my $sth = $dbh->prepare($query);
45 $sth->execute(@filter_values) || $form->dberror($query . " (" . join(", ", @filter_values) . ")");
47 while (my $ref = $sth->fetchrow_hashref()) {
48 push(@{$parts}, $ref);
53 $main::lxdebug->leave_sub();
58 sub retrieve_projects {
59 $main::lxdebug->enter_sub();
61 my ($self, $myconfig, $form, $order_by, $order_dir) = @_;
63 my $dbh = $form->dbconnect($myconfig);
65 my (@filter_values, $filter);
66 if ($form->{"projectnumber"}) {
67 $filter .= " AND (projectnumber ILIKE ?)";
68 push(@filter_values, '%' . $form->{"projectnumber"} . '%');
70 if ($form->{"description"}) {
71 $filter .= " AND (description ILIKE ?)";
72 push(@filter_values, '%' . $form->{"description"} . '%');
74 substr($filter, 1, 3) = "WHERE" if ($filter);
76 $order_by =~ s/[^a-zA-Z_]//g;
77 $order_dir = $order_dir ? "ASC" : "DESC";
79 my $query = "SELECT id, projectnumber, description FROM project $filter ORDER BY $order_by $order_dir";
80 my $sth = $dbh->prepare($query);
81 $sth->execute(@filter_values) || $form->dberror($query . " (" . join(", ", @filter_values) . ")");
83 while (my $ref = $sth->fetchrow_hashref()) {
84 push(@{$projects}, $ref);
89 $main::lxdebug->leave_sub();
94 sub retrieve_employees {
95 $main::lxdebug->enter_sub();
97 my ($self, $myconfig, $form, $order_by, $order_dir) = @_;
99 my $dbh = $form->dbconnect($myconfig);
101 my (@filter_values, $filter);
102 if ($form->{"name"}) {
103 $filter .= " AND (name ILIKE ?)";
104 push(@filter_values, '%' . $form->{"name"} . '%');
106 substr($filter, 1, 3) = "WHERE" if ($filter);
108 $order_by =~ s/[^a-zA-Z_]//g;
109 $order_dir = $order_dir ? "ASC" : "DESC";
111 my $query = "SELECT id, name FROM employee $filter ORDER BY $order_by $order_dir";
112 my $sth = $dbh->prepare($query);
113 $sth->execute(@filter_values) || $form->dberror($query . " (" . join(", ", @filter_values) . ")");
115 while (my $ref = $sth->fetchrow_hashref()) {
116 push(@{$employees}, $ref);
121 $main::lxdebug->leave_sub();
126 sub retrieve_delivery_customer {
127 $main::lxdebug->enter_sub();
129 my ($self, $myconfig, $form, $order_by, $order_dir) = @_;
131 my $dbh = $form->dbconnect($myconfig);
133 my (@filter_values, $filter);
134 if ($form->{"name"}) {
135 $filter .= " (name ILIKE '%$form->{name}%') AND";
136 push(@filter_values, '%' . $form->{"name"} . '%');
138 #substr($filter, 1, 3) = "WHERE" if ($filter);
140 $order_by =~ s/[^a-zA-Z_]//g;
141 $order_dir = $order_dir ? "ASC" : "DESC";
143 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";
144 my $sth = $dbh->prepare($query);
145 $sth->execute() || $form->dberror($query . " (" . join(", ", @filter_values) . ")");
146 my $delivery_customers = [];
147 while (my $ref = $sth->fetchrow_hashref()) {
148 push(@{$delivery_customers}, $ref);
153 $main::lxdebug->leave_sub();
155 return $delivery_customers;
158 sub retrieve_vendor {
159 $main::lxdebug->enter_sub();
161 my ($self, $myconfig, $form, $order_by, $order_dir) = @_;
163 my $dbh = $form->dbconnect($myconfig);
165 my (@filter_values, $filter);
166 if ($form->{"name"}) {
167 $filter .= " (name ILIKE '%$form->{name}%') AND";
168 push(@filter_values, '%' . $form->{"name"} . '%');
170 #substr($filter, 1, 3) = "WHERE" if ($filter);
172 $order_by =~ s/[^a-zA-Z_]//g;
173 $order_dir = $order_dir ? "ASC" : "DESC";
175 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";
176 my $sth = $dbh->prepare($query);
177 $sth->execute() || $form->dberror($query . " (" . join(", ", @filter_values) . ")");
179 while (my $ref = $sth->fetchrow_hashref()) {
180 push(@{$vendors}, $ref);
185 $main::lxdebug->leave_sub();