sub GetReservesForBranch {
my ($frombranch) = @_;
my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare( "
- SELECT borrowernumber,reservedate,itemnumber,waitingdate
+ my $query = "SELECT borrowernumber,reservedate,itemnumber,waitingdate
FROM reserves
WHERE priority='0'
AND cancellationdate IS NULL
- AND found='W'
- AND branchcode=?
- ORDER BY waitingdate" );
- $sth->execute($frombranch);
+ AND found='W' ";
+ if ($frombranch){
+ $query .= " AND branchcode=? ";
+ }
+ $query .= "ORDER BY waitingdate" ;
+ my $sth = $dbh->prepare($query);
+ if ($frombranch){
+ $sth->execute($frombranch);
+ }
+ else {
+ $sth->execute();
+ }
my @transreserv;
my $i = 0;
while ( my $data = $sth->fetchrow_hashref ) {
my @getreserves;
if (C4::Context->preference('IndependantBranches')){
+ # get reserves for the branch we are logged into
@getreserves = GetReservesForBranch($default);
}
else {
- @getreserves = GetReservesForBranch($default);
- # need to have a routine to get all waiting reserves
+ # get all reserves waiting
+ @getreserves = GetReservesForBranch();
}
foreach my $num (@getreserves) {
my $itemtypeinfo = getitemtypeinfo( $gettitle->{'itemtype'} );
$getreserv{'waitingdate'} = format_date( $num->{'waitingdate'} );
- next unless $num->{'waitingdate'} ne '0000-00-00';
+ next unless ($num->{'waitingdate'} && $num->{'waitingdate'} ne '0000-00-00');
my ( $waiting_year, $waiting_month, $waiting_day ) = split /-/,
$num->{'waitingdate'};
( $waiting_year, $waiting_month, $waiting_day ) =