Added PODs.
[koha.git] / C4 / Circulation.pm
1 package C4::Circulation; #assumes C4/Circulation
2
3 #package to deal with circulation 
4
5
6 # Copyright 2000-2002 Katipo Communications
7 #
8 # This file is part of Koha.
9 #
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
13 # version.
14 #
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.
18 #
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
22
23 use strict;
24 require Exporter;
25 use DBI;
26 use C4::Database;
27 use C4::Circulation::Issues;
28 use C4::Circulation::Returns;
29 use C4::Circulation::Renewals;
30 use C4::Circulation::Borrower;
31 use C4::Reserves;
32 #use C4::Interface;
33 use C4::Security;
34
35 use vars qw($VERSION @ISA @EXPORT);
36   
37 # set the version for version checking
38 $VERSION = 0.01;
39     
40 @ISA = qw(Exporter);
41 @EXPORT = qw(&Start_circ &scanborrower);
42
43 sub Start_circ{
44   my ($env)=@_;
45   #connect to database
46   #start interface
47   &startint($env,'Circulation');
48   my $donext = 'Circ';
49   my $reason;
50   my $data;
51   while ($donext ne 'Quit') {
52     if ($donext  eq "Circ") {
53       clearscreen();        
54       ($reason,$data) = menu($env,'console','Circulation', 
55         ('Issues','Returns','Borrower Enquiries','Reserves','Log In'));
56       #debug_msg($env,"data = $data");
57     } else {
58       $data = $donext;
59     }
60     if ($data eq 'Issues') {  
61       $donext=Issue($env); #C4::Circulation::Issues
62       #debug_msg("","do next $donext");
63     } elsif ($data eq 'Returns') {
64       $donext=Returns($env); #C4::Circulation::Returns
65     } elsif ($data eq 'Borrower Enquiries'){
66       $donext=Borenq($env); #C4::Circulation::Borrower
67     } elsif ($data eq 'Reserves'){
68       $donext=EnterReserves($env); #C4::Reserves
69     } elsif ($data eq 'Log In') {
70       &endint($env);
71       &Login($env);   #C4::Security
72       &startint($env,'Circulation');
73     } elsif ($data eq 'Quit') { 
74       $donext = $data;
75     }
76     #debug_msg($env,"donext -  $donext");
77   }
78   &endint($env)  
79 }
80
81 sub pastitems{
82   #Get list of all items borrower has currently on issue
83   my ($env,$bornum,$dbh)=@_;
84   my $sth=$dbh->prepare("Select * from issues,items,biblio
85     where borrowernumber=$bornum and issues.itemnumber=items.itemnumber
86     and items.biblionumber=biblio.biblionumber
87     and returndate is null
88     order by date_due");
89   $sth->execute;
90   my $i=0;
91   my @items;
92   my @items2;
93   #$items[0]=" "x29;
94   #$items2[0]=" "x29;
95   $items[0]=" "x72;
96   $items2[0]=" "x72;
97   while (my $data=$sth->fetchrow_hashref) {
98      my $line = "$data->{'date_due'} $data->{'title'}";
99      # $items[$i]=fmtstr($env,$line,"L29");
100      $items[$i]=fmtstr($env,$line,"L72");
101      $i++;
102   }
103   return(\@items,\@items2);
104   $sth->finish;
105 }
106
107 sub checkoverdues{
108   #checks whether a borrower has overdue items
109   my ($env,$bornum,$dbh)=@_;
110   my $sth=$dbh->prepare("Select * from issues,items,biblio where
111   borrowernumber=$bornum and issues.itemnumber=items.itemnumber and
112   items.biblionumber=biblio.biblionumber");
113   $sth->execute;
114   my $row=1;
115   my $col=40;
116   while (my $data=$sth->fetchrow_hashref){
117     output($row,$col,$data->{'title'});
118     $row++;
119   }
120   $sth->finish;
121 }
122
123 sub previousissue {
124   my ($env,$itemnum,$dbh,$bornum)=@_;
125   my $sth=$dbh->prepare("Select firstname,surname,issues.borrowernumber,cardnumber,returndate
126   from issues,borrowers where 
127   issues.itemnumber='$itemnum' and
128   issues.borrowernumber=borrowers.borrowernumber and issues.returndate is
129 NULL");
130   $sth->execute;
131   my $borrower=$sth->fetchrow_hashref;
132   $sth->finish;
133   if ($borrower->{'borrowernumber'} ne ''){
134     if ($bornum eq $borrower->{'borrowernumber'}){
135       # no need to issue
136       my ($renewstatus) = &renewstatus($env,$dbh,$bornum,$itemnum);
137       my $resp = &msg_yn("Book is issued to this borrower", "Renew?");
138       if ($resp == "y") {
139         &renewbook($env,$dbh,$bornum,$itemnum);
140       }  
141       
142     } else {
143       my $text="Issued to $borrower->{'firstname'} $borrower->{'surname'} ($borrower->{'cardnumber'})";    
144       my $resp = &msg_yn($text,"Mark as returned?");
145       if ($resp == "y") {
146         &returnrecord($env,$dbh,$borrower->{'borrowernumber'},$itemnum);
147         # can issue
148       } else {
149         # can't issue
150       } 
151     }
152   } 
153   return($borrower->{'borrowernumber'});
154   $sth->finish;
155 }
156
157
158 sub checkreserve{
159   # Check for reserves for biblio 
160   # does not look at constraints yet
161   my ($env,$dbh,$itemnum)=@_;
162   my $resbor = "";
163   my $query = "select * from reserves,items 
164   where (items.itemnumber = '$itemnum')
165   and (items.biblionumber = reserves.biblionumber)
166   and (reserves.found is null) order by priority";
167   my $sth = $dbh->prepare($query);
168   $sth->execute();
169   if (my $data=$sth->fetchrow_hashref) {
170     $resbor = $data->{'borrowernumber'}; 
171   }
172   return ($resbor);
173   $sth->finish;
174 }
175
176 sub checkwaiting{
177   # check for reserves waiting
178   my ($env,$dbh,$bornum)=@_;
179   my @itemswaiting="";
180   my $query = "select * from reserves
181   where (borrowernumber = '$bornum')
182   and (reserves.found='W')";
183   my $sth = $dbh->prepare($query);
184   $sth->execute();
185   if (my $data=$sth->fetchrow_hashref) {
186     push @itemswaiting,$data->{'itemnumber'}; 
187   }
188   return (\@itemswaiting);
189   $sth->finish;
190 }
191
192 sub scanbook {
193   my ($env,$interface)=@_;
194   #scan barcode
195   my ($number,$reason)=dialog("Book Barcode:");
196   $number=uc $number;
197   return ($number,$reason);
198 }
199
200 sub scanborrower {
201   my ($env,$interface)=@_;
202   #scan barcode
203   my ($number,$reason,$book)=&borrower_dialog($env); #C4::Interface
204   $number= $number;
205   $book=uc $book;
206   return ($number,$reason,$book);
207 }
208
209
210 END { }       # module clean-up code here (global destructor)