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 # 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.
45 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
47 # set the version for version checking
51 @EXPORT = qw(&pastitems &checkoverdues &previousissue
52 &checkreserve &checkwaiting &scanbook &scanborrower &getbranch &getprinter);
53 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
55 # your exported package globals go here,
56 # as well as any optionally exported functions
58 @EXPORT_OK = qw($Var1 %Hashit);
61 # non-exported package globals go here
62 use vars qw(@more $stuff);
64 # initalize package globals, first exported ones
69 # then the others (which are still accessible as $Some::Module::stuff)
73 # all file-scoped lexicals must be created before
74 # the functions below that use them.
76 # file-private lexicals go here
80 # here's a file-private function as a closure,
81 # callable as &$priv_func; it cannot be prototyped.
86 # make all your functions, whether exported or not;
90 my $dbh = C4::Context->dbh;
91 my $query = "select * from branches order by branchcode";
92 my $sth = $dbh->prepare($query);
96 while (my $data = $sth->fetchrow_hashref) {
99 brmenu ($env,\@branches);
101 my $data = $sth->fetchrow_hashref;
102 $env->{'branchcode'}=$data->{'branchcode'};
104 my $query = "select * from branches
105 where branchcode = '$env->{'branchcode'}'";
106 $sth = $dbh->prepare($query);
108 my $data = $sth->fetchrow_hashref;
109 $env->{'brdata'} = $data;
110 $env->{'branchname'} = $data->{'branchname'};
116 my $dbh = C4::Context->dbh;
117 my $query = "select * from printers order by printername";
118 my $sth = $dbh->prepare($query);
122 while (my $data = $sth->fetchrow_hashref) {
123 push @printers,$data;
125 prmenu ($env,\@printers);
127 my $data=$sth->fetchrow_hashref;
128 $env->{'queue'}=$data->{'printqueue'};
129 $env->{'printtype'}=$data->{'printtype'};
134 # FIXME - This is not the same as &C4::Circulation::pastitems, though
135 # the two appear to share some code.
137 #Get list of all items borrower has currently on issue
138 my ($env,$bornum,$dbh)=@_;
139 my $query1 = "select * from issues where (borrowernumber=$bornum)
140 and (returndate is null) order by date_due";
141 my $sth=$dbh->prepare($query1);
146 while (my $data1=$sth->fetchrow_hashref) {
147 my $data = itemnodata($env,$dbh,$data1->{'itemnumber'}); #C4::Search
148 my @date = split("-",$data1->{'date_due'});
149 my $odate = (@date[2]+0)."-".(@date[1]+0)."-".@date[0];
150 my $line = C4::Circulation::Issues::formatitem($env,$data,$odate,"");
155 return(\@items,\@items2);
159 #checks whether a borrower has overdue items
160 my ($env,$bornum,$dbh)=@_;
161 my @datearr = localtime;
162 my $today = ($datearr[5] + 1900)."-".($datearr[4]+1)."-".$datearr[3];
163 my $query = "Select count(*) from issues where borrowernumber=$bornum and
164 returndate is NULL and date_due < '$today'";
165 my $sth=$dbh->prepare($query);
167 my $data = $sth->fetchrow_hashref;
169 return $data->{'count(*)'};
172 # FIXME - This is quite similar to &C4::Circulation::previousissue
174 my ($env,$itemnum,$dbh,$bornum)=@_;
175 my $sth=$dbh->prepare("Select
176 firstname,surname,issues.borrowernumber,cardnumber,returndate
177 from issues,borrowers where
178 issues.itemnumber='$itemnum' and
179 issues.borrowernumber=borrowers.borrowernumber
180 and issues.returndate is NULL");
182 my $borrower=$sth->fetchrow_hashref;
186 if ($borrower->{'borrowernumber'} ne ''){
187 if ($bornum eq $borrower->{'borrowernumber'}){
189 my ($renewstatus) = C4::Circulation::Renewals::renewstatus($env,$dbh,$bornum,$itemnum);
190 my ($resbor,$resrec) = checkreserve($env,$dbh,$itemnum);
191 if ($renewstatus == "0") {
192 info_msg($env,"</S>Issued to this borrower - No renewals<!S>");
194 } elsif ($resbor ne "") {
195 my $resp = C4::InterfaceCDK::msg_ny($env,"Book is issued to this borrower",
196 "and is reserved - Renew?");
198 $newdate = C4::Circulation::Renewals::renewbook($env,$dbh,$bornum,$itemnum);
204 my $resp = C4::InterfaceCDK::msg_yn($env,"Book is issued to this borrower", "Renew?");
206 $newdate = C4::Circulation::Renewals::renewbook($env,$dbh,$bornum,$itemnum);
213 my $text="Issued to $borrower->{'firstname'} $borrower->{'surname'} ($borrower->{'cardnumber'})";
214 my $resp = C4::InterfaceCDK::msg_yn($env,$text,"Mark as returned?");
216 &returnrecord($env,$dbh,$borrower->{'borrowernumber'},$itemnum);
222 return($borrower->{'borrowernumber'},$canissue,$newdate);
227 # Check for reserves for biblio
228 my ($env,$dbh,$itemnum)=@_;
230 my $query = "select * from reserves,items
231 where (items.itemnumber = '$itemnum')
232 and (reserves.cancellationdate is NULL)
233 and (items.biblionumber = reserves.biblionumber)
234 and ((reserves.found = 'W')
235 or (reserves.found is null))
237 my $sth = $dbh->prepare($query);
240 if (my $data=$sth->fetchrow_hashref) {
242 my $const = $data->{'constrainttype'};
244 $resbor = $data->{'borrowernumber'};
247 my $cquery = "select * from reserveconstraints,items
248 where (borrowernumber='$data->{'borrowernumber'}')
249 and reservedate='$data->{'reservedate'}'
250 and reserveconstraints.biblionumber='$data->{'biblionumber'}'
251 and (items.itemnumber=$itemnum and
252 items.biblioitemnumber = reserveconstraints.biblioitemnumber)";
253 my $csth = $dbh->prepare($cquery);
255 if (my $cdata=$csth->fetchrow_hashref) {$found = 1;}
257 if ($found eq 1) {$resbor = $data->{'borrowernumber'};}
259 if ($found eq 0) {$resbor = $data->{'borrowernumber'};}
265 return ($resbor,$resrec);
269 # check for reserves waiting
270 my ($env,$dbh,$bornum)=@_;
272 my $query = "select * from reserves
273 where (borrowernumber = '$bornum')
274 and (reserves.found='W') and cancellationdate is NULL";
275 my $sth = $dbh->prepare($query);
278 if (my $data=$sth->fetchrow_hashref) {
279 @itemswaiting[$cnt] =$data;
283 return ($cnt,\@itemswaiting);
286 # FIXME - This is identical to &C4::Circulation::scanbook
288 my ($env,$interface)=@_;
290 my ($number,$reason)=dialog("Book Barcode:");
292 return ($number,$reason);
295 # FIXME - This is very similar to &C4::Circulation::scanborrower
297 my ($env,$interface)=@_;
299 my ($number,$reason,$book)=C4::InterfaceCDK::borrower_dialog($env); #C4::InterfaceCDK
302 return ($number,$reason,$book);
306 END { } # module clean-up code here (global destructor)