|
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-249
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) = &GetReserves($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 417-425
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; |
|
|
443 |
my $multi_holds_allowed_same = 0; |
| 444 |
my $multi_holds_allowed_diff = 0; |
| 423 |
|
445 |
|
| 424 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
446 |
my $controlbranch = C4::Context->preference('ReservesControlBranch'); |
| 425 |
my $itype = C4::Context->preference('item-level_itypes') ? "itype" : "itemtype"; |
447 |
my $itype = C4::Context->preference('item-level_itypes') ? "itype" : "itemtype"; |
|
Lines 428-454
sub CanItemBeReserved{
Link Here
|
| 428 |
my $item = GetItem($itemnumber); |
450 |
my $item = GetItem($itemnumber); |
| 429 |
my $borrower = C4::Members::GetMember('borrowernumber'=>$borrowernumber); |
451 |
my $borrower = C4::Members::GetMember('borrowernumber'=>$borrowernumber); |
| 430 |
|
452 |
|
| 431 |
# we retrieve user rights on this itemtype and branchcode |
453 |
my $querycount = " |
| 432 |
my $sth = $dbh->prepare("SELECT categorycode, itemtype, branchcode, reservesallowed |
454 |
SELECT count(*) AS count |
| 433 |
FROM issuingrules |
455 |
FROM reserves |
| 434 |
WHERE (categorycode in (?,'*') ) |
456 |
LEFT JOIN items USING (itemnumber) |
| 435 |
AND (itemtype IN (?,'*')) |
457 |
LEFT JOIN biblioitems ON (reserves.biblionumber=biblioitems.biblionumber) |
| 436 |
AND (branchcode IN (?,'*')) |
458 |
LEFT JOIN borrowers USING (borrowernumber) |
| 437 |
ORDER BY |
459 |
WHERE borrowernumber = ? |
| 438 |
categorycode DESC, |
460 |
"; |
| 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 |
|
461 |
|
| 453 |
my $itemtype = $item->{$itype}; |
462 |
my $itemtype = $item->{$itype}; |
| 454 |
my $categorycode = $borrower->{categorycode}; |
463 |
my $categorycode = $borrower->{categorycode}; |
|
Lines 464-471
sub CanItemBeReserved{
Link Here
|
| 464 |
} |
473 |
} |
| 465 |
|
474 |
|
| 466 |
# we retrieve rights |
475 |
# we retrieve rights |
| 467 |
$sth->execute($categorycode, $itemtype, $branchcode); |
476 |
my $rights = C4::Circulation::GetIssuingRule( $categorycode, $itemtype, $branchcode ); |
| 468 |
if(my $rights = $sth->fetchrow_hashref()){ |
477 |
if ( defined $rights ) { |
| 469 |
$itemtype = $rights->{itemtype}; |
478 |
$itemtype = $rights->{itemtype}; |
| 470 |
$allowedreserves = $rights->{reservesallowed}; |
479 |
$allowedreserves = $rights->{reservesallowed}; |
| 471 |
}else{ |
480 |
}else{ |
|
Lines 489-500
sub CanItemBeReserved{
Link Here
|
| 489 |
if(my $rowcount = $sthcount->fetchrow_hashref()){ |
498 |
if(my $rowcount = $sthcount->fetchrow_hashref()){ |
| 490 |
$reservecount = $rowcount->{count}; |
499 |
$reservecount = $rowcount->{count}; |
| 491 |
} |
500 |
} |
| 492 |
|
|
|
| 493 |
# we check if it's ok or not |
501 |
# we check if it's ok or not |
| 494 |
if( $reservecount < $allowedreserves ){ |
502 |
if( $reservecount >= $allowedreserves ){ ## too many reserves |
| 495 |
return 1; |
|
|
| 496 |
}else{ |
| 497 |
return 0; |
503 |
return 0; |
|
|
504 |
}else{ |
| 505 |
return 1; |
| 498 |
} |
506 |
} |
| 499 |
} |
507 |
} |
| 500 |
#-------------------------------------------------------------------------------- |
508 |
#-------------------------------------------------------------------------------- |
|
Lines 511-521
sub GetReserveCount {
Link Here
|
| 511 |
|
519 |
|
| 512 |
my $dbh = C4::Context->dbh; |
520 |
my $dbh = C4::Context->dbh; |
| 513 |
|
521 |
|
| 514 |
my $query = ' |
522 |
my $query = " |
| 515 |
SELECT COUNT(*) AS counter |
523 |
SELECT COUNT(*) AS counter |
| 516 |
FROM reserves |
524 |
FROM reserves |
| 517 |
WHERE borrowernumber = ? |
525 |
WHERE borrowernumber = ? |
| 518 |
'; |
526 |
"; |
| 519 |
my $sth = $dbh->prepare($query); |
527 |
my $sth = $dbh->prepare($query); |
| 520 |
$sth->execute($borrowernumber); |
528 |
$sth->execute($borrowernumber); |
| 521 |
my $row = $sth->fetchrow_hashref; |
529 |
my $row = $sth->fetchrow_hashref; |
|
Lines 687-693
sub GetReservesToBranch {
Link Here
|
| 687 |
my ( $frombranch ) = @_; |
695 |
my ( $frombranch ) = @_; |
| 688 |
my $dbh = C4::Context->dbh; |
696 |
my $dbh = C4::Context->dbh; |
| 689 |
my $sth = $dbh->prepare( |
697 |
my $sth = $dbh->prepare( |
| 690 |
"SELECT borrowernumber,reservedate,itemnumber,timestamp |
698 |
"SELECT reserve_id,borrowernumber,reservedate,itemnumber,timestamp |
| 691 |
FROM reserves |
699 |
FROM reserves |
| 692 |
WHERE priority='0' |
700 |
WHERE priority='0' |
| 693 |
AND branchcode=?" |
701 |
AND branchcode=?" |
|
Lines 710-731
sub GetReservesToBranch {
Link Here
|
| 710 |
|
718 |
|
| 711 |
sub GetReservesForBranch { |
719 |
sub GetReservesForBranch { |
| 712 |
my ($frombranch) = @_; |
720 |
my ($frombranch) = @_; |
| 713 |
my $dbh = C4::Context->dbh; |
721 |
my $dbh = C4::Context->dbh; |
| 714 |
my $query = "SELECT borrowernumber,reservedate,itemnumber,waitingdate |
722 |
|
|
|
723 |
my $query = " |
| 724 |
SELECT reserve_id,borrowernumber,reservedate,itemnumber,waitingdate |
| 715 |
FROM reserves |
725 |
FROM reserves |
| 716 |
WHERE priority='0' |
726 |
WHERE priority='0' |
| 717 |
AND found='W' "; |
727 |
AND found='W' |
| 718 |
if ($frombranch){ |
728 |
"; |
| 719 |
$query .= " AND branchcode=? "; |
729 |
$query .= " AND branchcode=? " if ( $frombranch ); |
| 720 |
} |
|
|
| 721 |
$query .= "ORDER BY waitingdate" ; |
730 |
$query .= "ORDER BY waitingdate" ; |
|
|
731 |
|
| 722 |
my $sth = $dbh->prepare($query); |
732 |
my $sth = $dbh->prepare($query); |
| 723 |
if ($frombranch){ |
733 |
if ($frombranch){ |
| 724 |
$sth->execute($frombranch); |
734 |
$sth->execute($frombranch); |
| 725 |
} |
735 |
} else { |
| 726 |
else { |
736 |
$sth->execute(); |
| 727 |
$sth->execute(); |
737 |
} |
| 728 |
} |
738 |
|
| 729 |
my @transreserv; |
739 |
my @transreserv; |
| 730 |
my $i = 0; |
740 |
my $i = 0; |
| 731 |
while ( my $data = $sth->fetchrow_hashref ) { |
741 |
while ( my $data = $sth->fetchrow_hashref ) { |
|
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 ); |
| 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 |
|
|
| 931 |
cancel, but not both: if both are given, C<&CancelReserve> uses |
| 932 |
C<$itemnumber>. |
| 933 |
|
| 934 |
C<$borrowernumber> is the borrower number of the patron on whose |
| 935 |
behalf the book was reserved. |
| 936 |
|
| 937 |
If C<$biblionumber> was given, C<&CancelReserve> also adjusts the |
| 938 |
priorities of the other people who are waiting on the book. |
| 939 |
|
| 940 |
=cut |
940 |
=cut |
| 941 |
|
941 |
|
| 942 |
sub CancelReserve { |
942 |
sub CancelReserve { |
| 943 |
my ( $biblio, $item, $borr ) = @_; |
943 |
my ( $reserve_id ) = @_; |
| 944 |
my $dbh = C4::Context->dbh; |
944 |
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 |
|
945 |
|
| 1004 |
$query = qq/ |
946 |
my $query = " |
| 1005 |
INSERT INTO old_reserves |
947 |
UPDATE reserves |
| 1006 |
SELECT * FROM reserves |
948 |
SET cancellationdate = now(), |
| 1007 |
WHERE biblionumber = ? |
949 |
found = Null, |
| 1008 |
AND borrowernumber = ? |
950 |
priority = 0 |
| 1009 |
/; |
951 |
WHERE reserve_id = ? |
| 1010 |
$sth = $dbh->prepare($query); |
952 |
"; |
| 1011 |
$sth->execute( $biblio, $borr ); |
953 |
my $sth = $dbh->prepare($query); |
|
|
954 |
$sth->execute( $reserve_id ); |
| 955 |
$sth->finish; |
| 1012 |
|
956 |
|
| 1013 |
$query = qq/ |
957 |
$query = " |
| 1014 |
DELETE FROM reserves |
958 |
INSERT INTO old_reserves |
| 1015 |
WHERE biblionumber = ? |
959 |
SELECT * FROM reserves |
| 1016 |
AND borrowernumber = ? |
960 |
WHERE reserve_id = ? |
| 1017 |
/; |
961 |
"; |
| 1018 |
$sth = $dbh->prepare($query); |
962 |
$sth = $dbh->prepare($query); |
| 1019 |
$sth->execute( $biblio, $borr ); |
963 |
$sth->execute( $reserve_id ); |
| 1020 |
|
964 |
|
| 1021 |
# now fix the priority on the others.... |
965 |
$query = " |
| 1022 |
_FixPriority( $biblio, $borr ); |
966 |
DELETE FROM reserves |
| 1023 |
} |
967 |
WHERE reserve_id = ? |
|
|
968 |
"; |
| 969 |
$sth = $dbh->prepare($query); |
| 970 |
$sth->execute( $reserve_id ); |
| 971 |
|
| 972 |
# now fix the priority on the others.... |
| 973 |
_FixPriority( $reserve_id ); |
| 1024 |
} |
974 |
} |
| 1025 |
|
975 |
|
| 1026 |
=head2 ModReserve |
976 |
=head2 ModReserve |
| 1027 |
|
977 |
|
| 1028 |
ModReserve($rank, $biblio, $borrower, $branch[, $itemnumber]) |
978 |
ModReserve($rank, $reserve_id, $branch[, $itemnumber]) |
| 1029 |
|
979 |
|
| 1030 |
Change a hold request's priority or cancel it. |
980 |
Change a hold request's priority or cancel it. |
| 1031 |
|
981 |
|
|
Lines 1056-1113
itemnumber and supplying itemnumber.
Link Here
|
| 1056 |
|
1006 |
|
| 1057 |
sub ModReserve { |
1007 |
sub ModReserve { |
| 1058 |
#subroutine to update a reserve |
1008 |
#subroutine to update a reserve |
| 1059 |
my ( $rank, $biblio, $borrower, $branch , $itemnumber, $suspend_until) = @_; |
1009 |
my ( $rank, $reserve_id, $branch , $itemnumber, $suspend_until) = @_; |
| 1060 |
return if $rank eq "W"; |
1010 |
return if $rank eq "W"; |
| 1061 |
return if $rank eq "n"; |
1011 |
return if $rank eq "n"; |
| 1062 |
my $dbh = C4::Context->dbh; |
1012 |
my $dbh = C4::Context->dbh; |
| 1063 |
if ( $rank eq "del" ) { |
1013 |
if ( $rank eq "del" ) { |
| 1064 |
my $query = qq/ |
1014 |
my $query = " |
| 1065 |
UPDATE reserves |
1015 |
UPDATE reserves |
| 1066 |
SET cancellationdate=now() |
1016 |
SET cancellationdate=now() |
| 1067 |
WHERE biblionumber = ? |
1017 |
WHERE reserve_id = ? |
| 1068 |
AND borrowernumber = ? |
1018 |
"; |
| 1069 |
/; |
|
|
| 1070 |
my $sth = $dbh->prepare($query); |
1019 |
my $sth = $dbh->prepare($query); |
| 1071 |
$sth->execute( $biblio, $borrower ); |
1020 |
$sth->execute( $reserve_id ); |
| 1072 |
$sth->finish; |
1021 |
$sth->finish; |
| 1073 |
$query = qq/ |
1022 |
$query = " |
| 1074 |
INSERT INTO old_reserves |
1023 |
INSERT INTO old_reserves |
| 1075 |
SELECT * |
1024 |
SELECT * |
| 1076 |
FROM reserves |
1025 |
FROM reserves |
| 1077 |
WHERE biblionumber = ? |
1026 |
WHERE reserve_id = ? |
| 1078 |
AND borrowernumber = ? |
1027 |
"; |
| 1079 |
/; |
|
|
| 1080 |
$sth = $dbh->prepare($query); |
1028 |
$sth = $dbh->prepare($query); |
| 1081 |
$sth->execute( $biblio, $borrower ); |
1029 |
$sth->execute( $reserve_id ); |
| 1082 |
$query = qq/ |
1030 |
$query = " |
| 1083 |
DELETE FROM reserves |
1031 |
DELETE FROM reserves |
| 1084 |
WHERE biblionumber = ? |
1032 |
WHERE reserve_id = ? |
| 1085 |
AND borrowernumber = ? |
1033 |
"; |
| 1086 |
/; |
|
|
| 1087 |
$sth = $dbh->prepare($query); |
1034 |
$sth = $dbh->prepare($query); |
| 1088 |
$sth->execute( $biblio, $borrower ); |
1035 |
$sth->execute( $reserve_id ); |
| 1089 |
|
1036 |
|
| 1090 |
} |
1037 |
} |
| 1091 |
elsif ($rank =~ /^\d+/ and $rank > 0) { |
1038 |
elsif ($rank =~ /^\d+/ and $rank > 0) { |
| 1092 |
my $query = " |
1039 |
my $query = " |
| 1093 |
UPDATE reserves SET priority = ? ,branchcode = ?, itemnumber = ?, found = NULL, waitingdate = NULL |
1040 |
UPDATE reserves SET priority = ? ,branchcode = ?, itemnumber = ?, found = NULL, waitingdate = NULL |
| 1094 |
WHERE biblionumber = ? |
1041 |
WHERE reserve_id = ? |
| 1095 |
AND borrowernumber = ? |
|
|
| 1096 |
"; |
1042 |
"; |
| 1097 |
my $sth = $dbh->prepare($query); |
1043 |
my $sth = $dbh->prepare($query); |
| 1098 |
$sth->execute( $rank, $branch,$itemnumber, $biblio, $borrower); |
1044 |
$sth->execute( $rank, $branch, $itemnumber, $reserve_id ); |
| 1099 |
$sth->finish; |
1045 |
$sth->finish; |
| 1100 |
|
1046 |
|
| 1101 |
if ( defined( $suspend_until ) ) { |
1047 |
if ( defined( $suspend_until ) ) { |
| 1102 |
if ( $suspend_until ) { |
1048 |
if ( $suspend_until ) { |
| 1103 |
$suspend_until = C4::Dates->new( $suspend_until )->output("iso"); |
1049 |
$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 ) ); |
1050 |
$dbh->do("UPDATE reserves SET suspend = 1, suspend_until = ? WHERE reserve_id = ?", undef, ( $suspend_until, $reserve_id ) ); |
| 1105 |
} else { |
1051 |
} else { |
| 1106 |
$dbh->do("UPDATE reserves SET suspend_until = NULL WHERE biblionumber = ? AND borrowernumber = ?", undef, ( $biblio, $borrower ) ); |
1052 |
$dbh->do("UPDATE reserves SET suspend_until = NULL WHERE reserve_id = ?", undef, ( $reserve_id ) ); |
| 1107 |
} |
1053 |
} |
| 1108 |
} |
1054 |
} |
| 1109 |
|
1055 |
|
| 1110 |
_FixPriority( $biblio, $borrower, $rank); |
1056 |
_FixPriority( $reserve_id, $rank ); |
| 1111 |
} |
1057 |
} |
| 1112 |
} |
1058 |
} |
| 1113 |
|
1059 |
|
|
Lines 1127-1132
sub ModReserveFill {
Link Here
|
| 1127 |
my ($res) = @_; |
1073 |
my ($res) = @_; |
| 1128 |
my $dbh = C4::Context->dbh; |
1074 |
my $dbh = C4::Context->dbh; |
| 1129 |
# fill in a reserve record.... |
1075 |
# fill in a reserve record.... |
|
|
1076 |
my $reserve_id = $res->{'reserve_id'}; |
| 1130 |
my $biblionumber = $res->{'biblionumber'}; |
1077 |
my $biblionumber = $res->{'biblionumber'}; |
| 1131 |
my $borrowernumber = $res->{'borrowernumber'}; |
1078 |
my $borrowernumber = $res->{'borrowernumber'}; |
| 1132 |
my $resdate = $res->{'reservedate'}; |
1079 |
my $resdate = $res->{'reservedate'}; |
|
Lines 1175-1181
sub ModReserveFill {
Link Here
|
| 1175 |
# now fix the priority on the others (if the priority wasn't |
1122 |
# now fix the priority on the others (if the priority wasn't |
| 1176 |
# already sorted!).... |
1123 |
# already sorted!).... |
| 1177 |
unless ( $priority == 0 ) { |
1124 |
unless ( $priority == 0 ) { |
| 1178 |
_FixPriority( $biblionumber, $borrowernumber ); |
1125 |
_FixPriority( $reserve_id ); |
| 1179 |
} |
1126 |
} |
| 1180 |
} |
1127 |
} |
| 1181 |
|
1128 |
|
|
Lines 1302-1321
Reduce the values of queuded list
Link Here
|
| 1302 |
=cut |
1249 |
=cut |
| 1303 |
|
1250 |
|
| 1304 |
sub ModReserveMinusPriority { |
1251 |
sub ModReserveMinusPriority { |
| 1305 |
my ( $itemnumber, $borrowernumber, $biblionumber ) = @_; |
1252 |
my ( $itemnumber, $reserve_id ) = @_; |
| 1306 |
|
1253 |
|
| 1307 |
#first step update the value of the first person on reserv |
1254 |
#first step update the value of the first person on reserv |
| 1308 |
my $dbh = C4::Context->dbh; |
1255 |
my $dbh = C4::Context->dbh; |
| 1309 |
my $query = " |
1256 |
my $query = " |
| 1310 |
UPDATE reserves |
1257 |
UPDATE reserves |
| 1311 |
SET priority = 0 , itemnumber = ? |
1258 |
SET priority = 0 , itemnumber = ? |
| 1312 |
WHERE borrowernumber=? |
1259 |
WHERE reserve_id = ? |
| 1313 |
AND biblionumber=? |
|
|
| 1314 |
"; |
1260 |
"; |
| 1315 |
my $sth_upd = $dbh->prepare($query); |
1261 |
my $sth_upd = $dbh->prepare($query); |
| 1316 |
$sth_upd->execute( $itemnumber, $borrowernumber, $biblionumber ); |
1262 |
$sth_upd->execute( $itemnumber, $reserve_id ); |
| 1317 |
# second step update all others reservs |
1263 |
# second step update all others reservs |
| 1318 |
_FixPriority($biblionumber, $borrowernumber, '0'); |
1264 |
_FixPriority( $reserve_id, '0'); |
| 1319 |
} |
1265 |
} |
| 1320 |
|
1266 |
|
| 1321 |
=head2 GetReserveInfo |
1267 |
=head2 GetReserveInfo |
|
Lines 1328-1334
Current implementation this query should have a single result.
Link Here
|
| 1328 |
=cut |
1274 |
=cut |
| 1329 |
|
1275 |
|
| 1330 |
sub GetReserveInfo { |
1276 |
sub GetReserveInfo { |
| 1331 |
my ( $borrowernumber, $biblionumber ) = @_; |
1277 |
my ( $reserve_id ) = @_; |
| 1332 |
my $dbh = C4::Context->dbh; |
1278 |
my $dbh = C4::Context->dbh; |
| 1333 |
my $strsth="SELECT |
1279 |
my $strsth="SELECT |
| 1334 |
reservedate, |
1280 |
reservedate, |
|
Lines 1362-1372
sub GetReserveInfo {
Link Here
|
| 1362 |
LEFT JOIN items USING(itemnumber) |
1308 |
LEFT JOIN items USING(itemnumber) |
| 1363 |
LEFT JOIN borrowers USING(borrowernumber) |
1309 |
LEFT JOIN borrowers USING(borrowernumber) |
| 1364 |
LEFT JOIN biblio ON (reserves.biblionumber=biblio.biblionumber) |
1310 |
LEFT JOIN biblio ON (reserves.biblionumber=biblio.biblionumber) |
| 1365 |
WHERE |
1311 |
WHERE reserves.reserve_id = ?"; |
| 1366 |
reserves.borrowernumber=? |
|
|
| 1367 |
AND reserves.biblionumber=?"; |
| 1368 |
my $sth = $dbh->prepare($strsth); |
1312 |
my $sth = $dbh->prepare($strsth); |
| 1369 |
$sth->execute($borrowernumber,$biblionumber); |
1313 |
$sth->execute($reserve_id); |
| 1370 |
|
1314 |
|
| 1371 |
my $data = $sth->fetchrow_hashref; |
1315 |
my $data = $sth->fetchrow_hashref; |
| 1372 |
return $data; |
1316 |
return $data; |
|
Lines 1455-1483
Input: $where is 'up', 'down', 'top' or 'bottom'. Biblionumber, Date reserve was
Link Here
|
| 1455 |
=cut |
1399 |
=cut |
| 1456 |
|
1400 |
|
| 1457 |
sub AlterPriority { |
1401 |
sub AlterPriority { |
| 1458 |
my ( $where, $borrowernumber, $biblionumber ) = @_; |
1402 |
my ( $where, $reserve_id ) = @_; |
| 1459 |
|
1403 |
#warn "C4::Reserves::AlterPriority( $where, $reserve_id )"; |
| 1460 |
my $dbh = C4::Context->dbh; |
1404 |
my $dbh = C4::Context->dbh; |
| 1461 |
|
1405 |
|
| 1462 |
## Find this reserve |
1406 |
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 |
|
1407 |
|
| 1468 |
if ( $where eq 'up' || $where eq 'down' ) { |
1408 |
if ( $where eq 'up' || $where eq 'down' ) { |
| 1469 |
|
1409 |
|
| 1470 |
my $priority = $reserve->{'priority'}; |
1410 |
my $priority = $reserve->{'priority'}; |
| 1471 |
$priority = $where eq 'up' ? $priority - 1 : $priority + 1; |
1411 |
$priority = $where eq 'up' ? $priority - 1 : $priority + 1; |
| 1472 |
_FixPriority( $biblionumber, $borrowernumber, $priority ) |
1412 |
_FixPriority( $reserve_id, $priority ) |
| 1473 |
|
1413 |
|
| 1474 |
} elsif ( $where eq 'top' ) { |
1414 |
} elsif ( $where eq 'top' ) { |
| 1475 |
|
1415 |
|
| 1476 |
_FixPriority( $biblionumber, $borrowernumber, '1' ) |
1416 |
_FixPriority( $reserve_id, '1' ) |
| 1477 |
|
1417 |
|
| 1478 |
} elsif ( $where eq 'bottom' ) { |
1418 |
} elsif ( $where eq 'bottom' ) { |
| 1479 |
|
1419 |
|
| 1480 |
_FixPriority( $biblionumber, $borrowernumber, '999999' ) |
1420 |
_FixPriority( $reserve_id, '999999' ) |
| 1481 |
|
1421 |
|
| 1482 |
} |
1422 |
} |
| 1483 |
} |
1423 |
} |
|
Lines 1491-1517
This function sets the lowestPriority field to true if is false, and false if it
Link Here
|
| 1491 |
=cut |
1431 |
=cut |
| 1492 |
|
1432 |
|
| 1493 |
sub ToggleLowestPriority { |
1433 |
sub ToggleLowestPriority { |
| 1494 |
my ( $borrowernumber, $biblionumber ) = @_; |
1434 |
my ( $reserve_id ) = @_; |
| 1495 |
|
1435 |
|
| 1496 |
my $dbh = C4::Context->dbh; |
1436 |
my $dbh = C4::Context->dbh; |
| 1497 |
|
1437 |
|
| 1498 |
my $sth = $dbh->prepare( |
1438 |
my $sth = $dbh->prepare( "UPDATE reserves SET lowestPriority = NOT lowestPriority WHERE reserve_id = ?"); |
| 1499 |
"UPDATE reserves SET lowestPriority = NOT lowestPriority |
1439 |
$sth->execute( $reserve_id ); |
| 1500 |
WHERE biblionumber = ? |
|
|
| 1501 |
AND borrowernumber = ?" |
| 1502 |
); |
| 1503 |
$sth->execute( |
| 1504 |
$biblionumber, |
| 1505 |
$borrowernumber, |
| 1506 |
); |
| 1507 |
$sth->finish; |
1440 |
$sth->finish; |
| 1508 |
|
1441 |
|
| 1509 |
_FixPriority( $biblionumber, $borrowernumber, '999999' ); |
1442 |
_FixPriority( $reserve_id, '999999' ); |
| 1510 |
} |
1443 |
} |
| 1511 |
|
1444 |
|
| 1512 |
=head2 ToggleSuspend |
1445 |
=head2 ToggleSuspend |
| 1513 |
|
1446 |
|
| 1514 |
ToggleSuspend( $borrowernumber, $biblionumber ); |
1447 |
ToggleSuspend( $reserve_id ); |
| 1515 |
|
1448 |
|
| 1516 |
This function sets the suspend field to true if is false, and false if it is true. |
1449 |
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 |
1450 |
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 |
1453 |
=cut |
| 1521 |
|
1454 |
|
| 1522 |
sub ToggleSuspend { |
1455 |
sub ToggleSuspend { |
| 1523 |
my ( $borrowernumber, $biblionumber, $suspend_until ) = @_; |
1456 |
my ( $reserve_id, $suspend_until ) = @_; |
| 1524 |
|
1457 |
|
| 1525 |
$suspend_until = output_pref( dt_from_string( $suspend_until ), 'iso' ) if ( $suspend_until ); |
1458 |
$suspend_until = output_pref( dt_from_string( $suspend_until ), 'iso' ) if ( $suspend_until ); |
| 1526 |
|
1459 |
|
|
Lines 1531-1544
sub ToggleSuspend {
Link Here
|
| 1531 |
my $sth = $dbh->prepare( |
1464 |
my $sth = $dbh->prepare( |
| 1532 |
"UPDATE reserves SET suspend = NOT suspend, |
1465 |
"UPDATE reserves SET suspend = NOT suspend, |
| 1533 |
suspend_until = CASE WHEN suspend = 0 THEN NULL ELSE $do_until END |
1466 |
suspend_until = CASE WHEN suspend = 0 THEN NULL ELSE $do_until END |
| 1534 |
WHERE biblionumber = ? |
1467 |
WHERE reserve_id = ? |
| 1535 |
AND borrowernumber = ? |
|
|
| 1536 |
"); |
1468 |
"); |
| 1537 |
|
1469 |
|
| 1538 |
my @params; |
1470 |
my @params; |
| 1539 |
push( @params, $suspend_until ) if ( $suspend_until ); |
1471 |
push( @params, $suspend_until ) if ( $suspend_until ); |
| 1540 |
push( @params, $biblionumber ); |
1472 |
push( @params, $reserve_id ); |
| 1541 |
push( @params, $borrowernumber ); |
|
|
| 1542 |
|
1473 |
|
| 1543 |
$sth->execute( @params ); |
1474 |
$sth->execute( @params ); |
| 1544 |
$sth->finish; |
1475 |
$sth->finish; |
|
Lines 1603-1609
sub SuspendAll {
Link Here
|
| 1603 |
|
1534 |
|
| 1604 |
=head2 _FixPriority |
1535 |
=head2 _FixPriority |
| 1605 |
|
1536 |
|
| 1606 |
&_FixPriority($biblio,$borrowernumber,$rank,$ignoreSetLowestRank); |
1537 |
&_FixPriority( $reserve_id, $rank, $ignoreSetLowestRank); |
| 1607 |
|
1538 |
|
| 1608 |
Only used internally (so don't export it) |
1539 |
Only used internally (so don't export it) |
| 1609 |
Changed how this functions works # |
1540 |
Changed how this functions works # |
|
Lines 1615-1655
in new priority rank
Link Here
|
| 1615 |
=cut |
1546 |
=cut |
| 1616 |
|
1547 |
|
| 1617 |
sub _FixPriority { |
1548 |
sub _FixPriority { |
| 1618 |
my ( $biblio, $borrowernumber, $rank, $ignoreSetLowestRank ) = @_; |
1549 |
my ( $reserve_id, $rank, $ignoreSetLowestRank ) = @_; |
| 1619 |
my $dbh = C4::Context->dbh; |
1550 |
my $dbh = C4::Context->dbh; |
| 1620 |
if ( $rank eq "del" ) { |
1551 |
|
| 1621 |
CancelReserve( $biblio, undef, $borrowernumber ); |
1552 |
my $res = GetReserve( $reserve_id ); |
| 1622 |
} |
1553 |
|
| 1623 |
if ( $rank eq "W" || $rank eq "0" ) { |
1554 |
if ( $rank eq "del" ) { |
|
|
1555 |
CancelReserve( $reserve_id ); |
| 1556 |
} |
| 1557 |
elsif ( $rank eq "W" || $rank eq "0" ) { |
| 1624 |
|
1558 |
|
| 1625 |
# make sure priority for waiting or in-transit items is 0 |
1559 |
# make sure priority for waiting or in-transit items is 0 |
| 1626 |
my $query = qq/ |
1560 |
my $query = " |
| 1627 |
UPDATE reserves |
1561 |
UPDATE reserves |
| 1628 |
SET priority = 0 |
1562 |
SET priority = 0 |
| 1629 |
WHERE biblionumber = ? |
1563 |
WHERE reserve_id = ? |
| 1630 |
AND borrowernumber = ? |
1564 |
AND found IN ('W', 'T') |
| 1631 |
AND found IN ('W', 'T') |
1565 |
"; |
| 1632 |
/; |
|
|
| 1633 |
my $sth = $dbh->prepare($query); |
1566 |
my $sth = $dbh->prepare($query); |
| 1634 |
$sth->execute( $biblio, $borrowernumber ); |
1567 |
$sth->execute( $reserve_id ); |
| 1635 |
} |
1568 |
} |
| 1636 |
my @priority; |
1569 |
my @priority; |
| 1637 |
my @reservedates; |
1570 |
my @reservedates; |
| 1638 |
|
1571 |
|
| 1639 |
# get whats left |
1572 |
# get whats left |
| 1640 |
# FIXME adding a new security in returned elements for changing priority, |
1573 |
my $query = " |
| 1641 |
# now, we don't care anymore any reservations with itemnumber linked (suppose a waiting reserve) |
1574 |
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 |
1575 |
FROM reserves |
| 1647 |
WHERE biblionumber = ? |
1576 |
WHERE biblionumber = ? |
| 1648 |
AND ((found <> 'W' AND found <> 'T') or found is NULL) |
1577 |
AND ((found <> 'W' AND found <> 'T') OR found IS NULL) |
| 1649 |
ORDER BY priority ASC |
1578 |
ORDER BY priority ASC |
| 1650 |
/; |
1579 |
"; |
| 1651 |
my $sth = $dbh->prepare($query); |
1580 |
my $sth = $dbh->prepare($query); |
| 1652 |
$sth->execute($biblio); |
1581 |
$sth->execute( $res->{'biblionumber'} ); |
| 1653 |
while ( my $line = $sth->fetchrow_hashref ) { |
1582 |
while ( my $line = $sth->fetchrow_hashref ) { |
| 1654 |
push( @reservedates, $line ); |
1583 |
push( @reservedates, $line ); |
| 1655 |
push( @priority, $line ); |
1584 |
push( @priority, $line ); |
|
Lines 1659-1665
sub _FixPriority {
Link Here
|
| 1659 |
my $i; |
1588 |
my $i; |
| 1660 |
my $key = -1; # to allow for 0 to be a valid result |
1589 |
my $key = -1; # to allow for 0 to be a valid result |
| 1661 |
for ( $i = 0 ; $i < @priority ; $i++ ) { |
1590 |
for ( $i = 0 ; $i < @priority ; $i++ ) { |
| 1662 |
if ( $borrowernumber == $priority[$i]->{'borrowernumber'} ) { |
1591 |
if ( $reserve_id == $priority[$i]->{'reserve_id'} ) { |
| 1663 |
$key = $i; # save the index |
1592 |
$key = $i; # save the index |
| 1664 |
last; |
1593 |
last; |
| 1665 |
} |
1594 |
} |
|
Lines 1675-1703
sub _FixPriority {
Link Here
|
| 1675 |
|
1604 |
|
| 1676 |
# now fix the priority on those that are left.... |
1605 |
# now fix the priority on those that are left.... |
| 1677 |
$query = " |
1606 |
$query = " |
| 1678 |
UPDATE reserves |
1607 |
UPDATE reserves |
| 1679 |
SET priority = ? |
1608 |
SET priority = ? |
| 1680 |
WHERE biblionumber = ? |
1609 |
WHERE reserve_id = ? |
| 1681 |
AND borrowernumber = ? |
|
|
| 1682 |
AND reservedate = ? |
| 1683 |
AND found IS NULL |
| 1684 |
"; |
1610 |
"; |
| 1685 |
$sth = $dbh->prepare($query); |
1611 |
$sth = $dbh->prepare($query); |
| 1686 |
for ( my $j = 0 ; $j < @priority ; $j++ ) { |
1612 |
for ( my $j = 0 ; $j < @priority ; $j++ ) { |
| 1687 |
$sth->execute( |
1613 |
$sth->execute( |
| 1688 |
$j + 1, $biblio, |
1614 |
$j + 1, |
| 1689 |
$priority[$j]->{'borrowernumber'}, |
1615 |
$priority[$j]->{'reserve_id'} |
| 1690 |
$priority[$j]->{'reservedate'} |
|
|
| 1691 |
); |
1616 |
); |
| 1692 |
$sth->finish; |
1617 |
$sth->finish; |
| 1693 |
} |
1618 |
} |
| 1694 |
|
1619 |
|
| 1695 |
$sth = $dbh->prepare( "SELECT borrowernumber FROM reserves WHERE lowestPriority = 1 ORDER BY priority" ); |
1620 |
$sth = $dbh->prepare( "SELECT reserve_id FROM reserves WHERE lowestPriority = 1 ORDER BY priority" ); |
| 1696 |
$sth->execute(); |
1621 |
$sth->execute(); |
| 1697 |
|
1622 |
|
| 1698 |
unless ( $ignoreSetLowestRank ) { |
1623 |
unless ( $ignoreSetLowestRank ) { |
| 1699 |
while ( my $res = $sth->fetchrow_hashref() ) { |
1624 |
while ( my $res = $sth->fetchrow_hashref() ) { |
| 1700 |
_FixPriority( $biblio, $res->{'borrowernumber'}, '999999', 1 ); |
1625 |
_FixPriority( $res->{'reserve_id'}, '999999', 1 ); |
| 1701 |
} |
1626 |
} |
| 1702 |
} |
1627 |
} |
| 1703 |
} |
1628 |
} |
|
Lines 1969-1975
sub _ShiftPriorityByDateAndPriority {
Link Here
|
| 1969 |
|
1894 |
|
| 1970 |
=head2 MoveReserve |
1895 |
=head2 MoveReserve |
| 1971 |
|
1896 |
|
| 1972 |
MoveReserve( $itemnumber, $borrowernumber, $cancelreserve ) |
1897 |
MoveReserve( $reserve_id, $cancelreserve ) |
| 1973 |
|
1898 |
|
| 1974 |
Use when checking out an item to handle reserves |
1899 |
Use when checking out an item to handle reserves |
| 1975 |
If $cancelreserve boolean is set to true, it will remove existing reserve |
1900 |
If $cancelreserve boolean is set to true, it will remove existing reserve |
|
Lines 2025-2031
This shifts the holds from C<$from_biblio> to C<$to_biblio> and reorders them by
Link Here
|
| 2025 |
sub MergeHolds { |
1950 |
sub MergeHolds { |
| 2026 |
my ( $dbh, $to_biblio, $from_biblio ) = @_; |
1951 |
my ( $dbh, $to_biblio, $from_biblio ) = @_; |
| 2027 |
my $sth = $dbh->prepare( |
1952 |
my $sth = $dbh->prepare( |
| 2028 |
"SELECT count(*) as reservenumber FROM reserves WHERE biblionumber = ?" |
1953 |
"SELECT count(*) as reserve_id FROM reserves WHERE biblionumber = ?" |
| 2029 |
); |
1954 |
); |
| 2030 |
$sth->execute($from_biblio); |
1955 |
$sth->execute($from_biblio); |
| 2031 |
if ( my $data = $sth->fetchrow_hashref() ) { |
1956 |
if ( my $data = $sth->fetchrow_hashref() ) { |