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

(-)a/C4/Reserves.pm (-17 / +35 lines)
Lines 40-47 use C4::Dates qw( format_date_in_iso ); Link Here
40
use Koha::DateUtils;
40
use Koha::DateUtils;
41
use Koha::Calendar;
41
use Koha::Calendar;
42
use Koha::Database;
42
use Koha::Database;
43
use Koha::Hold;
44
use Koha::Holds;
43
45
44
use List::MoreUtils qw( firstidx any );
46
use List::MoreUtils qw( firstidx any );
47
use Carp;
45
48
46
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
49
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
47
50
Lines 155-172 sub AddReserve { Link Here
155
        $bibitems,  $priority, $resdate, $expdate, $notes,
158
        $bibitems,  $priority, $resdate, $expdate, $notes,
156
        $title,      $checkitem, $found
159
        $title,      $checkitem, $found
157
    ) = @_;
160
    ) = @_;
161
162
    if ( Koha::Holds->search( { borrowernumber => $borrowernumber, biblionumber => $biblionumber } )->count() > 0 ) {
163
        carp("AddReserve: borrower $borrowernumber already has a hold for biblionumber $biblionumber");
164
        return;
165
    }
166
167
    my $fee = GetReserveFee( $borrowernumber, $biblionumber );
168
158
    my $dbh     = C4::Context->dbh;
169
    my $dbh     = C4::Context->dbh;
170
159
    $resdate = format_date_in_iso( $resdate ) if ( $resdate );
171
    $resdate = format_date_in_iso( $resdate ) if ( $resdate );
160
    $resdate = C4::Dates->today( 'iso' ) unless ( $resdate );
172
    $resdate = C4::Dates->today( 'iso' ) unless ( $resdate );
173
161
    if ($expdate) {
174
    if ($expdate) {
162
        $expdate = format_date_in_iso( $expdate );
175
        $expdate = format_date_in_iso( $expdate );
163
    } else {
176
    } else {
164
        undef $expdate; # make reserves.expirationdate default to null rather than '0000-00-00'
177
        undef $expdate; # make reserves.expirationdate default to null rather than '0000-00-00'
165
    }
178
    }
166
    if ( C4::Context->preference( 'AllowHoldDateInFuture' ) ) {
179
167
	# Make room in reserves for this before those of a later reserve date
180
    if ( C4::Context->preference('AllowHoldDateInFuture') ) {
168
	$priority = _ShiftPriorityByDateAndPriority( $biblionumber, $resdate, $priority );
181
182
        # Make room in reserves for this before those of a later reserve date
183
        $priority = _ShiftPriorityByDateAndPriority( $biblionumber, $resdate, $priority );
169
    }
184
    }
185
170
    my $waitingdate;
186
    my $waitingdate;
171
187
172
    # If the reserv had the waiting status, we had the value of the resdate
188
    # If the reserv had the waiting status, we had the value of the resdate
Lines 175-194 sub AddReserve { Link Here
175
    }
191
    }
176
192
177
    # updates take place here
193
    # updates take place here
178
    my $query = qq{
194
    my $hold = Koha::Hold->new(
179
        INSERT INTO reserves
195
        {
180
            (borrowernumber,biblionumber,reservedate,branchcode,
196
            borrowernumber => $borrowernumber,
181
            priority,reservenotes,itemnumber,found,waitingdate,expirationdate)
197
            biblionumber   => $biblionumber,
182
        VALUES
198
            reservedate    => $resdate,
183
             (?,?,?,?,?,
199
            branchcode     => $branch,
184
             ?,?,?,?,?)
200
            priority       => $priority,
185
             };
201
            reservenotes   => $notes,
186
    my $sth = $dbh->prepare($query);
202
            itemnumber     => $checkitem,
187
    $sth->execute(
203
            found          => $found,
188
        $borrowernumber, $biblionumber, $resdate, $branch,      $priority,
204
            waitingdate    => $waitingdate,
189
        $notes,          $checkitem,    $found,   $waitingdate, $expdate
205
            expirationdate => $expdate
190
    );
206
        }
191
    my $reserve_id = $sth->{mysql_insertid};
207
    )->store();
208
    my $reserve_id = $hold->id();
209
192
    # add a reserve fee if needed
210
    # add a reserve fee if needed
193
    my $fee = GetReserveFee( $borrowernumber, $biblionumber );
211
    my $fee = GetReserveFee( $borrowernumber, $biblionumber );
194
    ChargeReserveFee( $borrowernumber, $fee, $title );
