1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger Accounting
11 # Author: Philip Reetz
12 # Email: p.reetz@linet-services.de
13 # Web: http://www.linet-services.de/
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
30 # Software license module
32 #======================================================================
39 $main::lxdebug->enter_sub();
41 my ($self, $myconfig, $form) = @_;
43 $dbh = $form->dbconnect($myconfig);
46 qq| INSERT INTO license (licensenumber) VALUES ('$form->{licensenumber}')|;
47 $sth = $dbh->prepare($query);
48 $sth->execute || $form->dberror($query);
52 qq|SELECT l.id FROM license l WHERE l.licensenumber = '$form->{licensenumber}'|;
53 $sth = $dbh->prepare($query);
54 $sth->execute || $form->dberror($query);
55 ($license_id) = $sth->fetchrow_array;
59 $query = qq|UPDATE license SET
60 validuntil = '$form->{validuntil}',
61 licensenumber = '$form->{licensenumber}',
62 parts_id = $form->{parts_id},
63 customer_id = $form->{customer_id},
64 comment = '$form->{comment}',
65 quantity = $form->{quantity}
66 WHERE id=$license_id|;
67 $sth = $dbh->prepare($query);
68 $sth->execute || $form->dberror($query);
71 if ($form->{own_product}) {
72 $form->update_balance($dbh, "parts", "onhand", qq|id = $form->{parts_id}|,
78 $main::lxdebug->leave_sub();
84 $main::lxdebug->enter_sub();
86 my ($self, $myconfig, $form) = @_;
89 my $dbh = $form->dbconnect($myconfig);
91 my $f = $dbh->quote('%' . $form->{"customer_name"} . '%');
92 my $query = qq|SELECT * FROM customer WHERE name ilike $f|;
93 my $sth = $dbh->prepare($query);
94 $sth->execute || $form->dberror($query);
95 $form->{"all_customers"} = [];
96 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
97 push(@{ $form->{"all_customers"} }, $ref);
101 $main::lxdebug->leave_sub();
105 $main::lxdebug->enter_sub();
107 my ($self, $myconfig, $form) = @_;
108 my ($ref, $sth, $f, $s, $query);
109 my $dbh = $form->dbconnect($myconfig);
111 if ($form->{"partnumber"} || $form->{"description"}) {
112 $f = "(parts_id IN (SELECT id FROM parts WHERE ";
113 if ($form->{"partnumber"}) {
116 . $dbh->quote('%' . $form->{"partnumber"} . '%') . ")";
118 if ($form->{"description"}) {
119 $f .= " AND " if ($form->{"partnumber"});
121 "(description ILIKE "
122 . $dbh->quote('%' . $form->{"description"} . '%') . ")";
127 if ($form->{"customer_name"}) {
128 $f .= " AND " if ($f);
130 "(l.customer_id IN (SELECT id FROM customer WHERE name ILIKE "
131 . $dbh->quote('%' . $form->{"customer_name"} . '%') . "))";
134 if (!$form->{"all"} && $form->{"expiring_in"}) {
135 $f .= " AND " if ($f);
137 "(validuntil < now() + "
138 . $dbh->quote("" . $form->{"expiring_in"} . " months") . ")";
141 if (!$form->{"show_expired"}) {
142 $f .= " AND " if ($f);
143 $f .= "(validuntil >= now())";
147 $f = "WHERE (inventory_accno_id notnull) AND $f";
149 $f = "WHERE (inventory_accno_id notnull)";
152 if ($form->{"sortby"} eq "partnumber") {
154 } elsif ($form->{"sortby"} eq "description") {
155 $s = "p.description";
156 } elsif ($form->{"sortby"} eq "name") {
158 } elsif ($form->{"sortby"} eq "validuntil") {
163 if ($form->{"sortasc"}) {
170 "SELECT l.*, p.partnumber, p.description, c.name, a.invnumber "
172 . "LEFT JOIN parts p ON (p.id = l.parts_id) "
173 . "LEFT JOIN customer c ON (c.id = l.customer_id) "
174 . "LEFT JOIN ar a ON "
175 . "(a.id = (SELECT i.trans_id FROM invoice i WHERE i.id = "
176 . "(SELECT li.trans_id FROM licenseinvoice li WHERE li.license_id = l.id))) "
179 $sth = $dbh->prepare($query);
180 $sth->execute() || $form->dberror($query);
181 $form->{"licenses"} = [];
182 while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
183 push(@{ $form->{"licenses"} }, $ref);
188 $main::lxdebug->leave_sub();
192 $main::lxdebug->enter_sub();
194 my ($self, $myconfig, $form) = @_;
195 my ($ref, $sth, $query);
196 my $dbh = $form->dbconnect($myconfig);
199 "SELECT l.*, p.partnumber, p.description, c.name, c.street, "
200 . "c.zipcode, c.city, c.country, c.contact, c.phone, c.fax, c.homepage, "
201 . "c.email, c.notes, c.customernumber, c.language, a.invnumber "
203 . "LEFT JOIN parts p ON (p.id = l.parts_id) "
204 . "LEFT JOIN customer c ON (c.id = l.customer_id) "
205 . "LEFT JOIN ar a ON "
206 . "(a.id = (SELECT i.trans_id FROM invoice i WHERE i.id = "
207 . "(SELECT li.trans_id FROM licenseinvoice li WHERE li.license_id = l.id))) "
208 . "LEFT JOIN invoice i ON "
210 . "(SELECT li.trans_id FROM licenseinvoice li WHERE li.license_id = l.id)) "
213 $sth = $dbh->prepare($query);
214 $sth->execute() || $form->dberror($query);
215 $form->{"license"} = $sth->fetchrow_hashref(NAME_lc);
218 $main::lxdebug->leave_sub();