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

(-)a/C4/Reserves.pm (-32 / +34 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 156-177 sub AddReserve { Link Here
156
        $constraint, $bibitems,  $priority, $resdate, $expdate, $notes,
159
        $constraint, $bibitems,  $priority, $resdate, $expdate, $notes,
157
        $title,      $checkitem, $found
160
        $title,      $checkitem, $found
158
    ) = @_;
161
    ) = @_;
162
163
    if ( Koha::Holds->search( { borrowernumber => $borrowernumber, biblionumber => $biblionumber } )->count() > 0 ) {
164
        carp("AddReserve: borrower $borrowernumber already has a hold for biblionumber $biblionumber");
165
        return;
166
    }
167
159
    my $fee =
168
    my $fee =
160
          GetReserveFee($borrowernumber, $biblionumber, $constraint,
169
          GetReserveFee($borrowernumber, $biblionumber, $constraint,
161
            $bibitems );
170
            $bibitems );
171
162
    my $dbh     = C4::Context->dbh;
172
    my $dbh     = C4::Context->dbh;
163
    my $const   = lc substr( $constraint, 0, 1 );
173
    my $const   = lc substr( $constraint, 0, 1 );
174
164
    $resdate = format_date_in_iso( $resdate ) if ( $resdate );
175
    $resdate = format_date_in_iso( $resdate ) if ( $resdate );
165
    $resdate = C4::Dates->today( 'iso' ) unless ( $resdate );
176
    $resdate = C4::Dates->today( 'iso' ) unless ( $resdate );
177
166
    if ($expdate) {
178
    if ($expdate) {
167
        $expdate = format_date_in_iso( $expdate );
179
        $expdate = format_date_in_iso( $expdate );
168
    } else {
180
    } else {
169
        undef $expdate; # make reserves.expirationdate default to null rather than '0000-00-00'
181
        undef $expdate; # make reserves.expirationdate default to null rather than '0000-00-00'
170
    }
182
    }
171
    if ( C4::Context->preference( 'AllowHoldDateInFuture' ) ) {
183
172
	# Make room in reserves for this before those of a later reserve date
184
    if ( C4::Context->preference('AllowHoldDateInFuture') ) {
173
	$priority = _ShiftPriorityByDateAndPriority( $biblionumber, $resdate, $priority );
185
186
        # Make room in reserves for this before those of a later reserve date
187
        $priority = _ShiftPriorityByDateAndPriority( $biblionumber, $resdate, $priority );
174
    }
188
    }
189
175
    my $waitingdate;
190
    my $waitingdate;
176
191
177
    # If the reserv had the waiting status, we had the value of the resdate
192
    # If the reserv had the waiting status, we had the value of the resdate
Lines 194-215 sub AddReserve { Link Here
194
            "Reserve Charge - $title", $fee );
209
            "Reserve Charge - $title", $fee );
195
    }
210
    }
196
211
197
    #if ($const eq 'a'){
212
    my $hold = Koha::Hold->new(
198
    my $query = qq{
213
        {
199
        INSERT INTO reserves
214
            borrowernumber => $borrowernumber,
200
            (borrowernumber,biblionumber,reservedate,branchcode,constrainttype,
215
            biblionumber   => $biblionumber,
201
            priority,reservenotes,itemnumber,found,waitingdate,expirationdate)
216
            reservedate    => $resdate,
202
        VALUES
217
            branchcode     => $branch,
203
             (?,?,?,?,?,
218
            constrainttype => $const,
204
             ?,?,?,?,?,?)
219
            priority       => $priority,
205
             };
220
            reservenotes   => $notes,
206
    my $sth = $dbh->prepare($query);
221
            itemnumber     => $checkitem,
207
    $sth->execute(
222
            found          => $found,
208
        $borrowernumber, $biblionumber, $resdate, $branch,
223
            waitingdate    => $waitingdate,
209
        $const,          $priority,     $notes,   $checkitem,
224
            expirationdate => $expdate
210
        $found,          $waitingdate,	$expdate
225
        }
211
    );
226
    )->store();
212
    my $reserve_id = $sth->{mysql_insertid};
227
    my $reserve_id = $hold->id();
213
228
214
    # Send e-mail to librarian if syspref is active
229
    # Send e-mail to librarian if syspref is active
215
    if(C4::Context->preference("emailLibrarianWhenHoldIsPlaced")){
230
    if(C4::Context->preference("emailLibrarianWhenHoldIsPlaced")){
Lines 240-258 sub AddReserve { Link Here
240
        }
255
        }
241
    }
256
    }
242
257
243
    #}
244
    ($const eq "o" || $const eq "e") or return;   # FIXME: why not have a useful return value?
245
    $query = qq{
246
        INSERT INTO reserveconstraints
247
            (borrowernumber,biblionumber,reservedate,biblioitemnumber)
248
        VALUES
249
            (?,?,?,?)
250
    };
251
    $sth = $dbh->prepare($query);    # keep prepare outside the loop!
252
    foreach (@$bibitems) {
253
        $sth->execute($borrowernumber, $biblionumber, $resdate, $_);
254
    }
255
        
256
    return $reserve_id;
258
    return $reserve_id;