212
    ChargeReserveFee( $borrowernumber, $fee, $title );
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt (+7 lines)
Lines 48-53 Link Here
48
48
49
                    [% IF ( patronupdate ) %]<div class="alert alert-info"><h3>Thank you!</h3><p>Your corrections have been submitted to the library, and a staff member will update your record as soon as possible.</p></div>[% END %]
49
                    [% IF ( patronupdate ) %]<div class="alert alert-info"><h3>Thank you!</h3><p>Your corrections have been submitted to the library, and a staff member will update your record as soon as possible.</p></div>[% END %]
50
50
51
                    [% IF failed_holds %]
52
                        <div class="alert alert-info">
53
                            <h3>Notice:</h3>
54
                            <p>One or more holds were not placed due to existing holds.</p>
55
                        </div>
56
                    [% END %]
57
51
                    [% IF ( BORROWER_INF.warndeparture ) %]
58
                    [% IF ( BORROWER_INF.warndeparture ) %]
52
                        <div class="alert" id="warndeparture">
59
                        <div class="alert" id="warndeparture">
53
                            <strong>Please note:</strong><span> Your card will expire on <span id="warndeparture_date">[% BORROWER_INF.warndeparture | $KohaDates %]</span>. Please contact the library for more information.</span>
60
                            <strong>Please note:</strong><span> Your card will expire on <span id="warndeparture_date">[% BORROWER_INF.warndeparture | $KohaDates %]</span>. Please contact the library for more information.</span>
(-)a/opac/opac-reserve.pl (-2 / +4 lines)
Lines 221-226 if ( $query->param('place_reserve') ) { Link Here
221
        &get_out($query, $cookie, $template->output);
221
        &get_out($query, $cookie, $template->output);
222
    }
222
    }
223
223
224
    my $failed_holds = 0;
