5 # Copyright 2000-2002 Katipo Communications
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA 02111-1307 USA
22 # FIXME - I suspect that this module is obsolete.
31 #use C4::InterfaceCDK;
32 #use C4::Interface::ReserveentCDK;
33 use C4::Circulation::Main;
34 use C4::Circulation::Borrower;
36 use vars qw($VERSION @ISA @EXPORT);
38 # set the version for version checking
42 @EXPORT = qw(&EnterReserves CalcReserveFee CreateReserve );
44 # FIXME - This doesn't appear to ever be used, except in modules that
45 # appear to be obsolete.
48 my $titlepanel = titlepanel($env,"Reserves","Enter Selection");
49 my @flds = ("No of entries","Barcode","ISBN","Title","Keywords","Author","Subject");
50 my @fldlens = ("5","15","15","50","50","50","50");
51 my ($reason,$num,$itemnumber,$isbn,$title,$keyword,$author,$subject) =
52 FindBiblioScreen($env,"Reserves",7,\@flds,\@fldlens);
58 $search{'title'}= $title;
59 $search{'keyword'}=$keyword;
60 $search{'author'}=$author;
61 $search{'subject'}=$subject;
62 $search{'item'}=$itemnumber;
63 $search{'isbn'}=$isbn;
70 my $title = titlepanel($env,"Reserves","Searching");
71 if ($itemnumber ne '' || $isbn ne ''){
72 ($count,@results)=&CatSearch($env,'precise',\%search,$num,$offset);
75 ($count,@results)=&CatSearch($env,'subject',\%search,$num,$offset);
78 ($count,@results)=&KeywordSearch($env,'intra',\%search,$num,$offset);
80 ($count,@results)=&CatSearch($env,'loose',\%search,$num,$offset);
84 my $no_ents = @results;
88 my @ents = split("\t",@results[0]);
89 $biblionumber = @ents[2];
95 while ($i < $no_ents) {
96 my @ents = split("\t",@results[$i]);
97 $line = fmtstr($env,@ents[1],"L70");
98 my $auth = substr(@ents[0],0,30);
99 substr($line,(70-length($auth)-2),length($auth)+2) = " ".$auth;
100 @bibtitles[$i]=$line;
101 $biblio_xref{$line}=@ents[2];
104 my $title = titlepanel($env,"Reserves","Select Title");
105 my ($results,$bibres) = SelectBiblio($env,$count,\@bibtitles);
106 if ($results eq "") {
107 $biblionumber = $biblio_xref{$bibres};
113 if ($biblionumber eq "") {
114 error_msg($env,"No items found");
116 my @items = GetItems($env,$biblionumber);
118 my $dbh = C4::Context->dbh;
120 my $sth = $dbh->prepare("Select * from biblio where biblionumber = ?");
121 $sth->execute($biblionumber);
122 my $data=$sth->fetchrow_hashref;
125 my $sth=$dbh->prepare("select * from branches where issuing=1 order by branchname");
127 while (my $branchrec=$sth->fetchrow_hashref) {
129 fmtstr($env,$branchrec->{'branchcode'},"L2")." ".$branchrec->{'branchname'};
130 push @branches,$branchdet;
134 while ($donext eq "") {
135 my $title = titlepanel($env,"Reserves","Create Reserve");
136 my ($reason,$borcode,$branch,$constraint,$bibitems) =
137 MakeReserveScreen($env, $data, \@items, \@branches);
138 if ($borcode ne "") {
139 my ($borrnum,$borrower) = findoneborrower($env,$dbh,$borcode);
141 if ($borrnum ne "") {
143 CalcReserveFee($env,$borrnum,$biblionumber,$constraint,$bibitems);
144 CreateReserve($env,$branch,$borrnum,$biblionumber,$constraint,$bibitems,$fee);
151 } else { $donext = "Circ" }
159 # FIXME - A functionally identical version of this function appears in
160 # C4::Reserves2. Pick one and stick with it.
162 my ($env,$borrnum,$biblionumber,$constraint,$bibitems) = @_;
164 my $dbh = C4::Context->dbh;
165 my $const = lc substr($constraint,0,1);
166 my $sth = $dbh->prepare("select * from borrowers,categories
167 where (borrowernumber = ?)
168 and (borrowers.categorycode = categories.categorycode)");
169 $sth->execute($borrnum);
170 my $data = $sth->fetchrow_hashref;
172 my $fee = $data->{'reservefee'};
173 my $cntitems = @->$bibitems;
175 # check for items on issue
176 # first find biblioitem records
178 my $sth1 = $dbh->prepare("select * from biblio,biblioitems
179 where (biblio.biblionumber = ?)
180 and (biblio.biblionumber = biblioitems.biblionumber)");
181 $sth1->execute($biblionumber);
182 while (my $data1=$sth1->fetchrow_hashref) {
184 push @biblioitems,$data1;
188 while ($x < $cntitems) {
189 if (@$bibitems->{'biblioitemnumber'} == $data->{'biblioitemnumber'}) {
194 if ($const eq 'o') {if ($found == 1) {push @biblioitems,$data;}
195 } else {if ($found == 0) {push @biblioitems,$data;} }
199 my $cntitemsfound = @biblioitems;
203 while ($x < $cntitemsfound) {
204 my $bitdata = @biblioitems[$x];
205 my $sth2 = $dbh->prepare("select * from items
206 where biblioitemnumber = ?");
207 $sth2->execute($bitdata->{'biblioitemnumber'});
208 while (my $itdata=$sth2->fetchrow_hashref) {
209 my $sth3 = $dbh->prepare("select * from issues
210 where itemnumber = ? and returndate is null");
211 $sth3->execute($itdata->{'itemnumber'});
212 if (my $isdata=$sth3->fetchrow_hashref) { } else {$allissued = 0; }
216 if ($allissued == 0) {
217 my $rsth = $dbh->prepare("select * from reserves
218 where biblionumber = ?");
219 $rsth->execute($biblionumber);
220 if (my $rdata = $rsth->fetchrow_hashref) { } else {
226 } # end CalcReserveFee
228 # FIXME - A somewhat different version of this function appears in
229 # C4::Reserves2. Pick one and stick with it.
231 my ($env,$branch,$borrnum,$biblionumber,$constraint,$bibitems,$fee) = @_;
232 my $dbh = C4::Context->dbh;
233 #$dbh->{RaiseError} = 1;
234 #$dbh->{AutoCommit} = 0;
235 my $const = lc substr($constraint,0,1);
236 my @datearr = localtime(time);
237 my $resdate = (1900+$datearr[5])."-".($datearr[4]+1)."-".$datearr[3];
239 # updates take place here
241 my $nextacctno = &getnextacctno($env,$borrnum,$dbh);
242 my $usth = $dbh->prepare("insert into accountlines
243 (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
244 values (?,?,now(),?,'Reserve Charge','Res',?)");
245 $usth->execute($borrnum,$nextacctno,$fee,$fee);
248 my $sth = $dbh->prepare("insert into reserves (borrowernumber,biblionumber,reservedate,branchcode,constrainttype) values (?,?,?,?,?)");
249 $sth->execute($borrnum,$biblionumber,$resdate,$branch,$const);
250 if (($const eq "o") || ($const eq "e")) {
251 my $numitems = @$bibitems;
253 while ($i < $numitems) {
254 my $biblioitem = @$bibitems[$i];
255 my $sth = $dbh->prepare("insert into reserveconstraints
256 (borrowernumber,biblionumber,reservedate,biblioitemnumber)
258 $sth->execute($borrnum,$biblionumber,$resdate,$biblioitem);
262 UpdateStats($env,'branch','reserve',$fee);
268 # # error_msg($env,"Update failed");
272 } # end CreateReserve