257
}
259
}
258
260
(-)a/Koha/Hold.pm (+52 lines)
Line 0 Link Here
1
package Koha::Hold;
2
3
# Copyright ByWater Solutions 2015
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Carp;
23
24
use Koha::Database;
25
26
use base qw(Koha::Object);
27
28
=head1 NAME
29
30
Koha::Hold - Koha Hold Object class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=cut
37
38
=head3 type
39
40
=cut
41
42
sub type {
43
    return 'Reserve';
44
}
45
46
=head1 AUTHOR
47
48
Kyle M Hall <kyle@bywatersolutions.com>
49
50
=cut
51
52
1;
(-)a/Koha/Holds.pm (+58 lines)
Line 0 Link Here
1
package Koha::Holds;
2
3
# Copyright ByWater Solutions 2014
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Carp;
23
24
use Koha::Database;
25
26
use Koha::Hold;
27
28
use base qw(Koha::Objects);
29
30
=head1 NAME
31
32
Koha::Hold - Koha Hold Object class
33
34
=head1 API
35
36
=head2 Class Methods
37
38
=cut
39
40
=head3 type
41
42
=cut
43
44
sub type {
45
    return 'Reserve';
46
}
47
48
sub object_class {
49
    return 'Koha::Hold';
50
}
51
52
=head1 AUTHOR
53
54
Kyle M Hall <kyle@bywatersolutions.com>
55
56
=cut
57
58
1;
(-)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,   'a',
289
                $biblioNum,   'a',
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 383-399 if ( $borr->{'opacnote'} ) { Link Here
383
}
383
}
384
384
385
$template->param(
385
$template->param(
386
    bor_messages_loop    => GetMessages( $borrowernumber, 'B', 'NONE' ),
386
    bor_messages_loop        => GetMessages( $borrowernumber, 'B', 'NONE' ),
387
    waiting_count      => $wcount,
387
    waiting_count            => $wcount,
388
    patronupdate => $patronupdate,
388
    patronupdate             => $patronupdate,
389
    OpacRenewalAllowed => C4::Context->preference("OpacRenewalAllowed"),
389
    OpacRenewalAllowed       => C4::Context->preference("OpacRenewalAllowed"),
390
    userview => 1,
390
    userview                 => 1,
391
);
391
    SuspendHoldsOpac         => C4::Context->preference('SuspendHoldsOpac'),
392
393
$template->param(
394
    SuspendHoldsOpac => C4::Context->preference('SuspendHoldsOpac'),
395
    AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
392
    AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
396
    OpacHoldNotes => C4::Context->preference('OpacHoldNotes'),
393
    OpacHoldNotes            => C4::Context->preference('OpacHoldNotes'),
394
    failed_holds             => $query->param('failed_holds'),
397
);
395
);
398
396
399
output_html_with_http_headers $query, $cookie, $template->output;
397
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 389-399 ModReserveAffect( $itemnumber, $requesters{'CPL'} , 0); #confirm hold Link Here
389
is(defined $results[3]?1:0, 1, 'GetReservesFromItemnumber returns a future wait (confirmed future hold)');
396
is(defined $results[3]?1:0, 1, 'GetReservesFromItemnumber returns a future wait (confirmed future hold)');
390
# End of tests for bug 9788
397
# End of tests for bug 9788
391
398
399
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
392
# Tests for CalculatePriority (bug 8918)
400
# Tests for CalculatePriority (bug 8918)
393
my $p = C4::Reserves::CalculatePriority($bibnum2);
401
my $p = C4::Reserves::CalculatePriority($bibnum2);
394
is($p, 4, 'CalculatePriority should now return priority 4');
402
is($p, 4, 'CalculatePriority should now return priority 4');
395
$resdate=undef;
403
$resdate=undef;
396
AddReserve('CPL',  $requesters{'CPL'}, $bibnum2,
404
AddReserve('CPL',  $requesters{'CPL2'}, $bibnum2,
397
           $constraint, $bibitems,  $p, $resdate, $expdate, $notes,
405
           $constraint, $bibitems,  $p, $resdate, $expdate, $notes,
398
           $title,      $checkitem, $found);
406
           $title,      $checkitem, $found);
399
$p = C4::Reserves::CalculatePriority($bibnum2);
407
$p = C4::Reserves::CalculatePriority($bibnum2);
Lines 412-418 ModReserveAffect( $itemnumber, $requesters{'CPL'} , 0); Link Here
412
$p = C4::Reserves::CalculatePriority($bibnum);
420
$p = C4::Reserves::CalculatePriority($bibnum);
413
is($p, 1, 'CalculatePriority should now return priority 1');
421
is($p, 1, 'CalculatePriority should now return priority 1');
414
#add another biblio hold, no resdate
422
#add another biblio hold, no resdate
415
AddReserve('CPL',  $requesters{'CPL'}, $bibnum,
423
AddReserve('CPL',  $requesters{'CPL2'}, $bibnum,
416
           $constraint, $bibitems,  $p, $resdate, $expdate, $notes,
424
           $constraint, $bibitems,  $p, $resdate, $expdate, $notes,
417
           $title,      $checkitem, $found);
425
           $title,      $checkitem, $found);
418
$p = C4::Reserves::CalculatePriority($bibnum);
426
$p = C4::Reserves::CalculatePriority($bibnum);
Lines 421-427 is($p, 2, 'CalculatePriority should now return priority 2'); Link Here
421
C4::Context->set_preference('AllowHoldDateInFuture', 1);
429
C4::Context->set_preference('AllowHoldDateInFuture', 1);
422
$resdate= dt_from_string();
430
$resdate= dt_from_string();
423
$resdate->add_duration(DateTime::Duration->new(days => 1));
431
$resdate->add_duration(DateTime::Duration->new(days => 1));
424
AddReserve('CPL',  $requesters{'CPL'}, $bibnum,
432
AddReserve('CPL',  $requesters{'CPL3'}, $bibnum,
425
           $constraint, $bibitems,  $p, output_pref($resdate), $expdate, $notes,
433
           $constraint, $bibitems,  $p, output_pref($resdate), $expdate, $notes,
426
           $title,      $checkitem, $found);
434
           $title,      $checkitem, $found);
427
$p = C4::Reserves::CalculatePriority($bibnum);
435
$p = C4::Reserves::CalculatePriority($bibnum);
428
- 

Return to bug 5144