1 package C4::Circulation::Main;
5 #package to deal with circulation
8 # Copyright 2000-2002 Katipo Communications
10 # This file is part of Koha.
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
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.
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
29 use C4::Circulation::Issues;
30 # FIXME - C4::Circulation::Main and C4::Circulation::Issues
31 # use each other, so functions get redefined.
32 use C4::Circulation::Returns;
33 # FIXME - C4::Circulation::Main and C4::Circulation::Returns
34 # use each other, so functions get redefined.
35 use C4::Circulation::Renewals;
36 # FIXME - C4::Circulation::Main and C4::Circulation::Renewals
37 # use each other, so functions get redefined.
38 use C4::Circulation::Borrower;
39 # FIXME - C4::Circulation::Main and C4::Circulation::Borrower
40 # use each other, so functions get redefined.
46 use vars qw($VERSION @ISA @EXPORT);
48 # set the version for version checking
52 @EXPORT = qw(&pastitems &checkoverdues &previousissue
53 &checkreserve &checkwaiting &scanbook &scanborrower &getbranch &getprinter);
57 C4::Circulation::Main - Koha circulation desk functions
61 use C4::Circulation::Main;
65 This module provides functions useful to the circulation desk,
66 primarily for checking reserves and overdue items.
74 # FIXME - This is only used in C4::Circmain and telnet/startint.pl,
75 # which look obsolete. Presumably this means this function is obsolete
77 # Otherwise, it needs a POD.
80 my $dbh = C4::Context->dbh;
81 my $sth = $dbh->prepare("select * from branches order by branchcode");
85 while (my $data = $sth->fetchrow_hashref) {
88 brmenu ($env,\@branches);
90 my $data = $sth->fetchrow_hashref;
91 $env->{'branchcode'}=$data->{'branchcode'};
93 $sth = $dbh->prepare("select * from branches
94 where branchcode = ?");
95 $sth->execute($env->{'branchcode'});
96 my $data = $sth->fetchrow_hashref;
97 $env->{'brdata'} = $data;
98 $env->{'branchname'} = $data->{'branchname'};
102 # FIXME - This is only used in C4::Circmain and telnet/startint.pl,
103 # which look obsolete. Presumably this means this function is obsolete
105 # Otherwise, it needs a POD.
108 my $dbh = C4::Context->dbh;
109 my $sth = $dbh->prepare("select * from printers order by printername");
113 while (my $data = $sth->fetchrow_hashref) {
114 push @printers,$data;
116 prmenu ($env,\@printers);
118 my $data=$sth->fetchrow_hashref;
119 $env->{'queue'}=$data->{'printqueue'};
120 $env->{'printtype'}=$data->{'printtype'};
125 # FIXME - This is not the same as &C4::Circulation::pastitems, though
126 # the two appear to share some code.
127 # FIXME - This function is called in &C4::Circulation::Issues::Issue
128 # and in telnet/borrwraper.pl, both of which look obsolete. Presumably
129 # this means this function is obsolete as well.
130 # Otherwise, it needs a POD.
132 #Get list of all items borrower has currently on issue
133 my ($env,$bornum,$dbh)=@_;
134 my $sth=$dbh->prepare("select * from issues where (borrowernumber=?)
135 and (returndate is null) order by date_due");
136 $sth->execute($bornum);
140 while (my $data1=$sth->fetchrow_hashref) {
141 my $data = itemnodata($env,$dbh,$data1->{'itemnumber'}); #C4::Search
142 my @date = split("-",$data1->{'date_due'});
143 my $odate = (@date[2]+0)."-".(@date[1]+0)."-".@date[0];
144 my $line = C4::Circulation::Issues::formatitem($env,$data,$odate,"");
149 return(\@items,\@items2);
154 $num_items = &checkoverdues($env, $borrowernumber, $dbh);
156 Returns the number of overdue books a patron has.
160 C<$borrowernumber> is the patron's borrower number.
162 C<$dbh> is a DBI handle to the Koha database.
167 #checks whether a borrower has overdue items
168 # FIXME - Use C4::Context->dbh instead of getting $dbh as an argument
169 my ($env,$bornum,$dbh)=@_;
170 my $sth=$dbh->prepare("Select count(*) from issues where borrowernumber=? and
171 returndate is NULL and date_due < curdate()");
172 $sth->execute($bornum);
173 my $data = $sth->fetchrow_hashref;
175 return $data->{'count(*)'};
178 # FIXME - This is quite similar to &C4::Circulation::previousissue
179 # FIXME - Never used. Obsolete, presumably.
180 # Otherwise, it needs a POD.
182 my ($env,$itemnum,$dbh,$bornum)=@_;
183 my $sth=$dbh->prepare("Select
184 firstname,surname,issues.borrowernumber,cardnumber,returndate
185 from issues,borrowers where
186 issues.itemnumber='$itemnum' and
187 issues.borrowernumber=borrowers.borrowernumber
188 and issues.returndate is NULL");
190 my $borrower=$sth->fetchrow_hashref;
194 if ($borrower->{'borrowernumber'} ne ''){
195 if ($bornum eq $borrower->{'borrowernumber'}){
197 my ($renewstatus) = C4::Circulation::Renewals::renewstatus($env,$dbh,$bornum,$itemnum);
198 my ($resbor,$resrec) = checkreserve($env,$dbh,$itemnum);
199 if ($renewstatus == "0") {
200 info_msg($env,"</S>Issued to this borrower - No renewals<!S>");
202 } elsif ($resbor ne "") {
203 my $resp = C4::InterfaceCDK::msg_ny($env,"Book is issued to this borrower",
204 "and is reserved - Renew?");
206 $newdate = C4::Circulation::Renewals::renewbook($env,$dbh,$bornum,$itemnum);
212 my $resp = C4::InterfaceCDK::msg_yn($env,"Book is issued to this borrower", "Renew?");
214 $newdate = C4::Circulation::Renewals::renewbook($env,$dbh,$bornum,$itemnum);
221 my $text="Issued to $borrower->{'firstname'} $borrower->{'surname'} ($borrower->{'cardnumber'})";
222 my $resp = C4::InterfaceCDK::msg_yn($env,$text,"Mark as returned?");
224 &returnrecord($env,$dbh,$borrower->{'borrowernumber'},$itemnum);
230 return($borrower->{'borrowernumber'},$canissue,$newdate);
235 ($borrowernumber, $reserve) = &checkreserve($env, $dbh, $itemnumber);
239 C<$dbh> is a DBI handle to the Koha database.
241 C<$itemnumber> is the number of the item to find.
243 C<&checkreserve> returns two values:
245 C<$borrowernumber> is the borrower number of the patron for whom the
246 book is reserved, or the empty string. I can't tell when it returns a
247 number and when it returns a string, nor what it means.
249 C<$reserve> describes the reserved item. It is a reference-to-hash
250 whose keys are the fields of the reserves and items tables of the Koha
256 # Check for reserves for biblio
257 # FIXME - Use C4::Context->dbh to get $dbh, instead of passing it
258 # on the argument list.
259 my ($env,$dbh,$itemnum)=@_;
261 # Find this item in the reserves.
262 # Apparently reserves.found=='W' means "Waiting".
263 # FIXME - Is it necessary to get every field from both tables?
264 my $sth = $dbh->prepare("select * from reserves,items
265 where (items.itemnumber = ?)
266 and (reserves.cancellationdate is NULL)
267 and (items.biblionumber = reserves.biblionumber)
268 and ((reserves.found = 'W')
269 or (reserves.found is null))
271 $sth->execute($itemnum);
273 if (my $data=$sth->fetchrow_hashref) {
275 my $const = $data->{'constrainttype'};
276 if ($const eq "a") { # FIXME - What does 'a' mean?
277 $resbor = $data->{'borrowernumber'};
280 my $csth = $dbh->prepare("select * from reserveconstraints,items
281 where (borrowernumber=?)
283 and reserveconstraints.biblionumber=?
284 and (items.itemnumber=? and
285 items.biblioitemnumber = reserveconstraints.biblioitemnumber)");
286 $csth->execute($data->{'borrowernumber'},$data->{'reservedate'},$data->{'biblionumber'},$itemnum);
287 if (my $cdata=$csth->fetchrow_hashref) {$found = 1;}
288 if ($const eq 'o') { # FIXME - What does 'o' mean?
289 if ($found eq 1) {$resbor = $data->{'borrowernumber'};}
291 if ($found eq 0) {$resbor = $data->{'borrowernumber'};}
297 return ($resbor,$resrec);
300 # FIXME - This is only used in C4::Circulation::Borrower, which
301 # appears to be obsolete. Presumably this function is obsolete as
302 # well. Otherwise, it needs a POD.
304 # check for reserves waiting
305 my ($env,$dbh,$bornum)=@_;
307 my $sth = $dbh->prepare("select * from reserves
308 where (borrowernumber = ?)
309 and (reserves.found='W') and cancellationdate is NULL");
310 $sth->execute($bornum);
312 if (my $data=$sth->fetchrow_hashref) {
313 @itemswaiting[$cnt] =$data;
317 return ($cnt,\@itemswaiting);
320 # FIXME - This is identical to &C4::Circulation::scanbook
321 # FIXME - This function is only used in tkperl/tkcirc, if anywhere
322 # (it's hard to tell). Presumably it's obsolete.
323 # Otherwise, it needs a POD.
325 my ($env,$interface)=@_;
327 my ($number,$reason)=dialog("Book Barcode:");
329 return ($number,$reason);
332 # FIXME - This is very similar to &C4::Circulation::scanborrower
333 # FIXME - This is only used in C4::Circulation::Borrower, which
334 # appears to be obsolete. Presumably this function is obsolete as
336 # Otherwise, it needs a POD.
338 my ($env,$interface)=@_;
340 my ($number,$reason,$book)=C4::InterfaceCDK::borrower_dialog($env); #C4::InterfaceCDK
341 $number= $number; # FIXME - WTF?
343 return ($number,$reason,$book);
353 Koha Developement team <info@koha.org>