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 C4::ILSDI::Utility;
32
use C4::ILSDI::Utility;
Lines 727-735 Cancels an active reserve request for the borrower. Link Here
727
Parameters:
727
Parameters:
728
728
729
  - patron_id (Required)
729
  - patron_id (Required)
730
	a borrowernumber
730
        a borrowernumber
731
  - item_id (Required)
731
  - item_id (Required)
732
	an itemnumber 
732
        a reserve_id
733
733
734
=cut
734
=cut
735
735
Lines 741-765 sub CancelHold { Link Here
741
    my $borrower = GetMemberDetails( $borrowernumber );
741
    my $borrower = GetMemberDetails( $borrowernumber );
742
    return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
742
    return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
743
743
744
    # Get the item or return an error code
744
    # Get the reserve or return an error code
745
    my $itemnumber = $cgi->param('item_id');
745
    my $reserve_id = $cgi->param('item_id');
746
    my $item = GetItem( $itemnumber );
746
    my $reserve = C4::Reserves::GetReserve($reserve_id);
747
    return { code => 'RecordNotFound' } unless $$item{itemnumber};
747
    return { code => 'RecordNotFound' } unless $reserve;
748
748
    return { code => 'RecordNotFound' } unless ($reserve->{borrowernumber} == $borrowernumber);
749
    # Get borrower's reserves
750
    my @reserves = GetReservesFromBorrowernumber( $borrowernumber, undef );
751
    my @reserveditems;
752
753
    # ...and loop over it to build an array of reserved itemnumbers
754
    foreach my $reserve (@reserves) {
755
        push @reserveditems, $reserve->{'itemnumber'};
756
    }
757
758
    # if the item was not reserved by the borrower, returns an error code
759
    return { code => 'NotCanceled' } unless any { $itemnumber eq $_ } @reserveditems;
760
749
761
    # Cancel the reserve
750
    C4::Reserves::CancelReserveFromId($reserve_id);
762
    CancelReserve({ itemnumber => $itemnumber, borrowernumber => $borrowernumber });
763
751
764
    return { code => 'Canceled' };
752
    return { code => 'Canceled' };
765
}
753
}
(-)a/C4/Reserves.pm (-1 / +80 lines)
Lines 104-109 BEGIN { Link Here
104
        &GetReserveFee
104
        &GetReserveFee
105
        &GetReserveInfo
105
        &GetReserveInfo
106
        &GetReserveStatus
106
        &GetReserveStatus
107
        &GetReserve
107
        
108
        
108
        &GetOtherReserves
109
        &GetOtherReserves
109
        
110
        
Lines 119-124 BEGIN { Link Here
119
        &CanBookBeReserved
120
        &CanBookBeReserved
120
	&CanItemBeReserved
121
	&CanItemBeReserved
121
        &CancelReserve
122
        &CancelReserve
123
        &CancelReserveFromId
122
        &CancelExpiredReserves
124
        &CancelExpiredReserves
123
125
124
        &AutoUnsuspendReserves
126
        &AutoUnsuspendReserves
Lines 814-819 sub GetReserveStatus { Link Here
814
    return ''; # empty string here will remove need for checking undef, or less log lines
816
    return ''; # empty string here will remove need for checking undef, or less log lines
815
}
817
}
816
818
819
=head2 GetReserve
820
821
    my $reserve = C4::Reserves::GetReserve($reserve_id);
822
823
Take a reserve_id and returns a hashref containing reserve informations.
824
Return undef if reserve_id doesn't exist.
825
826
=cut
827
828
sub GetReserve {
829
    my ($reserve_id) = @_;
830
831
    return unless $reserve_id;
832
833
    my $dbh = C4::Context->dbh;
834
    my $query = qq{
835
        SELECT *
836
        FROM reserves
837
        WHERE reserve_id = ?
838
    };
839
    my $sth = $dbh->prepare($query);
840
841
    $sth->execute($reserve_id);
842
    my $reserve = $sth->fetchrow_hashref;
843
844
    return $reserve;
845
}
846
817
=head2 CheckReserves
847
=head2 CheckReserves
818
848
819
  ($status, $reserve, $all_reserves) = &CheckReserves($itemnumber);
849
  ($status, $reserve, $all_reserves) = &CheckReserves($itemnumber);
Lines 1037-1042 sub CancelReserve { Link Here
1037
    _FixPriority( $reserve_id );
1067
    _FixPriority( $reserve_id );
1038
}
1068
}
1039
1069
1070
=head2 CancelReserveFromId
1071
1072
    C4::Reserves::CancelReserveFromId($reserve_id);
1073
1074
Cancel a reserve, given its reserve_id
1075
1076
=cut
1077
1078
sub CancelReserveFromId {
1079
    my ($reserve_id) = @_;
1080
1081
    my $reserve = GetReserve($reserve_id);
1082
    if ($reserve) {
1083
        my $dbh = C4::Context->dbh;
1084
1085
        # update the database, removing the record...
1086
        my $query = qq{
1087
            UPDATE reserves
1088
            SET cancellationdate = NOW(),
1089
                found = NULL,
1090
                priority = 0
1091
            WHERE reserve_id = ?
1092
        };
1093
        my $sth = $dbh->prepare($query);
1094
        $sth->execute($reserve_id);
1095
        $sth->finish;
1096
1097
        $query = qq{
1098
            INSERT INTO old_reserves
1099
            SELECT * FROM reserves
1100
            WHERE reserve_id = ?
1101
        };
1102
        $sth = $dbh->prepare($query);
1103
        $sth->execute($reserve_id);
1104
1105
        $query = qq{
1106
            DELETE FROM reserves
1107
            WHERE reserve_id = ?
1108
        };
1109
        $sth = $dbh->prepare($query);
1110
        $sth->execute($reserve_id);
1111
1112
        # now fix the priority on the others...
1113
        _FixPriority( $reserve->{biblionumber}, $reserve->{borrowernumber} );
1114
    }
1115
1116
    return $reserve;
1117
}
1118
1119
1040
=head2 ModReserve
1120
=head2 ModReserve
1041
1121
1042
  ModReserve({ rank => $rank,
1122
  ModReserve({ rank => $rank,
1043
- 

Return to bug 8868