Replaced expressions of the form "$x = $x <op> $y" with "$x <op>= $y".
[koha.git] / C4 / Circulation.pm
1 package C4::Circulation;
2
3 # $Id$
4
5 #package to deal with circulation
6
7
8 # Copyright 2000-2002 Katipo Communications
9 #
10 # This file is part of Koha.
11 #
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
15 # version.
16 #
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License along with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA  02111-1307 USA
24
25 # FIXME - This package is never used. Is it obsolete?
26
27 use strict;
28 require Exporter;
29 use DBI;
30 use C4::Circulation::Issues;
31 use C4::Circulation::Returns;
32 use C4::Circulation::Renewals;
33 use C4::Circulation::Borrower;
34 use C4::Reserves;
35 #use C4::Interface;
36 use C4::Security;
37
38 use vars qw($VERSION @ISA @EXPORT);
39
40 # set the version for version checking
41 $VERSION = 0.01;
42
43 @ISA = qw(Exporter);
44 @EXPORT = qw(&Start_circ &scanborrower);
45
46 sub Start_circ{
47   my ($env)=@_;
48   #connect to database
49   #start interface
50   &startint($env,'Circulation');
51   my $donext = 'Circ';
52   my $reason;
53   my $data;
54   while ($donext ne 'Quit') {
55     if ($donext  eq "Circ") {
56       clearscreen();
57       ($reason,$data) = menu($env,'console','Circulation',
58         ('Issues','Returns','Borrower Enquiries','Reserves','Log In'));
59       #debug_msg($env,"data = $data");
60     } else {
61       $data = $donext;
62     }
63     if ($data eq 'Issues') {
64       $donext=Issue($env); #C4::Circulation::Issues
65       #debug_msg("","do next $donext");
66     } elsif ($data eq 'Returns') {
67       $donext=Returns($env); #C4::Circulation::Returns
68     } elsif ($data eq 'Borrower Enquiries'){
69       $donext=Borenq($env); #C4::Circulation::Borrower
70     } elsif ($data eq 'Reserves'){
71       $donext=EnterReserves($env); #C4::Reserves
72     } elsif ($data eq 'Log In') {
73       &endint($env);
74       &Login($env);   #C4::Security
75       &startint($env,'Circulation');
76     } elsif ($data eq 'Quit') {
77       $donext = $data;
78     }
79     #debug_msg($env,"donext -  $donext");
80   }
81   &endint($env)
82 }
83
84 # Not exported.
85 # FIXME - This is not the same as &C4::Circulation::Main::pastitems,
86 # though the two appear to share some code.
87 sub pastitems{
88   #Get list of all items borrower has currently on issue
89   my ($env,$bornum,$dbh)=@_;
90   my $sth=$dbh->prepare("Select * from issues,items,biblio
91     where borrowernumber=$bornum and issues.itemnumber=items.itemnumber
92     and items.biblionumber=biblio.biblionumber
93     and returndate is null
94     order by date_due");
95   $sth->execute;
96   my $i=0;
97   my @items;
98   my @items2;
99   #$items[0]=" "x29;
100   #$items2[0]=" "x29;
101   $items[0]=" "x72;
102   $items2[0]=" "x72;
103   while (my $data=$sth->fetchrow_hashref) {
104      my $line = "$data->{'date_due'} $data->{'title'}";
105      # $items[$i]=fmtstr($env,$line,"L29");
106      $items[$i]=fmtstr($env,$line,"L72");
107      $i++;
108   }
109   return(\@items,\@items2);
110   $sth->finish;
111 }
112
113 sub checkoverdues{
114   #checks whether a borrower has overdue items
115   my ($env,$bornum,$dbh)=@_;
116   my $sth=$dbh->prepare("Select * from issues,items,biblio where
117   borrowernumber=$bornum and issues.itemnumber=items.itemnumber and
118   items.biblionumber=biblio.biblionumber");
119   $sth->execute;
120   my $row=1;
121   my $col=40;
122   while (my $data=$sth->fetchrow_hashref){
123     output($row,$col,$data->{'title'});
124     $row++;
125   }
126   $sth->finish;
127 }
128
129 # FIXME - This is quite similar to &C4::Circulation::Main::previousissue
130 # FIXME - Never used. Obsolete, presumably.
131 sub previousissue {
132   my ($env,$itemnum,$dbh,$bornum)=@_;
133   my $sth=$dbh->prepare("Select firstname,surname,issues.borrowernumber,cardnumber,returndate
134   from issues,borrowers where
135   issues.itemnumber='$itemnum' and
136   issues.borrowernumber=borrowers.borrowernumber and issues.returndate is
137 NULL");
138   $sth->execute;
139   my $borrower=$sth->fetchrow_hashref;
140   $sth->finish;
141   if ($borrower->{'borrowernumber'} ne ''){
142     if ($bornum eq $borrower->{'borrowernumber'}){
143       # no need to issue
144       my ($renewstatus) = &renewstatus($env,$dbh,$bornum,$itemnum);
145       my $resp = &msg_yn("Book is issued to this borrower", "Renew?");
146       if ($resp == "y") {
147         &renewbook($env,$dbh,$bornum,$itemnum);
148       }
149
150     } else {
151       my $text="Issued to $borrower->{'firstname'} $borrower->{'surname'} ($borrower->{'cardnumber'})";
152       my $resp = &msg_yn($text,"Mark as returned?");
153       if ($resp == "y") {
154         &returnrecord($env,$dbh,$borrower->{'borrowernumber'},$itemnum);
155         # can issue
156       } else {
157         # can't issue
158       }
159     }
160   }
161   return($borrower->{'borrowernumber'});
162   $sth->finish;
163 }
164
165
166 sub checkreserve{
167   # Check for reserves for biblio
168   # does not look at constraints yet
169   my ($env,$dbh,$itemnum)=@_;
170   my $resbor = "";
171   my $query = "select * from reserves,items
172   where (items.itemnumber = '$itemnum')
173   and (items.biblionumber = reserves.biblionumber)
174   and (reserves.found is null) order by priority";
175   my $sth = $dbh->prepare($query);
176   $sth->execute();
177   if (my $data=$sth->fetchrow_hashref) {
178     $resbor = $data->{'borrowernumber'};
179   }
180   return ($resbor);
181   $sth->finish;
182 }
183
184 sub checkwaiting{
185   # check for reserves waiting
186   my ($env,$dbh,$bornum)=@_;
187   my @itemswaiting="";
188   my $query = "select * from reserves
189   where (borrowernumber = '$bornum')
190   and (reserves.found='W')";
191   my $sth = $dbh->prepare($query);
192   $sth->execute();
193   if (my $data=$sth->fetchrow_hashref) {
194     push @itemswaiting,$data->{'itemnumber'};
195   }
196   return (\@itemswaiting);
197   $sth->finish;
198 }
199
200 # FIXME - This is identical to &C4::Circulation/Main::scanbook
201 sub scanbook {
202   my ($env,$interface)=@_;
203   #scan barcode
204   my ($number,$reason)=dialog("Book Barcode:");
205   $number=uc $number;
206   return ($number,$reason);
207 }
208
209 # FIXME - This is very similar to &C4::Circulation::Main::scanborrower
210 sub scanborrower {
211   my ($env,$interface)=@_;
212   #scan barcode
213   my ($number,$reason,$book)=&borrower_dialog($env); #C4::Interface
214   $number= $number;             # FIXME - WTF?
215   $book=uc $book;
216   return ($number,$reason,$book);
217 }