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

(-)a/C4/ILSDI/Services.pm (-12 / +18 lines)
Lines 25-31 use C4::Items; Link Here
25
use C4::Circulation;
25
use C4::Circulation;
26
use C4::Accounts;
26
use C4::Accounts;
27
use C4::Biblio;
27
use C4::Biblio;
28
use C4::Reserves qw(AddReserve GetReservesFromBorrowernumber CanBookBeReserved CanItemBeReserved IsAvailableForItemLevelRequest);
28
use C4::Reserves qw(AddReserve CanBookBeReserved CanItemBeReserved IsAvailableForItemLevelRequest);
29
use C4::Context;
29
use C4::Context;
30
use C4::AuthoritiesMarc;
30
use C4::AuthoritiesMarc;
31
use XML::Simple;
31
use XML::Simple;
Lines 37-42 use C4::Members::Attributes qw(GetBorrowerAttributes); Link Here
37
37
38
use Koha::Biblios;
38
use Koha::Biblios;
39
use Koha::Libraries;
39
use Koha::Libraries;
40
use Koha::Patrons;
40
41
41
=head1 NAME
42
=head1 NAME
42
43
Lines 375-380 sub GetPatronInfo { Link Here
375
    my $borrowernumber = $cgi->param('patron_id');
376
    my $borrowernumber = $cgi->param('patron_id');
376
    my $borrower = GetMember( borrowernumber => $borrowernumber );
377
    my $borrower = GetMember( borrowernumber => $borrowernumber );
377
    return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
378
    return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
379
    my $patron = Koha::Patrons->find( $borrowernumber );
378
380
379
    # Cleaning the borrower hashref
381
    # Cleaning the borrower hashref
380
    my $flags = C4::Members::patronflags( $borrower );
382
    my $flags = C4::Members::patronflags( $borrower );
Lines 414-436 sub GetPatronInfo { Link Here
414
    if ( $cgi->param('show_holds') && $cgi->param('show_holds') eq "1" ) {
416
    if ( $cgi->param('show_holds') && $cgi->param('show_holds') eq "1" ) {
415
417
416
        # Get borrower's reserves
418
        # Get borrower's reserves
417
        my @reserves = GetReservesFromBorrowernumber( $borrowernumber, undef );
419
        my $holds = $patron->holds;
418
        foreach my $reserve (@reserves) {
420
        while ( my $hold = $holds->next ) {
419
421
422
            my $unblessed_hold = $hold->unblessed;
420
            # Get additional informations
423
            # Get additional informations
421
            my $item = GetBiblioFromItemNumber( $reserve->{'itemnumber'}, undef );
424
            my $item = GetBiblioFromItemNumber( $hold->itemnumber, undef );
422
            my $library = Koha::Libraries->find( $reserve->{branchcode} );
425
            my $library = Koha::Libraries->find( $hold->branchcode ); # Should $hold->get_library
423
            my $branchname = $library ? $library->branchname : '';
426
            my $branchname = $library ? $library->branchname : '';
424
427
425
            # Remove unwanted fields
428
            # Remove unwanted fields
426
            delete $item->{'more_subfields_xml'};
429
            delete $item->{'more_subfields_xml'};
427
430
428
            # Add additional fields
431
            # Add additional fields
429
            $reserve->{'item'}       = $item;
432
            $unblessed_hold->{item}       = $item;
430
            $reserve->{'branchname'} = $branchname;
433
            $unblessed_hold->{branchname} = $branchname;
431
            $reserve->{'title'}      = GetBiblio( $reserve->{'biblionumber'} )->{'title'};
434
            $unblessed_hold->{title}      = GetBiblio( $hold->biblionumber )->{'title'}; # Should be $hold->get_biblio
435
436
            push @{ $borrower->{holds}{hold} }, $unblessed_hold;
432
        }
437
        }
433
        $borrower->{'holds'}->{'hold'} = \@reserves;
434
    }
438
    }
435
439
436
    # Issues management
440
    # Issues management
Lines 500-505 sub GetServices { Link Here
500
    my $borrower = GetMember( borrowernumber => $borrowernumber );
504
    my $borrower = GetMember( borrowernumber => $borrowernumber );
501
    return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
505
    return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
502
506
507
    my $patron = Koha::Patrons->find( $borrowernumber );
508
503
    # Get the item, or return an error code if not found
509
    # Get the item, or return an error code if not found
504
    my $itemnumber = $cgi->param('item_id');
510
    my $itemnumber = $cgi->param('item_id');
505
    my $item = GetItem( $itemnumber );
511
    my $item = GetItem( $itemnumber );
Lines 519-528 sub GetServices { Link Here
519
    }
525
    }
520
526
521
    # Reserve cancellation management
527
    # Reserve cancellation management
522
    my @reserves = GetReservesFromBorrowernumber( $borrowernumber, undef );
528
    my $holds = $patron->holds;
523
    my @reserveditems;
529
    my @reserveditems;
524
    foreach my $reserve (@reserves) {
530
    while ( my $hold = $holds->next ) { # FIXME This could be improved
525
        push @reserveditems, $reserve->{'itemnumber'};
531
        push @reserveditems, $hold->itemnumber;
526
    }
532
    }
527
    if ( grep { $itemnumber eq $_ } @reserveditems ) {
533
    if ( grep { $itemnumber eq $_ } @reserveditems ) {
528
        push @availablefor, 'hold cancellation';
534
        push @availablefor, 'hold cancellation';
(-)a/C4/Members.pm (-3 / +5 lines)
Lines 267-278 sub patronflags { Link Here
267
        }
267
        }
268
        $flags{'ODUES'} = \%flaginfo;
268
        $flags{'ODUES'} = \%flaginfo;
269
    }
269
    }
270
    my @itemswaiting = C4::Reserves::GetReservesFromBorrowernumber( $patroninformation->{'borrowernumber'},'W' );
270
271
    my $nowaiting = scalar @itemswaiting;
271
    my $patron = Koha::Patrons->find( $patroninformation->{borrowernumber} );
272
    my $waiting_holds = $patron->holds->search({ found => 'W' });
273
    my $nowaiting = $waiting_holds->count;
272
    if ( $nowaiting > 0 ) {
274
    if ( $nowaiting > 0 ) {
273
        my %flaginfo;
275
        my %flaginfo;
274
        $flaginfo{'message'}  = "Reserved items available";
276
        $flaginfo{'message'}  = "Reserved items available";
275
        $flaginfo{'itemlist'} = \@itemswaiting;
277
        $flaginfo{'itemlist'} = $waiting_holds->unblessed;
276
        $flags{'WAITING'}     = \%flaginfo;
278
        $flags{'WAITING'}     = \%flaginfo;
277
    }
279
    }
278
    return ( \%flags );
280
    return ( \%flags );
(-)a/C4/SIP/ILS/Patron.pm (-7 / +13 lines)
Lines 24-29 use C4::Items qw( GetBarcodeFromItemnumber GetItemnumbersForBiblio); Link Here
24
use C4::Auth qw(checkpw);
24
use C4::Auth qw(checkpw);
25
25
26
use Koha::Libraries;
26
use Koha::Libraries;
27
use Koha::Patrons;
27
28
28
our $kp;    # koha patron
29
our $kp;    # koha patron
29
30
Lines 431-450 sub _get_address { Link Here
431
432
432
sub _get_outstanding_holds {
433
sub _get_outstanding_holds {
433
    my $borrowernumber = shift;
434
    my $borrowernumber = shift;
434
    my @hold_array = grep { !defined $_->{found} || $_->{found} ne 'W'} GetReservesFromBorrowernumber($borrowernumber);
435
435
    foreach my $h (@hold_array) {
436
    my $patron = Koha::Patrons->find( $borrowernumber );
437
    my $holds = $patron->holds->search( { -or => [ { found => undef }, { found => { '!=' => 'W' } } ] } );
438
    my @holds;
439
    while ( my $hold = $holds->next ) {
436
        my $item;
440
        my $item;
437
        if ($h->{itemnumber}) {
441
        if ($hold->itemnumber) {
438
            $item = $h->{itemnumber};
442
            $item = $hold->itemnumber;
439
        }
443
        }
440
        else {
444
        else {
441
            # We need to return a barcode for the biblio so the client
445
            # We need to return a barcode for the biblio so the client
442
            # can request the biblio info
446
            # can request the biblio info
443
            $item = ( GetItemnumbersForBiblio($h->{biblionumber}) )->[0];
447
            $item = ( GetItemnumbersForBiblio($hold->biblionumber) )->[0];
444
        }
448
        }
445
        $h->{barcode} = GetBarcodeFromItemnumber($item);
449
        my $unblessed_hold = $hold->unblessed;
450
        $unblessed_hold->{barcode} = GetBarcodeFromItemnumber($item);
451
        push @holds, $unblessed_hold;
446
    }
452
    }
447
    return \@hold_array;
453
    return \@holds;
448
}
454
}
449
455
450
1;
456
1;
(-)a/Koha/Patron/Discharge.pm (-4 / +5 lines)
Lines 7-13 use Carp; Link Here
7
7
8
use C4::Templates qw ( gettemplate );
8
use C4::Templates qw ( gettemplate );
9
use C4::Members qw( GetPendingIssues );
9
use C4::Members qw( GetPendingIssues );
10
use C4::Reserves qw( GetReservesFromBorrowernumber CancelReserve );
10
use C4::Reserves qw( CancelReserve );
11
11
12
use Koha::Database;
12
use Koha::Database;
13
use Koha::DateUtils qw( dt_from_string output_pref );
13
use Koha::DateUtils qw( dt_from_string output_pref );
Lines 79-87 sub discharge { Link Here
79
    return unless $borrowernumber and can_be_discharged( { borrowernumber => $borrowernumber } );
79
    return unless $borrowernumber and can_be_discharged( { borrowernumber => $borrowernumber } );
80
80
81
    # Cancel reserves
81
    # Cancel reserves
82
    my @reserves = GetReservesFromBorrowernumber($borrowernumber);
82
    my $patron = Koha::Patrons->find( $borrowernumber );
83
    for my $reserve (@reserves) {
83
    my $holds = $patron->holds;
84
        CancelReserve( { reserve_id => $reserve->{reserve_id} } );
84
    while ( my $hold = $holds->next ) {
85
        CancelReserve( { reserve_id => $hold->reserve_id } );
85
    }
86
    }
86
87
87
    # Debar the member
88
    # Debar the member
(-)a/circ/returns.pl (-8 / +4 lines)
Lines 50-57 use C4::RotatingCollections; Link Here
50
use Koha::AuthorisedValues;
50
use Koha::AuthorisedValues;
51
use Koha::DateUtils;
51
use Koha::DateUtils;
52
use Koha::Calendar;
52
use Koha::Calendar;
53
use Koha::Checkouts;
54
use Koha::BiblioFrameworks;
53
use Koha::BiblioFrameworks;
54
use Koha::Checkouts;
55
use Koha::Patrons;
55
56
56
my $query = new CGI;
57
my $query = new CGI;
57
58
Lines 336-348 if ($barcode) { Link Here
336
337
337
        if (C4::Context->preference("WaitingNotifyAtCheckin") ) {
338
        if (C4::Context->preference("WaitingNotifyAtCheckin") ) {
338
            #Check for waiting holds
339
            #Check for waiting holds
339
            my @reserves = GetReservesFromBorrowernumber($borrower->{'borrowernumber'});
340
            my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
340
            my $waiting_holds = 0;
341
            my $waiting_holds = $patron->holds->search({ found => 'W', branchcode => $userenv_branch })->count;
341
            foreach my $num_res (@reserves) {
342
                if ( $num_res->{'found'} eq 'W' && $num_res->{'branchcode'} eq $userenv_branch) {
343
                    $waiting_holds++;
344
                }
345
            }
346
            if ($waiting_holds > 0) {
342
            if ($waiting_holds > 0) {
347
                $template->param(
343
                $template->param(
348
                    waiting_holds       => $waiting_holds,
344
                    waiting_holds       => $waiting_holds,
(-)a/members/discharge.pl (-2 / +4 lines)
Lines 38-43 use C4::Reserves; Link Here
38
use C4::Letters;
38
use C4::Letters;
39
use Koha::Patron::Discharge;
39
use Koha::Patron::Discharge;
40
use Koha::Patron::Images;
40
use Koha::Patron::Images;
41
use Koha::Patrons;
41
42
42
use Koha::DateUtils;
43
use Koha::DateUtils;
43
44
Lines 70-77 if ( $input->param('borrowernumber') ) { Link Here
70
    });
71
    });
71
72
72
    # Getting reserves
73
    # Getting reserves
73
    my @reserves    = GetReservesFromBorrowernumber($borrowernumber);
74
    my $patron = Koha::Patrons->find( $borrowernumber );
74
    my $has_reserves = scalar(@reserves);
75
    my $holds = $patron->holds;
76
    my $has_reserves = $holds->count;
75
77
76
    # Generating discharge if needed
78
    # Generating discharge if needed
77
    if ( $input->param('discharge') and $can_be_discharged ) {
79
    if ( $input->param('discharge') and $can_be_discharged ) {
(-)a/opac/opac-reserve.pl (-6 / +8 lines)
Lines 199-205 foreach my $biblioNumber (@biblionumbers) { Link Here
199
if ( $query->param('place_reserve') ) {
199
if ( $query->param('place_reserve') ) {
200
    my $reserve_cnt = 0;
200
    my $reserve_cnt = 0;
201
    if ($maxreserves) {
201
    if ($maxreserves) {
202
        $reserve_cnt = GetReservesFromBorrowernumber( $borrowernumber );
202
        my $patron = Koha::Patrons->find( $borrowernumber );
203
        $reserve_cnt = $patron->holds->count;
203
    }
204
    }
204
205
205
    # List is composed of alternating biblio/item/branch
206
    # List is composed of alternating biblio/item/branch
Lines 350-356 if ( $borr->{lost} && ($borr->{lost} == 1) ) { Link Here
350
    );
351
    );
351
}
352
}
352
353
353
if ( Koha::Patrons->find( $borrowernumber )->is_debarred ) {
354
my $patron = Koha::Patrons->find( $borrowernumber );
355
if ( $patron->is_debarred ) {
354
    $noreserves = 1;
356
    $noreserves = 1;
355
    $template->param(
357
    $template->param(
356
        message          => 1,
358
        message          => 1,
Lines 360-372 if ( Koha::Patrons->find( $borrowernumber )->is_debarred ) { Link Here
360
    );
362
    );
361
}
363
}
362
364
363
my @reserves = GetReservesFromBorrowernumber( $borrowernumber );
365
my $holds = $patron->holds;
364
my $reserves_count = scalar(@reserves);
366
my $reserves_count = $holds->count;
365
$template->param( RESERVES => \@reserves );
367
$template->param( RESERVES => $holds->unblessed );
366
if ( $maxreserves && ( $reserves_count >= $maxreserves ) ) {
368
if ( $maxreserves && ( $reserves_count >= $maxreserves ) ) {
367
    $template->param( message => 1 );
369
    $template->param( message => 1 );
368
    $noreserves = 1;
370
    $noreserves = 1;
369
    $template->param( too_many_reserves => scalar(@reserves));
371
    $template->param( too_many_reserves => $holds->count );
370
}
372
}
371
373
372
unless ( $noreserves ) {
374
unless ( $noreserves ) {
(-)a/t/db_dependent/Holds.t (-8 / +10 lines)
Lines 17-22 use Koha::Database; Link Here
17
use Koha::DateUtils qw( dt_from_string output_pref );
17
use Koha::DateUtils qw( dt_from_string output_pref );
18
use Koha::Biblios;
18
use Koha::Biblios;
19
use Koha::Holds;
19
use Koha::Holds;
20
use Koha::Patrons;
20
21
21
BEGIN {
22
BEGIN {
22
    use FindBin;
23
    use FindBin;
Lines 121-128 my $hold_found = $hold->found(); Link Here
121
$hold->set({ found => 'W'})->store();
122
$hold->set({ found => 'W'})->store();
122
is( Koha::Holds->waiting()->count(), 1, "Koha::Holds->waiting returns waiting holds" );
123
is( Koha::Holds->waiting()->count(), 1, "Koha::Holds->waiting returns waiting holds" );
123
124
124
my ( $reserve ) = GetReservesFromBorrowernumber($borrowernumbers[0]);
125
my $patron = Koha::Patrons->find( $borrowernumbers[0] );
125
ok( $reserve->{'borrowernumber'} eq $borrowernumbers[0], "Test GetReservesFromBorrowernumber()");
126
$holds = $patron->holds;
127
is( $holds->next->borrowernumber, $borrowernumbers[0], "Test Koha::Patron->holds");
126
128
127
129
128
ok( GetReserveCount( $borrowernumbers[0] ), "Test GetReserveCount()" );
130
ok( GetReserveCount( $borrowernumbers[0] ), "Test GetReserveCount()" );
Lines 146-152 ModReserve({ Link Here
146
    suspend_until => output_pref( { dt => dt_from_string( "2013-01-01", "iso" ), dateonly => 1 } ),
148
    suspend_until => output_pref( { dt => dt_from_string( "2013-01-01", "iso" ), dateonly => 1 } ),
147
});
149
});
148
150
149
$reserve = GetReserve( $reserve_id );
151
my $reserve = GetReserve( $reserve_id );
150
ok( $reserve->{'priority'} eq '4', "Test GetReserve(), priority changed correctly" );
152
ok( $reserve->{'priority'} eq '4', "Test GetReserve(), priority changed correctly" );
151
ok( $reserve->{'suspend'}, "Test GetReserve(), suspend hold" );
153
ok( $reserve->{'suspend'}, "Test GetReserve(), suspend hold" );
152
is( $reserve->{'suspend_until'}, '2013-01-01 00:00:00', "Test GetReserve(), suspend until date" );
154
is( $reserve->{'suspend_until'}, '2013-01-01 00:00:00', "Test GetReserve(), suspend until date" );
Lines 196-212 AddReserve( Link Here
196
    my $checkitem,
198
    my $checkitem,
197
    my $found,
199
    my $found,
198
);
200
);
199
( $reserve ) = GetReservesFromBorrowernumber($borrowernumber);
201
$patron = Koha::Patrons->find( $borrowernumber );
202
$holds = $patron->holds;
200
my $reserveid = C4::Reserves::GetReserveId(
203
my $reserveid = C4::Reserves::GetReserveId(
201
    {
204
    {
202
        biblionumber => $biblionumber,
205
        biblionumber => $biblionumber,
203
        borrowernumber => $borrowernumber
206
        borrowernumber => $borrowernumber
204
    }
207
    }
205
);
208
);
206
is( $reserveid, $reserve->{reserve_id}, "Test GetReserveId" );
209
is( $reserveid, $holds->next->reserve_id, "Test GetReserveId" );
207
ModReserveMinusPriority( $itemnumber, $reserve->{'reserve_id'} );
210
ModReserveMinusPriority( $itemnumber, $reserve->{'reserve_id'} );
208
( $reserve ) = GetReservesFromBorrowernumber($borrowernumber);
211
$holds = $patron->holds;
209
ok( $reserve->{'itemnumber'} eq $itemnumber, "Test ModReserveMinusPriority()" );
212
is( $holds->next->itemnumber, $itemnumber, "Test ModReserveMinusPriority()" );
210
213
211
214
212
my $reserve2 = GetReserveInfo( $reserve->{'reserve_id'} );
215
my $reserve2 = GetReserveInfo( $reserve->{'reserve_id'} );
213
- 

Return to bug 17738