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

(-)a/C4/Biblio.pm (-1 / +1 lines)
Lines 439-445 sub DelBiblio { Link Here
439
    require C4::Reserves;
439
    require C4::Reserves;
440
    my ($count, $reserves) = C4::Reserves::GetReservesFromBiblionumber($biblionumber);
440
    my ($count, $reserves) = C4::Reserves::GetReservesFromBiblionumber($biblionumber);
441
    foreach my $res ( @$reserves ) {
441
    foreach my $res ( @$reserves ) {
442
        C4::Reserves::CancelReserve( $res->{'biblionumber'}, $res->{'itemnumber'}, $res->{'borrowernumber'} );
442
        C4::Reserves::CancelReserve({ reserve_id => $res->{'reserve_id'} });
443
    }
443
    }
444
444
445
    # Delete in Zebra. Be careful NOT to move this line after _koha_delete_biblio
445
    # 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 (-284 / +271 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 417-424 This function return 1 if an item can be issued by this borrower. Link Here
417
437
418
sub CanItemBeReserved{
438
sub CanItemBeReserved{
419
    my ($borrowernumber, $itemnumber) = @_;
439
    my ($borrowernumber, $itemnumber) = @_;
420
    
440
421
    my $dbh             = C4::Context->dbh;
441
    my $dbh = C4::Context->dbh;
422
    my $allowedreserves = 0;
442
    my $allowedreserves = 0;
423
            
443
            
424
    my $controlbranch = C4::Context->preference('ReservesControlBranch');
444
    my $controlbranch = C4::Context->preference('ReservesControlBranch');
Lines 428-454 sub CanItemBeReserved{ Link Here
428
    my $item     = GetItem($itemnumber);
448
    my $item     = GetItem($itemnumber);
429
    my $borrower = C4::Members::GetMember('borrowernumber'=>$borrowernumber);     
449
    my $borrower = C4::Members::GetMember('borrowernumber'=>$borrowernumber);     
430
    
450
    
431
    # we retrieve user rights on this itemtype and branchcode
451
    my $querycount = "
432
    my $sth = $dbh->prepare("SELECT categorycode, itemtype, branchcode, reservesallowed 
452
        SELECT count(*) AS count
433
                             FROM issuingrules 
453
        FROM reserves
434
                             WHERE (categorycode in (?,'*') ) 
454
        LEFT JOIN items USING (itemnumber)
435
                             AND (itemtype IN (?,'*')) 
455
        LEFT JOIN biblioitems ON (reserves.biblionumber=biblioitems.biblionumber)
436
                             AND (branchcode IN (?,'*')) 
456
        LEFT JOIN borrowers USING (borrowernumber)
437
                             ORDER BY 
457
        WHERE borrowernumber = ?
438
                               categorycode DESC, 
458
    ";
439
                               itemtype     DESC, 
440
                               branchcode   DESC;"
441
                           );
442
                           
443
    my $querycount ="SELECT 
444
                            count(*) as count
445
                            FROM reserves
446
                                LEFT JOIN items USING (itemnumber)
447
                                LEFT JOIN biblioitems ON (reserves.biblionumber=biblioitems.biblionumber)
448
                                LEFT JOIN borrowers USING (borrowernumber)
449
                            WHERE borrowernumber = ?
450
                                ";
451
    
452
    
459
    
453
    my $itemtype     = $item->{$itype};
460
    my $itemtype     = $item->{$itype};
454
    my $categorycode = $borrower->{categorycode};
461
    my $categorycode = $borrower->{categorycode};
Lines 464-471 sub CanItemBeReserved{ Link Here
464
    }
471
    }
465
    
472
    
466
    # we retrieve rights 
473
    # we retrieve rights 
467
    $sth->execute($categorycode, $itemtype, $branchcode);
474
    my $rights = C4::Circulation::GetIssuingRule( $categorycode, $itemtype, $branchcode );
468
    if(my $rights = $sth->fetchrow_hashref()){
475
    if ( defined $rights ) {
469
        $itemtype        = $rights->{itemtype};
476
        $itemtype        = $rights->{itemtype};
470
        $allowedreserves = $rights->{reservesallowed}; 
477
        $allowedreserves = $rights->{reservesallowed}; 
471
    }else{
478
    }else{
Lines 489-500 sub CanItemBeReserved{ Link Here
489
    if(my $rowcount = $sthcount->fetchrow_hashref()){
496
    if(my $rowcount = $sthcount->fetchrow_hashref()){
490
        $reservecount = $rowcount->{count};
497
        $reservecount = $rowcount->{count};
491
    }
498
    }
492
    
493
    # we check if it's ok or not
499
    # we check if it's ok or not
494
    if( $reservecount < $allowedreserves ){
500
    if( $reservecount >= $allowedreserves ){ ## too many reserves
495
        return 1;
496
    }else{
497
        return 0;
501
        return 0;
502
    }else{
503
        return 1;
498
    }
504
    }
499
}
505
}
500
#--------------------------------------------------------------------------------
506
#--------------------------------------------------------------------------------
Lines 511-521 sub GetReserveCount { Link Here
511
517
512
    my $dbh = C4::Context->dbh;
518
    my $dbh = C4::Context->dbh;
513
519
514
    my $query = '
520
    my $query = "
515
        SELECT COUNT(*) AS counter
521
        SELECT COUNT(*) AS counter
516
        FROM reserves
522
        FROM reserves
517
          WHERE borrowernumber = ?
523
        WHERE borrowernumber = ?
518
    ';
524
    ";
519
    my $sth = $dbh->prepare($query);
525
    my $sth = $dbh->prepare($query);
520
    $sth->execute($borrowernumber);
526
    $sth->execute($borrowernumber);
521
    my $row = $sth->fetchrow_hashref;
527
    my $row = $sth->fetchrow_hashref;
Lines 542-549 sub GetOtherReserves { Link Here
542
            #minus priorities of others reservs
548
            #minus priorities of others reservs
543
            ModReserveMinusPriority(
549
            ModReserveMinusPriority(
544
                $itemnumber,
550
                $itemnumber,
545
                $checkreserves->{'borrowernumber'},
551
                $checkreserves->{'reserve_id'},
546
                $iteminfo->{'biblionumber'}
547
            );
552
            );
548
553
549
            #launch the subroutine dotransfer
554
            #launch the subroutine dotransfer
Lines 560-567 sub GetOtherReserves { Link Here
560
            $messages->{'waiting'} = 1;
565
            $messages->{'waiting'} = 1;
561
            ModReserveMinusPriority(
566
            ModReserveMinusPriority(
562
                $itemnumber,
567
                $itemnumber,
563
                $checkreserves->{'borrowernumber'},
568
                $checkreserves->{'reserve_id'},
564
                $iteminfo->{'biblionumber'}
565
            );
569
            );
566
            ModReserveStatus($itemnumber,'W');
570
            ModReserveStatus($itemnumber,'W');
567
        }
571
        }
Lines 687-693 sub GetReservesToBranch { Link Here
687
    my ( $frombranch ) = @_;
691
    my ( $frombranch ) = @_;
688
    my $dbh = C4::Context->dbh;
692
    my $dbh = C4::Context->dbh;
689
    my $sth = $dbh->prepare(
693
    my $sth = $dbh->prepare(
690
        "SELECT borrowernumber,reservedate,itemnumber,timestamp
694
        "SELECT reserve_id,borrowernumber,reservedate,itemnumber,timestamp
691
         FROM reserves 
695
         FROM reserves 
692
         WHERE priority='0' 
696
         WHERE priority='0' 
693
           AND branchcode=?"
697
           AND branchcode=?"
Lines 710-731 sub GetReservesToBranch { Link Here
710
714
711
sub GetReservesForBranch {
715
sub GetReservesForBranch {
712
    my ($frombranch) = @_;
716
    my ($frombranch) = @_;
713
    my $dbh          = C4::Context->dbh;
717
    my $dbh = C4::Context->dbh;
714
	my $query        = "SELECT borrowernumber,reservedate,itemnumber,waitingdate
718
719
    my $query = "
720
        SELECT reserve_id,borrowernumber,reservedate,itemnumber,waitingdate
715
        FROM   reserves 
721
        FROM   reserves 
716
        WHERE   priority='0'
722
        WHERE   priority='0'
717
            AND found='W' ";
723
        AND found='W'
718
    if ($frombranch){
724
    ";
719
        $query .= " AND branchcode=? ";
725
    $query .= " AND branchcode=? " if ( $frombranch );
720
	}
721
    $query .= "ORDER BY waitingdate" ;
726
    $query .= "ORDER BY waitingdate" ;
727
722
    my $sth = $dbh->prepare($query);
728
    my $sth = $dbh->prepare($query);
723
    if ($frombranch){
729
    if ($frombranch){
724
		$sth->execute($frombranch);
730
     $sth->execute($frombranch);
725
	}
731
    } else {
726
    else {
732
        $sth->execute();
727
		$sth->execute();
733
    }
728
	}
734
729
    my @transreserv;
735
    my @transreserv;
730
    my $i = 0;
736
    my $i = 0;
731
    while ( my $data = $sth->fetchrow_hashref ) {
737
    while ( my $data = $sth->fetchrow_hashref ) {
Lines 735-740 sub GetReservesForBranch { Link Here
735
    return (@transreserv);
741
    return (@transreserv);
736
}
742
}
737
743
744
## FIXME: I don't think this does what it thinks it does.
745
## It only ever checks the first reserve result, even though
746
## multiple reserves for that bib can have the itemnumber set
747
## the sub is only used once in the codebase.
738
sub GetReserveStatus {
748
sub GetReserveStatus {
739
    my ($itemnumber) = @_;
749
    my ($itemnumber) = @_;
740
    
750
    
Lines 880-886 sub CancelExpiredReserves { Link Here
880
    $sth->execute();
890
    $sth->execute();
881
891
882
    while ( my $res = $sth->fetchrow_hashref() ) {
892
    while ( my $res = $sth->fetchrow_hashref() ) {
883
        CancelReserve( $res->{'biblionumber'}, '', $res->{'borrowernumber'} );
893
        CancelReserve({ reserve_id => $res->{'reserve_id'} });
884
    }
894
    }
885
  
895
  
886
    # Cancel reserves that have been waiting too long
896
    # Cancel reserves that have been waiting too long
Lines 897-903 sub CancelExpiredReserves { Link Here
897
                manualinvoice($res->{'borrowernumber'}, $res->{'itemnumber'}, 'Hold waiting too long', 'F', $charge);
907
                manualinvoice($res->{'borrowernumber'}, $res->{'itemnumber'}, 'Hold waiting too long', 'F', $charge);
898
            }
908
            }
899
909
900
            CancelReserve( $res->{'biblionumber'}, '', $res->{'borrowernumber'} );
910
            CancelReserve({ reserve_id => $res->{'reserve_id'} });
901
        }
911
        }
902
    }
912
    }
903
913
Lines 923-1031 sub AutoUnsuspendReserves { Link Here
923
933
924
=head2 CancelReserve
934
=head2 CancelReserve
925
935
926
  &CancelReserve($biblionumber, $itemnumber, $borrowernumber);
936
  CancelReserve({ reserve_id => $reserve_id, [ biblionumber => $biblionumber, borrowernumber => $borrrowernumber, itemnumber => $itemnumber ] });
927
937
928
Cancels a reserve.
938
Cancels a reserve.
929
939
930
Use either C<$biblionumber> or C<$itemnumber> to specify the item to
940
=cut
931
cancel, but not both: if both are given, C<&CancelReserve> uses
932
C<$itemnumber>.
933
941
934
C<$borrowernumber> is the borrower number of the patron on whose
942
sub CancelReserve {
935
behalf the book was reserved.
943
    my ( $params ) = @_;
936
944
937
If C<$biblionumber> was given, C<&CancelReserve> also adjusts the
945
    my $reserve_id = $params->{'reserve_id'};
938
priorities of the other people who are waiting on the book.
946
    $reserve_id = GetReserveId( $params ) unless ( $reserve_id );
939
947
940
=cut
948
    return unless ( $reserve_id );
941
949
942
sub CancelReserve {
943
    my ( $biblio, $item, $borr ) = @_;
944
    my $dbh = C4::Context->dbh;
950
    my $dbh = C4::Context->dbh;
945
        if ( $item and $borr ) {
946
        # removing a waiting reserve record....
947
        # update the database...
948
        my $query = "
949
            UPDATE reserves
950
            SET    cancellationdate = now(),
951
                   found            = Null,
952
                   priority         = 0
953
            WHERE  itemnumber       = ?
954
             AND   borrowernumber   = ?
955
        ";
956
        my $sth = $dbh->prepare($query);
957
        $sth->execute( $item, $borr );
958
        $sth->finish;
959
        $query = "
960
            INSERT INTO old_reserves
961
            SELECT * FROM reserves
962
            WHERE  itemnumber       = ?
963
             AND   borrowernumber   = ?
964
        ";
965
        $sth = $dbh->prepare($query);
966
        $sth->execute( $item, $borr );
967
        $query = "
968
            DELETE FROM reserves
969
            WHERE  itemnumber       = ?
970
             AND   borrowernumber   = ?
971
        ";
972
        $sth = $dbh->prepare($query);
973
        $sth->execute( $item, $borr );
974
    }
975
    else {
976
        # removing a reserve record....
977
        # get the prioritiy on this record....
978
        my $priority;
979
        my $query = qq/
980
            SELECT priority FROM reserves
981
            WHERE biblionumber   = ?
982
              AND borrowernumber = ?
983
              AND cancellationdate IS NULL
984
              AND itemnumber IS NULL
985
        /;
986
        my $sth = $dbh->prepare($query);
987
        $sth->execute( $biblio, $borr );
988
        ($priority) = $sth->fetchrow_array;
989
        $sth->finish;
990
        $query = qq/
991
            UPDATE reserves
992
            SET    cancellationdate = now(),
993
                   found            = Null,
994
                   priority         = 0
995
            WHERE  biblionumber     = ?
996
              AND  borrowernumber   = ?
997
        /;
998
999
        # update the database, removing the record...
1000
        $sth = $dbh->prepare($query);
1001
        $sth->execute( $biblio, $borr );
1002
        $sth->finish;
1003
951
1004
        $query = qq/
952
    my $query = "
1005
            INSERT INTO old_reserves
953
        UPDATE reserves
1006
            SELECT * FROM reserves
954
        SET    cancellationdate = now(),
1007
            WHERE  biblionumber     = ?
955
               found            = Null,
1008
              AND  borrowernumber   = ?
956
               priority         = 0
1009
        /;
957
        WHERE  reserve_id = ?
1010
        $sth = $dbh->prepare($query);
958
    ";
1011
        $sth->execute( $biblio, $borr );
959
    my $sth = $dbh->prepare($query);
960
    $sth->execute( $reserve_id );
961
    $sth->finish;
1012
962
1013
        $query = qq/
963
    $query = "
1014
            DELETE FROM reserves
964
        INSERT INTO old_reserves
1015
            WHERE  biblionumber     = ?
965
        SELECT * FROM reserves
1016
              AND  borrowernumber   = ?
966
        WHERE  reserve_id = ?
1017
        /;
967
    ";
1018
        $sth = $dbh->prepare($query);
968
    $sth = $dbh->prepare($query);
1019
        $sth->execute( $biblio, $borr );
969
    $sth->execute( $reserve_id );
1020
970
1021
        # now fix the priority on the others....
971
    $query = "
1022
        _FixPriority( $biblio, $borr );
972
        DELETE FROM reserves
1023
    }
973
        WHERE  reserve_id = ?
974
    ";
975
    $sth = $dbh->prepare($query);
976
    $sth->execute( $reserve_id );
977
978
    # now fix the priority on the others....
979
    _FixPriority( $reserve_id );
1024
}
980
}
1025
981
1026
=head2 ModReserve
982
=head2 ModReserve
1027
983
1028
  ModReserve($rank, $biblio, $borrower, $branch[, $itemnumber])
984
  ModReserve({ rank => $rank,
985
               reserve_id => $reserve_id,
986
               branchcode => $branchcode
987
               [, itemnumber => $itemnumber ]
988
               [, biblionumber => $biblionumber, $borrowernumber => $borrowernumber ]
989
              });
1029
990
1030
Change a hold request's priority or cancel it.
991
Change a hold request's priority or cancel it.
1031
992
Lines 1055-1113 itemnumber and supplying itemnumber. Link Here
1055
=cut
1016
=cut
1056
1017
1057
sub ModReserve {
1018
sub ModReserve {
1058
    #subroutine to update a reserve
1019
    my ( $params ) = @_;
1059
    my ( $rank, $biblio, $borrower, $branch , $itemnumber, $suspend_until) = @_;
1020
1060
     return if $rank eq "W";
1021
    my $rank = $params->{'rank'};
1061
     return if $rank eq "n";
1022
    my $reserve_id = $params->{'reserve_id'};
1023
    my $branchcode = $params->{'branchcode'};
1024
    my $itemnumber = $params->{'itemnumber'};
1025
    my $suspend_until = $params->{'suspend_until'};
1026
    my $borrowernumber = $params->{'borrowernumber'};
1027
    my $biblionumber = $params->{'biblionumber'};
1028
1029
    return if $rank eq "W";
1030
    return if $rank eq "n";
1031
1032
    return unless ( $reserve_id || ( $borrowernumber && ( $biblionumber || $itemnumber ) ) );
1033
    $reserve_id = GetReserveId({ biblionumber => $biblionumber, borrowernumber => $borrowernumber, itemnumber => $itemnumber }) unless ( $reserve_id );
1034
1062
    my $dbh = C4::Context->dbh;
1035
    my $dbh = C4::Context->dbh;
1063
    if ( $rank eq "del" ) {
1036
    if ( $rank eq "del" ) {
1064
        my $query = qq/
1037
        my $query = "
1065
            UPDATE reserves
1038
            UPDATE reserves
1066
            SET    cancellationdate=now()
1039
            SET    cancellationdate=now()
1067
            WHERE  biblionumber   = ?
1040
            WHERE  reserve_id = ?
1068
             AND   borrowernumber = ?
1041
        ";
1069
        /;
1070
        my $sth = $dbh->prepare($query);
1042
        my $sth = $dbh->prepare($query);
1071
        $sth->execute( $biblio, $borrower );
1043
        $sth->execute( $reserve_id );
1072
        $sth->finish;
1044
        $sth->finish;
1073
        $query = qq/
1045
        $query = "
1074
            INSERT INTO old_reserves
1046
            INSERT INTO old_reserves
1075
            SELECT *
1047
            SELECT *
1076
            FROM   reserves 
1048
            FROM   reserves 
1077
            WHERE  biblionumber   = ?
1049
            WHERE  reserve_id = ?
1078
             AND   borrowernumber = ?
1050
        ";
1079
        /;
1080
        $sth = $dbh->prepare($query);
1051
        $sth = $dbh->prepare($query);
1081
        $sth->execute( $biblio, $borrower );
1052
        $sth->execute( $reserve_id );
1082
        $query = qq/
1053
        $query = "
1083
            DELETE FROM reserves 
1054
            DELETE FROM reserves 
1084
            WHERE  biblionumber   = ?
1055
            WHERE  reserve_id = ?
1085
             AND   borrowernumber = ?
1056
        ";
1086
        /;
1087
        $sth = $dbh->prepare($query);
1057
        $sth = $dbh->prepare($query);
1088
        $sth->execute( $biblio, $borrower );
1058
        $sth->execute( $reserve_id );
1089
        
1059
        
1090
    }
1060
    }
1091
    elsif ($rank =~ /^\d+/ and $rank > 0) {
1061
    elsif ($rank =~ /^\d+/ and $rank > 0) {
1092
        my $query = "
1062
        my $query = "
1093
            UPDATE reserves SET priority = ? ,branchcode = ?, itemnumber = ?, found = NULL, waitingdate = NULL
1063
            UPDATE reserves SET priority = ? ,branchcode = ?, itemnumber = ?, found = NULL, waitingdate = NULL
1094
            WHERE biblionumber   = ?
1064
            WHERE reserve_id = ?
1095
            AND borrowernumber = ?
1096
        ";
1065
        ";
1097
        my $sth = $dbh->prepare($query);
1066
        my $sth = $dbh->prepare($query);
1098
        $sth->execute( $rank, $branch,$itemnumber, $biblio, $borrower);
1067
        $sth->execute( $rank, $branchcode, $itemnumber, $reserve_id );
1099
        $sth->finish;
1068
        $sth->finish;
1100
1069
1101
        if ( defined( $suspend_until ) ) {
1070
        if ( defined( $suspend_until ) ) {
1102
            if ( $suspend_until ) {
1071
            if ( $suspend_until ) {
1103
                $suspend_until = C4::Dates->new( $suspend_until )->output("iso");
1072
                $suspend_until = C4::Dates->new( $suspend_until )->output("iso");
1104
                $dbh->do("UPDATE reserves SET suspend = 1, suspend_until = ? WHERE biblionumber = ? AND borrowernumber = ?", undef, ( $suspend_until, $biblio, $borrower ) );
1073
                $dbh->do("UPDATE reserves SET suspend = 1, suspend_until = ? WHERE reserve_id = ?", undef, ( $suspend_until, $reserve_id ) );
1105
            } else {
1074
            } else {
1106
                $dbh->do("UPDATE reserves SET suspend_until = NULL WHERE biblionumber = ? AND borrowernumber = ?", undef, ( $biblio, $borrower ) );
1075
                $dbh->do("UPDATE reserves SET suspend_until = NULL WHERE reserve_id = ?", undef, ( $reserve_id ) );
1107
            }
1076
            }
1108
        }
1077
        }
1109
1078
1110
        _FixPriority( $biblio, $borrower, $rank);
1079
        _FixPriority( $reserve_id, $rank );
1111
    }
1080
    }
1112
}
1081
}
1113
1082
Lines 1127-1132 sub ModReserveFill { Link Here
1127
    my ($res) = @_;
1096
    my ($res) = @_;
1128
    my $dbh = C4::Context->dbh;
1097
    my $dbh = C4::Context->dbh;
1129
    # fill in a reserve record....
1098
    # fill in a reserve record....
1099
    my $reserve_id = $res->{'reserve_id'};
1130
    my $biblionumber = $res->{'biblionumber'};
1100
    my $biblionumber = $res->{'biblionumber'};
1131
    my $borrowernumber    = $res->{'borrowernumber'};
1101
    my $borrowernumber    = $res->{'borrowernumber'};
1132
    my $resdate = $res->{'reservedate'};
1102
    my $resdate = $res->{'reservedate'};
Lines 1175-1181 sub ModReserveFill { Link Here
1175
    # now fix the priority on the others (if the priority wasn't
1145
    # now fix the priority on the others (if the priority wasn't
1176
    # already sorted!)....
1146
    # already sorted!)....
1177
    unless ( $priority == 0 ) {
1147
    unless ( $priority == 0 ) {
1178
        _FixPriority( $biblionumber, $borrowernumber );
1148
        _FixPriority( $reserve_id );
1179
    }
1149
    }
1180
}
1150
}
1181
1151
Lines 1285-1291 sub ModReserveCancelAll { Link Here
1285
    my ( $itemnumber, $borrowernumber ) = @_;
1255
    my ( $itemnumber, $borrowernumber ) = @_;
1286
1256
1287
    #step 1 : cancel the reservation
1257
    #step 1 : cancel the reservation
1288
    my $CancelReserve = CancelReserve( undef, $itemnumber, $borrowernumber );
1258
    my $CancelReserve = CancelReserve({ itemnumber => $itemnumber, borrowernumber => $borrowernumber });
1289
1259
1290
    #step 2 launch the subroutine of the others reserves
1260
    #step 2 launch the subroutine of the others reserves
1291
    ( $messages, $nextreservinfo ) = GetOtherReserves($itemnumber);
1261
    ( $messages, $nextreservinfo ) = GetOtherReserves($itemnumber);
Lines 1297-1326 sub ModReserveCancelAll { Link Here
1297
1267
1298
  &ModReserveMinusPriority($itemnumber,$borrowernumber,$biblionumber)
1268
  &ModReserveMinusPriority($itemnumber,$borrowernumber,$biblionumber)
1299
1269
1300
Reduce the values of queuded list     
1270
Reduce the values of queued list
1301
1271
1302
=cut
1272
=cut
1303
1273
1304
sub ModReserveMinusPriority {
1274
sub ModReserveMinusPriority {
1305
    my ( $itemnumber, $borrowernumber, $biblionumber ) = @_;
1275
    my ( $itemnumber, $reserve_id ) = @_;
1306
1276
1307
    #first step update the value of the first person on reserv
1277
    #first step update the value of the first person on reserv
1308
    my $dbh   = C4::Context->dbh;
1278
    my $dbh   = C4::Context->dbh;
1309
    my $query = "
1279
    my $query = "
1310
        UPDATE reserves
1280
        UPDATE reserves
1311
        SET    priority = 0 , itemnumber = ? 
1281
        SET    priority = 0 , itemnumber = ? 
1312
        WHERE  borrowernumber=?
1282
        WHERE  reserve_id = ?
1313
          AND  biblionumber=?
1314
    ";
1283
    ";
1315
    my $sth_upd = $dbh->prepare($query);
1284
    my $sth_upd = $dbh->prepare($query);
1316
    $sth_upd->execute( $itemnumber, $borrowernumber, $biblionumber );
1285
    $sth_upd->execute( $itemnumber, $reserve_id );
1317
    # second step update all others reservs
1286
    # second step update all others reservs
1318
    _FixPriority($biblionumber, $borrowernumber, '0');
1287
    _FixPriority( $reserve_id, '0');
1319
}
1288
}
1320
1289
1321
=head2 GetReserveInfo
1290
=head2 GetReserveInfo
1322
1291
1323
  &GetReserveInfo($borrowernumber,$biblionumber);
1292
  &GetReserveInfo($reserve_id);
1324
1293
1325
Get item and borrower details for a current hold.
1294
Get item and borrower details for a current hold.
1326
Current implementation this query should have a single result.
1295
Current implementation this query should have a single result.
Lines 1328-1376 Current implementation this query should have a single result. Link Here
1328
=cut
1297
=cut
1329
1298
1330
sub GetReserveInfo {
1299
sub GetReserveInfo {
1331
	my ( $borrowernumber, $biblionumber ) = @_;
1300
    my ( $reserve_id ) = @_;
1332
    my $dbh = C4::Context->dbh;
1301
    my $dbh = C4::Context->dbh;
1333
	my $strsth="SELECT 
1302
    my $strsth="SELECT
1334
	               reservedate, 
1303
                   reserve_id,
1335
	               reservenotes, 
1304
                   reservedate, 
1336
	               reserves.borrowernumber,
1305
                   reservenotes, 
1337
				   reserves.biblionumber, 
1306
                   reserves.borrowernumber,
1338
				   reserves.branchcode,
1307
                   reserves.biblionumber, 
1339
				   reserves.waitingdate,
1308
                   reserves.branchcode,
1340
				   notificationdate, 
1309
                   reserves.waitingdate,
1341
				   reminderdate, 
1310
                   notificationdate, 
1342
				   priority, 
1311
                   reminderdate, 
1343
				   found,
1312
                   priority, 
1344
				   firstname, 
1313
                   found,
1345
				   surname, 
1314
                   firstname, 
1346
				   phone, 
1315
                   surname, 
1347
				   email, 
1316
                   phone, 
1348
				   address, 
1317
                   email, 
1349
				   address2,
1318
                   address, 
1350
				   cardnumber, 
1319
                   address2,
1351
				   city, 
1320
                   cardnumber, 
1352
				   zipcode,
1321
                   city, 
1353
				   biblio.title, 
1322
                   zipcode,
1354
				   biblio.author,
1323
                   biblio.title, 
1355
				   items.holdingbranch, 
1324
                   biblio.author,
1356
				   items.itemcallnumber, 
1325
                   items.holdingbranch, 
1357
				   items.itemnumber,
1326
                   items.itemcallnumber, 
1358
				   items.location, 
1327
                   items.itemnumber,
1359
				   barcode, 
1328
                   items.location, 
1360
				   notes
1329
                   barcode, 
1361
			FROM reserves 
1330
                   notes
1362
			 LEFT JOIN items USING(itemnumber) 
1331
                FROM reserves 
1363
		     LEFT JOIN borrowers USING(borrowernumber)
1332
                LEFT JOIN items USING(itemnumber) 
1364
		     LEFT JOIN biblio ON  (reserves.biblionumber=biblio.biblionumber) 
1333
                LEFT JOIN borrowers USING(borrowernumber)
1365
			WHERE 
1334
                LEFT JOIN biblio ON  (reserves.biblionumber=biblio.biblionumber)
1366
				reserves.borrowernumber=?
1335
                WHERE reserves.reserve_id = ?";
1367
				AND reserves.biblionumber=?";
1336
    my $sth = $dbh->prepare($strsth);
1368
	my $sth = $dbh->prepare($strsth); 
1337
    $sth->execute($reserve_id);
1369
	$sth->execute($borrowernumber,$biblionumber);
1370
1371
	my $data = $sth->fetchrow_hashref;
1372
	return $data;
1373
1338
1339
    my $data = $sth->fetchrow_hashref;
1340
    return $data;
1374
}
1341
}
1375
1342
1376
=head2 IsAvailableForItemLevelRequest
1343
=head2 IsAvailableForItemLevelRequest
Lines 1447-1453 sub IsAvailableForItemLevelRequest { Link Here
1447
1414
1448
=head2 AlterPriority
1415
=head2 AlterPriority
1449
1416
1450
  AlterPriority( $where, $borrowernumber, $biblionumber, $reservedate );
1417
  AlterPriority( $where, $reserve_id );
1451
1418
1452
This function changes a reserve's priority up, down, to the top, or to the bottom.
1419
This function changes a reserve's priority up, down, to the top, or to the bottom.
1453
Input: $where is 'up', 'down', 'top' or 'bottom'. Biblionumber, Date reserve was placed
1420
Input: $where is 'up', 'down', 'top' or 'bottom'. Biblionumber, Date reserve was placed
Lines 1455-1483 Input: $where is 'up', 'down', 'top' or 'bottom'. Biblionumber, Date reserve was Link Here
1455
=cut
1422
=cut
1456
1423
1457
sub AlterPriority {
1424
sub AlterPriority {
1458
    my ( $where, $borrowernumber, $biblionumber ) = @_;
1425
    my ( $where, $reserve_id ) = @_;
1459
1426
1460
    my $dbh = C4::Context->dbh;
1427
    my $dbh = C4::Context->dbh;
1461
1428
1462
    ## Find this reserve
1429
    my $reserve = GetReserve( $reserve_id );
1463
    my $sth = $dbh->prepare('SELECT * FROM reserves WHERE biblionumber = ? AND borrowernumber = ? AND cancellationdate IS NULL');
1464
    $sth->execute( $biblionumber, $borrowernumber );
1465
    my $reserve = $sth->fetchrow_hashref();
1466
    $sth->finish();
1467
1430
1468
    if ( $where eq 'up' || $where eq 'down' ) {
1431
    if ( $where eq 'up' || $where eq 'down' ) {
1469
    
1432
    
1470
      my $priority = $reserve->{'priority'};        
1433
      my $priority = $reserve->{'priority'};        
1471
      $priority = $where eq 'up' ? $priority - 1 : $priority + 1;
1434
      $priority = $where eq 'up' ? $priority - 1 : $priority + 1;
1472
      _FixPriority( $biblionumber, $borrowernumber, $priority )
1435
      _FixPriority( $reserve_id, $priority )
1473
1436
1474
    } elsif ( $where eq 'top' ) {
1437
    } elsif ( $where eq 'top' ) {
1475
1438
1476
      _FixPriority( $biblionumber, $borrowernumber, '1' )
1439
      _FixPriority( $reserve_id, '1' )
1477
1440
1478
    } elsif ( $where eq 'bottom' ) {
1441
    } elsif ( $where eq 'bottom' ) {
1479
1442
1480
      _FixPriority( $biblionumber, $borrowernumber, '999999' )
1443
      _FixPriority( $reserve_id, '999999' )
1481
1444
1482
    }
1445
    }
1483
}
1446
}
Lines 1491-1517 This function sets the lowestPriority field to true if is false, and false if it Link Here
1491
=cut
1454
=cut
1492
1455
1493
sub ToggleLowestPriority {
1456
sub ToggleLowestPriority {
1494
    my ( $borrowernumber, $biblionumber ) = @_;
1457
    my ( $reserve_id ) = @_;
1495
1458
1496
    my $dbh = C4::Context->dbh;
1459
    my $dbh = C4::Context->dbh;
1497
1460
1498
    my $sth = $dbh->prepare(
1461
    my $sth = $dbh->prepare( "UPDATE reserves SET lowestPriority = NOT lowestPriority WHERE reserve_id = ?");
1499
        "UPDATE reserves SET lowestPriority = NOT lowestPriority
1462
    $sth->execute( $reserve_id );
1500
         WHERE biblionumber = ?
1501
         AND borrowernumber = ?"
1502
    );
1503
    $sth->execute(
1504
        $biblionumber,
1505
        $borrowernumber,
1506
    );
1507
    $sth->finish;
1463
    $sth->finish;
1508
    
1464
    
1509
    _FixPriority( $biblionumber, $borrowernumber, '999999' );
1465
    _FixPriority( $reserve_id, '999999' );
1510
}
1466
}
1511
1467
1512
=head2 ToggleSuspend
1468
=head2 ToggleSuspend
1513
1469
1514
  ToggleSuspend( $borrowernumber, $biblionumber );
1470
  ToggleSuspend( $reserve_id );
1515
1471
1516
This function sets the suspend field to true if is false, and false if it is true.
1472
This function sets the suspend field to true if is false, and false if it is true.
1517
If the reserve is currently suspended with a suspend_until date, that date will
1473
If the reserve is currently suspended with a suspend_until date, that date will
Lines 1520-1526 be cleared when it is unsuspended. Link Here
1520
=cut
1476
=cut
1521
1477
1522
sub ToggleSuspend {
1478
sub ToggleSuspend {
1523
    my ( $borrowernumber, $biblionumber, $suspend_until ) = @_;
1479
    my ( $reserve_id, $suspend_until ) = @_;
1524
1480
1525
    $suspend_until = output_pref( dt_from_string( $suspend_until ), 'iso' ) if ( $suspend_until );
1481
    $suspend_until = output_pref( dt_from_string( $suspend_until ), 'iso' ) if ( $suspend_until );
1526
1482
Lines 1531-1544 sub ToggleSuspend { Link Here
1531
    my $sth = $dbh->prepare(
1487
    my $sth = $dbh->prepare(
1532
        "UPDATE reserves SET suspend = NOT suspend,
1488
        "UPDATE reserves SET suspend = NOT suspend,
1533
        suspend_until = CASE WHEN suspend = 0 THEN NULL ELSE $do_until END
1489
        suspend_until = CASE WHEN suspend = 0 THEN NULL ELSE $do_until END
1534
        WHERE biblionumber = ?
1490
        WHERE reserve_id = ?
1535
        AND borrowernumber = ?
1536
    ");
1491
    ");
1537
1492
1538
    my @params;
1493
    my @params;
1539
    push( @params, $suspend_until ) if ( $suspend_until );
1494
    push( @params, $suspend_until ) if ( $suspend_until );
1540
    push( @params, $biblionumber );
1495
    push( @params, $reserve_id );
1541
    push( @params, $borrowernumber );
1542
1496
1543
    $sth->execute( @params );
1497
    $sth->execute( @params );
1544
    $sth->finish;
1498
    $sth->finish;
Lines 1603-1609 sub SuspendAll { Link Here
1603
1557
1604
=head2 _FixPriority
1558
=head2 _FixPriority
1605
1559
1606
  &_FixPriority($biblio,$borrowernumber,$rank,$ignoreSetLowestRank);
1560
  &_FixPriority( $reserve_id, $rank, $ignoreSetLowestRank);
1607
1561
1608
Only used internally (so don't export it)
1562
Only used internally (so don't export it)
1609
Changed how this functions works #
1563
Changed how this functions works #
Lines 1615-1655 in new priority rank Link Here
1615
=cut 
1569
=cut 
1616
1570
1617
sub _FixPriority {
1571
sub _FixPriority {
1618
    my ( $biblio, $borrowernumber, $rank, $ignoreSetLowestRank ) = @_;
1572
    my ( $reserve_id, $rank, $ignoreSetLowestRank ) = @_;
1619
    my $dbh = C4::Context->dbh;
1573
    my $dbh = C4::Context->dbh;
1620
     if ( $rank eq "del" ) {
1574
1621
         CancelReserve( $biblio, undef, $borrowernumber );
1575
    my $res = GetReserve( $reserve_id );
1622
     }
1576
1623
    if ( $rank eq "W" || $rank eq "0" ) {
1577
    if ( $rank eq "del" ) {
1578
         CancelReserve({ reserve_id => $reserve_id });
1579
    }
1580
    elsif ( $rank eq "W" || $rank eq "0" ) {
1624
1581
1625
        # make sure priority for waiting or in-transit items is 0
1582
        # make sure priority for waiting or in-transit items is 0
1626
        my $query = qq/
1583
        my $query = "
1627
            UPDATE reserves
1584
            UPDATE reserves
1628
            SET    priority = 0
1585
            SET    priority = 0
1629
            WHERE biblionumber = ?
1586
            WHERE reserve_id = ?
1630
              AND borrowernumber = ?
1587
            AND found IN ('W', 'T')
1631
              AND found IN ('W', 'T')
1588
        ";
1632
        /;
1633
        my $sth = $dbh->prepare($query);
1589
        my $sth = $dbh->prepare($query);
1634
        $sth->execute( $biblio, $borrowernumber );
1590
        $sth->execute( $reserve_id );
1635
    }
1591
    }
1636
    my @priority;
1592
    my @priority;
1637
    my @reservedates;
1593
    my @reservedates;
1638
1594
1639
    # get whats left
1595
    # get whats left
1640
# FIXME adding a new security in returned elements for changing priority,
1596
    my $query = "
1641
# now, we don't care anymore any reservations with itemnumber linked (suppose a waiting reserve)
1597
        SELECT reserve_id, borrowernumber, reservedate, constrainttype
1642
	# This is wrong a waiting reserve has W set
1643
	# The assumption that having an itemnumber set means waiting is wrong and should be corrected any place it occurs
1644
    my $query = qq/
1645
        SELECT borrowernumber, reservedate, constrainttype
1646
        FROM   reserves
1598
        FROM   reserves
1647
        WHERE  biblionumber   = ?
1599
        WHERE  biblionumber   = ?
1648
          AND  ((found <> 'W' AND found <> 'T') or found is NULL)
1600
          AND  ((found <> 'W' AND found <> 'T') OR found IS NULL)
1649
        ORDER BY priority ASC
1601
        ORDER BY priority ASC
1650
    /;
1602
    ";
1651
    my $sth = $dbh->prepare($query);
1603
    my $sth = $dbh->prepare($query);
1652
    $sth->execute($biblio);
1604
    $sth->execute( $res->{'biblionumber'} );
1653
    while ( my $line = $sth->fetchrow_hashref ) {
1605
    while ( my $line = $sth->fetchrow_hashref ) {
1654
        push( @reservedates, $line );
1606
        push( @reservedates, $line );
1655
        push( @priority,     $line );
1607
        push( @priority,     $line );
Lines 1659-1665 sub _FixPriority { Link Here
1659
    my $i;
1611
    my $i;
1660
    my $key = -1;    # to allow for 0 to be a valid result
1612
    my $key = -1;    # to allow for 0 to be a valid result
1661
    for ( $i = 0 ; $i < @priority ; $i++ ) {
1613
    for ( $i = 0 ; $i < @priority ; $i++ ) {
1662
        if ( $borrowernumber == $priority[$i]->{'borrowernumber'} ) {
1614
        if ( $reserve_id == $priority[$i]->{'reserve_id'} ) {
1663
            $key = $i;    # save the index
1615
            $key = $i;    # save the index
1664
            last;
1616
            last;
1665
        }
1617
        }
Lines 1675-1703 sub _FixPriority { Link Here
1675
1627
1676
    # now fix the priority on those that are left....
1628
    # now fix the priority on those that are left....
1677
    $query = "
1629
    $query = "
1678
            UPDATE reserves
1630
        UPDATE reserves
1679
            SET    priority = ?
1631
        SET    priority = ?
1680
                WHERE  biblionumber = ?
1632
        WHERE  reserve_id = ?
1681
                 AND borrowernumber   = ?
1682
                 AND reservedate = ?
1683
         AND found IS NULL
1684
    ";
1633
    ";
1685
    $sth = $dbh->prepare($query);
1634
    $sth = $dbh->prepare($query);
1686
    for ( my $j = 0 ; $j < @priority ; $j++ ) {
1635
    for ( my $j = 0 ; $j < @priority ; $j++ ) {
1687
        $sth->execute(
1636
        $sth->execute(
1688
            $j + 1, $biblio,
1637
            $j + 1,
1689
            $priority[$j]->{'borrowernumber'},
1638
            $priority[$j]->{'reserve_id'}
1690
            $priority[$j]->{'reservedate'}
1691
        );
1639
        );
1692
        $sth->finish;
1640
        $sth->finish;
1693
    }
1641
    }
1694
    
1642
    
1695
    $sth = $dbh->prepare( "SELECT borrowernumber FROM reserves WHERE lowestPriority = 1 ORDER BY priority" );
1643
    $sth = $dbh->prepare( "SELECT reserve_id FROM reserves WHERE lowestPriority = 1 ORDER BY priority" );
1696
    $sth->execute();
1644
    $sth->execute();
1697
    
1645
    
1698
    unless ( $ignoreSetLowestRank ) {
1646
    unless ( $ignoreSetLowestRank ) {
1699
      while ( my $res = $sth->fetchrow_hashref() ) {
1647
      while ( my $res = $sth->fetchrow_hashref() ) {
1700
        _FixPriority( $biblio, $res->{'borrowernumber'}, '999999', 1 );
1648
        _FixPriority( $res->{'reserve_id'}, '999999', 1 );
1701
      }
1649
      }
1702
    }
1650
    }
1703
}
1651
}
Lines 1736-1742 sub _Findgroupreserve { Link Here
1736
               reserves.priority            AS priority,
1684
               reserves.priority            AS priority,
1737
               reserves.timestamp           AS timestamp,
1685
               reserves.timestamp           AS timestamp,
1738
               biblioitems.biblioitemnumber AS biblioitemnumber,
1686
               biblioitems.biblioitemnumber AS biblioitemnumber,
1739
               reserves.itemnumber          AS itemnumber
1687
               reserves.itemnumber          AS itemnumber,
1688
               reserves.reserve_id          AS reserve_id,
1740
        FROM reserves
1689
        FROM reserves
1741
        JOIN biblioitems USING (biblionumber)
1690
        JOIN biblioitems USING (biblionumber)
1742
        JOIN hold_fill_targets USING (biblionumber, borrowernumber, itemnumber)
1691
        JOIN hold_fill_targets USING (biblionumber, borrowernumber, itemnumber)
Lines 2011-2018 sub MoveReserve { Link Here
2011
            RevertWaitingStatus({ itemnumber => $itemnumber });
1960
            RevertWaitingStatus({ itemnumber => $itemnumber });
2012
        }
1961
        }
2013
        elsif ( $cancelreserve eq 'cancel' || $cancelreserve ) { # cancel reserves on this item
1962
        elsif ( $cancelreserve eq 'cancel' || $cancelreserve ) { # cancel reserves on this item
2014
            CancelReserve(0, $res->{'itemnumber'}, $res->{'borrowernumber'});
1963
            CancelReserve({
2015
            CancelReserve($res->{'biblionumber'}, 0, $res->{'borrowernumber'});
1964
                biblionumber   => $res->{'biblionumber'},
1965
                itemnumber     => $res->{'itemnumber'},
1966
                borrowernumber => $res->{'borrowernumber'}
1967
            });
2016
        }
1968
        }
2017
    }
1969
    }
2018
}
1970
}
Lines 2028-2034 This shifts the holds from C<$from_biblio> to C<$to_biblio> and reorders them by Link Here
2028
sub MergeHolds {
1980
sub MergeHolds {
2029
    my ( $dbh, $to_biblio, $from_biblio ) = @_;
1981
    my ( $dbh, $to_biblio, $from_biblio ) = @_;
2030
    my $sth = $dbh->prepare(
1982
    my $sth = $dbh->prepare(
2031
        "SELECT count(*) as reservenumber FROM reserves WHERE biblionumber = ?"
1983
        "SELECT count(*) as reserve_id FROM reserves WHERE biblionumber = ?"
2032
    );
1984
    );
2033
    $sth->execute($from_biblio);
1985
    $sth->execute($from_biblio);
2034
    if ( my $data = $sth->fetchrow_hashref() ) {
1986
    if ( my $data = $sth->fetchrow_hashref() ) {
Lines 2121-2126 sub RevertWaitingStatus { Link Here
2121
    return $sth->execute( $reserve->{'reserve_id'} );
2073
    return $sth->execute( $reserve->{'reserve_id'} );
2122
}
2074
}
2123
2075
2076
=head2 GetReserveId
2077
2078
  $reserve_id = GetReserveId({ biblionumber => $biblionumber, borrowernumber => $borrowernumber [, itemnumber => $itemnumber ] });
2079
2080
  Returnes the first reserve id that matches the given criteria
2081
2082
=cut
2083
2084
sub GetReserveId {
2085
    my ( $params ) = @_;
2086
2087
    return unless ( ( $params->{'biblionumber'} || $params->{'itemnumber'} ) && $params->{'borrowernumber'} );
2088
2089
    my $dbh = C4::Context->dbh();
2090
2091
    my $sql = "SELECT reserve_id FROM reserves WHERE ";
2092
2093
    my @params;
2094
    my @limits;
2095
    foreach my $key ( keys %$params ) {
2096
        if ( defined( $params->{$key} ) ) {
2097
            push( @limits, "$key = ?" );
2098
            push( @params, $params->{$key} );
2099
        }
2100
    }
2101
2102
    $sql .= join( " AND ", @limits );
2103
2104
    my $sth = $dbh->prepare( $sql );
2105
    $sth->execute( @params );
2106
    my $row = $sth->fetchrow_hashref();
2107
2108
    return $row->{'reserve_id'};
2109
}
2110
2124
=head2 ReserveSlip
2111
=head2 ReserveSlip
2125
2112
2126
  ReserveSlip($branchcode, $borrowernumber, $biblionumber)
2113
  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 353-359 if ($borrowernumber) { Link Here
353
        $getreserv{nottransfered} = 0;
353
        $getreserv{nottransfered} = 0;
354
354
355
        $getreserv{reservedate}    = format_date( $num_res->{'reservedate'} );
355
        $getreserv{reservedate}    = format_date( $num_res->{'reservedate'} );
356
        $getreserv{reservenumber}  = $num_res->{'reservenumber'};
356
        $getreserv{reserve_id}  = $num_res->{'reserve_id'};
357
        $getreserv{title}          = $getiteminfo->{'title'};
357
        $getreserv{title}          = $getiteminfo->{'title'};
358
        $getreserv{itemtype}       = $itemtypeinfo->{'description'};
358
        $getreserv{itemtype}       = $itemtypeinfo->{'description'};
359
        $getreserv{author}         = $getiteminfo->{'author'};
359
        $getreserv{author}         = $getiteminfo->{'author'};
(-)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 / +37 lines)
Lines 99-120 $action ||= q{}; Link Here
99
99
100
if ( $action eq 'move' ) {
100
if ( $action eq 'move' ) {
101
  my $where = $input->param('where');
101
  my $where = $input->param('where');
102
  my $borrowernumber = $input->param('borrowernumber');
102
  my $reserve_id = $input->param('reserve_id');
103
  my $biblionumber = $input->param('biblionumber');
103
  AlterPriority( $where, $reserve_id );
104
  AlterPriority( $where, $borrowernumber, $biblionumber );
105
} elsif ( $action eq 'cancel' ) {
104
} elsif ( $action eq 'cancel' ) {
106
  my $borrowernumber = $input->param('borrowernumber');
105
  my $reserve_id = $input->param('reserve_id');
107
  my $biblionumber = $input->param('biblionumber');
106
  CancelReserve({ reserve_id => $reserve_id });
108
  CancelReserve( $biblionumber, '', $borrowernumber );
109
} elsif ( $action eq 'setLowestPriority' ) {
107
} elsif ( $action eq 'setLowestPriority' ) {
110
  my $borrowernumber = $input->param('borrowernumber');
108
  my $reserve_id = $input->param('reserve_id');
111
  my $biblionumber   = $input->param('biblionumber');
109
  ToggleLowestPriority( $reserve_id );
112
  ToggleLowestPriority( $borrowernumber, $biblionumber );
113
} elsif ( $action eq 'toggleSuspend' ) {
110
} elsif ( $action eq 'toggleSuspend' ) {
114
  my $borrowernumber = $input->param('borrowernumber');
111
  my $reserve_id = $input->param('reserve_id');
115
  my $biblionumber   = $input->param('biblionumber');
116
  my $suspend_until  = $input->param('suspend_until');
112
  my $suspend_until  = $input->param('suspend_until');
117
  ToggleSuspend( $borrowernumber, $biblionumber, $suspend_until );
113
  ToggleSuspend( $reserve_id, $suspend_until );
118
}
114
}
119
115
120
if ($findborrower) {
116
if ($findborrower) {
Lines 148-154 if ($borrowernumber_hold && !$action) { Link Here
148
      GetReserveCount( $borrowerinfo->{'borrowernumber'} );
144
      GetReserveCount( $borrowerinfo->{'borrowernumber'} );
149
145
150
    if ( C4::Context->preference('maxreserves') && ($number_reserves >= C4::Context->preference('maxreserves')) ) {
146
    if ( C4::Context->preference('maxreserves') && ($number_reserves >= C4::Context->preference('maxreserves')) ) {
151
		$warnings = 1;
147
       $warnings = 1;
152
        $maxreserves = 1;
148
        $maxreserves = 1;
153
    }
149
    }
154
150
Lines 162-168 if ($borrowernumber_hold && !$action) { Link Here
162
158
163
    # check if the borrower make the reserv in a different branch
159
    # check if the borrower make the reserv in a different branch
164
    if ( $borrowerinfo->{'branchcode'} ne C4::Context->userenv->{'branch'} ) {
160
    if ( $borrowerinfo->{'branchcode'} ne C4::Context->userenv->{'branch'} ) {
165
		$messages = 1;
161
      $messages = 1;
166
        $diffbranch = 1;
162
        $diffbranch = 1;
167
    }
163
    }
168
164
Lines 184-191 if ($borrowernumber_hold && !$action) { Link Here
184
                maxreserves         => $maxreserves,
180
                maxreserves         => $maxreserves,
185
                expiry              => $expiry,
181
                expiry              => $expiry,
186
                diffbranch          => $diffbranch,
182
                diffbranch          => $diffbranch,
187
				messages            => $messages,
183
                messages            => $messages,
188
				warnings            => $warnings
184
                warnings            => $warnings
189
    );
185
    );
190
}
186
}
191
187
Lines 225-230 if ($borrowerslist) { Link Here
225
221
226
# FIXME launch another time GetMember perhaps until
222
# FIXME launch another time GetMember perhaps until
227
my $borrowerinfo = GetMember( borrowernumber => $borrowernumber_hold );
223
my $borrowerinfo = GetMember( borrowernumber => $borrowernumber_hold );
224
my $max_holds_per_record = C4::Context->preference('MaxHoldsPerRecord');
228
225
229
my @biblionumbers = ();
226
my @biblionumbers = ();
230
my $biblionumbers = $input->param('biblionumbers');
227
my $biblionumbers = $input->param('biblionumbers');
Lines 239-250 my @biblioloop = (); Link Here
239
foreach my $biblionumber (@biblionumbers) {
236
foreach my $biblionumber (@biblionumbers) {
240
237
241
    my %biblioloopiter = ();
238
    my %biblioloopiter = ();
242
	my $maxreserves;
239
    my $maxreserves;
243
240
244
    my $dat          = GetBiblioData($biblionumber);
241
    my $dat = GetBiblioData($biblionumber);
245
242
246
    unless ( CanBookBeReserved($borrowerinfo->{borrowernumber}, $biblionumber) ) {
243
    unless ( CanBookBeReserved($borrowerinfo->{borrowernumber}, $biblionumber) ) {
247
		$warnings = 1;
244
        $warnings = 1;
248
        $maxreserves = 1;
245
        $maxreserves = 1;
249
    }
246
    }
250
247
Lines 257-263 foreach my $biblionumber (@biblionumbers) { Link Here
257
    # get existing reserves .....
254
    # get existing reserves .....
258
    my ( $count, $reserves ) = GetReservesFromBiblionumber($biblionumber,1);
255
    my ( $count, $reserves ) = GetReservesFromBiblionumber($biblionumber,1);
259
    my $totalcount = $count;
256
    my $totalcount = $count;
260
    my $alreadyreserved;
257
    my $holds_count = 0;
258
    my $alreadyreserved = 0;
261
259
262
    foreach my $res (@$reserves) {
260
    foreach my $res (@$reserves) {
263
        if ( defined $res->{found} && $res->{found} eq 'W' ) {
261
        if ( defined $res->{found} && $res->{found} eq 'W' ) {
Lines 265-284 foreach my $biblionumber (@biblionumbers) { Link Here
265
        }
263
        }
266
264
267
        if ( defined $borrowerinfo && ($borrowerinfo->{borrowernumber} eq $res->{borrowernumber}) ) {
265
        if ( defined $borrowerinfo && ($borrowerinfo->{borrowernumber} eq $res->{borrowernumber}) ) {
268
            $warnings = 1;
266
            $holds_count++;
267
        }
268
    }
269
270
    if ( $holds_count >= $max_holds_per_record ) {
269
            $alreadyreserved = 1;
271
            $alreadyreserved = 1;
272
            $warnings = 1;
270
            $biblioloopiter{warn} = 1;
273
            $biblioloopiter{warn} = 1;
271
            $biblioloopiter{alreadyres} = 1;
274
            $biblioloopiter{alreadyres} = 1;
272
        }
273
    }
275
    }
274
276
275
    $template->param( alreadyreserved => $alreadyreserved,
277
    $template->param( alreadyreserved => $alreadyreserved,
276
                      messages => $messages,
278
        messages          => $messages,
277
                      warnings => $warnings,
279
        warnings          => $warnings,
278
                 maxreserves=>$maxreserves,
280
        maxreserves       => $maxreserves,
279
                     alreadypossession => $alreadypossession,
281
        alreadypossession => $alreadypossession,
280
					  );
282
    );
281
282
283
283
    # FIXME think @optionloop, is maybe obsolete, or  must be switchable by a systeme preference fixed rank or not
284
    # FIXME think @optionloop, is maybe obsolete, or  must be switchable by a systeme preference fixed rank or not
284
    # make priorities options
285
    # make priorities options
Lines 304-314 foreach my $biblionumber (@biblionumbers) { Link Here
304
    if (my $items = get_itemnumbers_of($biblionumber)->{$biblionumber}){
305
    if (my $items = get_itemnumbers_of($biblionumber)->{$biblionumber}){
305
        @itemnumbers  = @$items;
306
        @itemnumbers  = @$items;
306
    }
307
    }
307
	my @hostitems = get_hostitemnumbers_of($biblionumber);
308
    my @hostitems = get_hostitemnumbers_of($biblionumber);
308
	if (@hostitems){
309
    if (@hostitems){
309
		$template->param('hostitemsflag' => 1);
310
        $template->param('hostitemsflag' => 1);
310
		push(@itemnumbers, @hostitems);
311
        push(@itemnumbers, @hostitems);
311
	}
312
    }
312
313
313
    if (!@itemnumbers) {
314
    if (!@itemnumbers) {
314
        $template->param('noitems' => 1);
315
        $template->param('noitems' => 1);
Lines 386-392 foreach my $biblionumber (@biblionumbers) { Link Here
386
            }
387
            }
387
388
388
            # checking reserve
389
            # checking reserve
389
            my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($itemnumber);
390
            my ($reservedate,$reservedfor,$expectedAt,$reserve_id) = GetReservesFromItemnumber($itemnumber);
390
            my $ItemBorrowerReserveInfo = GetMember( borrowernumber => $reservedfor );
391
            my $ItemBorrowerReserveInfo = GetMember( borrowernumber => $reservedfor );
391
392
392
            if ( defined $reservedate ) {
393
            if ( defined $reservedate ) {
Lines 583-588 foreach my $biblionumber (@biblionumbers) { Link Here
583
        $reserve{'optionloop'} = \@optionloop;
584
        $reserve{'optionloop'} = \@optionloop;
584
        $reserve{'suspend'} = $res->{'suspend'};
585
        $reserve{'suspend'} = $res->{'suspend'};
585
        $reserve{'suspend_until'} = $res->{'suspend_until'};
586
        $reserve{'suspend_until'} = $res->{'suspend_until'};
587
        $reserve{'reserve_id'} = $res->{'reserve_id'};
588
586
        push( @reserveloop, \%reserve );
589
        push( @reserveloop, \%reserve );
587
    }
590
    }
588
591
(-)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