2 #-----------------------------------
3 # Script Name: reservelist.pl
6 # Author: Stephen Hedges shedges@skemotah.com
7 # Description: produces a comma separated list of currently
8 # available reserves, with item and borrower details
9 # Usage: reservelist.pl.
11 # 1.0 2003/9/18: original version
12 # 1.1 2003/10/1: modified to load into a MySQL table
13 #-----------------------------------
15 use lib '/usr/local/koha/intranet/modules/';
21 my ($biblionumber,$barcode,$holdingbranch,$pickbranch,$notes,$cardnumber,$lastname,$firstname,$phone,$title,$callno,$rdate,$borrno);
23 my $dbh = C4::Context->dbh;
25 $dbh->do("DELETE FROM reservelist"); # clear the old table for new info
27 my $sth=$dbh->prepare("SELECT biblionumber,reserves.branchcode,reservenotes,borrowers.borrowernumber,cardnumber,surname,firstname,phone,reservedate FROM reserves,borrowers WHERE reserves.borrowernumber=borrowers.borrowernumber AND priority=1 AND cancellationdate IS NULL GROUP BY biblionumber");
29 my $sth_load=$dbh->prepare("INSERT INTO reservelist (biblionumber,barcode,lastname,firstname,phone,borrowernumber,cardnumber,reservedate,title,callno,holdingbranch,pickbranch,notes) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");
31 $sth->execute(); # get the list of biblionumbers for unfilled reserves
33 GETIT: while (my $data=$sth->fetchrow_hashref){
34 $biblionumber = $data->{'biblionumber'}; # get the basic reserve info
35 $pickbranch = $data->{'branchcode'};
36 $notes = $data->{'reservenotes'};
37 $borrno = $data->{'borrowernumber'};
38 $cardnumber = $data->{'cardnumber'};
39 $lastname = $data->{'surname'};
40 $firstname = $data->{'firstname'};
41 $phone = $data->{'phone'};
42 $rdate = $data->{'reservedate'};
43 my @items = ItemInfo(undef,$biblionumber,''); # get the items for this biblio
44 my @itemorder; # prepare a new array to hold re-ordered items
46 # The following lines take the retrieved items and run them through various
47 # tests to decide if they are to be used and then put them in the preferred
49 foreach my $itm (@items) {
50 if ($itm->{"datedue"} eq "Reserved") { # is item ready for member?
51 if ($itm->{'holdingbranch'} eq $pickbranch) {
53 } elsif ($itm->{'homebranch'} eq 'NPL') {
55 } elsif ($itm->{'homebranch'} eq 'CPL') {
57 } elsif ($itm->{'homebranch'} eq 'COV') {
59 } elsif ($itm->{'homebranch'} eq 'GPL') {
61 } elsif ($itm->{'homebranch'} eq 'ALB') {
63 } elsif ($itm->{'homebranch'} eq 'PPL') {
65 } elsif ($itm->{'homebranch'} eq 'APL') {
70 my $count = @itemorder;
71 next GETIT if $count<1; # if the re-ordered array is empty, skip to next
72 PREP: foreach my $itmlist (@itemorder) {
74 $barcode = $itmlist->{'barcode'};
75 $holdingbranch = $itmlist->{'holdingbranch'};
76 $title = $itmlist->{'title'};
77 $callno = $itmlist->{'classification'};
78 last PREP; # we only want the first def item in the array
81 $sth_load->execute($biblionumber,$barcode,$lastname,$firstname,$phone,$borrno,$cardnumber,$rdate,$title,$callno,$holdingbranch,$pickbranch,$notes);