3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
20 # FIXME - I suspect that this module is obsolete.
30 use C4::Interface::ReserveentCDK;
31 use C4::Circulation::Main;
32 use C4::Circulation::Borrower;
34 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
36 # set the version for version checking
40 @EXPORT = qw(&EnterReserves CalcReserveFee CreateReserve );
41 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
43 # your exported package globals go here,
44 # as well as any optionally exported functions
46 @EXPORT_OK = qw($Var1 %Hashit);
49 # non-exported package globals go here
50 use vars qw(@more $stuff);
52 # initalize package globals, first exported ones
57 # then the others (which are still accessible as $Some::Module::stuff)
61 # all file-scoped lexicals must be created before
62 # the functions below that use them.
64 # file-private lexicals go here
68 # here's a file-private function as a closure,
69 # callable as &$priv_func; it cannot be prototyped.
74 # make all your functions, whether exported or not;
76 # FIXME - This doesn't appear to ever be used, except in modules that
77 # appear to be obsolete.
80 my $titlepanel = titlepanel($env,"Reserves","Enter Selection");
81 my @flds = ("No of entries","Barcode","ISBN","Title","Keywords","Author","Subject");
82 my @fldlens = ("5","15","15","50","50","50","50");
83 my ($reason,$num,$itemnumber,$isbn,$title,$keyword,$author,$subject) =
84 FindBiblioScreen($env,"Reserves",7,\@flds,\@fldlens);
90 $search{'title'}= $title;
91 $search{'keyword'}=$keyword;
92 $search{'author'}=$author;
93 $search{'subject'}=$subject;
94 $search{'item'}=$itemnumber;
95 $search{'isbn'}=$isbn;
102 my $title = titlepanel($env,"Reserves","Searching");
103 if ($itemnumber ne '' || $isbn ne ''){
104 ($count,@results)=&CatSearch($env,'precise',\%search,$num,$offset);
107 ($count,@results)=&CatSearch($env,'subject',\%search,$num,$offset);
110 ($count,@results)=&KeywordSearch($env,'intra',\%search,$num,$offset);
112 ($count,@results)=&CatSearch($env,'loose',\%search,$num,$offset);
116 my $no_ents = @results;
120 my @ents = split("\t",@results[0]);
121 $biblionumber = @ents[2];
127 while ($i < $no_ents) {
128 my @ents = split("\t",@results[$i]);
129 $line = fmtstr($env,@ents[1],"L70");
130 my $auth = substr(@ents[0],0,30);
131 substr($line,(70-length($auth)-2),length($auth)+2) = " ".$auth;
132 @bibtitles[$i]=$line;
133 $biblio_xref{$line}=@ents[2];
136 my $title = titlepanel($env,"Reserves","Select Title");
137 my ($results,$bibres) = SelectBiblio($env,$count,\@bibtitles);
138 if ($results eq "") {
139 $biblionumber = $biblio_xref{$bibres};
145 if ($biblionumber eq "") {
146 error_msg($env,"No items found");
148 my @items = GetItems($env,$biblionumber);
150 my $dbh = C4::Context->dbh;
151 my $query = "Select * from biblio where biblionumber = $biblionumber";
152 my $sth = $dbh->prepare($query);
154 my $data=$sth->fetchrow_hashref;
157 my $query = "select * from branches where issuing=1 order by branchname";
158 my $sth=$dbh->prepare($query);
160 while (my $branchrec=$sth->fetchrow_hashref) {
162 fmtstr($env,$branchrec->{'branchcode'},"L2")." ".$branchrec->{'branchname'};
163 push @branches,$branchdet;
167 while ($donext eq "") {
168 my $title = titlepanel($env,"Reserves","Create Reserve");
169 my ($reason,$borcode,$branch,$constraint,$bibitems) =
170 MakeReserveScreen($env, $data, \@items, \@branches);
171 if ($borcode ne "") {
172 my ($borrnum,$borrower) = findoneborrower($env,$dbh,$borcode);
174 if ($borrnum ne "") {
176 CalcReserveFee($env,$borrnum,$biblionumber,$constraint,$bibitems);
177 CreateReserve($env,$branch,$borrnum,$biblionumber,$constraint,$bibitems,$fee);
184 } else { $donext = "Circ" }
192 # FIXME - A functionally identical version of this function appears in
193 # C4::Reserves2. Pick one and stick with it.
195 my ($env,$borrnum,$biblionumber,$constraint,$bibitems) = @_;
197 my $dbh = C4::Context->dbh;
198 my $const = lc substr($constraint,0,1);
199 my $query = "select * from borrowers,categories
200 where (borrowernumber = '$borrnum')
201 and (borrowers.categorycode = categories.categorycode)";
202 my $sth = $dbh->prepare($query);
204 my $data = $sth->fetchrow_hashref;
206 my $fee = $data->{'reservefee'};
207 my $cntitems = @->$bibitems;
209 # check for items on issue
210 # first find biblioitem records
212 my $query1 = "select * from biblio,biblioitems
213 where (biblio.biblionumber = '$biblionumber')
214 and (biblio.biblionumber = biblioitems.biblionumber)";
215 my $sth1 = $dbh->prepare($query1);
217 while (my $data1=$sth1->fetchrow_hashref) {
219 push @biblioitems,$data1;
223 while ($x < $cntitems) {
224 if (@$bibitems->{'biblioitemnumber'} == $data->{'biblioitemnumber'}) {
229 if ($const eq 'o') {if ($found == 1) {push @biblioitems,$data;}
230 } else {if ($found == 0) {push @biblioitems,$data;} }
234 my $cntitemsfound = @biblioitems;
238 while ($x < $cntitemsfound) {
239 my $bitdata = @biblioitems[$x];
240 my $query2 = "select * from items
241 where biblioitemnumber = '$bitdata->{'biblioitemnumber'}'";
242 my $sth2 = $dbh->prepare($query2);
244 while (my $itdata=$sth2->fetchrow_hashref) {
245 my $query3 = "select * from issues
246 where itemnumber = '$itdata->{'itemnumber'}' and returndate is null";
247 my $sth3 = $dbh->prepare($query3);
249 if (my $isdata=$sth3->fetchrow_hashref) { } else {$allissued = 0; }
253 if ($allissued == 0) {
254 my $rquery = "select * from reserves
255 where biblionumber = '$biblionumber'";
256 my $rsth = $dbh->prepare($rquery);
258 if (my $rdata = $rsth->fetchrow_hashref) { } else {
264 } # end CalcReserveFee
266 # FIXME - A somewhat different version of this function appears in
267 # C4::Reserves2. Pick one and stick with it.
269 my ($env,$branch,$borrnum,$biblionumber,$constraint,$bibitems,$fee) = @_;
270 my $dbh = C4::Context->dbh;
271 #$dbh->{RaiseError} = 1;
272 #$dbh->{AutoCommit} = 0;
273 my $const = lc substr($constraint,0,1);
274 my @datearr = localtime(time);
275 my $resdate = (1900+$datearr[5])."-".($datearr[4]+1)."-".$datearr[3];
277 # updates take place here
279 my $nextacctno = &getnextacctno($env,$borrnum,$dbh);
280 my $updquery = "insert into accountlines
281 (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
282 values ($borrnum,$nextacctno,now(),$fee,'Reserve Charge','Res',$fee)";
283 my $usth = $dbh->prepare($updquery);
287 my $query="insert into reserves (borrowernumber,biblionumber,reservedate,branchcode,constrainttype) values ('$borrnum','$biblionumber','$resdate','$branch','$const')";
288 my $sth = $dbh->prepare($query);
290 if (($const eq "o") || ($const eq "e")) {
291 my $numitems = @$bibitems;
293 while ($i < $numitems) {
294 my $biblioitem = @$bibitems[$i];
295 my $query = "insert into reserveconstraints
296 (borrowernumber,biblionumber,reservedate,biblioitemnumber)
297 values ('$borrnum','$biblionumber','$resdate','$biblioitem')";
298 my $sth = $dbh->prepare($query);
303 UpdateStats($env,'branch','reserve',$fee);
309 # # error_msg($env,"Update failed");
313 } # end CreateReserve
318 END { } # module clean-up code here (global destructor)