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

(-)a/C4/ILSDI/Services.pm (-21 / +9 lines)
Lines 26-32 use C4::Circulation; Link Here
26
use C4::Branch;
26
use C4::Branch;
27
use C4::Accounts;
27
use C4::Accounts;
28
use C4::Biblio;
28
use C4::Biblio;
29
use C4::Reserves qw(AddReserve CancelReserve GetReservesFromBiblionumber GetReservesFromBorrowernumber CanBookBeReserved CanItemBeReserved);
29
use C4::Reserves qw(AddReserve GetReservesFromBiblionumber GetReservesFromBorrowernumber CanBookBeReserved CanItemBeReserved);
30
use C4::Context;
30
use C4::Context;
31
use C4::AuthoritiesMarc;
31
use C4::AuthoritiesMarc;
32
use XML::Simple;
32
use XML::Simple;
Lines 722-730 Cancels an active reserve request for the borrower. Link Here
722
Parameters:
722
Parameters:
723
723
724
  - patron_id (Required)
724
  - patron_id (Required)
725
	a borrowernumber
725
        a borrowernumber
726
  - item_id (Required)
726
  - item_id (Required)
727
	an itemnumber 
727
        a reserve_id
728
728
729
=cut
729
=cut
730
730
Lines 736-760 sub CancelHold { Link Here
736
    my $borrower = GetMemberDetails( $borrowernumber );
736
    my $borrower = GetMemberDetails( $borrowernumber );
737
    return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
737
    return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
738
738
739
    # Get the item or return an error code
739
    # Get the reserve or return an error code
740
    my $itemnumber = $cgi->param('item_id');
740
    my $reserve_id = $cgi->param('item_id');
741
    my $item = GetItem( $itemnumber );
741
    my $reserve = C4::Reserves::GetReserve($reserve_id);
742
    return { code => 'RecordNotFound' } unless $$item{itemnumber};
742
    return { code => 'RecordNotFound' } unless $reserve;
743
743
    return { code => 'RecordNotFound' } unless ($reserve->{borrowernumber} == $borrowernumber);
744
    # Get borrower's reserves
745
    my @reserves = GetReservesFromBorrowernumber( $borrowernumber, undef );
746
    my @reserveditems;
747
748
    # ...and loop over it to build an array of reserved itemnumbers
749
    foreach my $reserve (@reserves) {
750
        push @reserveditems, $reserve->{'itemnumber'};
751
    }
752
753
    # if the item was not reserved by the borrower, returns an error code
754
    return { code => 'NotCanceled' } unless any { $itemnumber eq $_ } @reserveditems;
755
744
756
    # Cancel the reserve
745
    C4::Reserves::CancelReserve({reserve_id => $reserve_id});
757
    CancelReserve({ itemnumber => $itemnumber, borrowernumber => $borrowernumber });
758
746
759
    return { code => 'Canceled' };
747
    return { code => 'Canceled' };
760
}
748
}
(-)a/C4/Reserves.pm (-24 / +27 lines)
Lines 1032-1065 sub CancelReserve { Link Here
1032
    my $dbh = C4::Context->dbh;
1032
    my $dbh = C4::Context->dbh;
1033
1033
1034
    my $reserve = GetReserve( $reserve_id );
1034
    my $reserve = GetReserve( $reserve_id );
1035
    if ($reserve) {
1036
        my $query = "
1037
            UPDATE reserves
1038
            SET    cancellationdate = now(),
1039
                   found            = Null,
1040
                   priority         = 0
1041
            WHERE  reserve_id = ?
1042
        ";
1043
        my $sth = $dbh->prepare($query);
1044
        $sth->execute( $reserve_id );
1035
1045
1036
    my $query = "
1046
        $query = "
1037
        UPDATE reserves
1047
            INSERT INTO old_reserves
1038
        SET    cancellationdate = now(),
1048
            SELECT * FROM reserves
1039
               found            = Null,
1049
            WHERE  reserve_id = ?
1040
               priority         = 0
1050
        ";
1041
        WHERE  reserve_id = ?
1051
        $sth = $dbh->prepare($query);
1042
    ";
1052
        $sth->execute( $reserve_id );
1043
    my $sth = $dbh->prepare($query);
1044
    $sth->execute( $reserve_id );
1045
1053
1046
    $query = "
1054
        $query = "
1047
        INSERT INTO old_reserves
1055
            DELETE FROM reserves
1048
        SELECT * FROM reserves
1056
            WHERE  reserve_id = ?
1049
        WHERE  reserve_id = ?
1057
        ";
1050
    ";
1058
        $sth = $dbh->prepare($query);
1051
    $sth = $dbh->prepare($query);
1059
        $sth->execute( $reserve_id );
1052
    $sth->execute( $reserve_id );
1053
1060
1054
    $query = "
1061
        # now fix the priority on the others....
1055
        DELETE FROM reserves
1062
        _FixPriority({ biblionumber => $reserve->{biblionumber} });
1056
        WHERE  reserve_id = ?
1063
    }
1057
    ";
1058
    $sth = $dbh->prepare($query);
1059
    $sth->execute( $reserve_id );
1060
1064
1061
    # now fix the priority on the others....
1065
    return $reserve;
1062
    _FixPriority({ biblionumber => $reserve->{biblionumber} });
1063
}
1066
}
1064
1067
1065
=head2 ModReserve
1068
=head2 ModReserve
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/ilsdi.tt (-1 / +1 lines)
Lines 672-678 Link Here
672
                    <dt><strong>patron_id</strong> (Required)</dt>