224
    while (@selectedItems) {
225
    while (@selectedItems) {
225
        my $biblioNum = shift(@selectedItems);
226
        my $biblioNum = shift(@selectedItems);
226
        my $itemNum   = shift(@selectedItems);
227
        my $itemNum   = shift(@selectedItems);
Lines 283-289 if ( $query->param('place_reserve') ) { Link Here
283
284
284
        # Here we actually do the reserveration. Stage 3.
285
        # Here we actually do the reserveration. Stage 3.
285
        if ($canreserve) {
286
        if ($canreserve) {
286
            AddReserve(
287
            my $reserve_id = AddReserve(
287
                $branch,      $borrowernumber,
288
                $branch,      $borrowernumber,
288
                $biblioNum,
289
                $biblioNum,
289
                [$biblioNum], $rank,
290
                [$biblioNum], $rank,
Lines 291-301 if ( $query->param('place_reserve') ) { Link Here
291
                $notes,       $biblioData->{title},
292
                $notes,       $biblioData->{title},
292
                $itemNum,     $found
293
                $itemNum,     $found
293
            );
294
            );
295
            $failed_holds++ unless $reserve_id;
294
            ++$reserve_cnt;
296
            ++$reserve_cnt;
295
        }
297
        }
296
    }
298
    }
297
299
298
    print $query->redirect("/cgi-bin/koha/opac-user.pl#opac-user-holds");
300
    print $query->redirect("/cgi-bin/koha/opac-user.pl?failed_holds=$failed_holds#opac-user-holds");
299
    exit;
301
    exit;
300
}
302
}
301
303
(-)a/opac/opac-user.pl (-10 / +8 lines)
Lines 385-401 if ( $borr->{'opacnote'} ) { Link Here
385
}
385
}
386
386
387
$template->param(
387
$template->param(
388
    bor_messages_loop    => GetMessages( $borrowernumber, 'B', 'NONE' ),
388
    bor_messages_loop        => GetMessages( $borrowernumber, 'B', 'NONE' ),
389
    waiting_count      => $wcount,
389
    waiting_count            => $wcount,
390
    patronupdate => $patronupdate,
390
    patronupdate             => $patronupdate,
391
    OpacRenewalAllowed => C4::Context->preference("OpacRenewalAllowed"),
391
    OpacRenewalAllowed       => C4::Context->preference("OpacRenewalAllowed"),
392
    userview => 1,
392
    userview                 => 1,
393
);
393
    SuspendHoldsOpac         => C4::Context->preference('SuspendHoldsOpac'),
394
395
$template->param(
396
    SuspendHoldsOpac => C4::Context->preference('SuspendHoldsOpac'),
397
    AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
394
    AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
398
    OpacHoldNotes => C4::Context->preference('OpacHoldNotes'),
395
    OpacHoldNotes            => C4::Context->preference('OpacHoldNotes'),
396
    failed_holds             => $query->param('failed_holds'),
399
);
397
);
400
398
401
output_html_with_http_headers $query, $cookie, $template->output;
399
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/t/db_dependent/Reserves.t (-4 / +11 lines)
Lines 153-158 $requesters{'CPL'} = AddMember( Link Here
153
    categorycode => 'PT',
153
    categorycode => 'PT',
154
    surname      => 'borrower from CPL',
154
    surname      => 'borrower from CPL',
155
);
155
);
156
for my $i ( 2 .. 5 ) {
157
    $requesters{"CPL$i"} = AddMember(
158
        branchcode   => 'CPL',
159
        categorycode => 'PT',
160
        surname      => 'borrower $i from CPL',
161
    );
162
}
156
$requesters{'FPL'} = AddMember(
163
$requesters{'FPL'} = AddMember(
157
    branchcode   => 'FPL',
164
    branchcode   => 'FPL',
158
    categorycode => 'PT',
165
    categorycode => 'PT',
Lines 393-403 ModReserveAffect( $itemnumber, $requesters{'CPL'} , 0); #confirm hold Link Here
393
is(defined $results[3]?1:0, 1, 'GetReservesFromItemnumber returns a future wait (confirmed future hold)');
400
is(defined $results[3]?1:0, 1, 'GetReservesFromItemnumber returns a future wait (confirmed future hold)');
394
# End of tests for bug 9788
401
# End of tests for bug 9788
395
402
403
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
396
# Tests for CalculatePriority (bug 8918)
404
# Tests for CalculatePriority (bug 8918)
397
my $p = C4::Reserves::CalculatePriority($bibnum2);
405
my $p = C4::Reserves::CalculatePriority($bibnum2);
398
is($p, 4, 'CalculatePriority should now return priority 4');
406
is($p, 4, 'CalculatePriority should now return priority 4');
399
$resdate=undef;
407
$resdate=undef;
400
AddReserve('CPL',  $requesters{'CPL'}, $bibnum2,
408
AddReserve('CPL',  $requesters{'CPL2'}, $bibnum2,
401
           $bibitems,  $p, $resdate, $expdate, $notes,
409
           $bibitems,  $p, $resdate, $expdate, $notes,
402
           $title,      $checkitem, $found);
410
           $title,      $checkitem, $found);
403
$p = C4::Reserves::CalculatePriority($bibnum2);
411
$p = C4::Reserves::CalculatePriority($bibnum2);
Lines 416-422 ModReserveAffect( $itemnumber, $requesters{'CPL'} , 0); Link Here
416
$p = C4::Reserves::CalculatePriority($bibnum);
424
$p = C4::Reserves::CalculatePriority($bibnum);
417
is($p, 1, 'CalculatePriority should now return priority 1');
425
is($p, 1, 'CalculatePriority should now return priority 1');
418
#add another biblio hold, no resdate
426
#add another biblio hold, no resdate
419
AddReserve('CPL',  $requesters{'CPL'}, $bibnum,
427
AddReserve('CPL',  $requesters{'CPL2'}, $bibnum,
420
           $bibitems,  $p, $resdate, $expdate, $notes,
428
           $bibitems,  $p, $resdate, $expdate, $notes,
421
           $title,      $checkitem, $found);
429
           $title,      $checkitem, $found);
422
$p = C4::Reserves::CalculatePriority($bibnum);
430
$p = C4::Reserves::CalculatePriority($bibnum);
Lines 425-431 is($p, 2, 'CalculatePriority should now return priority 2'); Link Here
425
C4::Context->set_preference('AllowHoldDateInFuture', 1);
433
C4::Context->set_preference('AllowHoldDateInFuture', 1);
426
$resdate= dt_from_string();
434
$resdate= dt_from_string();
427
$resdate->add_duration(DateTime::Duration->new(days => 1));
435
$resdate->add_duration(DateTime::Duration->new(days => 1));
428
AddReserve('CPL',  $requesters{'CPL'}, $bibnum,
436
AddReserve('CPL',  $requesters{'CPL3'}, $bibnum,
429
           $bibitems,  $p, output_pref($resdate), $expdate, $notes,
437
           $bibitems,  $p, output_pref($resdate), $expdate, $notes,
430
           $title,      $checkitem, $found);
438
           $title,      $checkitem, $found);
431
$p = C4::Reserves::CalculatePriority($bibnum);
439
$p = C4::Reserves::CalculatePriority($bibnum);
432
- 

Return to bug 5144