1 package C4::Circulation::Main; #asummes 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 use C4::Circulation::Returns;
29 use C4::Circulation::Renewals;
30 use C4::Circulation::Borrower;
37 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
39 # set the version for version checking
43 @EXPORT = qw(&pastitems &checkoverdues &previousissue
44 &checkreserve &checkwaiting &scanbook &scanborrower &getbranch &getprinter);
45 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
47 # your exported package globals go here,
48 # as well as any optionally exported functions
50 @EXPORT_OK = qw($Var1 %Hashit);
53 # non-exported package globals go here
54 use vars qw(@more $stuff);
56 # initalize package globals, first exported ones
61 # then the others (which are still accessible as $Some::Module::stuff)
65 # all file-scoped lexicals must be created before
66 # the functions below that use them.
68 # file-private lexicals go here
72 # here's a file-private function as a closure,
73 # callable as &$priv_func; it cannot be prototyped.
78 # make all your functions, whether exported or not;
83 my $query = "select * from branches order by branchcode";
84 my $sth = $dbh->prepare($query);
88 while (my $data = $sth->fetchrow_hashref) {
91 brmenu ($env,\@branches);
93 my $data = $sth->fetchrow_hashref;
94 $env->{'branchcode'}=$data->{'branchcode'};
96 my $query = "select * from branches
97 where branchcode = '$env->{'branchcode'}'";
98 $sth = $dbh->prepare($query);
100 my $data = $sth->fetchrow_hashref;
101 $env->{'brdata'} = $data;
102 $env->{'branchname'} = $data->{'branchname'};
110 my $query = "select * from printers order by printername";
111 my $sth = $dbh->prepare($query);
115 while (my $data = $sth->fetchrow_hashref) {
116 push @printers,$data;
118 prmenu ($env,\@printers);
120 my $data=$sth->fetchrow_hashref;
121 $env->{'queue'}=$data->{'printqueue'};
122 $env->{'printtype'}=$data->{'printtype'};
129 #Get list of all items borrower has currently on issue
130 my ($env,$bornum,$dbh)=@_;
131 my $query1 = "select * from issues where (borrowernumber=$bornum)
132 and (returndate is null) order by date_due";
133 my $sth=$dbh->prepare($query1);
138 while (my $data1=$sth->fetchrow_hashref) {
139 my $data = itemnodata($env,$dbh,$data1->{'itemnumber'}); #C4::Search
140 my @date = split("-",$data1->{'date_due'});
141 my $odate = (@date[2]+0)."-".(@date[1]+0)."-".@date[0];
142 my $line = C4::Circulation::Issues::formatitem($env,$data,$odate,"");
147 return(\@items,\@items2);
151 #checks whether a borrower has overdue items
152 my ($env,$bornum,$dbh)=@_;
153 my @datearr = localtime;
154 my $today = ($datearr[5] + 1900)."-".($datearr[4]+1)."-".$datearr[3];
155 my $query = "Select count(*) from issues where borrowernumber=$bornum and
156 returndate is NULL and date_due < '$today'";
157 my $sth=$dbh->prepare($query);
159 my $data = $sth->fetchrow_hashref;
161 return $data->{'count(*)'};
165 my ($env,$itemnum,$dbh,$bornum)=@_;
166 my $sth=$dbh->prepare("Select
167 firstname,surname,issues.borrowernumber,cardnumber,returndate
168 from issues,borrowers where
169 issues.itemnumber='$itemnum' and
170 issues.borrowernumber=borrowers.borrowernumber
171 and issues.returndate is NULL");
173 my $borrower=$sth->fetchrow_hashref;
177 if ($borrower->{'borrowernumber'} ne ''){
178 if ($bornum eq $borrower->{'borrowernumber'}){
180 my ($renewstatus) = C4::Circulation::Renewals::renewstatus($env,$dbh,$bornum,$itemnum);
181 my ($resbor,$resrec) = checkreserve($env,$dbh,$itemnum);
182 if ($renewstatus == "0") {
183 info_msg($env,"</S>Issued to this borrower - No renewals<!S>");
185 } elsif ($resbor ne "") {
186 my $resp = C4::InterfaceCDK::msg_ny($env,"Book is issued to this borrower",
187 "and is reserved - Renew?");
189 $newdate = C4::Circulation::Renewals::renewbook($env,$dbh,$bornum,$itemnum);
195 my $resp = C4::InterfaceCDK::msg_yn($env,"Book is issued to this borrower", "Renew?");
197 $newdate = C4::Circulation::Renewals::renewbook($env,$dbh,$bornum,$itemnum);
204 my $text="Issued to $borrower->{'firstname'} $borrower->{'surname'} ($borrower->{'cardnumber'})";
205 my $resp = C4::InterfaceCDK::msg_yn($env,$text,"Mark as returned?");
207 &returnrecord($env,$dbh,$borrower->{'borrowernumber'},$itemnum);
213 return($borrower->{'borrowernumber'},$canissue,$newdate);
218 # Check for reserves for biblio
219 my ($env,$dbh,$itemnum)=@_;
221 my $query = "select * from reserves,items
222 where (items.itemnumber = '$itemnum')
223 and (reserves.cancellationdate is NULL)
224 and (items.biblionumber = reserves.biblionumber)
225 and ((reserves.found = 'W')
226 or (reserves.found is null))
228 my $sth = $dbh->prepare($query);
231 if (my $data=$sth->fetchrow_hashref) {
233 my $const = $data->{'constrainttype'};
235 $resbor = $data->{'borrowernumber'};
238 my $cquery = "select * from reserveconstraints,items
239 where (borrowernumber='$data->{'borrowernumber'}')
240 and reservedate='$data->{'reservedate'}'
241 and reserveconstraints.biblionumber='$data->{'biblionumber'}'
242 and (items.itemnumber=$itemnum and
243 items.biblioitemnumber = reserveconstraints.biblioitemnumber)";
244 my $csth = $dbh->prepare($cquery);
246 if (my $cdata=$csth->fetchrow_hashref) {$found = 1;}
248 if ($found eq 1) {$resbor = $data->{'borrowernumber'};}
250 if ($found eq 0) {$resbor = $data->{'borrowernumber'};}
256 return ($resbor,$resrec);
260 # check for reserves waiting
261 my ($env,$dbh,$bornum)=@_;
263 my $query = "select * from reserves
264 where (borrowernumber = '$bornum')
265 and (reserves.found='W') and cancellationdate is NULL";
266 my $sth = $dbh->prepare($query);
269 if (my $data=$sth->fetchrow_hashref) {
270 @itemswaiting[$cnt] =$data;
274 return ($cnt,\@itemswaiting);
278 my ($env,$interface)=@_;
280 my ($number,$reason)=dialog("Book Barcode:");
282 return ($number,$reason);
286 my ($env,$interface)=@_;
288 my ($number,$reason,$book)=C4::InterfaceCDK::borrower_dialog($env); #C4::InterfaceCDK
291 return ($number,$reason,$book);
295 END { } # module clean-up code here (global destructor)