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