672
                    <dt><strong>patron_id</strong> (Required)</dt>
673
                    <dd>the unique patron identifier in the ILS; the same identifier returned by LookupPatron or AuthenticatePatron</dd>
673
                    <dd>the unique patron identifier in the ILS; the same identifier returned by LookupPatron or AuthenticatePatron</dd>
674
                    <dt><strong>item_id</strong> (Required)</dt>
674
                    <dt><strong>item_id</strong> (Required)</dt>
675
                    <dd>system item identifier</dd>
675
                    <dd>system hold identifier (returned by GetRecords and GetPatronInfo into element 'reserve_id')</dd>
676
                </dl>
676
                </dl>
677
                <h4>Example call</h4>
677
                <h4>Example call</h4>
678
                <a href="ilsdi.pl?service=CancelHold&amp;patron_id=1&amp;item_id=1">
678
                <a href="ilsdi.pl?service=CancelHold&amp;patron_id=1&amp;item_id=1">
(-)a/t/db_dependent/Reserves.t (-3 / +21 lines)
Lines 2-9 Link Here
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
4
5
use Test::More tests => 35;
5
use Test::More tests => 43;
6
7
use MARC::Record;
6
use MARC::Record;
8
use DateTime::Duration;
7
use DateTime::Duration;
9
8
Lines 257-262 is( $messages->{ResFound}->{borrowernumber}, Link Here
257
    $requesters{'RPL'},
256
    $requesters{'RPL'},
258
    'for generous library, its items fill first hold request in line (bug 10272)');
257
    'for generous library, its items fill first hold request in line (bug 10272)');
259
258
259
my $reserves = GetReservesFromBiblionumber({biblionumber => $biblionumber});
260
isa_ok($reserves, 'ARRAY');
261
is(scalar @$reserves, 1, "Only one reserves for this biblio");
262
my $reserve_id = $reserves->[0]->{reserve_id};
263
264
$reserve = GetReserve($reserve_id);
265
isa_ok($reserve, 'HASH', "GetReserve return");
266
is($reserve->{biblionumber}, $biblionumber);
267
268
$reserve = CancelReserve({reserve_id => $reserve_id});
269
isa_ok($reserve, 'HASH', "CancelReserve return");
270
is($reserve->{biblionumber}, $biblionumber);
271
272
$reserve = GetReserve($reserve_id);
273
is($reserve, undef, "GetReserve returns undef after deletion");
274
275
$reserve = CancelReserve({reserve_id => $reserve_id});
276
is($reserve, undef, "CancelReserve return undef if reserve does not exist");
277
278
260
# Tests for bug 9761 (ConfirmFutureHolds): new CheckReserves lookahead parameter, and corresponding change in AddReturn
279
# Tests for bug 9761 (ConfirmFutureHolds): new CheckReserves lookahead parameter, and corresponding change in AddReturn
261
# Note that CheckReserve uses its lookahead parameter and does not check ConfirmFutureHolds pref (it should be passed if needed like AddReturn does)
280
# Note that CheckReserve uses its lookahead parameter and does not check ConfirmFutureHolds pref (it should be passed if needed like AddReturn does)
262
# Test 9761a: Add a reserve without date, CheckReserve should return it
281
# Test 9761a: Add a reserve without date, CheckReserve should return it
263
- 

Return to bug 8868