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 #======================================================================
 
  41   $main::lxdebug->enter_sub();
 
  43   my ($self, $myconfig, $form) = @_;
 
  45   my $dbh = $form->dbconnect($myconfig);
 
  48     qq| INSERT INTO license (licensenumber) VALUES ('$form->{licensenumber}')|;
 
  49   my $sth = $dbh->prepare($query);
 
  50   $sth->execute || $form->dberror($query);
 
  54     qq|SELECT l.id FROM license l WHERE l.licensenumber = '$form->{licensenumber}'|;
 
  55   $sth = $dbh->prepare($query);
 
  56   $sth->execute || $form->dberror($query);
 
  57   my ($license_id) = $sth->fetchrow_array;
 
  61   $query = qq|UPDATE license SET
 
  62               validuntil = '$form->{validuntil}',
 
  63               licensenumber = '$form->{licensenumber}',
 
  64               parts_id = $form->{parts_id},
 
  65               customer_id = $form->{customer_id},
 
  66               comment = '$form->{comment}',
 
  67               quantity = $form->{quantity}
 
  68               WHERE id=$license_id|;
 
  69   $sth = $dbh->prepare($query);
 
  70   $sth->execute || $form->dberror($query);
 
  75   $main::lxdebug->leave_sub();
 
  81   $main::lxdebug->enter_sub();
 
  83   my ($self, $myconfig, $form) = @_;
 
  86   my $dbh = $form->dbconnect($myconfig);
 
  88   my $f     = $dbh->quote('%' . $form->{"customer_name"} . '%');
 
  89   my $query = qq|SELECT * FROM customer WHERE name ilike $f|;
 
  90   my $sth   = $dbh->prepare($query);
 
  91   $sth->execute || $form->dberror($query);
 
  92   $form->{"all_customers"} = [];
 
  93   while ($ref = $sth->fetchrow_hashref("NAME_lc")) {
 
  94     push(@{ $form->{"all_customers"} }, $ref);
 
  98   $main::lxdebug->leave_sub();
 
 102   $main::lxdebug->enter_sub();
 
 104   my ($self, $myconfig, $form) = @_;
 
 105   my ($ref, $sth, $f, $s, $query);
 
 106   my $dbh = $form->dbconnect($myconfig);
 
 108   if ($form->{"partnumber"} || $form->{"description"}) {
 
 109     $f = "(parts_id IN (SELECT id FROM parts WHERE ";
 
 110     if ($form->{"partnumber"}) {
 
 113         . $dbh->quote('%' . $form->{"partnumber"} . '%') . ")";
 
 115     if ($form->{"description"}) {
 
 116       $f .= " AND " if ($form->{"partnumber"});
 
 118         "(description ILIKE "
 
 119         . $dbh->quote('%' . $form->{"description"} . '%') . ")";
 
 124   if ($form->{"customer_name"}) {
 
 125     $f .= " AND " if ($f);
 
 127       "(l.customer_id IN (SELECT id FROM customer WHERE name ILIKE "
 
 128       . $dbh->quote('%' . $form->{"customer_name"} . '%') . "))";
 
 131   if (!$form->{"all"} && $form->{"expiring_in"}) {
 
 132     $f .= " AND " if ($f);
 
 134       "(validuntil < now() + "
 
 135       . $dbh->quote("" . $form->{"expiring_in"} . " months") . ")";
 
 138   if (!$form->{"show_expired"}) {
 
 139     $f .= " AND " if ($f);
 
 140     $f .= "(validuntil >= now())";
 
 144     $f = "WHERE (inventory_accno_id notnull) AND $f";
 
 146     $f = "WHERE (inventory_accno_id notnull)";
 
 149   if ($form->{"sortby"} eq "partnumber") {
 
 151   } elsif ($form->{"sortby"} eq "description") {
 
 152     $s = "p.description";
 
 153   } elsif ($form->{"sortby"} eq "name") {
 
 155   } elsif ($form->{"sortby"} eq "validuntil") {
 
 160   if ($form->{"sortasc"}) {
 
 167       "SELECT l.*, p.partnumber, p.description, c.name, a.invnumber "
 
 169     . "LEFT JOIN parts p ON (p.id = l.parts_id) "
 
 170     . "LEFT JOIN customer c ON (c.id = l.customer_id) "
 
 171     . "LEFT JOIN ar a ON "
 
 172     . "(a.id = (SELECT i.trans_id FROM invoice i WHERE i.id = "
 
 173     . "(SELECT li.trans_id FROM licenseinvoice li WHERE li.license_id = l.id))) "
 
 176   $sth = $dbh->prepare($query);
 
 177   $sth->execute() || $form->dberror($query);
 
 178   $form->{"licenses"} = [];
 
 179   while ($ref = $sth->fetchrow_hashref("NAME_lc")) {
 
 180     push(@{ $form->{"licenses"} }, $ref);
 
 185   $main::lxdebug->leave_sub();
 
 189   $main::lxdebug->enter_sub();
 
 191   my ($self, $myconfig, $form) = @_;
 
 192   my ($ref, $sth, $query);
 
 193   my $dbh = $form->dbconnect($myconfig);
 
 196       "SELECT l.*, p.partnumber, p.description, c.name, c.street, "
 
 197     . "c.zipcode, c.city, c.country, c.contact, c.phone, c.fax, c.homepage, "
 
 198     . "c.email, c.notes, c.customernumber, c.language, a.invnumber "
 
 200     . "LEFT JOIN parts p ON (p.id = l.parts_id) "
 
 201     . "LEFT JOIN customer c ON (c.id = l.customer_id) "
 
 202     . "LEFT JOIN ar a ON "
 
 203     . "(a.id = (SELECT i.trans_id FROM invoice i WHERE i.id = "
 
 204     . "(SELECT li.trans_id FROM licenseinvoice li WHERE li.license_id = l.id))) "
 
 205     . "LEFT JOIN invoice i ON "
 
 207     . "(SELECT li.trans_id FROM licenseinvoice li WHERE li.license_id = l.id)) "
 
 210   $sth = $dbh->prepare($query);
 
 211   $sth->execute() || $form->dberror($query);
 
 212   $form->{"license"} = $sth->fetchrow_hashref("NAME_lc");
 
 215   $main::lxdebug->leave_sub();