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.
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;
119 my $query = "Select * from biblio where biblionumber = $biblionumber";
120 my $sth = $dbh->prepare($query);
122 my $data=$sth->fetchrow_hashref;
125 my $query = "select * from branches where issuing=1 order by branchname";
126 my $sth=$dbh->prepare($query);
128 while (my $branchrec=$sth->fetchrow_hashref) {
130 fmtstr($env,$branchrec->{'branchcode'},"L2")." ".$branchrec->{'branchname'};
131 push @branches,$branchdet;
135 while ($donext eq "") {
136 my $title = titlepanel($env,"Reserves","Create Reserve");
137 my ($reason,$borcode,$branch,$constraint,$bibitems) =
138 MakeReserveScreen($env, $data, \@items, \@branches);
139 if ($borcode ne "") {
140 my ($borrnum,$borrower) = findoneborrower($env,$dbh,$borcode);
142 if ($borrnum ne "") {
144 CalcReserveFee($env,$borrnum,$biblionumber,$constraint,$bibitems);
145 CreateReserve($env,$branch,$borrnum,$biblionumber,$constraint,$bibitems,$fee);
152 } else { $donext = "Circ" }
160 # FIXME - A functionally identical version of this function appears in
161 # C4::Reserves2. Pick one and stick with it.
163 my ($env,$borrnum,$biblionumber,$constraint,$bibitems) = @_;
165 my $dbh = C4::Context->dbh;
166 my $const = lc substr($constraint,0,1);
167 my $query = "select * from borrowers,categories
168 where (borrowernumber = '$borrnum')
169 and (borrowers.categorycode = categories.categorycode)";
170 my $sth = $dbh->prepare($query);
172 my $data = $sth->fetchrow_hashref;
174 my $fee = $data->{'reservefee'};
175 my $cntitems = @->$bibitems;
177 # check for items on issue
178 # first find biblioitem records
180 my $query1 = "select * from biblio,biblioitems
181 where (biblio.biblionumber = '$biblionumber')
182 and (biblio.biblionumber = biblioitems.biblionumber)";
183 my $sth1 = $dbh->prepare($query1);
185 while (my $data1=$sth1->fetchrow_hashref) {
187 push @biblioitems,$data1;
191 while ($x < $cntitems) {
192 if (@$bibitems->{'biblioitemnumber'} == $data->{'biblioitemnumber'}) {
197 if ($const eq 'o') {if ($found == 1) {push @biblioitems,$data;}
198 } else {if ($found == 0) {push @biblioitems,$data;} }
202 my $cntitemsfound = @biblioitems;
206 while ($x < $cntitemsfound) {
207 my $bitdata = @biblioitems[$x];
208 my $query2 = "select * from items
209 where biblioitemnumber = '$bitdata->{'biblioitemnumber'}'";
210 my $sth2 = $dbh->prepare($query2);
212 while (my $itdata=$sth2->fetchrow_hashref) {
213 my $query3 = "select * from issues
214 where itemnumber = '$itdata->{'itemnumber'}' and returndate is null";
215 my $sth3 = $dbh->prepare($query3);
217 if (my $isdata=$sth3->fetchrow_hashref) { } else {$allissued = 0; }
221 if ($allissued == 0) {
222 my $rquery = "select * from reserves
223 where biblionumber = '$biblionumber'";
224 my $rsth = $dbh->prepare($rquery);
226 if (my $rdata = $rsth->fetchrow_hashref) { } else {
232 } # end CalcReserveFee
234 # FIXME - A somewhat different version of this function appears in
235 # C4::Reserves2. Pick one and stick with it.
237 my ($env,$branch,$borrnum,$biblionumber,$constraint,$bibitems,$fee) = @_;
238 my $dbh = C4::Context->dbh;
239 #$dbh->{RaiseError} = 1;
240 #$dbh->{AutoCommit} = 0;
241 my $const = lc substr($constraint,0,1);
242 my @datearr = localtime(time);
243 my $resdate = (1900+$datearr[5])."-".($datearr[4]+1)."-".$datearr[3];
245 # updates take place here
247 my $nextacctno = &getnextacctno($env,$borrnum,$dbh);
248 my $updquery = "insert into accountlines
249 (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
250 values ($borrnum,$nextacctno,now(),$fee,'Reserve Charge','Res',$fee)";
251 my $usth = $dbh->prepare($updquery);
255 my $query="insert into reserves (borrowernumber,biblionumber,reservedate,branchcode,constrainttype) values ('$borrnum','$biblionumber','$resdate','$branch','$const')";
256 my $sth = $dbh->prepare($query);
258 if (($const eq "o") || ($const eq "e")) {
259 my $numitems = @$bibitems;
261 while ($i < $numitems) {
262 my $biblioitem = @$bibitems[$i];
263 my $query = "insert into reserveconstraints
264 (borrowernumber,biblionumber,reservedate,biblioitemnumber)
265 values ('$borrnum','$biblionumber','$resdate','$biblioitem')";
266 my $sth = $dbh->prepare($query);
271 UpdateStats($env,'branch','reserve',$fee);
277 # # error_msg($env,"Update failed");
281 } # end CreateReserve