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

(-)a/C4/Reserves.pm (-26 / +32 lines)
Lines 2001-2038 sub MoveReserve { Link Here
2001
2001
2002
    $cancelreserve //= 0;
2002
    $cancelreserve //= 0;
2003
2003
2004
    my $lookahead = C4::Context->preference('ConfirmFutureHolds'); #number of days to look for future holds
2004
    my $lookahead    = C4::Context->preference('ConfirmFutureHolds');    #number of days to look for future holds
2005
    my $item = Koha::Items->find($itemnumber);
2005
    my $item         = Koha::Items->find($itemnumber);
2006
    my $biblionumber = $item->biblionumber;
2007
2008
    my $borr_res;
2006
    my ( $restype, $res, undef ) = CheckReserves( $item, $lookahead );
2009
    my ( $restype, $res, undef ) = CheckReserves( $item, $lookahead );
2007
    return unless $res;
2008
2010
2009
    my $biblionumber = $res->{biblionumber};
2011
    # CheckReserves will only find holds that respect hold policies
2012
    # so we must check for forced holds if no reserve was found
2013
    if( !$res || $res->{borrowernumber} != $borrowernumber ) {
2014
        my $resdate = dt_from_string();
2015
        $resdate->add_duration( DateTime::Duration->new( days => $lookahead ) );
2016
2017
        $borr_res = Koha::Holds->search(
2018
            {
2019
                borrowernumber => $borrowernumber,
2020
                biblionumber   => $biblionumber,
2021
                reservedate    => { '<=' => output_pref({ dt => $resdate, dateonly => 1, dateformat => 'iso' }) }
2022
            },
2023
            { order_by => 'priority' }
2024
        )->next();
2025
2026
        # The item is reserved by the current patron
2027
        $borr_res->fill( { item_id => $itemnumber } ) if ($borr_res);
2010
2028
2011
    if ($res->{borrowernumber} == $borrowernumber) {
2012
        my $hold = Koha::Holds->find( $res->{reserve_id} );
2013
        $hold->fill({ item_id => $itemnumber });
2014
    }
2029
    }
2015
    else {
2030
    return unless $res;
2016
        # warn "Reserved";
2017
        # The item is reserved by someone else.
2018
        # Find this item in the reserves
2019
2031
2020
        my $borr_res  = Koha::Holds->search({
2032
    if ( $res && $res->{borrowernumber} == $borrowernumber ) {
2021
            borrowernumber => $borrowernumber,
2033
        my $hold = Koha::Holds->find( $res->{reserve_id} );
2022
            biblionumber   => $biblionumber,
2034
        $hold->fill( { item_id => $itemnumber } );
2023
        },{
2035
    } else {
2024
            order_by       => 'priority'
2025
        })->next();
2026
2036
2027
        if ( $borr_res ) {
2037
        # The item is reserved by someone else.
2028
            # The item is reserved by the current patron
2038
        # Find this item in the reserves
2029
            $borr_res->fill({ item_id => $itemnumber });
2030
        }
2031
2039
2032
        if ( $cancelreserve eq 'revert' ) { ## Revert waiting reserve to priority 1
2040
        if ( $cancelreserve eq 'revert' ) {    ## Revert waiting reserve to priority 1
2033
            RevertWaitingStatus({ itemnumber => $itemnumber });
2041
            RevertWaitingStatus( { itemnumber => $itemnumber } );
2034
        }
2042
        } elsif ( $cancelreserve eq 'cancel' || $cancelreserve ) {    # cancel reserves on this item
2035
        elsif ( $cancelreserve eq 'cancel' || $cancelreserve ) { # cancel reserves on this item
2036
            my $hold = Koha::Holds->find( $res->{reserve_id} );
2043
            my $hold = Koha::Holds->find( $res->{reserve_id} );
2037
            $hold->cancel;
2044
            $hold->cancel;
2038
        }
2045
        }
2039
- 

Return to bug 37774