1 package C4::Reserves; #asummes C4/Reserves
3 #requires DBI.pm to be installed
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307 USA
32 use C4::Interface::ReserveentCDK;
33 use C4::Circulation::Main;
34 use C4::Circulation::Borrower;
36 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
38 # set the version for version checking
42 @EXPORT = qw(&EnterReserves CalcReserveFee CreateReserve );
43 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
45 # your exported package globals go here,
46 # as well as any optionally exported functions
48 @EXPORT_OK = qw($Var1 %Hashit);
51 # non-exported package globals go here
52 use vars qw(@more $stuff);
54 # initalize package globals, first exported ones
59 # then the others (which are still accessible as $Some::Module::stuff)
63 # all file-scoped lexicals must be created before
64 # the functions below that use them.
66 # file-private lexicals go here
70 # here's a file-private function as a closure,
71 # callable as &$priv_func; it cannot be prototyped.
76 # make all your functions, whether exported or not;
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 = &C4Connect;
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" }
194 my ($env,$borrnum,$biblionumber,$constraint,$bibitems) = @_;
196 my $dbh = &C4Connect;
197 my $const = lc substr($constraint,0,1);
198 my $query = "select * from borrowers,categories
199 where (borrowernumber = '$borrnum')
200 and (borrowers.categorycode = categories.categorycode)";
201 my $sth = $dbh->prepare($query);
203 my $data = $sth->fetchrow_hashref;
205 my $fee = $data->{'reservefee'};
206 my $cntitems = @->$bibitems;
208 # check for items on issue
209 # first find biblioitem records
211 my $query1 = "select * from biblio,biblioitems
212 where (biblio.biblionumber = '$biblionumber')
213 and (biblio.biblionumber = biblioitems.biblionumber)";
214 my $sth1 = $dbh->prepare($query1);
216 while (my $data1=$sth1->fetchrow_hashref) {
218 push @biblioitems,$data1;
222 while ($x < $cntitems) {
223 if (@$bibitems->{'biblioitemnumber'} == $data->{'biblioitemnumber'}) {
228 if ($const eq 'o') {if ($found == 1) {push @biblioitems,$data;}
229 } else {if ($found == 0) {push @biblioitems,$data;} }
233 my $cntitemsfound = @biblioitems;
237 while ($x < $cntitemsfound) {
238 my $bitdata = @biblioitems[$x];
239 my $query2 = "select * from items
240 where biblioitemnumber = '$bitdata->{'biblioitemnumber'}'";
241 my $sth2 = $dbh->prepare($query2);
243 while (my $itdata=$sth2->fetchrow_hashref) {
244 my $query3 = "select * from issues
245 where itemnumber = '$itdata->{'itemnumber'}' and returndate is null";
246 my $sth3 = $dbh->prepare($query3);
248 if (my $isdata=$sth3->fetchrow_hashref) { } else {$allissued = 0; }
252 if ($allissued == 0) {
253 my $rquery = "select * from reserves
254 where biblionumber = '$biblionumber'";
255 my $rsth = $dbh->prepare($rquery);
257 if (my $rdata = $rsth->fetchrow_hashref) { } else {
264 } # end CalcReserveFee
267 my ($env,$branch,$borrnum,$biblionumber,$constraint,$bibitems,$fee) = @_;
268 my $dbh = &C4Connect;
269 #$dbh->{RaiseError} = 1;
270 #$dbh->{AutoCommit} = 0;
271 my $const = lc substr($constraint,0,1);
272 my @datearr = localtime(time);
273 my $resdate = (1900+$datearr[5])."-".($datearr[4]+1)."-".$datearr[3];
275 # updates take place here
277 my $nextacctno = &getnextacctno($env,$borrnum,$dbh);
278 my $updquery = "insert into accountlines
279 (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
280 values ($borrnum,$nextacctno,now(),$fee,'Reserve Charge','Res',$fee)";
281 my $usth = $dbh->prepare($updquery);
285 my $query="insert into reserves (borrowernumber,biblionumber,reservedate,branchcode,constrainttype) values ('$borrnum','$biblionumber','$resdate','$branch','$const')";
286 my $sth = $dbh->prepare($query);
288 if (($const eq "o") || ($const eq "e")) {
289 my $numitems = @$bibitems;
291 while ($i < $numitems) {
292 my $biblioitem = @$bibitems[$i];
293 my $query = "insert into reserveconstraints
294 (borrowernumber,biblionumber,reservedate,biblioitemnumber)
295 values ('$borrnum','$biblionumber','$resdate','$biblioitem')";
296 my $sth = $dbh->prepare($query);
301 UpdateStats($env,'branch','reserve',$fee);
307 # # error_msg($env,"Update failed");
312 } # end CreateReserve
317 END { } # module clean-up code here (global destructor)