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

(-)a/C4/Biblio.pm (-1 / +1 lines)
Lines 438-444 sub DelBiblio { Link Here
438
    require C4::Reserves;
438
    require C4::Reserves;
439
    my ($count, $reserves) = C4::Reserves::GetReservesFromBiblionumber($biblionumber);
439
    my ($count, $reserves) = C4::Reserves::GetReservesFromBiblionumber($biblionumber);
440
    foreach my $res ( @$reserves ) {
440
    foreach my $res ( @$reserves ) {
441
        C4::Reserves::CancelReserve( $res->{'biblionumber'}, $res->{'itemnumber'}, $res->{'borrowernumber'} );
441
        C4::Reserves::CancelReserve({ reserve_id => $res->{'reserve_id'} });
442
    }
442
    }
443
443
444
    # Delete in Zebra. Be careful NOT to move this line after _koha_delete_biblio
444
    # Delete in Zebra. Be careful NOT to move this line after _koha_delete_biblio
(-)a/C4/ILSDI/Services.pm (-1 / +1 lines)
Lines 762-768 sub CancelHold { Link Here
762
    return { code => 'NotCanceled' } unless any { $itemnumber eq $_ } @reserveditems;
762
    return { code => 'NotCanceled' } unless any { $itemnumber eq $_ } @reserveditems;
763
763
764
    # Cancel the reserve
764
    # Cancel the reserve
765
    CancelReserve( $itemnumber, undef, $borrowernumber );
765
    CancelReserve({ itemnumber => $itemnumber, borrowernumber => $borrowernumber });
766
766
767
    return { code => 'Canceled' };
767
    return { code => 'Canceled' };
768
}
768
}
(-)a/C4/Reserves.pm (-255 / +256 lines)
Lines 93-99 BEGIN { Link Here
93
    @ISA = qw(Exporter);
93
    @ISA = qw(Exporter);
94
    @EXPORT = qw(
94
    @EXPORT = qw(
95
        &AddReserve
95
        &AddReserve
96
  
96
97
        &GetReserve
97
        &GetReservesFromItemnumber
98
        &GetReservesFromItemnumber
98
        &GetReservesFromBiblionumber
99
        &GetReservesFromBiblionumber
99
        &GetReservesFromBorrowernumber
100
        &GetReservesFromBorrowernumber
Lines 244-252 sub AddReserve { Link Here
244
    return;     # FIXME: why not have a useful return value?
245
    return;     # FIXME: why not have a useful return value?
245
}
246
}
246
247
248
=head2 GetReserve
249
250
    $res = GetReserve( $reserve_id );
251
252
=cut
253
254
sub GetReserve {
255
    my ($reserve_id) = @_;
256
    #warn "C4::Reserves::GetReserve( $reserve_id )";
257
258
    my $dbh = C4::Context->dbh;
259
    my $query = "SELECT * FROM reserves WHERE reserve_id = ?";
260
    my $sth = $dbh->prepare( $query );
261
    $sth->execute( $reserve_id );
262
    my $res = $sth->fetchrow_hashref();
263
    return $res;
264
}
265
247
=head2 GetReservesFromBiblionumber
266
=head2 GetReservesFromBiblionumber
248
267
249
  ($count, $title_reserves) = &GetReserves($biblionumber);
268
  ($count, $title_reserves) = GetReservesFromBiblionumber($biblionumber);
250
269
251
This function gets the list of reservations for one C<$biblionumber>, returning a count
270
This function gets the list of reservations for one C<$biblionumber>, returning a count
252
of the reserves and an arrayref pointing to the reserves for C<$biblionumber>.
271
of the reserves and an arrayref pointing to the reserves for C<$biblionumber>.
Lines 260-266 sub GetReservesFromBiblionumber { Link Here
260
279
261
    # Find the desired items in the reserves
280
    # Find the desired items in the reserves
262
    my $query = "
281
    my $query = "
263
        SELECT  branchcode,
282
        SELECT  reserve_id,
283
                branchcode,
264
                timestamp AS rtimestamp,
284
                timestamp AS rtimestamp,
265
                priority,
285
                priority,
266
                biblionumber,
286
                biblionumber,
Lines 328-334 sub GetReservesFromBiblionumber { Link Here
328
348
329
=head2 GetReservesFromItemnumber
349
=head2 GetReservesFromItemnumber
330
350
331
 ( $reservedate, $borrowernumber, $branchcode ) = GetReservesFromItemnumber($itemnumber);
351
 ( $reservedate, $borrowernumber, $branchcode, $reserve_id ) = GetReservesFromItemnumber($itemnumber);
332
352
333
TODO :: Description here
353
TODO :: Description here
334
354
Lines 338-344 sub GetReservesFromItemnumber { Link Here
338
    my ( $itemnumber, $all_dates ) = @_;
358
    my ( $itemnumber, $all_dates ) = @_;
339
    my $dbh   = C4::Context->dbh;
359
    my $dbh   = C4::Context->dbh;
340
    my $query = "
360
    my $query = "
341
    SELECT reservedate,borrowernumber,branchcode
361
    SELECT reservedate,borrowernumber,branchcode,reserve_id
342
    FROM   reserves
362
    FROM   reserves
343
    WHERE  itemnumber=?
363
    WHERE  itemnumber=?
344
    ";
364
    ";
Lines 347-354 sub GetReservesFromItemnumber { Link Here
347
    }
367
    }
348
    my $sth_res = $dbh->prepare($query);
368
    my $sth_res = $dbh->prepare($query);
349
    $sth_res->execute($itemnumber);
369
    $sth_res->execute($itemnumber);
350
    my ( $reservedate, $borrowernumber,$branchcode ) = $sth_res->fetchrow_array;
370
    my ( $reservedate, $borrowernumber, $branchcode, $reserve_id ) = $sth_res->fetchrow_array;
351
    return ( $reservedate, $borrowernumber, $branchcode );
371
    return ( $reservedate, $borrowernumber, $branchcode, $reserve_id );
352
}
372
}
353
373
354
=head2 GetReservesFromBorrowernumber
374
=head2 GetReservesFromBorrowernumber
Lines 511-521 sub GetReserveCount { Link Here
511
531
512
    my $dbh = C4::Context->dbh;
532
    my $dbh = C4::Context->dbh;
513
533
514
    my $query = '
534
    my $query = "
515
        SELECT COUNT(*) AS counter
535
        SELECT COUNT(*) AS counter
516
        FROM reserves
536
        FROM reserves
517
          WHERE borrowernumber = ?
537
        WHERE borrowernumber = ?
518
    ';
538
    ";
519
    my $sth = $dbh->prepare($query);
539
    my $sth = $dbh->prepare($query);
520
    $sth->execute($borrowernumber);
540
    $sth->execute($borrowernumber);
521
    my $row = $sth->fetchrow_hashref;
541
    my $row = $sth->fetchrow_hashref;
Lines 542-549 sub GetOtherReserves { Link Here
542
            #minus priorities of others reservs
562
            #minus priorities of others reservs
543
            ModReserveMinusPriority(
563
            ModReserveMinusPriority(
544
                $itemnumber,
564
                $itemnumber,
545
                $checkreserves->{'borrowernumber'},
565
                $checkreserves->{'reserve_id'},
546
                $iteminfo->{'biblionumber'}
547
            );
566
            );
548
567
549
            #launch the subroutine dotransfer
568
            #launch the subroutine dotransfer
Lines 560-567 sub GetOtherReserves { Link Here
560
            $messages->{'waiting'} = 1;
579
            $messages->{'waiting'} = 1;
561
            ModReserveMinusPriority(
580
            ModReserveMinusPriority(
562
                $itemnumber,
581
                $itemnumber,
563
                $checkreserves->{'borrowernumber'},
582
                $checkreserves->{'reserve_id'},
564
                $iteminfo->{'biblionumber'}
565
            );
583
            );
566
            ModReserveStatus($itemnumber,'W');
584
            ModReserveStatus($itemnumber,'W');
567
        }
585
        }
Lines 687-693 sub GetReservesToBranch { Link Here
687
    my ( $frombranch ) = @_;
705
    my ( $frombranch ) = @_;
688
    my $dbh = C4::Context->dbh;
706
    my $dbh = C4::Context->dbh;
689
    my $sth = $dbh->prepare(
707
    my $sth = $dbh->prepare(
690
        "SELECT borrowernumber,reservedate,itemnumber,timestamp
708
        "SELECT reserve_id,borrowernumber,reservedate,itemnumber,timestamp
691
         FROM reserves 
709
         FROM reserves 
692
         WHERE priority='0' 
710
         WHERE priority='0' 
693
           AND branchcode=?"
711
           AND branchcode=?"
Lines 710-731 sub GetReservesToBranch { Link Here
710
728
711
sub GetReservesForBranch {
729
sub GetReservesForBranch {
712
    my ($frombranch) = @_;
730
    my ($frombranch) = @_;
713
    my $dbh          = C4::Context->dbh;
731
    my $dbh = C4::Context->dbh;
714
	my $query        = "SELECT borrowernumber,reservedate,itemnumber,waitingdate
732
733
    my $query = "
734
        SELECT reserve_id,borrowernumber,reservedate,itemnumber,waitingdate
715
        FROM   reserves 
735
        FROM   reserves 
716
        WHERE   priority='0'
736
        WHERE   priority='0'
717
            AND found='W' ";
737
        AND found='W'
718
    if ($frombranch){
738
    ";
719
        $query .= " AND branchcode=? ";
739
    $query .= " AND branchcode=? " if ( $frombranch );
720
	}
721
    $query .= "ORDER BY waitingdate" ;
740
    $query .= "ORDER BY waitingdate" ;
741
722
    my $sth = $dbh->prepare($query);
742
    my $sth = $dbh->prepare($query);
723
    if ($frombranch){
743
    if ($frombranch){
724
		$sth->execute($frombranch);
744
     $sth->execute($frombranch);
725
	}
745
    } else {
726
    else {
746
        $sth->execute();
727
		$sth->execute();
747
    }
728
	}
748
729
    my @transreserv;
749
    my @transreserv;
730
    my $i = 0;
750
    my $i = 0;
731
    while ( my $data = $sth->fetchrow_hashref ) {
751
    while ( my $data = $sth->fetchrow_hashref ) {
Lines 744-749 If several reserves exist, the reserve with the lower priority is given. Link Here
744
764
745
=cut
765
=cut
746
766
767
## FIXME: I don't think this does what it thinks it does.
768
## It only ever checks the first reserve result, even though
769
## multiple reserves for that bib can have the itemnumber set
770
## the sub is only used once in the codebase.
747
sub GetReserveStatus {
771
sub GetReserveStatus {
748
    my ($itemnumber, $biblionumber) = @_;
772
    my ($itemnumber, $biblionumber) = @_;
749
773
Lines 904-910 sub CancelExpiredReserves { Link Here
904
    $sth->execute();
928
    $sth->execute();
905
929
906
    while ( my $res = $sth->fetchrow_hashref() ) {
930
    while ( my $res = $sth->fetchrow_hashref() ) {
907
        CancelReserve( $res->{'biblionumber'}, '', $res->{'borrowernumber'} );
931
        CancelReserve({ reserve_id => $res->{'reserve_id'} });
908
    }
932
    }
909
  
933
  
910
    # Cancel reserves that have been waiting too long
934
    # Cancel reserves that have been waiting too long
Lines 921-927 sub CancelExpiredReserves { Link Here
921
                manualinvoice($res->{'borrowernumber'}, $res->{'itemnumber'}, 'Hold waiting too long', 'F', $charge);
945
                manualinvoice($res->{'borrowernumber'}, $res->{'itemnumber'}, 'Hold waiting too long', 'F', $charge);
922
            }
946
            }
923
947
924
            CancelReserve( $res->{'biblionumber'}, '', $res->{'borrowernumber'} );
948
            CancelReserve({ reserve_id => $res->{'reserve_id'} });
925
        }
949
        }
926
    }
950
    }
927
951
Lines 947-1055 sub AutoUnsuspendReserves { Link Here
947
971
948
=head2 CancelReserve
972
=head2 CancelReserve
949
973
950
  &CancelReserve($biblionumber, $itemnumber, $borrowernumber);
974
  CancelReserve({ reserve_id => $reserve_id, [ biblionumber => $biblionumber, borrowernumber => $borrrowernumber, itemnumber => $itemnumber ] });
951
975
952
Cancels a reserve.
976
Cancels a reserve.
953
977
954
Use either C<$biblionumber> or C<$itemnumber> to specify the item to
978
=cut
955
cancel, but not both: if both are given, C<&CancelReserve> uses
956
C<$itemnumber>.
957
979
958
C<$borrowernumber> is the borrower number of the patron on whose
980
sub CancelReserve {
959
behalf the book was reserved.
981
    my ( $params ) = @_;
960
982
961
If C<$biblionumber> was given, C<&CancelReserve> also adjusts the
983
    my $reserve_id = $params->{'reserve_id'};
962
priorities of the other people who are waiting on the book.
984
    $reserve_id = GetReserveId( $params ) unless ( $reserve_id );
963
985
964
=cut
986
    return unless ( $reserve_id );
965
987
966
sub CancelReserve {
967
    my ( $biblio, $item, $borr ) = @_;
968
    my $dbh = C4::Context->dbh;
988
    my $dbh = C4::Context->dbh;
969
        if ( $item and $borr ) {
970
        # removing a waiting reserve record....
971
        # update the database...
972
        my $query = "
973
            UPDATE reserves
974
            SET    cancellationdate = now(),
975
                   found            = Null,
976
                   priority         = 0
977
            WHERE  itemnumber       = ?
978
             AND   borrowernumber   = ?
979
        ";
980
        my $sth = $dbh->prepare($query);
981
        $sth->execute( $item, $borr );
982
        $sth->finish;
983
        $query = "
984
            INSERT INTO old_reserves
985
            SELECT * FROM reserves
986
            WHERE  itemnumber       = ?
987
             AND   borrowernumber   = ?
988
        ";
989
        $sth = $dbh->prepare($query);
990
        $sth->execute( $item, $borr );
991
        $query = "
992
            DELETE FROM reserves
993
            WHERE  itemnumber       = ?
994
             AND   borrowernumber   = ?
995
        ";
996
        $sth = $dbh->prepare($query);
997
        $sth->execute( $item, $borr );
998
    }
999
    else {
1000
        # removing a reserve record....
1001
        # get the prioritiy on this record....
1002
        my $priority;
1003
        my $query = qq/
1004
            SELECT priority FROM reserves
1005
            WHERE biblionumber   = ?
1006
              AND borrowernumber = ?
1007
              AND cancellationdate IS NULL
1008
              AND itemnumber IS NULL
1009
        /;
1010
        my $sth = $dbh->prepare($query);
1011
        $sth->execute( $biblio, $borr );
1012
        ($priority) = $sth->fetchrow_array;
1013
        $sth->finish;
1014
        $query = qq/
1015
            UPDATE reserves
1016
            SET    cancellationdate = now(),
1017
                   found            = Null,
1018
                   priority         = 0
1019
            WHERE  biblionumber     = ?
1020
              AND  borrowernumber   = ?
1021
        /;
1022
1023
        # update the database, removing the record...
1024
        $sth = $dbh->prepare($query);
1025
        $sth->execute( $biblio, $borr );
1026
        $sth->finish;
1027
989
1028
        $query = qq/
990
    my $query = "
1029
            INSERT INTO old_reserves
991
        UPDATE reserves
1030
            SELECT * FROM reserves
992
        SET    cancellationdate = now(),
1031
            WHERE  biblionumber     = ?
993
               found            = Null,
1032
              AND  borrowernumber   = ?
994
               priority         = 0
1033
        /;
995
        WHERE  reserve_id = ?
1034
        $sth = $dbh->prepare($query);
996
    ";
1035
        $sth->execute( $biblio, $borr );
997
    my $sth = $dbh->prepare($query);
998
    $sth->execute( $reserve_id );
999
    $sth->finish;
1036
1000
1037
        $query = qq/
1001
    $query = "
1038
            DELETE FROM reserves
1002
        INSERT INTO old_reserves
1039
            WHERE  biblionumber     = ?
1003
        SELECT * FROM reserves
1040
              AND  borrowernumber   = ?
1004
        WHERE  reserve_id = ?
1041
        /;
1005
    ";
1042
        $sth = $dbh->prepare($query);
1006
    $sth = $dbh->prepare($query);
1043
        $sth->execute( $biblio, $borr );
1007
    $sth->execute( $reserve_id );
1044
1008
1045
        # now fix the priority on the others....
1009
    $query = "
1046
        _FixPriority( $biblio, $borr );
1010
        DELETE FROM reserves
1047
    }
1011
        WHERE  reserve_id = ?
1012
    ";
1013
    $sth = $dbh->prepare($query);
1014
    $sth->execute( $reserve_id );
1015
1016
    # now fix the priority on the others....
1017
    _FixPriority( $reserve_id );
1048
}
1018
}
1049
1019
1050
=head2 ModReserve
1020
=head2 ModReserve
1051
1021
1052
  ModReserve($rank, $biblio, $borrower, $branch[, $itemnumber])
1022
  ModReserve({ rank => $rank,
1023
               reserve_id => $reserve_id,
1024
               branchcode => $branchcode
1025
               [, itemnumber => $itemnumber ]
1026
               [, biblionumber => $biblionumber, $borrowernumber => $borrowernumber ]
1027
              });
1053
1028
1054
Change a hold request's priority or cancel it.
1029
Change a hold request's priority or cancel it.
1055
1030
Lines 1079-1137 itemnumber and supplying itemnumber. Link Here
1079
=cut
1054
=cut
1080
1055
1081
sub ModReserve {
1056
sub ModReserve {
1082
    #subroutine to update a reserve
1057
    my ( $params ) = @_;
1083
    my ( $rank, $biblio, $borrower, $branch , $itemnumber, $suspend_until) = @_;
1058
1084
     return if $rank eq "W";
1059
    my $rank = $params->{'rank'};
1085
     return if $rank eq "n";
1060
    my $reserve_id = $params->{'reserve_id'};
1061
    my $branchcode = $params->{'branchcode'};
1062
    my $itemnumber = $params->{'itemnumber'};
1063
    my $suspend_until = $params->{'suspend_until'};
1064
    my $borrowernumber = $params->{'borrowernumber'};
1065
    my $biblionumber = $params->{'biblionumber'};
1066
1067
    return if $rank eq "W";
1068
    return if $rank eq "n";
1069
1070
    return unless ( $reserve_id || ( $borrowernumber && ( $biblionumber || $itemnumber ) ) );
1071
    $reserve_id = GetReserveId({ biblionumber => $biblionumber, borrowernumber => $borrowernumber, itemnumber => $itemnumber }) unless ( $reserve_id );
1072
1086
    my $dbh = C4::Context->dbh;
1073
    my $dbh = C4::Context->dbh;
1087
    if ( $rank eq "del" ) {
1074
    if ( $rank eq "del" ) {
1088
        my $query = qq/
1075
        my $query = "
1089
            UPDATE reserves
1076
            UPDATE reserves
1090
            SET    cancellationdate=now()
1077
            SET    cancellationdate=now()
1091
            WHERE  biblionumber   = ?
1078
            WHERE  reserve_id = ?
1092
             AND   borrowernumber = ?
1079
        ";
1093
        /;
1094
        my $sth = $dbh->prepare($query);
1080
        my $sth = $dbh->prepare($query);
1095
        $sth->execute( $biblio, $borrower );
1081
        $sth->execute( $reserve_id );
1096
        $sth->finish;
1082
        $sth->finish;
1097
        $query = qq/
1083
        $query = "
1098
            INSERT INTO old_reserves
1084
            INSERT INTO old_reserves
1099
            SELECT *
1085
            SELECT *
1100
            FROM   reserves 
1086
            FROM   reserves 
1101
            WHERE  biblionumber   = ?
1087
            WHERE  reserve_id = ?
1102
             AND   borrowernumber = ?
1088
        ";
1103
        /;
1104
        $sth = $dbh->prepare($query);
1089
        $sth = $dbh->prepare($query);
1105
        $sth->execute( $biblio, $borrower );
1090
        $sth->execute( $reserve_id );
1106
        $query = qq/
1091
        $query = "
1107
            DELETE FROM reserves 
1092
            DELETE FROM reserves 
1108
            WHERE  biblionumber   = ?
1093
            WHERE  reserve_id = ?
1109
             AND   borrowernumber = ?
1094
        ";
1110
        /;
1111
        $sth = $dbh->prepare($query);
1095
        $sth = $dbh->prepare($query);
1112
        $sth->execute( $biblio, $borrower );
1096
        $sth->execute( $reserve_id );
1113
        
1097
        
1114
    }
1098
    }
1115
    elsif ($rank =~ /^\d+/ and $rank > 0) {
1099
    elsif ($rank =~ /^\d+/ and $rank > 0) {
1116
        my $query = "
1100
        my $query = "
1117
            UPDATE reserves SET priority = ? ,branchcode = ?, itemnumber = ?, found = NULL, waitingdate = NULL
1101
            UPDATE reserves SET priority = ? ,branchcode = ?, itemnumber = ?, found = NULL, waitingdate = NULL
1118
            WHERE biblionumber   = ?
1102
            WHERE reserve_id = ?
1119
            AND borrowernumber = ?
1120
        ";
1103
        ";
1121
        my $sth = $dbh->prepare($query);
1104
        my $sth = $dbh->prepare($query);
1122
        $sth->execute( $rank, $branch,$itemnumber, $biblio, $borrower);
1105
        $sth->execute( $rank, $branchcode, $itemnumber, $reserve_id );
1123
        $sth->finish;
1106
        $sth->finish;
1124
1107
1125
        if ( defined( $suspend_until ) ) {
1108
        if ( defined( $suspend_until ) ) {
1126
            if ( $suspend_until ) {
1109
            if ( $suspend_until ) {
1127
                $suspend_until = C4::Dates->new( $suspend_until )->output("iso");
1110
                $suspend_until = C4::Dates->new( $suspend_until )->output("iso");
1128
                $dbh->do("UPDATE reserves SET suspend = 1, suspend_until = ? WHERE biblionumber = ? AND borrowernumber = ?", undef, ( $suspend_until, $biblio, $borrower ) );
1111
                $dbh->do("UPDATE reserves SET suspend = 1, suspend_until = ? WHERE reserve_id = ?", undef, ( $suspend_until, $reserve_id ) );
1129
            } else {
1112
            } else {
1130
                $dbh->do("UPDATE reserves SET suspend_until = NULL WHERE biblionumber = ? AND borrowernumber = ?", undef, ( $biblio, $borrower ) );
1113
                $dbh->do("UPDATE reserves SET suspend_until = NULL WHERE reserve_id = ?", undef, ( $reserve_id ) );
1131
            }
1114
            }
1132
        }
1115
        }
1133
1116
1134
        _FixPriority( $biblio, $borrower, $rank);
1117
        _FixPriority( $reserve_id, $rank );
1135
    }
1118
    }
1136
}
1119
}
1137
1120
Lines 1151-1156 sub ModReserveFill { Link Here
1151
    my ($res) = @_;
1134
    my ($res) = @_;
1152
    my $dbh = C4::Context->dbh;
1135
    my $dbh = C4::Context->dbh;
1153
    # fill in a reserve record....
1136
    # fill in a reserve record....
1137
    my $reserve_id = $res->{'reserve_id'};
1154
    my $biblionumber = $res->{'biblionumber'};
1138
    my $biblionumber = $res->{'biblionumber'};
1155
    my $borrowernumber    = $res->{'borrowernumber'};
1139
    my $borrowernumber    = $res->{'borrowernumber'};
1156
    my $resdate = $res->{'reservedate'};
1140
    my $resdate = $res->{'reservedate'};
Lines 1199-1205 sub ModReserveFill { Link Here
1199
    # now fix the priority on the others (if the priority wasn't
1183
    # now fix the priority on the others (if the priority wasn't
1200
    # already sorted!)....
1184
    # already sorted!)....
1201
    unless ( $priority == 0 ) {
1185
    unless ( $priority == 0 ) {
1202
        _FixPriority( $biblionumber, $borrowernumber );
1186
        _FixPriority( $reserve_id );
1203
    }
1187
    }
1204
}
1188
}
1205
1189
Lines 1309-1315 sub ModReserveCancelAll { Link Here
1309
    my ( $itemnumber, $borrowernumber ) = @_;
1293
    my ( $itemnumber, $borrowernumber ) = @_;
1310
1294
1311
    #step 1 : cancel the reservation
1295
    #step 1 : cancel the reservation
1312
    my $CancelReserve = CancelReserve( undef, $itemnumber, $borrowernumber );
1296
    my $CancelReserve = CancelReserve({ itemnumber => $itemnumber, borrowernumber => $borrowernumber });
1313
1297
1314
    #step 2 launch the subroutine of the others reserves
1298
    #step 2 launch the subroutine of the others reserves
1315
    ( $messages, $nextreservinfo ) = GetOtherReserves($itemnumber);
1299
    ( $messages, $nextreservinfo ) = GetOtherReserves($itemnumber);
Lines 1321-1350 sub ModReserveCancelAll { Link Here
1321
1305
1322
  &ModReserveMinusPriority($itemnumber,$borrowernumber,$biblionumber)
1306
  &ModReserveMinusPriority($itemnumber,$borrowernumber,$biblionumber)
1323
1307
1324
Reduce the values of queuded list     
1308
Reduce the values of queued list
1325
1309
1326
=cut
1310
=cut
1327
1311
1328
sub ModReserveMinusPriority {
1312
sub ModReserveMinusPriority {
1329
    my ( $itemnumber, $borrowernumber, $biblionumber ) = @_;
1313
    my ( $itemnumber, $reserve_id ) = @_;
1330
1314
1331
    #first step update the value of the first person on reserv
1315
    #first step update the value of the first person on reserv
1332
    my $dbh   = C4::Context->dbh;
1316
    my $dbh   = C4::Context->dbh;
1333
    my $query = "
1317
    my $query = "
1334
        UPDATE reserves
1318
        UPDATE reserves
1335
        SET    priority = 0 , itemnumber = ? 
1319
        SET    priority = 0 , itemnumber = ? 
1336
        WHERE  borrowernumber=?
1320
        WHERE  reserve_id = ?
1337
          AND  biblionumber=?
1338
    ";
1321
    ";
1339
    my $sth_upd = $dbh->prepare($query);
1322
    my $sth_upd = $dbh->prepare($query);
1340
    $sth_upd->execute( $itemnumber, $borrowernumber, $biblionumber );
1323
    $sth_upd->execute( $itemnumber, $reserve_id );
1341
    # second step update all others reservs
1324
    # second step update all others reservs
1342
    _FixPriority($biblionumber, $borrowernumber, '0');
1325
    _FixPriority( $reserve_id, '0');
1343
}
1326
}
1344
1327
1345
=head2 GetReserveInfo
1328
=head2 GetReserveInfo
1346
1329
1347
  &GetReserveInfo($borrowernumber,$biblionumber);
1330
  &GetReserveInfo($reserve_id);
1348
1331
1349
Get item and borrower details for a current hold.
1332
Get item and borrower details for a current hold.
1350
Current implementation this query should have a single result.
1333
Current implementation this query should have a single result.
Lines 1352-1400 Current implementation this query should have a single result. Link Here
1352
=cut
1335
=cut
1353
1336
1354
sub GetReserveInfo {
1337
sub GetReserveInfo {
1355
	my ( $borrowernumber, $biblionumber ) = @_;
1338
    my ( $reserve_id ) = @_;
1356
    my $dbh = C4::Context->dbh;
1339
    my $dbh = C4::Context->dbh;
1357
	my $strsth="SELECT 
1340
    my $strsth="SELECT
1358
	               reservedate, 
1341
                   reserve_id,
1359
	               reservenotes, 
1342
                   reservedate,
1360
	               reserves.borrowernumber,
1343
                   reservenotes,
1361
				   reserves.biblionumber, 
1344
                   reserves.borrowernumber,
1362
				   reserves.branchcode,
1345
                   reserves.biblionumber,
1363
				   reserves.waitingdate,
1346
                   reserves.branchcode,
1364
				   notificationdate, 
1347
                   reserves.waitingdate,
1365
				   reminderdate, 
1348
                   notificationdate,
1366
				   priority, 
1349
                   reminderdate,
1367
				   found,
1350
                   priority,
1368
				   firstname, 
1351
                   found,
1369
				   surname, 
1352
                   firstname,
1370
				   phone, 
1353
                   surname,
1371
				   email, 
1354
                   phone,
1372
				   address, 
1355
                   email,
1373
				   address2,
1356
                   address,
1374
				   cardnumber, 
1357
                   address2,
1375
				   city, 
1358
                   cardnumber,
1376
				   zipcode,
1359
                   city,
1377
				   biblio.title, 
1360
                   zipcode,
1378
				   biblio.author,
1361
                   biblio.title,
1379
				   items.holdingbranch, 
1362
                   biblio.author,
1380
				   items.itemcallnumber, 
1363
                   items.holdingbranch,
1381
				   items.itemnumber,
1364
                   items.itemcallnumber,
1382
				   items.location, 
1365
                   items.itemnumber,
1383
				   barcode, 
1366
                   items.location,
1384
				   notes
1367
                   barcode,
1385
			FROM reserves 
1368
                   notes
1386
			 LEFT JOIN items USING(itemnumber) 
1369
                FROM reserves
1387
		     LEFT JOIN borrowers USING(borrowernumber)
1370
                LEFT JOIN items USING(itemnumber)
1388
		     LEFT JOIN biblio ON  (reserves.biblionumber=biblio.biblionumber) 
1371
                LEFT JOIN borrowers USING(borrowernumber)
1389
			WHERE 
1372
                LEFT JOIN biblio ON  (reserves.biblionumber=biblio.biblionumber)
1390
				reserves.borrowernumber=?
1373
                WHERE reserves.reserve_id = ?";
1391
				AND reserves.biblionumber=?";
1374
    my $sth = $dbh->prepare($strsth);
1392
	my $sth = $dbh->prepare($strsth); 
1375
    $sth->execute($reserve_id);
1393
	$sth->execute($borrowernumber,$biblionumber);
1394
1395
	my $data = $sth->fetchrow_hashref;
1396
	return $data;
1397
1376
1377
    my $data = $sth->fetchrow_hashref;
1378
    return $data;
1398
}
1379
}
1399
1380
1400
=head2 IsAvailableForItemLevelRequest
1381
=head2 IsAvailableForItemLevelRequest
Lines 1471-1477 sub IsAvailableForItemLevelRequest { Link Here
1471
1452
1472
=head2 AlterPriority
1453
=head2 AlterPriority
1473
1454
1474
  AlterPriority( $where, $borrowernumber, $biblionumber, $reservedate );
1455
  AlterPriority( $where, $reserve_id );
1475
1456
1476
This function changes a reserve's priority up, down, to the top, or to the bottom.
1457
This function changes a reserve's priority up, down, to the top, or to the bottom.
1477
Input: $where is 'up', 'down', 'top' or 'bottom'. Biblionumber, Date reserve was placed
1458
Input: $where is 'up', 'down', 'top' or 'bottom'. Biblionumber, Date reserve was placed
Lines 1479-1507 Input: $where is 'up', 'down', 'top' or 'bottom'. Biblionumber, Date reserve was Link Here
1479
=cut
1460
=cut
1480
1461
1481
sub AlterPriority {
1462
sub AlterPriority {
1482
    my ( $where, $borrowernumber, $biblionumber ) = @_;
1463
    my ( $where, $reserve_id ) = @_;
1483
1464
1484
    my $dbh = C4::Context->dbh;
1465
    my $dbh = C4::Context->dbh;
1485
1466
1486
    ## Find this reserve
1467
    my $reserve = GetReserve( $reserve_id );
1487
    my $sth = $dbh->prepare('SELECT * FROM reserves WHERE biblionumber = ? AND borrowernumber = ? AND cancellationdate IS NULL');
1488
    $sth->execute( $biblionumber, $borrowernumber );
1489
    my $reserve = $sth->fetchrow_hashref();
1490
    $sth->finish();
1491
1468
1492
    if ( $where eq 'up' || $where eq 'down' ) {
1469
    if ( $where eq 'up' || $where eq 'down' ) {
1493
    
1470
    
1494
      my $priority = $reserve->{'priority'};        
1471
      my $priority = $reserve->{'priority'};        
1495
      $priority = $where eq 'up' ? $priority - 1 : $priority + 1;
1472
      $priority = $where eq 'up' ? $priority - 1 : $priority + 1;
1496
      _FixPriority( $biblionumber, $borrowernumber, $priority )
1473
      _FixPriority( $reserve_id, $priority )
1497
1474
1498
    } elsif ( $where eq 'top' ) {
1475
    } elsif ( $where eq 'top' ) {
1499
1476
1500
      _FixPriority( $biblionumber, $borrowernumber, '1' )
1477
      _FixPriority( $reserve_id, '1' )
1501
1478
1502
    } elsif ( $where eq 'bottom' ) {
1479
    } elsif ( $where eq 'bottom' ) {
1503
1480
1504
      _FixPriority( $biblionumber, $borrowernumber, '999999' )
1481
      _FixPriority( $reserve_id, '999999' )
1505
1482
1506
    }
1483
    }
1507
}
1484
}
Lines 1515-1541 This function sets the lowestPriority field to true if is false, and false if it Link Here
1515
=cut
1492
=cut
1516
1493
1517
sub ToggleLowestPriority {
1494
sub ToggleLowestPriority {
1518
    my ( $borrowernumber, $biblionumber ) = @_;
1495
    my ( $reserve_id ) = @_;
1519
1496
1520
    my $dbh = C4::Context->dbh;
1497
    my $dbh = C4::Context->dbh;
1521
1498
1522
    my $sth = $dbh->prepare(
1499
    my $sth = $dbh->prepare( "UPDATE reserves SET lowestPriority = NOT lowestPriority WHERE reserve_id = ?");
1523
        "UPDATE reserves SET lowestPriority = NOT lowestPriority
1500
    $sth->execute( $reserve_id );
1524
         WHERE biblionumber = ?
1525
         AND borrowernumber = ?"
1526
    );
1527
    $sth->execute(
1528
        $biblionumber,
1529
        $borrowernumber,
1530
    );
1531
    $sth->finish;
1501
    $sth->finish;
1532
    
1502
    
1533
    _FixPriority( $biblionumber, $borrowernumber, '999999' );
1503
    _FixPriority( $reserve_id, '999999' );
1534
}
1504
}
1535
1505
1536
=head2 ToggleSuspend
1506
=head2 ToggleSuspend
1537
1507
1538
  ToggleSuspend( $borrowernumber, $biblionumber );
1508
  ToggleSuspend( $reserve_id );
1539
1509
1540
This function sets the suspend field to true if is false, and false if it is true.
1510
This function sets the suspend field to true if is false, and false if it is true.
1541
If the reserve is currently suspended with a suspend_until date, that date will
1511
If the reserve is currently suspended with a suspend_until date, that date will
Lines 1544-1550 be cleared when it is unsuspended. Link Here
1544
=cut
1514
=cut
1545
1515
1546
sub ToggleSuspend {
1516
sub ToggleSuspend {
1547
    my ( $borrowernumber, $biblionumber, $suspend_until ) = @_;
1517
    my ( $reserve_id, $suspend_until ) = @_;
1548
1518
1549
    $suspend_until = output_pref( dt_from_string( $suspend_until ), 'iso' ) if ( $suspend_until );
1519
    $suspend_until = output_pref( dt_from_string( $suspend_until ), 'iso' ) if ( $suspend_until );
1550
1520
Lines 1555-1568 sub ToggleSuspend { Link Here
1555
    my $sth = $dbh->prepare(
1525
    my $sth = $dbh->prepare(
1556
        "UPDATE reserves SET suspend = NOT suspend,
1526
        "UPDATE reserves SET suspend = NOT suspend,
1557
        suspend_until = CASE WHEN suspend = 0 THEN NULL ELSE $do_until END
1527
        suspend_until = CASE WHEN suspend = 0 THEN NULL ELSE $do_until END
1558
        WHERE biblionumber = ?
1528
        WHERE reserve_id = ?
1559
        AND borrowernumber = ?
1560
    ");
1529
    ");
1561
1530
1562
    my @params;
1531
    my @params;
1563
    push( @params, $suspend_until ) if ( $suspend_until );
1532
    push( @params, $suspend_until ) if ( $suspend_until );
1564
    push( @params, $biblionumber );
1533
    push( @params, $reserve_id );
1565
    push( @params, $borrowernumber );
1566
1534
1567
    $sth->execute( @params );
1535
    $sth->execute( @params );
1568
    $sth->finish;
1536
    $sth->finish;
Lines 1627-1633 sub SuspendAll { Link Here
1627
1595
1628
=head2 _FixPriority
1596
=head2 _FixPriority
1629
1597
1630
  &_FixPriority($biblio,$borrowernumber,$rank,$ignoreSetLowestRank);
1598
  &_FixPriority( $reserve_id, $rank, $ignoreSetLowestRank);
1631
1599
1632
Only used internally (so don't export it)
1600
Only used internally (so don't export it)
1633
Changed how this functions works #
1601
Changed how this functions works #
Lines 1639-1679 in new priority rank Link Here
1639
=cut 
1607
=cut 
1640
1608
1641
sub _FixPriority {
1609
sub _FixPriority {
1642
    my ( $biblio, $borrowernumber, $rank, $ignoreSetLowestRank ) = @_;
1610
    my ( $reserve_id, $rank, $ignoreSetLowestRank ) = @_;
1643
    my $dbh = C4::Context->dbh;
1611
    my $dbh = C4::Context->dbh;
1644
     if ( $rank eq "del" ) {
1612
1645
         CancelReserve( $biblio, undef, $borrowernumber );
1613
    my $res = GetReserve( $reserve_id );
1646
     }
1614
1647
    if ( $rank eq "W" || $rank eq "0" ) {
1615
    if ( $rank eq "del" ) {
1616
         CancelReserve({ reserve_id => $reserve_id });
1617
    }
1618
    elsif ( $rank eq "W" || $rank eq "0" ) {
1648
1619
1649
        # make sure priority for waiting or in-transit items is 0
1620
        # make sure priority for waiting or in-transit items is 0
1650
        my $query = qq/
1621
        my $query = "
1651
            UPDATE reserves
1622
            UPDATE reserves
1652
            SET    priority = 0
1623
            SET    priority = 0
1653
            WHERE biblionumber = ?
1624
            WHERE reserve_id = ?
1654
              AND borrowernumber = ?
1625
            AND found IN ('W', 'T')
1655
              AND found IN ('W', 'T')
1626
        ";
1656
        /;
1657
        my $sth = $dbh->prepare($query);
1627
        my $sth = $dbh->prepare($query);
1658
        $sth->execute( $biblio, $borrowernumber );
1628
        $sth->execute( $reserve_id );
1659
    }
1629
    }
1660
    my @priority;
1630
    my @priority;
1661
    my @reservedates;
1631
    my @reservedates;
1662
1632
1663
    # get whats left
1633
    # get whats left
1664
# FIXME adding a new security in returned elements for changing priority,
1634
    my $query = "
1665
# now, we don't care anymore any reservations with itemnumber linked (suppose a waiting reserve)
1635
        SELECT reserve_id, borrowernumber, reservedate, constrainttype
1666
	# This is wrong a waiting reserve has W set
1667
	# The assumption that having an itemnumber set means waiting is wrong and should be corrected any place it occurs
1668
    my $query = qq/
1669
        SELECT borrowernumber, reservedate, constrainttype
1670
        FROM   reserves
1636
        FROM   reserves
1671
        WHERE  biblionumber   = ?
1637
        WHERE  biblionumber   = ?
1672
          AND  ((found <> 'W' AND found <> 'T') or found is NULL)
1638
          AND  ((found <> 'W' AND found <> 'T') OR found IS NULL)
1673
        ORDER BY priority ASC
1639
        ORDER BY priority ASC
1674
    /;
1640
    ";
1675
    my $sth = $dbh->prepare($query);
1641
    my $sth = $dbh->prepare($query);
1676
    $sth->execute($biblio);
1642
    $sth->execute( $res->{'biblionumber'} );
1677
    while ( my $line = $sth->fetchrow_hashref ) {
1643
    while ( my $line = $sth->fetchrow_hashref ) {
1678
        push( @reservedates, $line );
1644
        push( @reservedates, $line );
1679
        push( @priority,     $line );
1645
        push( @priority,     $line );
Lines 1683-1689 sub _FixPriority { Link Here
1683
    my $i;
1649
    my $i;
1684
    my $key = -1;    # to allow for 0 to be a valid result
1650
    my $key = -1;    # to allow for 0 to be a valid result
1685
    for ( $i = 0 ; $i < @priority ; $i++ ) {
1651
    for ( $i = 0 ; $i < @priority ; $i++ ) {
1686
        if ( $borrowernumber == $priority[$i]->{'borrowernumber'} ) {
1652
        if ( $reserve_id == $priority[$i]->{'reserve_id'} ) {
1687
            $key = $i;    # save the index
1653
            $key = $i;    # save the index
1688
            last;
1654
            last;
1689
        }
1655
        }
Lines 1699-1727 sub _FixPriority { Link Here
1699
1665
1700
    # now fix the priority on those that are left....
1666
    # now fix the priority on those that are left....
1701
    $query = "
1667
    $query = "
1702
            UPDATE reserves
1668
        UPDATE reserves
1703
            SET    priority = ?
1669
        SET    priority = ?
1704
                WHERE  biblionumber = ?
1670
        WHERE  reserve_id = ?
1705
                 AND borrowernumber   = ?
1706
                 AND reservedate = ?
1707
         AND found IS NULL
1708
    ";
1671
    ";
1709
    $sth = $dbh->prepare($query);
1672
    $sth = $dbh->prepare($query);
1710
    for ( my $j = 0 ; $j < @priority ; $j++ ) {
1673
    for ( my $j = 0 ; $j < @priority ; $j++ ) {
1711
        $sth->execute(
1674
        $sth->execute(
1712
            $j + 1, $biblio,
1675
            $j + 1,
1713
            $priority[$j]->{'borrowernumber'},
1676
            $priority[$j]->{'reserve_id'}
1714
            $priority[$j]->{'reservedate'}
1715
        );
1677
        );
1716
        $sth->finish;
1678
        $sth->finish;
1717
    }
1679
    }
1718
    
1680
    
1719
    $sth = $dbh->prepare( "SELECT borrowernumber FROM reserves WHERE lowestPriority = 1 ORDER BY priority" );
1681
    $sth = $dbh->prepare( "SELECT reserve_id FROM reserves WHERE lowestPriority = 1 ORDER BY priority" );
1720
    $sth->execute();
1682
    $sth->execute();
1721
    
1683
    
1722
    unless ( $ignoreSetLowestRank ) {
1684
    unless ( $ignoreSetLowestRank ) {
1723
      while ( my $res = $sth->fetchrow_hashref() ) {
1685
      while ( my $res = $sth->fetchrow_hashref() ) {
1724
        _FixPriority( $biblio, $res->{'borrowernumber'}, '999999', 1 );
1686
        _FixPriority( $res->{'reserve_id'}, '999999', 1 );
1725
      }
1687
      }
1726
    }
1688
    }
1727
}
1689
}
Lines 1760-1766 sub _Findgroupreserve { Link Here
1760
               reserves.priority            AS priority,
1722
               reserves.priority            AS priority,
1761
               reserves.timestamp           AS timestamp,
1723
               reserves.timestamp           AS timestamp,
1762
               biblioitems.biblioitemnumber AS biblioitemnumber,
1724
               biblioitems.biblioitemnumber AS biblioitemnumber,
1763
               reserves.itemnumber          AS itemnumber
1725
               reserves.itemnumber          AS itemnumber,
1726
               reserves.reserve_id          AS reserve_id
1764
        FROM reserves
1727
        FROM reserves
1765
        JOIN biblioitems USING (biblionumber)
1728
        JOIN biblioitems USING (biblionumber)
1766
        JOIN hold_fill_targets USING (biblionumber, borrowernumber, itemnumber)
1729
        JOIN hold_fill_targets USING (biblionumber, borrowernumber, itemnumber)
Lines 2028-2035 sub MoveReserve { Link Here
2028
            RevertWaitingStatus({ itemnumber => $itemnumber });
1991
            RevertWaitingStatus({ itemnumber => $itemnumber });
2029
        }
1992
        }
2030
        elsif ( $cancelreserve eq 'cancel' || $cancelreserve ) { # cancel reserves on this item
1993
        elsif ( $cancelreserve eq 'cancel' || $cancelreserve ) { # cancel reserves on this item
2031
            CancelReserve(0, $res->{'itemnumber'}, $res->{'borrowernumber'});
1994
            CancelReserve({
2032
            CancelReserve($res->{'biblionumber'}, 0, $res->{'borrowernumber'});
1995
                biblionumber   => $res->{'biblionumber'},
1996
                itemnumber     => $res->{'itemnumber'},
1997
                borrowernumber => $res->{'borrowernumber'}
1998
            });
2033
        }
1999
        }
2034
    }
2000
    }
2035
}
2001
}
Lines 2045-2051 This shifts the holds from C<$from_biblio> to C<$to_biblio> and reorders them by Link Here
2045
sub MergeHolds {
2011
sub MergeHolds {
2046
    my ( $dbh, $to_biblio, $from_biblio ) = @_;
2012
    my ( $dbh, $to_biblio, $from_biblio ) = @_;
2047
    my $sth = $dbh->prepare(
2013
    my $sth = $dbh->prepare(
2048
        "SELECT count(*) as reservenumber FROM reserves WHERE biblionumber = ?"
2014
        "SELECT count(*) as reserve_id FROM reserves WHERE biblionumber = ?"
2049
    );
2015
    );
2050
    $sth->execute($from_biblio);
2016
    $sth->execute($from_biblio);
2051
    if ( my $data = $sth->fetchrow_hashref() ) {
2017
    if ( my $data = $sth->fetchrow_hashref() ) {
Lines 2138-2143 sub RevertWaitingStatus { Link Here
2138
    return $sth->execute( $reserve->{'reserve_id'} );
2104
    return $sth->execute( $reserve->{'reserve_id'} );
2139
}
2105
}
2140
2106
2107
=head2 GetReserveId
2108
2109
  $reserve_id = GetReserveId({ biblionumber => $biblionumber, borrowernumber => $borrowernumber [, itemnumber => $itemnumber ] });
2110
2111
  Returnes the first reserve id that matches the given criteria
2112
2113
=cut
2114
2115
sub GetReserveId {
2116
    my ( $params ) = @_;
2117
2118
    return unless ( ( $params->{'biblionumber'} || $params->{'itemnumber'} ) && $params->{'borrowernumber'} );
2119
2120
    my $dbh = C4::Context->dbh();
2121
2122
    my $sql = "SELECT reserve_id FROM reserves WHERE ";
2123
2124
    my @params;
2125
    my @limits;
2126
    foreach my $key ( keys %$params ) {
2127
        if ( defined( $params->{$key} ) ) {
2128
            push( @limits, "$key = ?" );
2129
            push( @params, $params->{$key} );
2130
        }
2131
    }
2132
2133
    $sql .= join( " AND ", @limits );
2134
2135
    my $sth = $dbh->prepare( $sql );
2136
    $sth->execute( @params );
2137
    my $row = $sth->fetchrow_hashref();
2138
2139
    return $row->{'reserve_id'};
2140
}
2141
2141
=head2 ReserveSlip
2142
=head2 ReserveSlip
2142
2143
2143
  ReserveSlip($branchcode, $borrowernumber, $biblionumber)
2144
  ReserveSlip($branchcode, $borrowernumber, $biblionumber)
(-)a/C4/SIP/ILS/Transaction/Hold.pm (-13 / +10 lines)
Lines 85-94 sub drop_hold { Link Here
85
		return $self;
85
		return $self;
86
	}
86
	}
87
	my $bib = GetBiblioFromItemNumber(undef, $self->{item}->id);
87
	my $bib = GetBiblioFromItemNumber(undef, $self->{item}->id);
88
	# FIXME: figure out if it is a item or title hold.  Till then, cancel both.
88
89
	CancelReserve($bib->{biblionumber}, undef, $borrower->{borrowernumber});
89
      CancelReserve({
90
	CancelReserve(undef, $self->{item}->id, $borrower->{borrowernumber});
90
            biblionumber   => $bib->{biblionumber},
91
		# unfortunately no meaningful return value here either
91
        itemnumber     => $self->{item}->id,
92
           borrowernumber => $borrower->{borrowernumber}
93
      });
94
92
	$self->ok(1);
95
	$self->ok(1);
93
	return $self;
96
	return $self;
94
}
97
}
Lines 119-135 sub change_hold { Link Here
119
		return $self;
122
		return $self;
120
	}
123
	}
121
	my $bibno = $bib->{biblionumber};
124
	my $bibno = $bib->{biblionumber};
122
	ModReserve($bibno, $borrower->{borrowernumber}, $branch, GetBiblioItemByBiblioNumber($bibno));
125
  ModReserve({ biblionumber => $bibno, borrowernumber => $borrower->{borrowernumber}, branchcode => $branch });
123
		# unfortunately no meaningful return value
126
124
		# ModReserve needs to be fixed to maintain priority by iteself (Feb 2008)
125
	$self->ok(1);
127
	$self->ok(1);
126
	return $self;
128
	return $self;
127
}
129
}
130
128
1;
131
1;
129
__END__
132
__END__
130
131
# 11 friggin arguments
132
AddReserve($branch,$borrowernumber,$biblionumber,$constraint,$bibitems,$priority,$startdate,$notes,$title,$checkitem,$found)
133
134
ModReserve($rank, $biblio, $borrower, $branch , $itemnumber)
135
(-)a/circ/branchtransfers.pl (-2 / +8 lines)
Lines 80-86 my $ignoreRs = 0; Link Here
80
# Deal with the requests....
80
# Deal with the requests....
81
if ( $request eq "KillWaiting" ) {
81
if ( $request eq "KillWaiting" ) {
82
    my $item = $query->param('itemnumber');
82
    my $item = $query->param('itemnumber');
83
    CancelReserve( 0, $item, $borrowernumber );
83
    CancelReserve({
84
        itemnumber     => $item,
85
        borrowernumber => $borrowernumber
86
    });
84
    $cancelled   = 1;
87
    $cancelled   = 1;
85
    $reqmessage  = 1;
88
    $reqmessage  = 1;
86
}
89
}
Lines 93-99 elsif ( $request eq "SetWaiting" ) { Link Here
93
}
96
}
94
elsif ( $request eq 'KillReserved' ) {
97
elsif ( $request eq 'KillReserved' ) {
95
    my $biblio = $query->param('biblionumber');
98
    my $biblio = $query->param('biblionumber');
96
    CancelReserve( $biblio, 0, $borrowernumber );
99
    CancelReserve({
100
        biblionumber   => $biblio,
101
        borrowernumber => $borrowernumber
102
    });
97
    $cancelled   = 1;
103
    $cancelled   = 1;
98
    $reqmessage  = 1;
104
    $reqmessage  = 1;
99
}
105
}
(-)a/circ/circulation.pl (-1 / +1 lines)
Lines 359-365 if ($borrowernumber) { Link Here
359
        $getreserv{nottransfered} = 0;
359
        $getreserv{nottransfered} = 0;
360
360
361
        $getreserv{reservedate}    = format_date( $num_res->{'reservedate'} );
361
        $getreserv{reservedate}    = format_date( $num_res->{'reservedate'} );
362
        $getreserv{reservenumber}  = $num_res->{'reservenumber'};
362
        $getreserv{reserve_id}  = $num_res->{'reserve_id'};
363
        $getreserv{title}          = $getiteminfo->{'title'};
363
        $getreserv{title}          = $getiteminfo->{'title'};
364
        $getreserv{itemtype}       = $itemtypeinfo->{'description'};
364
        $getreserv{itemtype}       = $itemtypeinfo->{'description'};
365
        $getreserv{author}         = $getiteminfo->{'author'};
365
        $getreserv{author}         = $getiteminfo->{'author'};
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt (-10 / +11 lines)
Lines 596-601 function checkMultiHold() { Link Here
596
  [% FOREACH reserveloo IN biblioloo.reserveloop %]
596
  [% FOREACH reserveloo IN biblioloo.reserveloop %]
597
  [% UNLESS ( loop.odd ) %]<tr class="highlight">[% ELSE %]<tr>[% END %]
597
  [% UNLESS ( loop.odd ) %]<tr class="highlight">[% ELSE %]<tr>[% END %]
598
        <td>
598
        <td>
599
          <input type="hidden" name="reserve_id" value="[% reserveloo.reserve_id %]" />
599
          <input type="hidden" name="borrowernumber" value="[% reserveloo.borrowernumber %]" />
600
          <input type="hidden" name="borrowernumber" value="[% reserveloo.borrowernumber %]" />
600
          <input type="hidden" name="biblionumber" value="[% reserveloo.biblionumber %]" />
601
          <input type="hidden" name="biblionumber" value="[% reserveloo.biblionumber %]" />
601
          <select name="rank-request">
602
          <select name="rank-request">
Lines 615-633 function checkMultiHold() { Link Here
615
616
616
     [% IF ( CAN_user_reserveforothers_modify_holds_priority ) %]
617
     [% IF ( CAN_user_reserveforothers_modify_holds_priority ) %]
617
        <td style="white-space:nowrap;">
618
        <td style="white-space:nowrap;">
618
	        <a title="Move Hold Up" href="request.pl?action=move&amp;where=up&amp;borrowernumber=[% reserveloo.borrowernumber %]&amp;biblionumber=[% reserveloo.biblionumber %]&amp;date=[% reserveloo.date %]">
619
            <a title="Move Hold Up" href="request.pl?action=move&amp;where=up&amp;borrowernumber=[% reserveloo.borrowernumber %]&amp;biblionumber=[% reserveloo.biblionumber %]&amp;reserve_id=[% reserveloo.reserve_id %]&amp;date=[% reserveloo.date %]">
619
            <img src="/intranet-tmpl/[% theme %]/img/go-up.png" border="0" alt="Go up" />
620
            <img src="/intranet-tmpl/[% theme %]/img/go-up.png" border="0" alt="Go up" />
620
                </a>
621
                </a>
621
622
622
        <a title="Move hold to top" href="request.pl?action=move&amp;where=top&amp;borrowernumber=[% reserveloo.borrowernumber %]&amp;biblionumber=[% reserveloo.biblionumber %]&amp;date=[% reserveloo.date %]">
623
                <a title="Move Hold To Top" href="request.pl?action=move&amp;where=top&amp;borrowernumber=[% reserveloo.borrowernumber %]&amp;biblionumber=[% reserveloo.biblionumber %]&amp;reserve_id=[% reserveloo.reserve_id %]&amp;date=[% reserveloo.date %]">
623
                    <img src="/intranet-tmpl/[% theme %]/img/go-top.png" border="0" alt="Go top" />
624
                    <img src="/intranet-tmpl/[% theme %]/img/go-top.png" border="0" alt="Go top" />
624
                </a>
625
                </a>
625
626
626
                <a title="Move hold to bottom" href="request.pl?action=move&amp;where=bottom&amp;borrowernumber=[% reserveloo.borrowernumber %]&amp;biblionumber=[% reserveloo.biblionumber %]&amp;date=[% reserveloo.date %]">
627
                <a title="Move Hold To Bottom" href="request.pl?action=move&amp;where=bottom&amp;borrowernumber=[% reserveloo.borrowernumber %]&amp;biblionumber=[% reserveloo.biblionumber %]&amp;reserve_id=[% reserveloo.reserve_id %]&amp;date=[% reserveloo.date %]">
627
                    <img src="/intranet-tmpl/[% theme %]/img/go-bottom.png" border="0" alt="Go bottom" />
628
                    <img src="/intranet-tmpl/[% theme %]/img/go-bottom.png" border="0" alt="Go bottom" />
628
                </a>
629
                </a>
629
630
630
                <a title="Move hold down" href="request.pl?action=move&amp;where=down&amp;borrowernumber=[% reserveloo.borrowernumber %]&amp;biblionumber=[% reserveloo.biblionumber %]&amp;date=[% reserveloo.date %]">
631
                <a title="Move Hold Down" href="request.pl?action=move&amp;where=down&amp;borrowernumber=[% reserveloo.borrowernumber %]&amp;biblionumber=[% reserveloo.biblionumber %]&amp;reserve_id=[% reserveloo.reserve_id %]&amp;date=[% reserveloo.date %]">
631
                    <img src="/intranet-tmpl/[% theme %]/img/go-down.png" border="0" alt="Go down" />
632
                    <img src="/intranet-tmpl/[% theme %]/img/go-down.png" border="0" alt="Go down" />
632
                </a>
633
                </a>
633
        </td>
634
        </td>
Lines 707-713 function checkMultiHold() { Link Here
707
708
708
    [% IF ( CAN_user_reserveforothers_modify_holds_priority ) %]
709
    [% IF ( CAN_user_reserveforothers_modify_holds_priority ) %]
709
	<td>
710
	<td>
710
        <a title="Toggle lowest priority" href="request.pl?action=setLowestPriority&amp;borrowernumber=[% reserveloo.borrowernumber %]&amp;biblionumber=[% reserveloo.biblionumber %]&amp;date=[% reserveloo.date %]">
711
                <a title="Toggle Lowest Priority" href="request.pl?action=setLowestPriority&amp;borrowernumber=[% reserveloo.borrowernumber %]&amp;biblionumber=[% reserveloo.biblionumber %]&amp;reserve_id=[% reserveloo.reserve_id %]&amp;date=[% reserveloo.date %]">
711
			[% IF ( reserveloo.lowestPriority ) %]
712
			[% IF ( reserveloo.lowestPriority ) %]
712
                        <img src="/intranet-tmpl/[% theme %]/img/go-bottom.png" border="0" alt="Unset Lowest Priority" />
713
                        <img src="/intranet-tmpl/[% theme %]/img/go-bottom.png" border="0" alt="Unset Lowest Priority" />
713
		        [% ELSE %]
714
		        [% ELSE %]
Lines 718-724 function checkMultiHold() { Link Here
718
    [% END %]
719
    [% END %]
719
720
720
	<td>
721
	<td>
721
        <a title="Cancel hold" href="request.pl?action=cancel&amp;borrowernumber=[% reserveloo.borrowernumber %]&amp;biblionumber=[% reserveloo.biblionumber %]&amp;date=[% reserveloo.date %]">
722
           <a title="Cancel Hold" href="request.pl?action=cancel&amp;borrowernumber=[% reserveloo.borrowernumber %]&amp;biblionumber=[% reserveloo.biblionumber %]&amp;reserve_id=[% reserveloo.reserve_id %]&amp;date=[% reserveloo.date %]">
722
                    <img src="/intranet-tmpl/[% theme %]/img/x.png" border="0" alt="Cancel" />
723
                    <img src="/intranet-tmpl/[% theme %]/img/x.png" border="0" alt="Cancel" />
723
                </a>
724
                </a>
724
	</td>
725
	</td>
Lines 726-737 function checkMultiHold() { Link Here
726
        [% IF SuspendHoldsIntranet %]
727
        [% IF SuspendHoldsIntranet %]
727
	<td>
728
	<td>
728
	[% UNLESS ( reserveloo.wait ) %]
729
	[% UNLESS ( reserveloo.wait ) %]
729
            <input type="button" value="[% IF ( reserveloo.suspend ) %]Unsuspend[% ELSE %]Suspend[% END %]" onclick="window.location.href='request.pl?action=toggleSuspend&amp;borrowernumber=[% reserveloo.borrowernumber %]&amp;biblionumber=[% reserveloo.biblionumber %]&amp;date=[% reserveloo.date %]&amp;suspend_until=' + $('#suspend_until_[% reserveloo.borrowernumber %]').val()" />
730
            <input type="button" value="[% IF ( reserveloo.suspend ) %]Unsuspend[% ELSE %]Suspend[% END %]" onclick="window.location.href='request.pl?action=toggleSuspend&amp;reserve_id=[% reserveloo.reserve_id %]&amp;borrowernumber=[% reserveloo.borrowernumber %]&amp;biblionumber=[% reserveloo.biblionumber %]&amp;date=[% reserveloo.date %]&amp;suspend_until=' + $('#suspend_until_[% reserveloo.reserve_id %]').val()" />
730
731
731
            [% IF AutoResumeSuspendedHolds %]
732
            [% IF AutoResumeSuspendedHolds %]
732
	    <label for="suspend_until_[% reserveloo.borrowernumber %]">[% IF ( reserveloo.suspend ) %] on [% ELSE %] until [% END %]</label>
733
        <label for="suspend_until_[% reserveloo.reserve_id %]">[% IF ( reserveloo.suspend ) %] on [% ELSE %] until [% END %]</label>
733
        <input name="suspend_until" id="suspend_until_[% reserveloo.borrowernumber %]" size="10" readonly="readonly" value="[% reserveloo.suspend_until | $KohaDates %]" class="datepicker" />
734
            <input name="suspend_until" id="suspend_until_[% reserveloo.reserve_id %]" size="10" readonly="readonly" value="[% reserveloo.suspend_until | $KohaDates %]" class="datepicker" />
734
	    <a href='#' onclick="document.getElementById('suspend_until_[% reserveloo.borrowernumber %]').value='';">Clear Date</a>
735
            <a href='#' onclick="document.getElementById('suspend_until_[% reserveloo.reserve_id %]').value='';">Clear Date</a>
735
            [% END %]
736
            [% END %]
736
	[% ELSE %]
737
	[% ELSE %]
737
		<input type="hidden" name="suspend_until" value="" />
738
		<input type="hidden" name="suspend_until" value="" />
(-)a/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tt (-1 / +1 lines)
Lines 418-424 $.tablesorter.addParser({ Link Here
418
		[% IF ( RESERVE.cancelable ) %]
418
		[% IF ( RESERVE.cancelable ) %]
419
			<form action="/cgi-bin/koha/opac-modrequest.pl" method="post">
419
			<form action="/cgi-bin/koha/opac-modrequest.pl" method="post">
420
			<input type="hidden" name="biblionumber" value="[% RESERVE.biblionumber %]" />
420
			<input type="hidden" name="biblionumber" value="[% RESERVE.biblionumber %]" />
421
		<input type="hidden" name="reservenumber" value="[% RESERVE.reservenumber %]" />
421
          <input type="hidden" name="reserve_id" value="[% RESERVE.reserve_id %]" />
422
			<input type="submit" name="submit" class="icon delete cancel" value="Cancel" onclick="return confirmDelete(MSG_CONFIRM_DELETE_HOLD);" /></form>
422
			<input type="submit" name="submit" class="icon delete cancel" value="Cancel" onclick="return confirmDelete(MSG_CONFIRM_DELETE_HOLD);" /></form>
423
		[% ELSE %]
423
		[% ELSE %]
424
		[% END %]
424
		[% END %]
(-)a/opac/opac-modrequest.pl (-3 / +6 lines)
Lines 30-35 use C4::Output; Link Here
30
use C4::Reserves;
30
use C4::Reserves;
31
use C4::Auth;
31
use C4::Auth;
32
my $query = new CGI;
32
my $query = new CGI;
33
33
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
34
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
34
    {   
35
    {   
35
        template_name   => "opac-account.tmpl",
36
        template_name   => "opac-account.tmpl",
Lines 41-48 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
41
    }
42
    }
42
);
43
);
43
44
44
my $biblionumber = $query->param('biblionumber');
45
my $reserve_id = $query->param('reserve_id');
45
if ($biblionumber and $borrowernumber) {
46
46
	CancelReserve($biblionumber, '', $borrowernumber);
47
if ($reserve_id && $borrowernumber) {
48
  CancelReserve({ reserve_id => $reserve_id });
47
}
49
}
50
48
print $query->redirect("/cgi-bin/koha/opac-user.pl#opac-user-holds");
51
print $query->redirect("/cgi-bin/koha/opac-user.pl#opac-user-holds");
(-)a/reserve/modrequest.pl (-10 / +18 lines)
Lines 41-63 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
41
    }
41
    }
42
);
42
);
43
43
44
my @rank=$query->param('rank-request');
44
my @reserve_id = $query->param('reserve_id');
45
my @biblionumber=$query->param('biblionumber');
45
my @rank = $query->param('rank-request');
46
my @borrower=$query->param('borrowernumber');
46
my @biblionumber = $query->param('biblionumber');
47
my @branch=$query->param('pickup');
47
my @borrower = $query->param('borrowernumber');
48
my @itemnumber=$query->param('itemnumber');
48
my @branch = $query->param('pickup');
49
my @itemnumber = $query->param('itemnumber');
49
my @suspend_until=$query->param('suspend_until');
50
my @suspend_until=$query->param('suspend_until');
50
my $multi_hold = $query->param('multi_hold');
51
my $multi_hold = $query->param('multi_hold');
51
my $biblionumbers = $query->param('biblionumbers');
52
my $biblionumbers = $query->param('biblionumbers');
52
my $count=@rank;
53
my $count=@rank;
53
54
54
my $CancelBiblioNumber=$query->param('CancelBiblioNumber');
55
my $CancelBiblioNumber = $query->param('CancelBiblioNumber');
55
my $CancelBorrowerNumber=$query->param('CancelBorrowerNumber');
56
my $CancelBorrowerNumber = $query->param('CancelBorrowerNumber');
56
my $CancelItemnumber=$query->param('CancelItemnumber');
57
my $CancelItemnumber = $query->param('CancelItemnumber');
57
58
58
# 2 possibilitys : cancel an item reservation, or modify or cancel the queded list
59
# 2 possibilitys : cancel an item reservation, or modify or cancel the queded list
59
60
60
# 1) cancel an item reservation by fonction ModReserveCancelAll (in reserves.pm)
61
# 1) cancel an item reservation by function ModReserveCancelAll (in reserves.pm)
61
if ($CancelBorrowerNumber) {
62
if ($CancelBorrowerNumber) {
62
    ModReserveCancelAll($CancelItemnumber, $CancelBorrowerNumber);
63
    ModReserveCancelAll($CancelItemnumber, $CancelBorrowerNumber);
63
    $biblionumber[0] = $CancelBiblioNumber,
64
    $biblionumber[0] = $CancelBiblioNumber,
Lines 67-75 if ($CancelBorrowerNumber) { Link Here
67
else {
68
else {
68
    for (my $i=0;$i<$count;$i++){
69
    for (my $i=0;$i<$count;$i++){
69
        undef $itemnumber[$i] unless $itemnumber[$i] ne '';
70
        undef $itemnumber[$i] unless $itemnumber[$i] ne '';
70
        ModReserve($rank[$i],$biblionumber[$i],$borrower[$i],$branch[$i],$itemnumber[$i],$suspend_until[$i]); #from C4::Reserves
71
        ModReserve({
72
            rank => $rank[$i],
73
            reserve_id => $reserve_id[$i],
74
            branchcode => $branch[$i],
75
            itemnumber => $itemnumber[$i],
76
            suspend_until => $suspend_until[$i]
77
        });
71
    }
78
    }
72
}
79
}
80
73
my $from=$query->param('from');
81
my $from=$query->param('from');
74
$from ||= q{};
82
$from ||= q{};
75
if ( $from eq 'borrower'){
83
if ( $from eq 'borrower'){
(-)a/reserve/request.pl (-34 / +35 lines)
Lines 86-107 $action ||= q{}; Link Here
86
86
87
if ( $action eq 'move' ) {
87
if ( $action eq 'move' ) {
88
  my $where = $input->param('where');
88
  my $where = $input->param('where');
89
  my $borrowernumber = $input->param('borrowernumber');
89
  my $reserve_id = $input->param('reserve_id');
90
  my $biblionumber = $input->param('biblionumber');
90
  AlterPriority( $where, $reserve_id );
91
  AlterPriority( $where, $borrowernumber, $biblionumber );
92
} elsif ( $action eq 'cancel' ) {
91
} elsif ( $action eq 'cancel' ) {
93
  my $borrowernumber = $input->param('borrowernumber');
92
  my $reserve_id = $input->param('reserve_id');
94
  my $biblionumber = $input->param('biblionumber');
93
  CancelReserve({ reserve_id => $reserve_id });
95
  CancelReserve( $biblionumber, '', $borrowernumber );
96
} elsif ( $action eq 'setLowestPriority' ) {
94
} elsif ( $action eq 'setLowestPriority' ) {
97
  my $borrowernumber = $input->param('borrowernumber');
95
  my $reserve_id = $input->param('reserve_id');
98
  my $biblionumber   = $input->param('biblionumber');
96
  ToggleLowestPriority( $reserve_id );
99
  ToggleLowestPriority( $borrowernumber, $biblionumber );
100
} elsif ( $action eq 'toggleSuspend' ) {
97
} elsif ( $action eq 'toggleSuspend' ) {
101
  my $borrowernumber = $input->param('borrowernumber');
98
  my $reserve_id = $input->param('reserve_id');
102
  my $biblionumber   = $input->param('biblionumber');
103
  my $suspend_until  = $input->param('suspend_until');
99
  my $suspend_until  = $input->param('suspend_until');
104
  ToggleSuspend( $borrowernumber, $biblionumber, $suspend_until );
100
  ToggleSuspend( $reserve_id, $suspend_until );
105
}
101
}
106
102
107
if ($findborrower) {
103
if ($findborrower) {
Lines 135-141 if ($borrowernumber_hold && !$action) { Link Here
135
      GetReserveCount( $borrowerinfo->{'borrowernumber'} );
131
      GetReserveCount( $borrowerinfo->{'borrowernumber'} );
136
132
137
    if ( C4::Context->preference('maxreserves') && ($number_reserves >= C4::Context->preference('maxreserves')) ) {
133
    if ( C4::Context->preference('maxreserves') && ($number_reserves >= C4::Context->preference('maxreserves')) ) {
138
		$warnings = 1;
134
       $warnings = 1;
139
        $maxreserves = 1;
135
        $maxreserves = 1;
140
    }
136
    }
141
137
Lines 149-155 if ($borrowernumber_hold && !$action) { Link Here
149
145
150
    # check if the borrower make the reserv in a different branch
146
    # check if the borrower make the reserv in a different branch
151
    if ( $borrowerinfo->{'branchcode'} ne C4::Context->userenv->{'branch'} ) {
147
    if ( $borrowerinfo->{'branchcode'} ne C4::Context->userenv->{'branch'} ) {
152
		$messages = 1;
148
      $messages = 1;
153
        $diffbranch = 1;
149
        $diffbranch = 1;
154
    }
150
    }
155
151
Lines 171-178 if ($borrowernumber_hold && !$action) { Link Here
171
                maxreserves         => $maxreserves,
167
                maxreserves         => $maxreserves,
172
                expiry              => $expiry,
168
                expiry              => $expiry,
173
                diffbranch          => $diffbranch,
169
                diffbranch          => $diffbranch,
174
				messages            => $messages,
170
                messages            => $messages,
175
				warnings            => $warnings
171
                warnings            => $warnings
176
    );
172
    );
177
}
173
}
178
174
Lines 194-205 my @biblioloop = (); Link Here
194
foreach my $biblionumber (@biblionumbers) {
190
foreach my $biblionumber (@biblionumbers) {
195
191
196
    my %biblioloopiter = ();
192
    my %biblioloopiter = ();
197
	my $maxreserves;
193
    my $maxreserves;
198
194
199
    my $dat          = GetBiblioData($biblionumber);
195
    my $dat = GetBiblioData($biblionumber);
200
196
201
    unless ( CanBookBeReserved($borrowerinfo->{borrowernumber}, $biblionumber) ) {
197
    unless ( CanBookBeReserved($borrowerinfo->{borrowernumber}, $biblionumber) ) {
202
		$warnings = 1;
198
        $warnings = 1;
203
        $maxreserves = 1;
199
        $maxreserves = 1;
204
    }
200
    }
205
201
Lines 212-218 foreach my $biblionumber (@biblionumbers) { Link Here
212
    # get existing reserves .....
208
    # get existing reserves .....
213
    my ( $count, $reserves ) = GetReservesFromBiblionumber($biblionumber,1);
209
    my ( $count, $reserves ) = GetReservesFromBiblionumber($biblionumber,1);
214
    my $totalcount = $count;
210
    my $totalcount = $count;
215
    my $alreadyreserved;
211
    my $holds_count = 0;
212
    my $alreadyreserved = 0;
216
213
217
    foreach my $res (@$reserves) {
214
    foreach my $res (@$reserves) {
218
        if ( defined $res->{found} && $res->{found} eq 'W' ) {
215
        if ( defined $res->{found} && $res->{found} eq 'W' ) {
Lines 220-239 foreach my $biblionumber (@biblionumbers) { Link Here
220
        }
217
        }
221
218
222
        if ( defined $borrowerinfo && ($borrowerinfo->{borrowernumber} eq $res->{borrowernumber}) ) {
219
        if ( defined $borrowerinfo && ($borrowerinfo->{borrowernumber} eq $res->{borrowernumber}) ) {
223
            $warnings = 1;
220
            $holds_count++;
221
        }
222
    }
223
224
    if ( $holds_count ) {
224
            $alreadyreserved = 1;
225
            $alreadyreserved = 1;
226
            $warnings = 1;
225
            $biblioloopiter{warn} = 1;
227
            $biblioloopiter{warn} = 1;
226
            $biblioloopiter{alreadyres} = 1;
228
            $biblioloopiter{alreadyres} = 1;
227
        }
228
    }
229
    }
229
230
230
    $template->param( alreadyreserved => $alreadyreserved,
231
    $template->param( alreadyreserved => $alreadyreserved,
231
                      messages => $messages,
232
        messages          => $messages,
232
                      warnings => $warnings,
233
        warnings          => $warnings,
233
                 maxreserves=>$maxreserves,
234
        maxreserves       => $maxreserves,
234
                     alreadypossession => $alreadypossession,
235
        alreadypossession => $alreadypossession,
235
					  );
236
    );
236
237
237
238
    # FIXME think @optionloop, is maybe obsolete, or  must be switchable by a systeme preference fixed rank or not
238
    # FIXME think @optionloop, is maybe obsolete, or  must be switchable by a systeme preference fixed rank or not
239
    # make priorities options
239
    # make priorities options
Lines 259-269 foreach my $biblionumber (@biblionumbers) { Link Here
259
    if (my $items = get_itemnumbers_of($biblionumber)->{$biblionumber}){
259
    if (my $items = get_itemnumbers_of($biblionumber)->{$biblionumber}){
260
        @itemnumbers  = @$items;
260
        @itemnumbers  = @$items;
261
    }
261
    }
262
	my @hostitems = get_hostitemnumbers_of($biblionumber);
262
    my @hostitems = get_hostitemnumbers_of($biblionumber);
263
	if (@hostitems){
263
    if (@hostitems){
264
		$template->param('hostitemsflag' => 1);
264
        $template->param('hostitemsflag' => 1);
265
		push(@itemnumbers, @hostitems);
265
        push(@itemnumbers, @hostitems);
266
	}
266
    }
267
267
268
    if (!@itemnumbers) {
268
    if (!@itemnumbers) {
269
        $template->param('noitems' => 1);
269
        $template->param('noitems' => 1);
Lines 341-347 foreach my $biblionumber (@biblionumbers) { Link Here
341
            }
341
            }
342
342
343
            # checking reserve
343
            # checking reserve
344
            my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($itemnumber);
344
            my ($reservedate,$reservedfor,$expectedAt,$reserve_id) = GetReservesFromItemnumber($itemnumber);
345
            my $ItemBorrowerReserveInfo = GetMember( borrowernumber => $reservedfor );
345
            my $ItemBorrowerReserveInfo = GetMember( borrowernumber => $reservedfor );
346
346
347
            if ( defined $reservedate ) {
347
            if ( defined $reservedate ) {
Lines 537-542 foreach my $biblionumber (@biblionumbers) { Link Here
537
        $reserve{'optionloop'} = \@optionloop;
537
        $reserve{'optionloop'} = \@optionloop;
538
        $reserve{'suspend'} = $res->{'suspend'};
538
        $reserve{'suspend'} = $res->{'suspend'};
539
        $reserve{'suspend_until'} = $res->{'suspend_until'};
539
        $reserve{'suspend_until'} = $res->{'suspend_until'};
540
        $reserve{'reserve_id'} = $res->{'reserve_id'};
540
541
541
        if ( C4::Context->preference('IndependentBranches') && $flags->{'superlibrarian'} != 1 ) {
542
        if ( C4::Context->preference('IndependentBranches') && $flags->{'superlibrarian'} != 1 ) {
542
              $reserve{'branchloop'} = [ GetBranchDetail($res->{'branchcode'}) ];
543
              $reserve{'branchloop'} = [ GetBranchDetail($res->{'branchcode'}) ];
(-)a/serials/routing-preview.pl (-1 / +6 lines)
Lines 87-93 if($ok){ Link Here
87
            my $reserve = $sth->fetchrow_hashref;
87
            my $reserve = $sth->fetchrow_hashref;
88
88
89
            if($routing->{borrowernumber} == $reserve->{borrowernumber}){
89
            if($routing->{borrowernumber} == $reserve->{borrowernumber}){
90
                ModReserve($routing->{ranking},$biblio,$routing->{borrowernumber},$branch);
90
                ModReserve({
91
                    rank           => $routing->{ranking},
92
                    biblionumber   => $biblio,
93
                    borrowernumber => $routing->{borrowernumber},
94
                    branchcode     => $branch
95
                });
91
            } else {
96
            } else {
92
                AddReserve($branch,$routing->{borrowernumber},$biblio,$const,\@bibitems,$routing->{ranking}, undef, undef, $notes,$title);
97
                AddReserve($branch,$routing->{borrowernumber},$biblio,$const,\@bibitems,$routing->{ranking}, undef, undef, $notes,$title);
93
        }
98
        }
(-)a/t/db_dependent/Holds.t (-1 / +172 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use strict;
4
use warnings;
5
use C4::Branch;
6
7
use Test::More tests => 18;
8
use MARC::Record;
9
use C4::Biblio;
10
use C4::Items;
11
12
BEGIN {
13
      use FindBin;
14
   use lib $FindBin::Bin;
15
 use_ok('C4::Reserves');
16
}
17
18
my $borrowers_count = 5;
19
20
# Setup Test------------------------
21
# Helper biblio.
22
diag("Creating biblio instance for testing.");
23
my ($bibnum, $title, $bibitemnum) = create_helper_biblio();
24
25
# Helper item for that biblio.
26
diag("Creating item instance for testing.");
27
my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum);
28
29
# Get a borrower
30
my $dbh = C4::Context->dbh;
31
my $query = "SELECT borrowernumber FROM borrowers LIMIT $borrowers_count";
32
my $sth = $dbh->prepare($query);
33
$sth->execute;
34
my @borrowernumbers;
35
while ( my $row = $sth->fetchrow_hashref ) {
36
    push( @borrowernumbers, $row->{'borrowernumber'} );
37
}
38
39
my $biblionumber   = $bibnum;
40
41
my @branches = GetBranchesLoop();
42
my $branch = $branches[0][0]{value};
43
44
# Create five item level holds
45
foreach my $borrowernumber ( @borrowernumbers ) {
46
    AddReserve(
47
        $branch,
48
        $borrowernumber,
49
        $biblionumber,
50
        my $constraint = 'a',
51
        my $bibitems = q{},
52
        my $priority,
53
        my $resdate,
54
        my $expdate,
55
        my $notes = q{},
56
        $title,
57
        my $checkitem = $itemnumber,
58
        my $found,
59
    );
60
}
61
62
63
my ($count, $reserves) = GetReservesFromBiblionumber($biblionumber);
64
is( $count, $borrowers_count, "Test GetReserves()" );
65
66
67
my ( $reservedate, $borrowernumber, $branchcode, $reserve_id ) = GetReservesFromItemnumber($itemnumber);
68
ok($reserve_id, "Test GetReservesFromItemnumber()");
69
70
71
my ( $reserve ) = GetReservesFromBorrowernumber($borrowernumbers[0]);
72
ok( $reserve->{'borrowernumber'} eq $borrowernumbers[0], "Test GetReservesFromBorrowernumber()");
73
74
75
ok( GetReserveCount( $borrowernumbers[0] ), "Test GetReserveCount()" );
76
77
78
CancelReserve({ 'reserve_id' => $reserve_id });
79
($count, $reserves) = GetReservesFromBiblionumber($biblionumber);
80
ok( $count == $borrowers_count - 1, "Test CancelReserve()" );
81
82
83
( $reservedate, $borrowernumber, $branchcode, $reserve_id ) = GetReservesFromItemnumber($itemnumber);
84
ModReserve({
85
    reserve_id    => $reserve_id,
86
    rank          => '4',
87
    branchcode    => $branch,
88
    itemnumber    => $itemnumber,
89
    suspend_until => C4::Dates->new("2013-01-01","iso")->output(),
90
});
91
$reserve = GetReserve( $reserve_id );
92
ok( $reserve->{'priority'} eq '4', "Test GetReserve(), priority changed correctly" );
93
ok( $reserve->{'suspend'}, "Test GetReserve(), suspend hold" );
94
ok( $reserve->{'suspend_until'} eq '2013-01-01 00:00:00', "Test GetReserve(), suspend until date" );
95
96
ToggleSuspend( $reserve_id );
97
$reserve = GetReserve( $reserve_id );
98
ok( !$reserve->{'suspend'}, "Test ToggleSuspend(), no date" );
99
100
ToggleSuspend( $reserve_id, '2012-01-01' );
101
$reserve = GetReserve( $reserve_id );
102
ok( $reserve->{'suspend_until'} eq '2012-01-01 00:00:00', "Test ToggleSuspend(), with date" );
103
104
AutoUnsuspendReserves();
105
$reserve = GetReserve( $reserve_id );
106
ok( !$reserve->{'suspend'}, "Test AutoUnsuspendReserves()" );
107
108
# Add a new hold for the borrower whose hold we canceled earlier, this time at the bib level
109
AddReserve(
110
    $branch,
111
    $borrowernumber,
112
    $biblionumber,
113
    my $constraint = 'a',
114
    my $bibitems = q{},
115
    my $priority,
116
    my $resdate,
117
    my $expdate,
118
    my $notes = q{},
119
    $title,
120
    my $checkitem,
121
    my $found,
122
);
123
( $reserve ) = GetReservesFromBorrowernumber($borrowernumber);
124
ModReserveMinusPriority( $itemnumber, $reserve->{'reserve_id'} );
125
( $reserve ) = GetReservesFromBorrowernumber($borrowernumber);
126
ok( $reserve->{'itemnumber'} eq $itemnumber, "Test ModReserveMinusPriority()" );
127
128
129
my $reserve2 = GetReserveInfo( $reserve->{'reserve_id'} );
130
ok( $reserve->{'reserve_id'} eq $reserve2->{'reserve_id'}, "Test GetReserveInfo()" );
131
132
133
($count, $reserves) = GetReservesFromBiblionumber($biblionumber,1);
134
$reserve = $reserves->[1];
135
AlterPriority( 'top', $reserve->{'reserve_id'} );
136
$reserve = GetReserve( $reserve->{'reserve_id'} );
137
ok( $reserve->{'priority'} eq '1', "Test AlterPriority(), move to top" );
138
139
AlterPriority( 'down', $reserve->{'reserve_id'} );
140
$reserve = GetReserve( $reserve->{'reserve_id'} );
141
ok( $reserve->{'priority'} eq '2', "Test AlterPriority(), move down" );
142
143
AlterPriority( 'up', $reserve->{'reserve_id'} );
144
$reserve = GetReserve( $reserve->{'reserve_id'} );
145
ok( $reserve->{'priority'} eq '1', "Test AlterPriority(), move up" );
146
147
AlterPriority( 'bottom', $reserve->{'reserve_id'} );
148
$reserve = GetReserve( $reserve->{'reserve_id'} );
149
ok( $reserve->{'priority'} eq '5', "Test AlterPriority(), move to bottom" );
150
151
# Delete the reserves
152
diag("Deleting holds.");
153
$dbh->do("DELETE FROM reserves WHERE biblionumber = ?", undef, ( $biblionumber ) );
154
155
# Delete item.
156
diag("Deleting item testing instance.");
157
DelItem($dbh, $bibnum, $itemnumber);
158
159
# Delete helper Biblio.
160
diag("Deleting biblio testing instance.");
161
DelBiblio($bibnum);
162
163
# Helper method to set up a Biblio.
164
sub create_helper_biblio {
165
    my $bib = MARC::Record->new();
166
    my $title = 'Silence in the library';
167
    $bib->append_fields(
168
        MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
169
        MARC::Field->new('245', ' ', ' ', a => $title),
170
    );
171
    return ($bibnum, $title, $bibitemnum) = AddBiblio($bib, '');
172
}

Return to bug 9394