1 package C4::Reserves; #asummes C4/Reserves
3 #requires DBI.pm to be installed
14 use C4::Interface::ReserveentCDK;
15 use C4::Circulation::Main;
16 use C4::Circulation::Borrower;
18 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
20 # set the version for version checking
24 @EXPORT = qw(&EnterReserves CalcReserveFee CreateReserve );
25 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
27 # your exported package globals go here,
28 # as well as any optionally exported functions
30 @EXPORT_OK = qw($Var1 %Hashit);
33 # non-exported package globals go here
34 use vars qw(@more $stuff);
36 # initalize package globals, first exported ones
41 # then the others (which are still accessible as $Some::Module::stuff)
45 # all file-scoped lexicals must be created before
46 # the functions below that use them.
48 # file-private lexicals go here
52 # here's a file-private function as a closure,
53 # callable as &$priv_func; it cannot be prototyped.
58 # make all your functions, whether exported or not;
62 my $titlepanel = titlepanel($env,"Reserves","Enter Selection");
63 my @flds = ("No of entries","Barcode","ISBN","Title","Keywords","Author","Subject");
64 my @fldlens = ("5","15","15","50","50","50","50");
65 my ($reason,$num,$itemnumber,$isbn,$title,$keyword,$author,$subject) =
66 FindBiblioScreen($env,"Reserves",7,\@flds,\@fldlens);
72 $search{'title'}= $title;
73 $search{'keyword'}=$keyword;
74 $search{'author'}=$author;
75 $search{'subject'}=$subject;
76 $search{'item'}=$itemnumber;
77 $search{'isbn'}=$isbn;
84 my $title = titlepanel($env,"Reserves","Searching");
85 if ($itemnumber ne '' || $isbn ne ''){
86 ($count,@results)=&CatSearch($env,'precise',\%search,$num,$offset);
89 ($count,@results)=&CatSearch($env,'subject',\%search,$num,$offset);
92 ($count,@results)=&KeywordSearch($env,'intra',\%search,$num,$offset);
94 ($count,@results)=&CatSearch($env,'loose',\%search,$num,$offset);
98 my $no_ents = @results;
102 my @ents = split("\t",@results[0]);
103 $biblionumber = @ents[2];
109 while ($i < $no_ents) {
110 my @ents = split("\t",@results[$i]);
111 $line = fmtstr($env,@ents[1],"L70");
112 my $auth = substr(@ents[0],0,30);
113 substr($line,(70-length($auth)-2),length($auth)+2) = " ".$auth;
114 @bibtitles[$i]=$line;
115 $biblio_xref{$line}=@ents[2];
118 my $title = titlepanel($env,"Reserves","Select Title");
119 my ($results,$bibres) = SelectBiblio($env,$count,\@bibtitles);
120 if ($results eq "") {
121 $biblionumber = $biblio_xref{$bibres};
127 if ($biblionumber eq "") {
128 error_msg($env,"No items found");
130 my @items = GetItems($env,$biblionumber);
132 my $dbh = &C4Connect;
133 my $query = "Select * from biblio where biblionumber = $biblionumber";
134 my $sth = $dbh->prepare($query);
136 my $data=$sth->fetchrow_hashref;
139 my $query = "select * from branches where issuing=1 order by branchname";
140 my $sth=$dbh->prepare($query);
142 while (my $branchrec=$sth->fetchrow_hashref) {
144 fmtstr($env,$branchrec->{'branchcode'},"L2")." ".$branchrec->{'branchname'};
145 push @branches,$branchdet;
149 while ($donext eq "") {
150 my $title = titlepanel($env,"Reserves","Create Reserve");
151 my ($reason,$borcode,$branch,$constraint,$bibitems) =
152 MakeReserveScreen($env, $data, \@items, \@branches);
153 if ($borcode ne "") {
154 my ($borrnum,$borrower) = findoneborrower($env,$dbh,$borcode);
156 if ($borrnum ne "") {
158 CalcReserveFee($env,$borrnum,$biblionumber,$constraint,$bibitems);
159 CreateReserve($env,$branch,$borrnum,$biblionumber,$constraint,$bibitems,$fee);
166 } else { $donext = "Circ" }
176 my ($env,$borrnum,$biblionumber,$constraint,$bibitems) = @_;
178 my $dbh = &C4Connect;
179 my $const = lc substr($constraint,0,1);
180 my $query = "select * from borrowers,categories
181 where (borrowernumber = '$borrnum')
182 and (borrowers.categorycode = categories.categorycode)";
183 my $sth = $dbh->prepare($query);
185 my $data = $sth->fetchrow_hashref;
187 my $fee = $data->{'reservefee'};
188 my $cntitems = @->$bibitems;
190 # check for items on issue
191 # first find biblioitem records
193 my $query1 = "select * from biblio,biblioitems
194 where (biblio.biblionumber = '$biblionumber')
195 and (biblio.biblionumber = biblioitems.biblionumber)";
196 my $sth1 = $dbh->prepare($query1);
198 while (my $data1=$sth1->fetchrow_hashref) {
200 push @biblioitems,$data1;
204 while ($x < $cntitems) {
205 if (@$bibitems->{'biblioitemnumber'} == $data->{'biblioitemnumber'}) {
210 if ($const eq 'o') {if ($found == 1) {push @biblioitems,$data;}
211 } else {if ($found == 0) {push @biblioitems,$data;} }
215 my $cntitemsfound = @biblioitems;
219 while ($x < $cntitemsfound) {
220 my $bitdata = @biblioitems[$x];
221 my $query2 = "select * from items
222 where biblioitemnumber = '$bitdata->{'biblioitemnumber'}'";
223 my $sth2 = $dbh->prepare($query2);
225 while (my $itdata=$sth2->fetchrow_hashref) {
226 my $query3 = "select * from issues
227 where itemnumber = '$itdata->{'itemnumber'}' and returndate is null";
228 my $sth3 = $dbh->prepare($query3);
230 if (my $isdata=$sth3->fetchrow_hashref) { } else {$allissued = 0; }
234 if ($allissued == 0) {
235 my $rquery = "select * from reserves
236 where biblionumber = '$biblionumber'";
237 my $rsth = $dbh->prepare($rquery);
239 if (my $rdata = $rsth->fetchrow_hashref) { } else {
246 } # end CalcReserveFee
249 my ($env,$branch,$borrnum,$biblionumber,$constraint,$bibitems,$fee) = @_;
250 my $dbh = &C4Connect;
251 #$dbh->{RaiseError} = 1;
252 #$dbh->{AutoCommit} = 0;
253 my $const = lc substr($constraint,0,1);
254 my @datearr = localtime(time);
255 my $resdate = (1900+$datearr[5])."-".($datearr[4]+1)."-".$datearr[3];
257 # updates take place here
259 my $nextacctno = &getnextacctno($env,$borrnum,$dbh);
260 my $updquery = "insert into accountlines
261 (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
262 values ($borrnum,$nextacctno,now(),$fee,'Reserve Charge','Res',$fee)";
263 my $usth = $dbh->prepare($updquery);
267 my $query="insert into reserves (borrowernumber,biblionumber,reservedate,branchcode,constrainttype) values ('$borrnum','$biblionumber','$resdate','$branch','$const')";
268 my $sth = $dbh->prepare($query);
270 if (($const eq "o") || ($const eq "e")) {
271 my $numitems = @$bibitems;
273 while ($i < $numitems) {
274 my $biblioitem = @$bibitems[$i];
275 my $query = "insert into reserveconstraints
276 (borrowernumber,biblionumber,reservedate,biblioitemnumber)
277 values ('$borrnum','$biblionumber','$resdate','$biblioitem')";
278 my $sth = $dbh->prepare($query);
283 UpdateStats($env,'branch','reserve',$fee);
289 # # error_msg($env,"Update failed");
294 } # end CreateReserve
299 END { } # module clean-up code here (global destructor)