cleaning misc/amazonratings directory : it is included in amazon api, and no more...
[koha.git] / misc / cronjobs / reservelist.pl
1 #!/usr/bin/perl 
2 #-----------------------------------
3 # Script Name: reservelist.pl
4 # Script Version: 1.0
5 # Date:  2003/9/18
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.
10 # Revision History:
11 #    1.0  2003/9/18:  original version
12 #    1.1  2003/10/1:  modified to load into a MySQL table
13 #-----------------------------------
14
15 use lib '/usr/local/koha/intranet/modules/';
16
17 use strict;
18 use C4::Context;
19 use C4::Biblio;
20
21 my ($biblionumber,$barcode,$holdingbranch,$pickbranch,$notes,$cardnumber,$lastname,$firstname,$phone,$title,$callno,$rdate,$borrno);
22
23 my $dbh   = C4::Context->dbh;
24
25 $dbh->do("DELETE FROM reservelist");  # clear the old table for new info
26
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");
28
29 my $sth_load=$dbh->prepare("INSERT INTO reservelist (biblionumber,barcode,lastname,firstname,phone,borrowernumber,cardnumber,reservedate,title,callno,holdingbranch,pickbranch,notes) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");
30
31 $sth->execute();      # get the list of biblionumbers for unfilled reserves
32
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 = GetItemsInfo($biblionumber,''); # get the items for this biblio
44     my @itemorder;   #  prepare a new array to hold re-ordered items
45
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
48 # 'pick' order.
49     foreach my $itm (@items) {
50     if ($itm->{"datedue"} eq "Reserved") {   # is item ready for member?
51         if ($itm->{'holdingbranch'} eq $pickbranch) {
52         $itemorder[0]=$itm;
53         } elsif ($itm->{'homebranch'} eq 'NPL') {
54         $itemorder[1]=$itm;
55         } elsif ($itm->{'homebranch'} eq 'CPL') {
56         $itemorder[2]=$itm;
57         } elsif ($itm->{'homebranch'} eq 'COV') {
58         $itemorder[3]=$itm;
59         } elsif ($itm->{'homebranch'} eq 'GPL') {
60         $itemorder[4]=$itm;
61         } elsif ($itm->{'homebranch'} eq 'ALB') {
62         $itemorder[5]=$itm;
63         } elsif ($itm->{'homebranch'} eq 'PPL') {
64         $itemorder[6]=$itm;
65         } elsif ($itm->{'homebranch'} eq 'APL') {
66         $itemorder[7]=$itm;
67         }
68     }
69     }
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) {
73     if ($itmlist) {
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
79     }
80     }
81     $sth_load->execute($biblionumber,$barcode,$lastname,$firstname,$phone,$borrno,$cardnumber,$rdate,$title,$callno,$holdingbranch,$pickbranch,$notes);
82     $sth_load->finish;
83 }
84 $sth->finish;
85 $dbh->disconnect;