1 package C4::Circulation; #assumes C4/Circulation
3 #package to deal with circulation
6 # Copyright 2000-2002 Katipo Communications
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA 02111-1307 USA
26 use C4::Circulation::Issues;
27 use C4::Circulation::Returns;
28 use C4::Circulation::Renewals;
29 use C4::Circulation::Borrower;
34 use vars qw($VERSION @ISA @EXPORT);
36 # set the version for version checking
40 @EXPORT = qw(&Start_circ &scanborrower);
46 &startint($env,'Circulation');
50 while ($donext ne 'Quit') {
51 if ($donext eq "Circ") {
53 ($reason,$data) = menu($env,'console','Circulation',
54 ('Issues','Returns','Borrower Enquiries','Reserves','Log In'));
55 #debug_msg($env,"data = $data");
59 if ($data eq 'Issues') {
60 $donext=Issue($env); #C4::Circulation::Issues
61 #debug_msg("","do next $donext");
62 } elsif ($data eq 'Returns') {
63 $donext=Returns($env); #C4::Circulation::Returns
64 } elsif ($data eq 'Borrower Enquiries'){
65 $donext=Borenq($env); #C4::Circulation::Borrower
66 } elsif ($data eq 'Reserves'){
67 $donext=EnterReserves($env); #C4::Reserves
68 } elsif ($data eq 'Log In') {
70 &Login($env); #C4::Security
71 &startint($env,'Circulation');
72 } elsif ($data eq 'Quit') {
75 #debug_msg($env,"donext - $donext");
81 # FIXME - This is not the same as &C4::Circulation::Main::pastitems,
82 # though the two appear to share some code.
84 #Get list of all items borrower has currently on issue
85 my ($env,$bornum,$dbh)=@_;
86 my $sth=$dbh->prepare("Select * from issues,items,biblio
87 where borrowernumber=$bornum and issues.itemnumber=items.itemnumber
88 and items.biblionumber=biblio.biblionumber
89 and returndate is null
99 while (my $data=$sth->fetchrow_hashref) {
100 my $line = "$data->{'date_due'} $data->{'title'}";
101 # $items[$i]=fmtstr($env,$line,"L29");
102 $items[$i]=fmtstr($env,$line,"L72");
105 return(\@items,\@items2);
110 #checks whether a borrower has overdue items
111 my ($env,$bornum,$dbh)=@_;
112 my $sth=$dbh->prepare("Select * from issues,items,biblio where
113 borrowernumber=$bornum and issues.itemnumber=items.itemnumber and
114 items.biblionumber=biblio.biblionumber");
118 while (my $data=$sth->fetchrow_hashref){
119 output($row,$col,$data->{'title'});
125 # FIXME - This is quite similar to &C4::Circulation::Main::previousissue
127 my ($env,$itemnum,$dbh,$bornum)=@_;
128 my $sth=$dbh->prepare("Select firstname,surname,issues.borrowernumber,cardnumber,returndate
129 from issues,borrowers where
130 issues.itemnumber='$itemnum' and
131 issues.borrowernumber=borrowers.borrowernumber and issues.returndate is
134 my $borrower=$sth->fetchrow_hashref;
136 if ($borrower->{'borrowernumber'} ne ''){
137 if ($bornum eq $borrower->{'borrowernumber'}){
139 my ($renewstatus) = &renewstatus($env,$dbh,$bornum,$itemnum);
140 my $resp = &msg_yn("Book is issued to this borrower", "Renew?");
142 &renewbook($env,$dbh,$bornum,$itemnum);
146 my $text="Issued to $borrower->{'firstname'} $borrower->{'surname'} ($borrower->{'cardnumber'})";
147 my $resp = &msg_yn($text,"Mark as returned?");
149 &returnrecord($env,$dbh,$borrower->{'borrowernumber'},$itemnum);
156 return($borrower->{'borrowernumber'});
162 # Check for reserves for biblio
163 # does not look at constraints yet
164 my ($env,$dbh,$itemnum)=@_;
166 my $query = "select * from reserves,items
167 where (items.itemnumber = '$itemnum')
168 and (items.biblionumber = reserves.biblionumber)
169 and (reserves.found is null) order by priority";
170 my $sth = $dbh->prepare($query);
172 if (my $data=$sth->fetchrow_hashref) {
173 $resbor = $data->{'borrowernumber'};
180 # check for reserves waiting
181 my ($env,$dbh,$bornum)=@_;
183 my $query = "select * from reserves
184 where (borrowernumber = '$bornum')
185 and (reserves.found='W')";
186 my $sth = $dbh->prepare($query);
188 if (my $data=$sth->fetchrow_hashref) {
189 push @itemswaiting,$data->{'itemnumber'};
191 return (\@itemswaiting);
195 # FIXME - This is identical to &C4::Circulation/Main::scanbook
197 my ($env,$interface)=@_;
199 my ($number,$reason)=dialog("Book Barcode:");
201 return ($number,$reason);
204 # FIXME - This is very similar to &C4::Circulation::Main::scanborrower
206 my ($env,$interface)=@_;
208 my ($number,$reason,$book)=&borrower_dialog($env); #C4::Interface
211 return ($number,$reason,$book);
215 END { } # module clean-up code here (global destructor)