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
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'}) {
178 if ($const eq 'o') {if ($found == 1) {push @biblioitems,$data;}
179 } else {if ($found == 0) {push @biblioitems,$data;} }
183 my $cntitemsfound = @biblioitems;
187 while ($x < $cntitemsfound) {
188 my $bitdata = @biblioitems[$x];
189 my $query2 = "select * from items
190 where biblioitemnumber = '$bitdata->{'biblioitemnumber'}'";
191 my $sth2 = $dbh->prepare($query2);
193 while (my $itdata=$sth2->fetchrow_hashref) {
194 my $query3 = "select * from issues
195 where itemnumber = '$itdata->{'itemnumber'}' and
197 my $sth3 = $dbh->prepare($query3);
199 if (my $isdata=$sth3->fetchrow_hashref) { } else
204 if ($allissued == 0) {
205 my $rquery = "select * from reserves
206 where biblionumber = '$biblionumber'";
207 my $rsth = $dbh->prepare($rquery);
209 if (my $rdata = $rsth->fetchrow_hashref) { } else {
220 my ($env,$bornumber,$dbh)=@_;
222 my $query = "select * from accountlines
223 where (borrowernumber = '$bornumber')
224 order by accountno desc";
225 my $sth = $dbh->prepare($query);
227 if (my $accdata=$sth->fetchrow_hashref){
228 $nextaccntno = $accdata->{'accountno'} + 1;
231 return($nextaccntno);
235 #subroutine to update a reserve
236 my ($rank,$biblio,$borrower,$del,$branch)=@_;
238 my $query="Update reserves ";
240 $query.="set priority='$rank',branchcode='$branch' where
241 biblionumber=$biblio and borrowernumber=$borrower";
243 $query="Select * from reserves where biblionumber=$biblio and
244 borrowernumber=$borrower";
245 my $sth=$dbh->prepare($query);
247 my $data=$sth->fetchrow_hashref;
249 $query="Select * from reserves where biblionumber=$biblio and
250 priority > '$data->{'priority'}' and cancellationdate is NULL
252 my $sth2=$dbh->prepare($query) || die $dbh->errstr;
253 $sth2->execute || die $sth2->errstr;
254 while (my $data=$sth2->fetchrow_hashref){
255 $data->{'priority'}--;
256 $query="Update reserves set priority=$data->{'priority'} where
257 biblionumber=$data->{'biblionumber'} and
258 borrowernumber=$data->{'borrowernumber'}";
259 my $sth3=$dbh->prepare($query);
260 $sth3->execute || die $sth3->errstr;
264 $query="update reserves set cancellationdate=now() where biblionumber=$biblio
265 and borrowernumber=$borrower";
267 my $sth=$dbh->prepare($query);
273 sub getreservetitle {
274 my ($biblio,$bor,$date,$timestamp)=@_;
276 my $query="Select * from reserveconstraints,biblioitems where
277 reserveconstraints.biblioitemnumber=biblioitems.biblioitemnumber
278 and reserveconstraints.biblionumber=$biblio and reserveconstraints.borrowernumber
279 = $bor and reserveconstraints.reservedate='$date' and
280 reserveconstraints.timestamp=$timestamp";
281 my $sth=$dbh->prepare($query);
283 my $data=$sth->fetchrow_hashref;
295 END { } # module clean-up code here (global destructor)