1 package C4::Reserves2; #asummes C4/Reserves2
3 #requires DBI.pm to be installed
12 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
14 # set the version for version checking
18 @EXPORT = qw(&FindReserves &CreateReserve &updatereserves &getreservetitle
20 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
22 # your exported package globals go here,
23 # as well as any optionally exported functions
25 @EXPORT_OK = qw($Var1 %Hashit);
28 # non-exported package globals go here
29 use vars qw(@more $stuff);
31 # initalize package globals, first exported ones
36 # then the others (which are still accessible as $Some::Module::stuff)
40 # all file-scoped lexicals must be created before
41 # the functions below that use them.
43 # file-private lexicals go here
47 # here's a file-private function as a closure,
48 # callable as &$priv_func; it cannot be prototyped.
53 # make all your functions, whether exported or not;
58 my $query="Select *,reserves.branchcode,biblio.title as btitle
59 from reserves,borrowers,biblio ";
62 $query=$query." where reserves.biblionumber=$bib and
63 reserves.borrowernumber=borrowers.borrowernumber and
64 biblio.biblionumber=$bib and cancellationdate is NULL and
65 (found <> 'F' or found is NULL)";
67 $query=$query." where reserves.borrowernumber=borrowers.borrowernumber
68 and biblio.biblionumber=$bib and reserves.biblionumber=$bib
69 and cancellationdate is NULL and
70 (found <> 'F' or found is NULL)";
73 $query=$query." where borrowers.borrowernumber=$bor and
74 reserves.borrowernumber=borrowers.borrowernumber and reserves.biblionumber
75 =biblio.biblionumber and cancellationdate is NULL and
76 (found <> 'F' or found is NULL)";
78 $query.=" order by priority";
79 my $sth=$dbh->prepare($query);
83 while (my $data=$sth->fetchrow_hashref){
93 sub Findgroupreserve {
96 $bibitem=$dbh->quote($bibitem);
97 my $query="Select * from reserves,reserveconstraints where
98 reserves.biblionumber=reservesconstraints.biblionumber and
99 and reserveconstraints.biblioitemnumber=$bibitem
100 and reserves.cancellationdate is NULL
101 and (reserves.found <> 'F' or reserves.found is NULL)";
102 my $sth=$dbh->prepare($query);
106 while (my $data=$sth->fetchrow_hashref){
117 ($env,$branch,$borrnum,$biblionumber,$constraint,$bibitems,$priority,$notes,$title)= @_;
118 my $fee=CalcReserveFee($env,$borrnum,$biblionumber,$constraint,$bibitems);
119 my $dbh = &C4Connect;
120 my $const = lc substr($constraint,0,1);
121 my @datearr = localtime(time);
122 my $resdate =(1900+$datearr[5])."-".($datearr[4]+1)."-".$datearr[3];
124 # updates take place here
127 my $nextacctno = &getnextacctno($env,$borrnum,$dbh);
128 my $updquery = "insert into accountlines
129 (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
131 ($borrnum,$nextacctno,now(),$fee,'Reserve Charge - $title','Res',$fee)";
132 my $usth = $dbh->prepare($updquery);
137 my $query="insert into reserves
138 (borrowernumber,biblionumber,reservedate,branchcode,constrainttype,priority,reservenotes)
140 ('$borrnum','$biblionumber','$resdate','$branch','$const','$priority','$notes')";
141 my $sth = $dbh->prepare($query);
145 if (($const eq "o") || ($const eq "e")) {
146 my $numitems = @$bibitems;
148 while ($i < $numitems) {
149 my $biblioitem = @$bibitems[$i];
150 my $query = "insert into
152 (borrowernumber,biblionumber,reservedate,biblioitemnumber)
154 ('$borrnum','$biblionumber','$resdate','$biblioitem')";
155 my $sth = $dbh->prepare($query);
167 my ($env,$borrnum,$biblionumber,$constraint,$bibitems) = @_;
169 my $dbh = &C4Connect;
170 my $const = lc substr($constraint,0,1);
171 my $query = "select * from borrowers,categories
172 where (borrowernumber = '$borrnum')
173 and (borrowers.categorycode = categories.categorycode)";
174 my $sth = $dbh->prepare($query);
176 my $data = $sth->fetchrow_hashref;
178 my $fee = $data->{'reservefee'};
179 my $cntitems = @->$bibitems;
181 # check for items on issue
182 # first find biblioitem records
184 my $query1 = "select * from biblio,biblioitems
185 where (biblio.biblionumber = '$biblionumber')
186 and (biblio.biblionumber = biblioitems.biblionumber)";
187 my $sth1 = $dbh->prepare($query1);
189 while (my $data1=$sth1->fetchrow_hashref) {
191 push @biblioitems,$data1;
195 while ($x < $cntitems) {
196 if (@$bibitems->{'biblioitemnumber'} == $data->{'biblioitemnumber'}) {
203 push @biblioitems,$data1;
207 push @biblioitems,$data1;
213 my $cntitemsfound = @biblioitems;
217 while ($x < $cntitemsfound) {
218 my $bitdata = @biblioitems[$x];
219 my $query2 = "select * from items
220 where biblioitemnumber = '$bitdata->{'biblioitemnumber'}'";
221 my $sth2 = $dbh->prepare($query2);
223 while (my $itdata=$sth2->fetchrow_hashref) {
224 my $query3 = "select * from issues
225 where itemnumber = '$itdata->{'itemnumber'}' and
228 my $sth3 = $dbh->prepare($query3);
230 if (my $isdata=$sth3->fetchrow_hashref) {
237 if ($allissued == 0) {
238 my $rquery = "select * from reserves
239 where biblionumber = '$biblionumber'";
240 my $rsth = $dbh->prepare($rquery);
242 if (my $rdata = $rsth->fetchrow_hashref) {
254 my ($env,$bornumber,$dbh)=@_;
256 my $query = "select * from accountlines
257 where (borrowernumber = '$bornumber')
258 order by accountno desc";
259 my $sth = $dbh->prepare($query);
261 if (my $accdata=$sth->fetchrow_hashref){
262 $nextaccntno = $accdata->{'accountno'} + 1;
265 return($nextaccntno);
269 #subroutine to update a reserve
270 my ($rank,$biblio,$borrower,$del,$branch)=@_;
272 my $query="Update reserves ";
274 $query.="set priority='$rank',branchcode='$branch' where
275 biblionumber=$biblio and borrowernumber=$borrower";
277 $query="Select * from reserves where biblionumber=$biblio and
278 borrowernumber=$borrower";
279 my $sth=$dbh->prepare($query);
281 my $data=$sth->fetchrow_hashref;
283 $query="Select * from reserves where biblionumber=$biblio and
284 priority > '$data->{'priority'}' and cancellationdate is NULL
286 my $sth2=$dbh->prepare($query) || die $dbh->errstr;
287 $sth2->execute || die $sth2->errstr;
288 while (my $data=$sth2->fetchrow_hashref){
289 $data->{'priority'}--;
290 $query="Update reserves set priority=$data->{'priority'} where
291 biblionumber=$data->{'biblionumber'} and
292 borrowernumber=$data->{'borrowernumber'}";
293 my $sth3=$dbh->prepare($query);
294 $sth3->execute || die $sth3->errstr;
298 $query="update reserves set cancellationdate=now() where biblionumber=$biblio
299 and borrowernumber=$borrower";
301 my $sth=$dbh->prepare($query);
307 sub getreservetitle {
308 my ($biblio,$bor,$date,$timestamp)=@_;
310 my $query="Select * from reserveconstraints,biblioitems where
311 reserveconstraints.biblioitemnumber=biblioitems.biblioitemnumber
312 and reserveconstraints.biblionumber=$biblio and reserveconstraints.borrowernumber
313 = $bor and reserveconstraints.reservedate='$date' and
314 reserveconstraints.timestamp=$timestamp";
315 my $sth=$dbh->prepare($query);
317 my $data=$sth->fetchrow_hashref;
329 END { } # module clean-up code here (global destructor)