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 $query = "select * from branches order by branchcode";
82 my $sth = $dbh->prepare($query);
86 while (my $data = $sth->fetchrow_hashref) {
89 brmenu ($env,\@branches);
91 my $data = $sth->fetchrow_hashref;
92 $env->{'branchcode'}=$data->{'branchcode'};
94 my $query = "select * from branches
95 where branchcode = '$env->{'branchcode'}'";
96 $sth = $dbh->prepare($query);
98 my $data = $sth->fetchrow_hashref;
99 $env->{'brdata'} = $data;
100 $env->{'branchname'} = $data->{'branchname'};
104 # FIXME - This is only used in C4::Circmain and telnet/startint.pl,
105 # which look obsolete. Presumably this means this function is obsolete
107 # Otherwise, it needs a POD.
110 my $dbh = C4::Context->dbh;
111 my $query = "select * from printers order by printername";
112 my $sth = $dbh->prepare($query);
116 while (my $data = $sth->fetchrow_hashref) {
117 push @printers,$data;
119 prmenu ($env,\@printers);
121 my $data=$sth->fetchrow_hashref;
122 $env->{'queue'}=$data->{'printqueue'};
123 $env->{'printtype'}=$data->{'printtype'};
128 # FIXME - This is not the same as &C4::Circulation::pastitems, though
129 # the two appear to share some code.
130 # FIXME - This function is called in &C4::Circulation::Issues::Issue
131 # and in telnet/borrwraper.pl, both of which look obsolete. Presumably
132 # this means this function is obsolete as well.
133 # Otherwise, it needs a POD.
135 #Get list of all items borrower has currently on issue
136 my ($env,$bornum,$dbh)=@_;
137 my $query1 = "select * from issues where (borrowernumber=$bornum)
138 and (returndate is null) order by date_due";
139 my $sth=$dbh->prepare($query1);
144 while (my $data1=$sth->fetchrow_hashref) {
145 my $data = itemnodata($env,$dbh,$data1->{'itemnumber'}); #C4::Search
146 my @date = split("-",$data1->{'date_due'});
147 my $odate = (@date[2]+0)."-".(@date[1]+0)."-".@date[0];
148 my $line = C4::Circulation::Issues::formatitem($env,$data,$odate,"");
153 return(\@items,\@items2);
158 $num_items = &checkoverdues($env, $borrowernumber, $dbh);
160 Returns the number of overdue books a patron has.
164 C<$borrowernumber> is the patron's borrower number.
166 C<$dbh> is a DBI handle to the Koha database.
171 #checks whether a borrower has overdue items
172 # FIXME - Use C4::Context->dbh instead of getting $dbh as an argument
173 my ($env,$bornum,$dbh)=@_;
174 # FIXME - This is what POSIX::strftime is for.
175 my @datearr = localtime;
176 my $today = ($datearr[5] + 1900)."-".($datearr[4]+1)."-".$datearr[3];
177 # FIXME - MySQL can figure out what today is, so there's no need
178 # to calculate that separately. Just use
179 # ... date_due < curdate()
180 my $query = "Select count(*) from issues where borrowernumber=$bornum and
181 returndate is NULL and date_due < '$today'";
182 my $sth=$dbh->prepare($query);
184 my $data = $sth->fetchrow_hashref;
186 return $data->{'count(*)'};
189 # FIXME - This is quite similar to &C4::Circulation::previousissue
190 # FIXME - Never used. Obsolete, presumably.
191 # Otherwise, it needs a POD.
193 my ($env,$itemnum,$dbh,$bornum)=@_;
194 my $sth=$dbh->prepare("Select
195 firstname,surname,issues.borrowernumber,cardnumber,returndate
196 from issues,borrowers where
197 issues.itemnumber='$itemnum' and
198 issues.borrowernumber=borrowers.borrowernumber
199 and issues.returndate is NULL");
201 my $borrower=$sth->fetchrow_hashref;
205 if ($borrower->{'borrowernumber'} ne ''){
206 if ($bornum eq $borrower->{'borrowernumber'}){
208 my ($renewstatus) = C4::Circulation::Renewals::renewstatus($env,$dbh,$bornum,$itemnum);
209 my ($resbor,$resrec) = checkreserve($env,$dbh,$itemnum);
210 if ($renewstatus == "0") {
211 info_msg($env,"</S>Issued to this borrower - No renewals<!S>");
213 } elsif ($resbor ne "") {
214 my $resp = C4::InterfaceCDK::msg_ny($env,"Book is issued to this borrower",
215 "and is reserved - Renew?");
217 $newdate = C4::Circulation::Renewals::renewbook($env,$dbh,$bornum,$itemnum);
223 my $resp = C4::InterfaceCDK::msg_yn($env,"Book is issued to this borrower", "Renew?");
225 $newdate = C4::Circulation::Renewals::renewbook($env,$dbh,$bornum,$itemnum);
232 my $text="Issued to $borrower->{'firstname'} $borrower->{'surname'} ($borrower->{'cardnumber'})";
233 my $resp = C4::InterfaceCDK::msg_yn($env,$text,"Mark as returned?");
235 &returnrecord($env,$dbh,$borrower->{'borrowernumber'},$itemnum);
241 return($borrower->{'borrowernumber'},$canissue,$newdate);
246 ($borrowernumber, $reserve) = &checkreserve($env, $dbh, $itemnumber);
250 C<$dbh> is a DBI handle to the Koha database.
252 C<$itemnumber> is the number of the item to find.
254 C<&checkreserve> returns two values:
256 C<$borrowernumber> is the borrower number of the patron for whom the
257 book is reserved, or the empty string. I can't tell when it returns a
258 number and when it returns a string, nor what it means.
260 C<$reserve> describes the reserved item. It is a reference-to-hash
261 whose keys are the fields of the reserves and items tables of the Koha
267 # Check for reserves for biblio
268 # FIXME - Use C4::Context->dbh to get $dbh, instead of passing it
269 # on the argument list.
270 my ($env,$dbh,$itemnum)=@_;
272 # Find this item in the reserves.
273 # Apparently reserves.found=='W' means "Waiting".
274 # FIXME - Is it necessary to get every field from both tables?
275 my $query = "select * from reserves,items
276 where (items.itemnumber = '$itemnum')
277 and (reserves.cancellationdate is NULL)
278 and (items.biblionumber = reserves.biblionumber)
279 and ((reserves.found = 'W')
280 or (reserves.found is null))
282 my $sth = $dbh->prepare($query);
285 if (my $data=$sth->fetchrow_hashref) {
287 my $const = $data->{'constrainttype'};
288 if ($const eq "a") { # FIXME - What does 'a' mean?
289 $resbor = $data->{'borrowernumber'};
292 my $cquery = "select * from reserveconstraints,items
293 where (borrowernumber='$data->{'borrowernumber'}')
294 and reservedate='$data->{'reservedate'}'
295 and reserveconstraints.biblionumber='$data->{'biblionumber'}'
296 and (items.itemnumber=$itemnum and
297 items.biblioitemnumber = reserveconstraints.biblioitemnumber)";
298 my $csth = $dbh->prepare($cquery);
300 if (my $cdata=$csth->fetchrow_hashref) {$found = 1;}
301 if ($const eq 'o') { # FIXME - What does 'o' mean?
302 if ($found eq 1) {$resbor = $data->{'borrowernumber'};}
304 if ($found eq 0) {$resbor = $data->{'borrowernumber'};}
310 return ($resbor,$resrec);
313 # FIXME - This is only used in C4::Circulation::Borrower, which
314 # appears to be obsolete. Presumably this function is obsolete as
315 # well. Otherwise, it needs a POD.
317 # check for reserves waiting
318 my ($env,$dbh,$bornum)=@_;
320 my $query = "select * from reserves
321 where (borrowernumber = '$bornum')
322 and (reserves.found='W') and cancellationdate is NULL";
323 my $sth = $dbh->prepare($query);
326 if (my $data=$sth->fetchrow_hashref) {
327 @itemswaiting[$cnt] =$data;
331 return ($cnt,\@itemswaiting);
334 # FIXME - This is identical to &C4::Circulation::scanbook
335 # FIXME - This function is only used in tkperl/tkcirc, if anywhere
336 # (it's hard to tell). Presumably it's obsolete.
337 # Otherwise, it needs a POD.
339 my ($env,$interface)=@_;
341 my ($number,$reason)=dialog("Book Barcode:");
343 return ($number,$reason);
346 # FIXME - This is very similar to &C4::Circulation::scanborrower
347 # FIXME - This is only used in C4::Circulation::Borrower, which
348 # appears to be obsolete. Presumably this function is obsolete as
350 # Otherwise, it needs a POD.
352 my ($env,$interface)=@_;
354 my ($number,$reason,$book)=C4::InterfaceCDK::borrower_dialog($env); #C4::InterfaceCDK
355 $number= $number; # FIXME - WTF?
357 return ($number,$reason,$book);
367 Koha Developement team <info@koha.org>