View | Details | Raw Unified | Return to bug 8918
Collapse All | Expand All

(-)a/C4/ILSDI/Services.pm (-15 / +11 lines)
Lines 623-630 sub HoldTitle { Link Here
623
    }
623
    }
624
624
625
    # Add the reserve
625
    # Add the reserve
626
    #          $branch, $borrowernumber, $biblionumber, $constraint, $bibitems,  $priority, $notes, $title, $checkitem,  $found
626
    #    $branch,    $borrowernumber, $biblionumber,
627
    AddReserve( $branch, $borrowernumber, $biblionumber, 'a', undef, 0, undef, $title, undef, undef );
627
    #    $constraint, $bibitems,  $priority, $resdate, $expdate, $notes,
628
    #    $title,      $checkitem, $found
629
    my $priority= C4::Reserves::CalculatePriority( $biblionumber );
630
    AddReserve( $branch, $borrowernumber, $biblionumber, 'a', undef, $priority, undef, undef, undef, $title, undef, undef );
628
631
629
    # Hashref building
632
    # Hashref building
630
    my $out;
633
    my $out;
Lines 686-694 sub HoldItem { Link Here
686
    my $canbookbereserved = C4::Reserves::CanBookBeReserved( $borrowernumber, $biblionumber );
689
    my $canbookbereserved = C4::Reserves::CanBookBeReserved( $borrowernumber, $biblionumber );
687
    return { code => 'NotHoldable' } unless $canbookbereserved and $canitembereserved;
690
    return { code => 'NotHoldable' } unless $canbookbereserved and $canitembereserved;
688
691
689
    my $branch;
690
691
    # Pickup branch management
692
    # Pickup branch management
693
    my $branch;
692
    if ( $cgi->param('pickup_location') ) {
694
    if ( $cgi->param('pickup_location') ) {
693
        $branch = $cgi->param('pickup_location');
695
        $branch = $cgi->param('pickup_location');
694
        my $branches = GetBranches();
696
        my $branches = GetBranches();
Lines 697-714 sub HoldItem { Link Here
697
        $branch = $$borrower{branchcode};
699
        $branch = $$borrower{branchcode};
698
    }
700
    }
699
701
700
    my $rank;
701
    my $found;
702
703
    # Get rank and found
704
    $rank = '0' unless C4::Context->preference('ReservesNeedReturns');
705
    if ( $item->{'holdingbranch'} eq $branch ) {
706
        $found = 'W' unless C4::Context->preference('ReservesNeedReturns');
707
    }
708
709
    # Add the reserve
702
    # Add the reserve
710
    # $branch,$borrowernumber,$biblionumber,$constraint,$bibitems,$priority,$resdate,$expdate,$notes,$title,$checkitem,$found
703
    #    $branch,    $borrowernumber, $biblionumber,
711
    AddReserve( $branch, $borrowernumber, $biblionumber, 'a', undef, $rank, '', '', '', $title, $itemnumber, $found );
704
    #    $constraint, $bibitems,  $priority, $resdate, $expdate, $notes,
705
    #    $title,      $checkitem, $found
706
    my $priority= C4::Reserves::CalculatePriority( $biblionumber );
707
    AddReserve( $branch, $borrowernumber, $biblionumber, 'a', undef, $priority, undef, undef, undef, $title, $itemnumber, undef );
712
708
713
    # Hashref building
709
    # Hashref building
714
    my $out;
710
    my $out;
(-)a/C4/Reserves.pm (-1 / +36 lines)
Lines 2249-2254 sub GetReservesControlBranch { Link Here
2249
    return $branchcode;
2249
    return $branchcode;
2250
}
2250
}
2251
2251
2252
=head2 CalculatePriority
2253
2254
    my $p = CalculatePriority($biblionumber, $resdate);
2255
2256
Calculate priority for a new reserve on biblionumber.
2257
The reserve date parameter is optional. Plays a role if the preference
2258
AllowHoldDateInFuture is set.
2259
After calculation of this priority, it is recommended to call
2260
_ShiftPriorityByDateAndPriority. Note that this is currently done in
2261
AddReserves.
2262
2263
=cut
2264
2265
sub  CalculatePriority {
2266
    my ( $biblionumber, $resdate ) = @_;
2267
2268
    my $sql = qq{
2269
        SELECT COUNT(*) FROM reserves
2270
        WHERE biblionumber=? AND priority>0 AND
2271
            (found IS NULL or found='')
2272
    };
2273
        #skip found==W or found==T (waiting or transit holds)
2274
    if( $resdate ) {
2275
        $sql.= ' AND ( reservedate<=? )';
2276
    }
2277
    else {
2278
        $sql.= ' AND ( reservedate < NOW() )';
2279
    }
2280
    my $dbh = C4::Context->dbh();
2281
    my @row= $dbh->selectrow_array( $sql, undef, $resdate?
2282
        ($biblionumber, $resdate): ($biblionumber) );
2283
2284
    return @row? $row[0]+1: 1;
2285
        #if @row does not contain anything, something went wrong..
2286
}
2287
2252
=head1 AUTHOR
2288
=head1 AUTHOR
2253
2289
2254
Koha Development Team <http://koha-community.org/>
2290
Koha Development Team <http://koha-community.org/>
2255
- 

Return to bug 8918