1 package C4::Circulation::Main; #assumes C4/Circulation/Main
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 # FIXME - C4::Circulation::Main and C4::Circulation::Issues
29 # use each other, so functions get redefined.
30 use C4::Circulation::Returns;
31 # FIXME - C4::Circulation::Main and C4::Circulation::Returns
32 # use each other, so functions get redefined.
33 use C4::Circulation::Renewals;
34 # FIXME - C4::Circulation::Main and C4::Circulation::Renewals
35 # use each other, so functions get redefined.
36 use C4::Circulation::Borrower;
37 # FIXME - C4::Circulation::Main and C4::Circulation::Borrower
38 # use each other, so functions get redefined.
44 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
46 # set the version for version checking
50 @EXPORT = qw(&pastitems &checkoverdues &previousissue
51 &checkreserve &checkwaiting &scanbook &scanborrower &getbranch &getprinter);
52 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
54 # your exported package globals go here,
55 # as well as any optionally exported functions
57 @EXPORT_OK = qw($Var1 %Hashit);
60 # non-exported package globals go here
61 use vars qw(@more $stuff);
63 # initalize package globals, first exported ones
68 # then the others (which are still accessible as $Some::Module::stuff)
72 # all file-scoped lexicals must be created before
73 # the functions below that use them.
75 # file-private lexicals go here
79 # here's a file-private function as a closure,
80 # callable as &$priv_func; it cannot be prototyped.
85 # make all your functions, whether exported or not;
89 my $dbh = C4::Context->dbh;
90 my $query = "select * from branches order by branchcode";
91 my $sth = $dbh->prepare($query);
95 while (my $data = $sth->fetchrow_hashref) {
98 brmenu ($env,\@branches);
100 my $data = $sth->fetchrow_hashref;
101 $env->{'branchcode'}=$data->{'branchcode'};
103 my $query = "select * from branches
104 where branchcode = '$env->{'branchcode'}'";
105 $sth = $dbh->prepare($query);
107 my $data = $sth->fetchrow_hashref;
108 $env->{'brdata'} = $data;
109 $env->{'branchname'} = $data->{'branchname'};
115 my $dbh = C4::Context->dbh;
116 my $query = "select * from printers order by printername";
117 my $sth = $dbh->prepare($query);
121 while (my $data = $sth->fetchrow_hashref) {
122 push @printers,$data;
124 prmenu ($env,\@printers);
126 my $data=$sth->fetchrow_hashref;
127 $env->{'queue'}=$data->{'printqueue'};
128 $env->{'printtype'}=$data->{'printtype'};
133 # FIXME - This is not the same as &C4::Circulation::pastitems, though
134 # the two appear to share some code.
136 #Get list of all items borrower has currently on issue
137 my ($env,$bornum,$dbh)=@_;
138 my $query1 = "select * from issues where (borrowernumber=$bornum)
139 and (returndate is null) order by date_due";
140 my $sth=$dbh->prepare($query1);
145 while (my $data1=$sth->fetchrow_hashref) {
146 my $data = itemnodata($env,$dbh,$data1->{'itemnumber'}); #C4::Search
147 my @date = split("-",$data1->{'date_due'});
148 my $odate = (@date[2]+0)."-".(@date[1]+0)."-".@date[0];
149 my $line = C4::Circulation::Issues::formatitem($env,$data,$odate,"");
154 return(\@items,\@items2);
158 #checks whether a borrower has overdue items
159 my ($env,$bornum,$dbh)=@_;
160 my @datearr = localtime;
161 my $today = ($datearr[5] + 1900)."-".($datearr[4]+1)."-".$datearr[3];
162 my $query = "Select count(*) from issues where borrowernumber=$bornum and
163 returndate is NULL and date_due < '$today'";
164 my $sth=$dbh->prepare($query);
166 my $data = $sth->fetchrow_hashref;
168 return $data->{'count(*)'};
171 # FIXME - This is quite similar to &C4::Circulation::previousissue
173 my ($env,$itemnum,$dbh,$bornum)=@_;
174 my $sth=$dbh->prepare("Select
175 firstname,surname,issues.borrowernumber,cardnumber,returndate
176 from issues,borrowers where
177 issues.itemnumber='$itemnum' and
178 issues.borrowernumber=borrowers.borrowernumber
179 and issues.returndate is NULL");
181 my $borrower=$sth->fetchrow_hashref;
185 if ($borrower->{'borrowernumber'} ne ''){
186 if ($bornum eq $borrower->{'borrowernumber'}){
188 my ($renewstatus) = C4::Circulation::Renewals::renewstatus($env,$dbh,$bornum,$itemnum);
189 my ($resbor,$resrec) = checkreserve($env,$dbh,$itemnum);
190 if ($renewstatus == "0") {
191 info_msg($env,"</S>Issued to this borrower - No renewals<!S>");
193 } elsif ($resbor ne "") {
194 my $resp = C4::InterfaceCDK::msg_ny($env,"Book is issued to this borrower",
195 "and is reserved - Renew?");
197 $newdate = C4::Circulation::Renewals::renewbook($env,$dbh,$bornum,$itemnum);
203 my $resp = C4::InterfaceCDK::msg_yn($env,"Book is issued to this borrower", "Renew?");
205 $newdate = C4::Circulation::Renewals::renewbook($env,$dbh,$bornum,$itemnum);
212 my $text="Issued to $borrower->{'firstname'} $borrower->{'surname'} ($borrower->{'cardnumber'})";
213 my $resp = C4::InterfaceCDK::msg_yn($env,$text,"Mark as returned?");
215 &returnrecord($env,$dbh,$borrower->{'borrowernumber'},$itemnum);
221 return($borrower->{'borrowernumber'},$canissue,$newdate);
226 # Check for reserves for biblio
227 my ($env,$dbh,$itemnum)=@_;
229 my $query = "select * from reserves,items
230 where (items.itemnumber = '$itemnum')
231 and (reserves.cancellationdate is NULL)
232 and (items.biblionumber = reserves.biblionumber)
233 and ((reserves.found = 'W')
234 or (reserves.found is null))
236 my $sth = $dbh->prepare($query);
239 if (my $data=$sth->fetchrow_hashref) {
241 my $const = $data->{'constrainttype'};
243 $resbor = $data->{'borrowernumber'};
246 my $cquery = "select * from reserveconstraints,items
247 where (borrowernumber='$data->{'borrowernumber'}')
248 and reservedate='$data->{'reservedate'}'
249 and reserveconstraints.biblionumber='$data->{'biblionumber'}'
250 and (items.itemnumber=$itemnum and
251 items.biblioitemnumber = reserveconstraints.biblioitemnumber)";
252 my $csth = $dbh->prepare($cquery);
254 if (my $cdata=$csth->fetchrow_hashref) {$found = 1;}
256 if ($found eq 1) {$resbor = $data->{'borrowernumber'};}
258 if ($found eq 0) {$resbor = $data->{'borrowernumber'};}
264 return ($resbor,$resrec);
268 # check for reserves waiting
269 my ($env,$dbh,$bornum)=@_;
271 my $query = "select * from reserves
272 where (borrowernumber = '$bornum')
273 and (reserves.found='W') and cancellationdate is NULL";
274 my $sth = $dbh->prepare($query);
277 if (my $data=$sth->fetchrow_hashref) {
278 @itemswaiting[$cnt] =$data;
282 return ($cnt,\@itemswaiting);
285 # FIXME - This is identical to &C4::Circulation::scanbook
287 my ($env,$interface)=@_;
289 my ($number,$reason)=dialog("Book Barcode:");
291 return ($number,$reason);
294 # FIXME - This is very similar to &C4::Circulation::scanborrower
296 my ($env,$interface)=@_;
298 my ($number,$reason,$book)=C4::InterfaceCDK::borrower_dialog($env); #C4::InterfaceCDK
301 return ($number,$reason,$book);
305 END { } # module clean-up code here (global destructor)