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 365-370 sub GetPatronInfo { Link Here
365
    my $borrowernumber = $cgi->param('patron_id');
366
    my $borrowernumber = $cgi->param('patron_id');
366
    my $borrower = GetMemberDetails( $borrowernumber );
367
    my $borrower = GetMemberDetails( $borrowernumber );
367
    return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
368
    return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
369
    my $patron = Koha::Patrons->find( $borrowernumber );
368
370
369
    # Cleaning the borrower hashref
371
    # Cleaning the borrower hashref
370
    $borrower->{'charges'}    = $borrower->{'flags'}->{'CHARGES'}->{'amount'};
372
    $borrower->{'charges'}    = $borrower->{'flags'}->{'CHARGES'}->{'amount'};
Lines 404-415 sub GetPatronInfo { Link Here
404
    if ( $cgi->param('show_holds') && $cgi->param('show_holds') eq "1" ) {
406
    if ( $cgi->param('show_holds') && $cgi->param('show_holds') eq "1" ) {
405
407
406
        # Get borrower's reserves
408
        # Get borrower's reserves
407
        my @reserves = GetReservesFromBorrowernumber( $borrowernumber, undef );
409
        my $holds = $patron->holds;
408
        foreach my $reserve (@reserves) {
410
        while ( my $hold = $holds->next ) {
409
411
412
            my $unblessed_hold = $hold->unblessed;
410
            # Get additional informations
413
            # Get additional informations
411
            my $item = GetBiblioFromItemNumber( $reserve->{'itemnumber'}, undef );
414
            my $item = GetBiblioFromItemNumber( $hold->itemnumber, undef );
412
            my $library = Koha::Libraries->find( $reserve->{branchcode} );
415
            my $library = Koha::Libraries->find( $hold->branchcode ); # Should $hold->get_library
413
            my $branchname = $library ? $library->branchname : '';
416
            my $branchname = $library ? $library->branchname : '';
414
417
415
            # Remove unwanted fields
418
            # Remove unwanted fields
Lines 417-427 sub GetPatronInfo { Link Here
417
            delete $item->{'more_subfields_xml'};
420
            delete $item->{'more_subfields_xml'};
418
421
419
            # Add additional fields
422
            # Add additional fields
420
            $reserve->{'item'}       = $item;
423
            $unblessed_hold->{item}       = $item;
421
            $reserve->{'branchname'} = $branchname;
424
            $unblessed_hold->{branchname} = $branchname;
422
            $reserve->{'title'}      = GetBiblio( $reserve->{'biblionumber'} )->{'title'};
425
            $unblessed_hold->{title}      = GetBiblio( $hold->biblionumber )->{'title'}; # Should be $hold->get_biblio
426
427
            push @{ $borrower->{holds}{hold} }, $unblessed_hold;
423
        }
428
        }
424
        $borrower->{'holds'}->{'hold'} = \@reserves;
425
    }
429
    }
426
430
427
    # Issues management
431
    # Issues management
Lines 490-495 sub GetServices { Link Here
490
    my $borrower = GetMemberDetails( $borrowernumber );
494
    my $borrower = GetMemberDetails( $borrowernumber );
491
    return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
495
    return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
492
496
497
    my $patron = Koha::Patrons->find( $borrowernumber );
498
493
    # Get the item, or return an error code if not found
499
    # Get the item, or return an error code if not found
494
    my $itemnumber = $cgi->param('item_id');
500
    my $itemnumber = $cgi->param('item_id');
495
    my $item = GetItem( $itemnumber );
501
    my $item = GetItem( $itemnumber );
Lines 509-518 sub GetServices { Link Here
509
    }
515
    }
510
516
511
    # Reserve cancellation management
517
    # Reserve cancellation management
512
    my @reserves = GetReservesFromBorrowernumber( $borrowernumber, undef );
518
    my $holds = $patron->holds;
513
    my @reserveditems;
519
    my @reserveditems;
514
    foreach my $reserve (@reserves) {
520
    while ( my $hold = $holds->next ) { # FIXME This could be improved
515
        push @reserveditems, $reserve->{'itemnumber'};
521
        push @reserveditems, $hold->itemnumber;
516
    }
522
    }
517
    if ( grep { $itemnumber eq $_ } @reserveditems ) {
523
    if ( grep { $itemnumber eq $_ } @reserveditems ) {
518
        push @availablefor, 'hold cancellation';
524
        push @availablefor, 'hold cancellation';
(-)a/C4/Members.pm (-3 / +5 lines)
Lines 377-388 sub patronflags { Link Here
377
        }
377
        }
378
        $flags{'ODUES'} = \%flaginfo;
378
        $flags{'ODUES'} = \%flaginfo;
379
    }
379
    }
380
    my @itemswaiting = C4::Reserves::GetReservesFromBorrowernumber( $patroninformation->{'borrowernumber'},'W' );
380
381
    my $nowaiting = scalar @itemswaiting;
381
    my $patron = Koha::Patrons->find( $patroninformation->{borrowernumber} );
382
    my $waiting_holds = $patron->holds->search({ found => 'W' });
383
    my $nowaiting = $waiting_holds->count;
382
    if ( $nowaiting > 0 ) {
384
    if ( $nowaiting > 0 ) {
383
        my %flaginfo;
385
        my %flaginfo;
384
        $flaginfo{'message'}  = "Reserved items available";
386
        $flaginfo{'message'}  = "Reserved items available";
385
        $flaginfo{'itemlist'} = \@itemswaiting;
387
        $flaginfo{'itemlist'} = $waiting_holds->unblessed;
386
        $flags{'WAITING'}     = \%flaginfo;
388
        $flags{'WAITING'}     = \%flaginfo;
387
    }
389
    }
388
    return ( \%flags );
390
    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 (-7 / +3 lines)
Lines 50-55 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::Patrons;
53
54
54
my $query = new CGI;
55
my $query = new CGI;
55
56
Lines 332-344 if ($barcode) { Link Here
332
333
333
        if (C4::Context->preference("WaitingNotifyAtCheckin") ) {
334
        if (C4::Context->preference("WaitingNotifyAtCheckin") ) {
334
            #Check for waiting holds
335
            #Check for waiting holds
335
            my @reserves = GetReservesFromBorrowernumber($borrower->{'borrowernumber'});
336
            my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
336
            my $waiting_holds = 0;
337
            my $waiting_holds = $patron->holds->search({ found => 'W', branchcode => $userenv_branch })->count;
337
            foreach my $num_res (@reserves) {
338
                if ( $num_res->{'found'} eq 'W' && $num_res->{'branchcode'} eq $userenv_branch) {
339
                    $waiting_holds++;
340
                }
341
            }
342
            if ($waiting_holds > 0) {
338
            if ($waiting_holds > 0) {
343
                $template->param(
339
                $template->param(
344
                    waiting_holds       => $waiting_holds,
340
                    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 187-193 foreach my $biblioNumber (@biblionumbers) { Link Here
187
if ( $query->param('place_reserve') ) {
187
if ( $query->param('place_reserve') ) {
188
    my $reserve_cnt = 0;
188
    my $reserve_cnt = 0;
189
    if ($maxreserves) {
189
    if ($maxreserves) {
190
        $reserve_cnt = GetReservesFromBorrowernumber( $borrowernumber );
190
        my $patron = Koha::Patrons->find( $borrowernumber );
191
        $reserve_cnt = $patron->holds->count;
191
    }
192
    }
192
193
193
    # List is composed of alternating biblio/item/branch
194
    # List is composed of alternating biblio/item/branch
Lines 328-334 if ( $borr->{lost} && ($borr->{lost} == 1) ) { Link Here
328
    );
329
    );
329
}
330
}
330
331
331
if ( Koha::Patrons->find( $borrowernumber )->is_debarred ) {
332
my $patron = Koha::Patrons->find( $borrowernumber );
333
if ( $patron->is_debarred ) {
332
    $noreserves = 1;
334
    $noreserves = 1;
333
    $template->param(
335
    $template->param(
334
        message          => 1,
336
        message          => 1,
Lines 338-350 if ( Koha::Patrons->find( $borrowernumber )->is_debarred ) { Link Here
338
    );
340
    );
339
}
341
}
340
342
341
my @reserves = GetReservesFromBorrowernumber( $borrowernumber );
343
my $holds = $patron->holds;
342
my $reserves_count = scalar(@reserves);
344
my $reserves_count = $holds->count;
343
$template->param( RESERVES => \@reserves );
345
$template->param( RESERVES => $holds->unblessed );
344
if ( $maxreserves && ( $reserves_count >= $maxreserves ) ) {
346
if ( $maxreserves && ( $reserves_count >= $maxreserves ) ) {
345
    $template->param( message => 1 );
347
    $template->param( message => 1 );
346
    $noreserves = 1;
348
    $noreserves = 1;
347
    $template->param( too_many_reserves => scalar(@reserves));
349
    $template->param( too_many_reserves => $holds->count );
348
}
350
}
349
351
350
unless ( $noreserves ) {
352
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