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);
19 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
21 # your exported package globals go here,
22 # as well as any optionally exported functions
24 @EXPORT_OK = qw($Var1 %Hashit);
27 # non-exported package globals go here
28 use vars qw(@more $stuff);
30 # initalize package globals, first exported ones
35 # then the others (which are still accessible as $Some::Module::stuff)
39 # all file-scoped lexicals must be created before
40 # the functions below that use them.
42 # file-private lexicals go here
46 # here's a file-private function as a closure,
47 # callable as &$priv_func; it cannot be prototyped.
52 # make all your functions, whether exported or not;
57 my $query="Select *,reserves.branchcode,biblio.title as btitle
58 from reserves,borrowers,biblio ";
61 $query=$query." where reserves.biblionumber=$bib and
62 reserves.borrowernumber=borrowers.borrowernumber and
63 biblio.biblionumber=$bib and cancellationdate is NULL and
64 (found <> 'F' or found is NULL)";
66 $query=$query." where reserves.borrowernumber=borrowers.borrowernumber
67 and biblio.biblionumber=$bib and reserves.biblionumber=$bib
68 and cancellationdate is NULL and
69 (found <> 'F' or found is NULL)";
72 $query=$query." where borrowers.borrowernumber=$bor and
73 reserves.borrowernumber=borrowers.borrowernumber and reserves.biblionumber
74 =biblio.biblionumber and cancellationdate is NULL and
75 (found <> 'F' or found is NULL)";
77 $query.=" order by priority";
78 my $sth=$dbh->prepare($query);
82 while (my $data=$sth->fetchrow_hashref){
94 ($env,$branch,$borrnum,$biblionumber,$constraint,$bibitems,$priority,$notes,$title)= @_;
95 my $fee=CalcReserveFee($env,$borrnum,$biblionumber,$constraint,$bibitems);
97 my $const = lc substr($constraint,0,1);
98 my @datearr = localtime(time);
99 my $resdate =(1900+$datearr[5])."-".($datearr[4]+1)."-".$datearr[3];
101 # updates take place here
104 my $nextacctno = &getnextacctno($env,$borrnum,$dbh);
105 my $updquery = "insert into accountlines
106 (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
108 ($borrnum,$nextacctno,now(),$fee,'Reserve Charge - $title','Res',$fee)";
109 my $usth = $dbh->prepare($updquery);
114 my $query="insert into reserves
115 (borrowernumber,biblionumber,reservedate,branchcode,constrainttype,priority,reservenotes)
117 ('$borrnum','$biblionumber','$resdate','$branch','$const','$priority','$notes')";
118 my $sth = $dbh->prepare($query);
122 if (($const eq "o") || ($const eq "e")) {
123 my $numitems = @$bibitems;
125 while ($i < $numitems) {
126 my $biblioitem = @$bibitems[$i];
127 my $query = "insert into
129 (borrowernumber,biblionumber,reservedate,biblioitemnumber)
131 ('$borrnum','$biblionumber','$resdate','$biblioitem')";
132 my $sth = $dbh->prepare($query);
144 my ($env,$borrnum,$biblionumber,$constraint,$bibitems) = @_;
146 my $dbh = &C4Connect;
147 my $const = lc substr($constraint,0,1);
148 my $query = "select * from borrowers,categories
149 where (borrowernumber = '$borrnum')
150 and (borrowers.categorycode = categories.categorycode)";
151 my $sth = $dbh->prepare($query);
153 my $data = $sth->fetchrow_hashref;
155 my $fee = $data->{'reservefee'};
156 my $cntitems = @->$bibitems;
158 # check for items on issue
159 # first find biblioitem records
161 my $query1 = "select * from biblio,biblioitems
162 where (biblio.biblionumber = '$biblionumber')
163 and (biblio.biblionumber = biblioitems.biblionumber)";
164 my $sth1 = $dbh->prepare($query1);
166 while (my $data1=$sth1->fetchrow_hashref) {
168 push @biblioitems,$data1;
172 while ($x < $cntitems) {
173 if (@$bibitems->{'biblioitemnumber'} == $data->{'biblioitemnumber'}) {
180 push @biblioitems,$data1;
184 push @biblioitems,$data1;
190 my $cntitemsfound = @biblioitems;
194 while ($x < $cntitemsfound) {
195 my $bitdata = @biblioitems[$x];
196 my $query2 = "select * from items
197 where biblioitemnumber = '$bitdata->{'biblioitemnumber'}'";
198 my $sth2 = $dbh->prepare($query2);
200 while (my $itdata=$sth2->fetchrow_hashref) {
201 my $query3 = "select * from issues
202 where itemnumber = '$itdata->{'itemnumber'}' and
205 my $sth3 = $dbh->prepare($query3);
207 if (my $isdata=$sth3->fetchrow_hashref) {
214 if ($allissued == 0) {
215 my $rquery = "select * from reserves
216 where biblionumber = '$biblionumber'";
217 my $rsth = $dbh->prepare($rquery);
219 if (my $rdata = $rsth->fetchrow_hashref) {
231 my ($env,$bornumber,$dbh)=@_;
233 my $query = "select * from accountlines
234 where (borrowernumber = '$bornumber')
235 order by accountno desc";
236 my $sth = $dbh->prepare($query);
238 if (my $accdata=$sth->fetchrow_hashref){
239 $nextaccntno = $accdata->{'accountno'} + 1;
242 return($nextaccntno);
246 #subroutine to update a reserve
247 my ($rank,$biblio,$borrower,$del,$branch)=@_;
249 my $query="Update reserves ";
251 $query.="set priority='$rank',branchcode='$branch' where
252 biblionumber=$biblio and borrowernumber=$borrower";
254 $query="Select * from reserves where biblionumber=$biblio and
255 borrowernumber=$borrower";
256 my $sth=$dbh->prepare($query);
258 my $data=$sth->fetchrow_hashref;
260 $query="Select * from reserves where biblionumber=$biblio and
261 priority > '$data->{'priority'}' and cancellationdate is NULL
263 my $sth2=$dbh->prepare($query) || die $dbh->errstr;
264 $sth2->execute || die $sth2->errstr;
265 while (my $data=$sth2->fetchrow_hashref){
266 $data->{'priority'}--;
267 $query="Update reserves set priority=$data->{'priority'} where
268 biblionumber=$data->{'biblionumber'} and
269 borrowernumber=$data->{'borrowernumber'}";
270 my $sth3=$dbh->prepare($query);
271 $sth3->execute || die $sth3->errstr;
275 $query="update reserves set cancellationdate=now() where biblionumber=$biblio
276 and borrowernumber=$borrower";
278 my $sth=$dbh->prepare($query);
284 sub getreservetitle {
285 my ($biblio,$bor,$date,$timestamp)=@_;
287 my $query="Select * from reserveconstraints,biblioitems where
288 reserveconstraints.biblioitemnumber=biblioitems.biblioitemnumber
289 and reserveconstraints.biblionumber=$biblio and reserveconstraints.borrowernumber
290 = $bor and reserveconstraints.reservedate='$date' and
291 reserveconstraints.timestamp=$timestamp";
292 my $sth=$dbh->prepare($query);
294 my $data=$sth->fetchrow_hashref;
306 END { } # module clean-up code here (global destructor)