+
+#item may belong to a host biblio, if yes change biblioNum to hosts bilbionumber
+ if ( $itemNum ne '' ) {
+ my $hostbiblioNum = GetBiblionumberFromItemnumber($itemNum);
+ if ( $hostbiblioNum ne $biblioNum ) {
+ $biblioNum = $hostbiblioNum;
+ }
+ }
+
+ my $biblioData = $biblioDataHash{$biblioNum};
+ my $found;
+
+ # Check for user supplied reserve date
+ my $startdate;
+ if ( C4::Context->preference('AllowHoldDateInFuture')
+ && C4::Context->preference('OPACAllowHoldDateInFuture') )
+ {
+ $startdate = $query->param("reserve_date_$biblioNum");
+ }
+
+ my $expiration_date = $query->param("expiration_date_$biblioNum");
+
+ # If a specific item was selected and the pickup branch is the same as the
+ # holdingbranch, force the value $rank and $found.
+ my $rank = $biblioData->{rank};
+ if ( $itemNum ne '' ) {
+ $canreserve = 1 if CanItemBeReserved( $borrowernumber, $itemNum );
+ $rank = '0' unless C4::Context->preference('ReservesNeedReturns');
+ my $item = GetItem($itemNum);
+ if ( $item->{'holdingbranch'} eq $branch ) {
+ $found = 'W'
+ unless C4::Context->preference('ReservesNeedReturns');
+ }
+ }
+ else {
+ $canreserve = 1 if CanBookBeReserved( $borrowernumber, $biblioNum );
+
+ # Inserts a null into the 'itemnumber' field of 'reserves' table.
+ $itemNum = undef;
+ }
+
+ if ( $MAXIMUM_NUMBER_OF_RESERVES
+ && $reserve_cnt >= $MAXIMUM_NUMBER_OF_RESERVES )
+ {
+ $canreserve = 0;
+ }
+
+ # Here we actually do the reserveration. Stage 3.
+ if ($canreserve) {
+ AddReserve(
+ $branch, $borrowernumber,
+ $biblioNum, 'a',
+ [$biblioNum], $rank,
+ $startdate, $expiration_date,
+ $notes, $biblioData->{title},
+ $itemNum, $found
+ );
+ ++$reserve_cnt;