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 {
94 my ($bibitem,$biblio)=@_;
96 $bibitem=$dbh->quote($bibitem);
97 my $query="Select * from reserves
98 left join reserveconstraints on
99 reserves.biblionumber=reserveconstraints.biblionumber
101 reserves.biblionumber=$biblio and
102 ((reserveconstraints.biblioitemnumber=$bibitem
103 and reserves.borrowernumber=reserveconstraints.borrowernumber
104 and reserves.reservedate=reserveconstraints.reservedate)
105 or reserves.constrainttype='a')
106 and reserves.cancellationdate is NULL
107 and (reserves.found <> 'F' or reserves.found is NULL)";
109 my $sth=$dbh->prepare($query);
113 while (my $data=$sth->fetchrow_hashref){
124 ($env,$branch,$borrnum,$biblionumber,$constraint,$bibitems,$priority,$notes,$title)= @_;
125 my $fee=CalcReserveFee($env,$borrnum,$biblionumber,$constraint,$bibitems);
126 my $dbh = &C4Connect;
127 my $const = lc substr($constraint,0,1);
128 my @datearr = localtime(time);
129 my $resdate =(1900+$datearr[5])."-".($datearr[4]+1)."-".$datearr[3];
131 # updates take place here
134 my $nextacctno = &getnextacctno($env,$borrnum,$dbh);
135 my $updquery = "insert into accountlines
136 (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
138 ($borrnum,$nextacctno,now(),$fee,'Reserve Charge - $title','Res',$fee)";
139 my $usth = $dbh->prepare($updquery);
144 my $query="insert into reserves
145 (borrowernumber,biblionumber,reservedate,branchcode,constrainttype,priority,reservenotes)
147 ('$borrnum','$biblionumber','$resdate','$branch','$const','$priority','$notes')";
148 my $sth = $dbh->prepare($query);
152 if (($const eq "o") || ($const eq "e")) {
153 my $numitems = @$bibitems;
155 while ($i < $numitems) {
156 my $biblioitem = @$bibitems[$i];
157 my $query = "insert into
159 (borrowernumber,biblionumber,reservedate,biblioitemnumber)
161 ('$borrnum','$biblionumber','$resdate','$biblioitem')";
162 my $sth = $dbh->prepare($query);
174 my ($env,$borrnum,$biblionumber,$constraint,$bibitems) = @_;
176 my $dbh = &C4Connect;
177 my $const = lc substr($constraint,0,1);
178 my $query = "select * from borrowers,categories
179 where (borrowernumber = '$borrnum')
180 and (borrowers.categorycode = categories.categorycode)";
181 my $sth = $dbh->prepare($query);
183 my $data = $sth->fetchrow_hashref;
185 my $fee = $data->{'reservefee'};
186 my $cntitems = @->$bibitems;
188 # check for items on issue
189 # first find biblioitem records
191 my $query1 = "select * from biblio,biblioitems
192 where (biblio.biblionumber = '$biblionumber')
193 and (biblio.biblionumber = biblioitems.biblionumber)";
194 my $sth1 = $dbh->prepare($query1);
196 while (my $data1=$sth1->fetchrow_hashref) {
198 push @biblioitems,$data1;
202 while ($x < $cntitems) {
203 if (@$bibitems->{'biblioitemnumber'} == $data->{'biblioitemnumber'}) {
210 push @biblioitems,$data1;
214 push @biblioitems,$data1;
220 my $cntitemsfound = @biblioitems;
224 while ($x < $cntitemsfound) {
225 my $bitdata = @biblioitems[$x];
226 my $query2 = "select * from items
227 where biblioitemnumber = '$bitdata->{'biblioitemnumber'}'";
228 my $sth2 = $dbh->prepare($query2);
230 while (my $itdata=$sth2->fetchrow_hashref) {
231 my $query3 = "select * from issues
232 where itemnumber = '$itdata->{'itemnumber'}' and
235 my $sth3 = $dbh->prepare($query3);
237 if (my $isdata=$sth3->fetchrow_hashref) {
244 if ($allissued == 0) {
245 my $rquery = "select * from reserves
246 where biblionumber = '$biblionumber'";
247 my $rsth = $dbh->prepare($rquery);
249 if (my $rdata = $rsth->fetchrow_hashref) {
261 my ($env,$bornumber,$dbh)=@_;
263 my $query = "select * from accountlines
264 where (borrowernumber = '$bornumber')
265 order by accountno desc";
266 my $sth = $dbh->prepare($query);
268 if (my $accdata=$sth->fetchrow_hashref){
269 $nextaccntno = $accdata->{'accountno'} + 1;
272 return($nextaccntno);
276 #subroutine to update a reserve
277 my ($rank,$biblio,$borrower,$del,$branch)=@_;
279 my $query="Update reserves ";
281 $query.="set priority='$rank',branchcode='$branch' where
282 biblionumber=$biblio and borrowernumber=$borrower";
284 $query="Select * from reserves where biblionumber=$biblio and
285 borrowernumber=$borrower";
286 my $sth=$dbh->prepare($query);
288 my $data=$sth->fetchrow_hashref;
290 $query="Select * from reserves where biblionumber=$biblio and
291 priority > '$data->{'priority'}' and cancellationdate is NULL
293 my $sth2=$dbh->prepare($query) || die $dbh->errstr;
294 $sth2->execute || die $sth2->errstr;
295 while (my $data=$sth2->fetchrow_hashref){
296 $data->{'priority'}--;
297 $query="Update reserves set priority=$data->{'priority'} where
298 biblionumber=$data->{'biblionumber'} and
299 borrowernumber=$data->{'borrowernumber'}";
300 my $sth3=$dbh->prepare($query);
301 $sth3->execute || die $sth3->errstr;
305 $query="update reserves set cancellationdate=now() where biblionumber=$biblio
306 and borrowernumber=$borrower";
308 my $sth=$dbh->prepare($query);
314 sub getreservetitle {
315 my ($biblio,$bor,$date,$timestamp)=@_;
317 my $query="Select * from reserveconstraints,biblioitems where
318 reserveconstraints.biblioitemnumber=biblioitems.biblioitemnumber
319 and reserveconstraints.biblionumber=$biblio and reserveconstraints.borrowernumber
320 = $bor and reserveconstraints.reservedate='$date' and
321 reserveconstraints.timestamp=$timestamp";
322 my $sth=$dbh->prepare($query);
324 my $data=$sth->fetchrow_hashref;
336 END { } # module clean-up code here (global destructor)