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
27 use C4::Circulation::Issues;
28 use C4::Circulation::Returns;
29 use C4::Circulation::Renewals;
30 use C4::Circulation::Borrower;
35 use vars qw($VERSION @ISA @EXPORT);
37 # set the version for version checking
41 @EXPORT = qw(&Start_circ &scanborrower);
47 &startint($env,'Circulation');
51 while ($donext ne 'Quit') {
52 if ($donext eq "Circ") {
54 ($reason,$data) = menu($env,'console','Circulation',
55 ('Issues','Returns','Borrower Enquiries','Reserves','Log In'));
56 #debug_msg($env,"data = $data");
60 if ($data eq 'Issues') {
61 $donext=Issue($env); #C4::Circulation::Issues
62 #debug_msg("","do next $donext");
63 } elsif ($data eq 'Returns') {
64 $donext=Returns($env); #C4::Circulation::Returns
65 } elsif ($data eq 'Borrower Enquiries'){
66 $donext=Borenq($env); #C4::Circulation::Borrower
67 } elsif ($data eq 'Reserves'){
68 $donext=EnterReserves($env); #C4::Reserves
69 } elsif ($data eq 'Log In') {
71 &Login($env); #C4::Security
72 &startint($env,'Circulation');
73 } elsif ($data eq 'Quit') {
76 #debug_msg($env,"donext - $donext");
82 # FIXME - This is not the same as &C4::Circulation::Main::pastitems,
83 # though the two appear to share some code.
85 #Get list of all items borrower has currently on issue
86 my ($env,$bornum,$dbh)=@_;
87 my $sth=$dbh->prepare("Select * from issues,items,biblio
88 where borrowernumber=$bornum and issues.itemnumber=items.itemnumber
89 and items.biblionumber=biblio.biblionumber
90 and returndate is null
100 while (my $data=$sth->fetchrow_hashref) {
101 my $line = "$data->{'date_due'} $data->{'title'}";
102 # $items[$i]=fmtstr($env,$line,"L29");
103 $items[$i]=fmtstr($env,$line,"L72");
106 return(\@items,\@items2);
111 #checks whether a borrower has overdue items
112 my ($env,$bornum,$dbh)=@_;
113 my $sth=$dbh->prepare("Select * from issues,items,biblio where
114 borrowernumber=$bornum and issues.itemnumber=items.itemnumber and
115 items.biblionumber=biblio.biblionumber");
119 while (my $data=$sth->fetchrow_hashref){
120 output($row,$col,$data->{'title'});
126 # FIXME - This is quite similar to &C4::Circulation::Main::previousissue
128 my ($env,$itemnum,$dbh,$bornum)=@_;
129 my $sth=$dbh->prepare("Select firstname,surname,issues.borrowernumber,cardnumber,returndate
130 from issues,borrowers where
131 issues.itemnumber='$itemnum' and
132 issues.borrowernumber=borrowers.borrowernumber and issues.returndate is
135 my $borrower=$sth->fetchrow_hashref;
137 if ($borrower->{'borrowernumber'} ne ''){
138 if ($bornum eq $borrower->{'borrowernumber'}){
140 my ($renewstatus) = &renewstatus($env,$dbh,$bornum,$itemnum);
141 my $resp = &msg_yn("Book is issued to this borrower", "Renew?");
143 &renewbook($env,$dbh,$bornum,$itemnum);
147 my $text="Issued to $borrower->{'firstname'} $borrower->{'surname'} ($borrower->{'cardnumber'})";
148 my $resp = &msg_yn($text,"Mark as returned?");
150 &returnrecord($env,$dbh,$borrower->{'borrowernumber'},$itemnum);
157 return($borrower->{'borrowernumber'});
163 # Check for reserves for biblio
164 # does not look at constraints yet
165 my ($env,$dbh,$itemnum)=@_;
167 my $query = "select * from reserves,items
168 where (items.itemnumber = '$itemnum')
169 and (items.biblionumber = reserves.biblionumber)
170 and (reserves.found is null) order by priority";
171 my $sth = $dbh->prepare($query);
173 if (my $data=$sth->fetchrow_hashref) {
174 $resbor = $data->{'borrowernumber'};
181 # check for reserves waiting
182 my ($env,$dbh,$bornum)=@_;
184 my $query = "select * from reserves
185 where (borrowernumber = '$bornum')
186 and (reserves.found='W')";
187 my $sth = $dbh->prepare($query);
189 if (my $data=$sth->fetchrow_hashref) {
190 push @itemswaiting,$data->{'itemnumber'};
192 return (\@itemswaiting);
196 # FIXME - This is identical to &C4::Circulation/Main::scanbook
198 my ($env,$interface)=@_;
200 my ($number,$reason)=dialog("Book Barcode:");
202 return ($number,$reason);
205 # FIXME - This is very similar to &C4::Circulation::Main::scanborrower
207 my ($env,$interface)=@_;
209 my ($number,$reason,$book)=&borrower_dialog($env); #C4::Interface
212 return ($number,$reason,$book);
216 END { } # module clean-up code here (global destructor)