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

(-)a/C4/Biblio.pm (-3 / +5 lines)
Lines 43-48 use Koha::Authority::Types; Link Here
43
use Koha::Acquisition::Currencies;
43
use Koha::Acquisition::Currencies;
44
use Koha::Biblio::Metadata;
44
use Koha::Biblio::Metadata;
45
use Koha::Biblio::Metadatas;
45
use Koha::Biblio::Metadatas;
46
use Koha::Holds;
46
use Koha::SearchEngine;
47
use Koha::SearchEngine;
47
use Koha::Libraries;
48
use Koha::Libraries;
48
49
Lines 409-418 sub DelBiblio { Link Here
409
    }
410
    }
410
411
411
    # We delete any existing holds
412
    # We delete any existing holds
413
    my $biblio = Koha::Biblios->find( $biblionumber );
414
    my $holds = $biblio->holds;
412
    require C4::Reserves;
415
    require C4::Reserves;
413
    my $reserves = C4::Reserves::GetReservesFromBiblionumber({ biblionumber => $biblionumber });
416
    while ( my $hold = $holds->next ) {
414
    foreach my $res ( @$reserves ) {
417
        C4::Reserves::CancelReserve({ reserve_id => $hold->reserve_id }); # TODO Replace with $hold->cancel
415
        C4::Reserves::CancelReserve({ reserve_id => $res->{'reserve_id'} });
416
    }
418
    }
417
419
418
    # Delete in Zebra. Be careful NOT to move this line after _koha_delete_biblio
420
    # Delete in Zebra. Be careful NOT to move this line after _koha_delete_biblio
(-)a/C4/ILSDI/Services.pm (-3 / +5 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 GetReservesFromBiblionumber GetReservesFromBorrowernumber CanBookBeReserved CanItemBeReserved IsAvailableForItemLevelRequest);
28
use C4::Reserves qw(AddReserve GetReservesFromBorrowernumber 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 35-40 use DateTime; Link Here
35
use C4::Auth;
35
use C4::Auth;
36
use C4::Members::Attributes qw(GetBorrowerAttributes);
36
use C4::Members::Attributes qw(GetBorrowerAttributes);
37
37
38
use Koha::Biblios;
38
use Koha::Libraries;
39
use Koha::Libraries;
39
40
40
=head1 NAME
41
=head1 NAME
Lines 217-223 sub GetRecords { Link Here
217
218
218
        # Get most of the needed data
219
        # Get most of the needed data
219
        my $biblioitemnumber = $biblioitem->{'biblioitemnumber'};
220
        my $biblioitemnumber = $biblioitem->{'biblioitemnumber'};
220
        my $reserves         = GetReservesFromBiblionumber({ biblionumber => $biblionumber });
221
        my $biblio = Koha::Biblios->find( $biblionumber );
222
        my $holds  = $biblio->holds_placed_before_today->unblessed;
221
        my $issues           = GetBiblioIssues($biblionumber);
223
        my $issues           = GetBiblioIssues($biblionumber);
222
        my $items            = GetItemsByBiblioitemnumber($biblioitemnumber);
224
        my $items            = GetItemsByBiblioitemnumber($biblioitemnumber);
223
225
Lines 236-242 sub GetRecords { Link Here
236
238
237
        # Hashref building...
239
        # Hashref building...
238
        $biblioitem->{'items'}->{'item'}       = $items;
240
        $biblioitem->{'items'}->{'item'}       = $items;
239
        $biblioitem->{'reserves'}->{'reserve'} = $reserves;
241
        $biblioitem->{'reserves'}->{'reserve'} = $holds;
240
        $biblioitem->{'issues'}->{'issue'}     = $issues;
242
        $biblioitem->{'issues'}->{'issue'}     = $issues;
241
243
242
        push @records, $biblioitem;
244
        push @records, $biblioitem;
(-)a/C4/SIP/ILS/Item.pm (-8 / +4 lines)
Lines 22-27 use C4::Circulation; Link Here
22
use C4::Members;
22
use C4::Members;
23
use C4::Reserves;
23
use C4::Reserves;
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::Biblios;
25
26
26
27
27
=encoding UTF-8
28
=encoding UTF-8
Lines 65-76 use Koha::Database; Link Here
65
);
66
);
66
=cut
67
=cut
67
68
68
sub priority_sort {
69
    defined $a->{priority} or return -1;
70
    defined $b->{priority} or return 1;
71
    return $a->{priority} <=> $b->{priority};
72
}
73
74
sub new {
69
sub new {
75
	my ($class, $item_id) = @_;
70
	my ($class, $item_id) = @_;
76
	my $type = ref($class) || $class;
71
	my $type = ref($class) || $class;
Lines 99-106 sub new { Link Here
99
    }
94
    }
100
	my $borrower = GetMember(borrowernumber=>$issue->{'borrowernumber'});
95
	my $borrower = GetMember(borrowernumber=>$issue->{'borrowernumber'});
101
	$item->{patron} = $borrower->{'cardnumber'};
96
	$item->{patron} = $borrower->{'cardnumber'};
102
    my $reserves = GetReservesFromBiblionumber({ biblionumber => $item->{biblionumber} });
97
    my $biblio = Koha::Biblios->find( $item->{biblionumber } );
103
    $item->{hold_queue} = [ sort priority_sort @$reserves ];
98
    my $holds = $biblio->holds_placed_before_today->unblessed;
99
    $item->{hold_queue} = $holds;
104
	$item->{hold_shelf}    = [( grep {   defined $_->{found}  and $_->{found} eq 'W' } @{$item->{hold_queue}} )];
100
	$item->{hold_shelf}    = [( grep {   defined $_->{found}  and $_->{found} eq 'W' } @{$item->{hold_queue}} )];
105
	$item->{pending_queue} = [( grep {(! defined $_->{found}) or  $_->{found} ne 'W' } @{$item->{hold_queue}} )];
101
	$item->{pending_queue} = [( grep {(! defined $_->{found}) or  $_->{found} ne 'W' } @{$item->{hold_queue}} )];
106
	$self = $item;
102
	$self = $item;
(-)a/acqui/parcel.pl (-5 / +7 lines)
Lines 65-75 use C4::Items; Link Here
65
use CGI qw ( -utf8 );
65
use CGI qw ( -utf8 );
66
use C4::Output;
66
use C4::Output;
67
use C4::Suggestions;
67
use C4::Suggestions;
68
use C4::Reserves qw/GetReservesFromBiblionumber/;
69
68
70
use Koha::Acquisition::Bookseller;
69
use Koha::Acquisition::Bookseller;
71
use Koha::Biblios;
70
use Koha::Biblios;
72
use Koha::DateUtils;
71
use Koha::DateUtils;
72
use Koha::Biblios;
73
73
74
use JSON;
74
use JSON;
75
75
Lines 140-149 for my $order ( @orders ) { Link Here
140
    $line{invoice} = $invoice->{invoicenumber};
140
    $line{invoice} = $invoice->{invoicenumber};
141
    $line{holds} = 0;
141
    $line{holds} = 0;
142
    my @itemnumbers = GetItemnumbersFromOrder( $order->{ordernumber} );
142
    my @itemnumbers = GetItemnumbersFromOrder( $order->{ordernumber} );
143
    for my $itemnumber ( @itemnumbers ) {
143
    my $biblio = Koha::Biblios->find( $order->{ordernumber} );
144
        my $holds = GetReservesFromBiblionumber({ biblionumber => $line{biblionumber}, itemnumber => $itemnumber });
144
    $line{holds} = $biblio->holds_placed_before_today->search(
145
        $line{holds} += scalar( @$holds );
145
        {
146
    }
146
            itemnumber => { -in => \@itemnumbers },
147
        }
148
    )->count;
147
    $line{budget} = GetBudgetByOrderNumber( $line{ordernumber} );
149
    $line{budget} = GetBudgetByOrderNumber( $line{ordernumber} );
148
150
149
    $line{tax_value} = $line{tax_value_on_receiving};
151
    $line{tax_value} = $line{tax_value_on_receiving};
(-)a/catalogue/ISBDdetail.pl (-3 / +5 lines)
Lines 47-52 use C4::Members; # to use GetMember Link Here
47
use C4::Serials;    # CountSubscriptionFromBiblionumber
47
use C4::Serials;    # CountSubscriptionFromBiblionumber
48
use C4::Search;		# enabled_staff_search_views
48
use C4::Search;		# enabled_staff_search_views
49
use C4::Acquisition qw(GetOrdersByBiblionumber);
49
use C4::Acquisition qw(GetOrdersByBiblionumber);
50
51
use Koha::Biblios;
50
use Koha::RecordProcessor;
52
use Koha::RecordProcessor;
51
53
52
54
Lines 165-173 $template->param (countorders => $count_orders_using_biblio); Link Here
165
my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
167
my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
166
$template->param (countdeletedorders => $count_deletedorders_using_biblio);
168
$template->param (countdeletedorders => $count_deletedorders_using_biblio);
167
169
168
my $holds = C4::Reserves::GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
170
my $biblio = Koha::Biblios->find( $biblionumber );
169
my $holdcount = scalar( @$holds );
171
my $holds = $biblio->holds;
170
$template->param( holdcount => scalar ( @$holds ) );
172
$template->param( holdcount => $holds->count );
171
173
172
output_html_with_http_headers $query, $cookie, $template->output;
174
output_html_with_http_headers $query, $cookie, $template->output;
173
175
(-)a/catalogue/MARCdetail.pl (-3 / +5 lines)
Lines 59-64 use C4::Acquisition; Link Here
59
use C4::Members; # to use GetMember
59
use C4::Members; # to use GetMember
60
use C4::Serials;    #uses getsubscriptionsfrombiblionumber GetSubscriptionsFromBiblionumber
60
use C4::Serials;    #uses getsubscriptionsfrombiblionumber GetSubscriptionsFromBiblionumber
61
use C4::Search;		# enabled_staff_search_views
61
use C4::Search;		# enabled_staff_search_views
62
63
use Koha::Biblios;
62
use Koha::BiblioFrameworks;
64
use Koha::BiblioFrameworks;
63
65
64
use List::MoreUtils qw( uniq );
66
use List::MoreUtils qw( uniq );
Lines 340-347 $template->param (countorders => $count_orders_using_biblio); Link Here
340
my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
342
my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
341
$template->param (countdeletedorders => $count_deletedorders_using_biblio);
343
$template->param (countdeletedorders => $count_deletedorders_using_biblio);
342
344
343
my $holds = C4::Reserves::GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
345
$biblio = Koha::Biblios->find( $biblionumber );
344
my $holdcount = scalar( @$holds );
346
my $holds = $biblio->holds;
345
$template->param( holdcount => scalar ( @$holds ) );
347
$template->param( holdcount => $holds->count );
346
348
347
output_html_with_http_headers $query, $cookie, $template->output;
349
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/catalogue/detail.pl (-2 / +4 lines)
Lines 42-47 use C4::HTML5Media; Link Here
42
use C4::CourseReserves qw(GetItemCourseReservesInfo);
42
use C4::CourseReserves qw(GetItemCourseReservesInfo);
43
use C4::Acquisition qw(GetOrdersByBiblionumber);
43
use C4::Acquisition qw(GetOrdersByBiblionumber);
44
use Koha::AuthorisedValues;
44
use Koha::AuthorisedValues;
45
use Koha::Biblios;
45
use Koha::Patrons;
46
use Koha::Patrons;
46
use Koha::Virtualshelves;
47
use Koha::Virtualshelves;
47
48
Lines 461-468 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->pref Link Here
461
}
462
}
462
463
463
#we only need to pass the number of holds to the template
464
#we only need to pass the number of holds to the template
464
my $holds = C4::Reserves::GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
465
my $biblio = Koha::Biblios->find( $biblionumber );
465
$template->param( holdcount => scalar ( @$holds ) );
466
my $holds = $biblio->holds;
467
$template->param( holdcount => $holds->count );
466
468
467
my $StaffDetailItemSelection = C4::Context->preference('StaffDetailItemSelection');
469
my $StaffDetailItemSelection = C4::Context->preference('StaffDetailItemSelection');
468
if ($StaffDetailItemSelection) {
470
if ($StaffDetailItemSelection) {
(-)a/catalogue/imageviewer.pl (-3 / +5 lines)
Lines 29-34 use C4::Images; Link Here
29
use C4::Search;
29
use C4::Search;
30
use C4::Acquisition qw(GetOrdersByBiblionumber);
30
use C4::Acquisition qw(GetOrdersByBiblionumber);
31
31
32
use Koha::Biblios;
33
32
my $query = new CGI;
34
my $query = new CGI;
33
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
35
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
34
    {
36
    {
Lines 107-114 $template->param (countorders => $count_orders_using_biblio); Link Here
107
my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
109
my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
108
$template->param (countdeletedorders => $count_deletedorders_using_biblio);
110
$template->param (countdeletedorders => $count_deletedorders_using_biblio);
109
111
110
my $holds= C4::Reserves::GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
112
$biblio = Koha::Biblios->find( $biblionumber );
111
my $holdcount = scalar( @$holds );
113
my $holds = $biblio->holds;
112
$template->param( holdcount => scalar ( @$holds ) );
114
$template->param( holdcount => $holds->count );
113
115
114
output_html_with_http_headers $query, $cookie, $template->output;
116
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/catalogue/labeledMARCdetail.pl (-3 / +4 lines)
Lines 31-36 use C4::Members; # to use GetMember Link Here
31
use C4::Search;		# enabled_staff_search_views
31
use C4::Search;		# enabled_staff_search_views
32
use C4::Acquisition qw(GetOrdersByBiblionumber);
32
use C4::Acquisition qw(GetOrdersByBiblionumber);
33
33
34
use Koha::Biblios;
34
use Koha::BiblioFrameworks;
35
use Koha::BiblioFrameworks;
35
36
36
my $query        = new CGI;
37
my $query        = new CGI;
Lines 151-158 $template->param (countorders => $count_orders_using_biblio); Link Here
151
my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
152
my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
152
$template->param (countdeletedorders => $count_deletedorders_using_biblio);
153
$template->param (countdeletedorders => $count_deletedorders_using_biblio);
153
154
154
my $holds= C4::Reserves::GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
155
$biblio = Koha::Biblios->find( $biblionumber );
155
my $holdcount = scalar( @$holds );
156
my $holds = $biblio->holds;
156
$template->param( holdcount => scalar ( @$holds ) );
157
$template->param( holdcount => $holds->count );
157
158
158
output_html_with_http_headers $query, $cookie, $template->output;
159
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/catalogue/moredetail.pl (-4 / +4 lines)
Lines 32-41 use C4::Auth; Link Here
32
use C4::Serials;
32
use C4::Serials;
33
use C4::Members; # to use GetMember
33
use C4::Members; # to use GetMember
34
use C4::Search;		# enabled_staff_search_views
34
use C4::Search;		# enabled_staff_search_views
35
use C4::Reserves qw(GetReservesFromBiblionumber);
36
35
37
use Koha::Acquisition::Booksellers;
36
use Koha::Acquisition::Booksellers;
38
use Koha::AuthorisedValues;
37
use Koha::AuthorisedValues;
38
use Koha::Biblios;
39
use Koha::DateUtils;
39
use Koha::DateUtils;
40
use Koha::Items;
40
use Koha::Items;
41
use Koha::Patrons;
41
use Koha::Patrons;
Lines 258-266 $template->param (countorders => $count_orders_using_biblio); Link Here
258
my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
258
my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
259
$template->param (countdeletedorders => $count_deletedorders_using_biblio);
259
$template->param (countdeletedorders => $count_deletedorders_using_biblio);
260
260
261
my $holds = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
261
my $biblio = Koha::Biblios->find( $biblionumber );
262
my $holdcount = scalar( @$holds );
262
my $holds = $biblio->holds;
263
$template->param( holdcount => scalar ( @$holds ) );
263
$template->param( holdcount => $holds->count );
264
264
265
output_html_with_http_headers $query, $cookie, $template->output;
265
output_html_with_http_headers $query, $cookie, $template->output;
266
266
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_delete_records.tt (-2 / +2 lines)
Lines 173-183 $(document).ready(function() { Link Here
173
            <tbody>
173
            <tbody>
174
              [% FOR biblio IN records %]
174
              [% FOR biblio IN records %]
175
                <tr>
175
                <tr>
176
                  <td><input type="checkbox" name="record_id" id="record_id_[% biblio.biblionumber %]" value="[% biblio.biblionumber %]" data-items="[% biblio.itemnumbers.size %]" data-issues="[% biblio.issues_count %]" data-reserves="[% biblio.reserves.size %]" /></td>
176
                  <td><input type="checkbox" name="record_id" id="record_id_[% biblio.biblionumber %]" value="[% biblio.biblionumber %]" data-items="[% biblio.itemnumbers.size %]" data-issues="[% biblio.issues_count %]" data-reserves="[% biblio.holds_count %]" /></td>
177
                  <td><label for="record_id_[% biblio.biblionumber %]">[% biblio.biblionumber %]</label></td>
177
                  <td><label for="record_id_[% biblio.biblionumber %]">[% biblio.biblionumber %]</label></td>
178
                  <td>[% INCLUDE 'biblio-default-view.inc' biblionumber=biblio.biblionumber %][% biblio.title %][% IF ( biblio.subtitle ) %][% FOREACH subtitle IN biblio.subtitle %] [% subtitle.subfield |html %][% END %][% END %]</a></td>
178
                  <td>[% INCLUDE 'biblio-default-view.inc' biblionumber=biblio.biblionumber %][% biblio.title %][% IF ( biblio.subtitle ) %][% FOREACH subtitle IN biblio.subtitle %] [% subtitle.subfield |html %][% END %][% END %]</a></td>
179
                  <td><a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% biblio.biblionumber %]">[% biblio.itemnumbers.size %]</a></td>
179
                  <td><a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% biblio.biblionumber %]">[% biblio.itemnumbers.size %]</a></td>
180
                  <td><a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% biblio.biblionumber %]">[% biblio.reserves.size %]</a></td>
180
                  <td><a href="/cgi-bin/koha/reserve/request.pl?biblionumber=[% biblio.biblionumber %]">[% biblio.holds_count %]</a></td>
181
                  <td><a href="/cgi-bin/koha/catalogue/issuehistory.pl?biblionumber=[% biblio.biblionumber %]">[% biblio.issues_count %]</a></td>
181
                  <td><a href="/cgi-bin/koha/catalogue/issuehistory.pl?biblionumber=[% biblio.biblionumber %]">[% biblio.issues_count %]</a></td>
182
                </tr>
182
                </tr>
183
              [% END %]
183
              [% END %]
(-)a/opac/opac-detail.pl (-8 / +10 lines)
Lines 49-54 use C4::HTML5Media; Link Here
49
use C4::CourseReserves qw(GetItemCourseReservesInfo);
49
use C4::CourseReserves qw(GetItemCourseReservesInfo);
50
use Koha::RecordProcessor;
50
use Koha::RecordProcessor;
51
use Koha::AuthorisedValues;
51
use Koha::AuthorisedValues;
52
use Koha::Biblios;
52
use Koha::Virtualshelves;
53
use Koha::Virtualshelves;
53
use Koha::Ratings;
54
use Koha::Ratings;
54
use Koha::Reviews;
55
use Koha::Reviews;
Lines 591-605 for ( C4::Context->preference("OPACShowHoldQueueDetails") ) { Link Here
591
}
592
}
592
my $has_hold;
593
my $has_hold;
593
if ( $show_holds_count || $show_priority) {
594
if ( $show_holds_count || $show_priority) {
594
    my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
595
    my $biblio = Koha::Biblios->find( $biblionumber );
595
    $template->param( holds_count  => scalar( @$reserves ) ) if $show_holds_count;
596
    my $holds = $biblio->holds;
596
    foreach (@$reserves) {
597
    $template->param( holds_count  => $holds->count );
597
        $item_reserves{ $_->{itemnumber} }++ if $_->{itemnumber};
598
    while ( my $hold = $holds->new ) {
598
        if ($show_priority && $_->{borrowernumber} == $borrowernumber) {
599
        $item_reserves{ $hold->itemnumber }++ if $hold->itemnumber;
600
        if ($show_priority && $hold->borrowernumber == $borrowernumber) {
599
            $has_hold = 1;
601
            $has_hold = 1;
600
            $_->{itemnumber}
602
            $hold->itemnumber
601
                ? ($priority{ $_->{itemnumber} } = $_->{priority})
603
                ? ($priority{ $hold->itemnumber } = $hold->priority)
602
                : ($template->param( priority => $_->{priority} ));
604
                : ($template->param( priority => $hold->priority ));
603
        }
605
        }
604
    }
606
    }
605
}
607
}
(-)a/opac/opac-reserve.pl (-5 / +5 lines)
Lines 163-174 foreach my $biblioNumber (@biblionumbers) { Link Here
163
    }
163
    }
164
164
165
    # Compute the priority rank.
165
    # Compute the priority rank.
166
    my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblioNumber, all_dates => 1 });
166
    my $biblio = Koha::Biblios->find( $biblioNumber );
167
    my $rank = scalar( @$reserves );
167
    my $holds = $biblio->holds;
168
    my $rank = $holds->count;
168
    $biblioData->{reservecount} = 1;    # new reserve
169
    $biblioData->{reservecount} = 1;    # new reserve
169
    foreach my $res (@{$reserves}) {
170
    while ( my $hold = $holds->next ) {
170
        my $found = $res->{found};
171
        if ( $hold->is_waiting ) {
171
        if ( $found && $found eq 'W' ) {
172
            $rank--;
172
            $rank--;
173
        }
173
        }
174
        else {
174
        else {
(-)a/serials/routing-preview.pl (-13 / +14 lines)
Lines 33-38 use C4::Biblio; Link Here
33
use C4::Items;
33
use C4::Items;
34
use C4::Serials;
34
use C4::Serials;
35
use URI::Escape;
35
use URI::Escape;
36
37
use Koha::Biblios;
36
use Koha::Libraries;
38
use Koha::Libraries;
37
39
38
my $query = new CGI;
40
my $query = new CGI;
Lines 62-99 my ($template, $loggedinuser, $cookie); Link Here
62
64
63
if($ok){
65
if($ok){
64
    # get biblio information....
66
    # get biblio information....
65
    my $biblio = $subs->{'biblionumber'};
67
    my $biblionumber = $subs->{'biblionumber'};
66
	my ($count2,@bibitems) = GetBiblioItemByBiblioNumber($biblio);
68
    my ($count2,@bibitems) = GetBiblioItemByBiblioNumber($biblionumber);
67
	my @itemresults = GetItemsInfo( $subs->{biblionumber} );
69
	my @itemresults = GetItemsInfo( $subs->{biblionumber} );
68
	my $branch = $itemresults[0]->{'holdingbranch'};
70
	my $branch = $itemresults[0]->{'holdingbranch'};
69
    my $branchname = Koha::Libraries->find($branch)->branchname;
71
    my $branchname = Koha::Libraries->find($branch)->branchname;
70
72
71
	if (C4::Context->preference('RoutingListAddReserves')){
73
	if (C4::Context->preference('RoutingListAddReserves')){
72
		# get existing reserves .....
74
		# get existing reserves .....
73
        my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblio });
75
74
        my $count = scalar( @$reserves );
76
        my $biblio = Koha::Biblios->find( $biblionumber );
75
        my $totalcount = $count;
77
        my $holds = $biblio->holds_placed_before_today;
76
		foreach my $res (@$reserves) {
78
        my $count = $holds->count;
77
			if ($res->{'found'} eq 'W') {
79
        while ( my $hold = $holds->next ) {
78
				$count--;
80
            $count-- if $hold->is_waiting;
79
			}
81
        }
80
		}
81
		my $notes;
82
		my $notes;
82
		my $title = $subs->{'bibliotitle'};
83
		my $title = $subs->{'bibliotitle'};
83
        for my $routing ( @routinglist ) {
84
        for my $routing ( @routinglist ) {
84
            my $sth = $dbh->prepare('SELECT * FROM reserves WHERE biblionumber = ? AND borrowernumber = ? LIMIT 1');
85
            my $sth = $dbh->prepare('SELECT * FROM reserves WHERE biblionumber = ? AND borrowernumber = ? LIMIT 1');
85
            $sth->execute($biblio,$routing->{borrowernumber});
86
            $sth->execute($biblionumber,$routing->{borrowernumber});
86
            my $reserve = $sth->fetchrow_hashref;
87
            my $reserve = $sth->fetchrow_hashref;
87
88
88
            if($routing->{borrowernumber} == $reserve->{borrowernumber}){
89
            if($routing->{borrowernumber} == $reserve->{borrowernumber}){
89
                ModReserve({
90
                ModReserve({
90
                    rank           => $routing->{ranking},
91
                    rank           => $routing->{ranking},
91
                    biblionumber   => $biblio,
92
                    biblionumber   => $biblionumber,
92
                    borrowernumber => $routing->{borrowernumber},
93
                    borrowernumber => $routing->{borrowernumber},
93
                    branchcode     => $branch
94
                    branchcode     => $branch
94
                });
95
                });
95
            } else {
96
            } else {
96
                AddReserve($branch,$routing->{borrowernumber},$biblio,\@bibitems,$routing->{ranking}, undef, undef, $notes,$title);
97
                AddReserve($branch,$routing->{borrowernumber},$biblionumber,\@bibitems,$routing->{ranking}, undef, undef, $notes,$title);
97
        }
98
        }
98
    }
99
    }
99
	}
100
	}
(-)a/t/db_dependent/Holds.t (-14 / +15 lines)
Lines 15-20 use C4::Members; Link Here
15
use C4::Calendar;
15
use C4::Calendar;
16
use Koha::Database;
16
use Koha::Database;
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::Holds;
19
use Koha::Holds;
19
20
20
BEGIN {
21
BEGIN {
Lines 84-97 foreach my $borrowernumber ( @borrowernumbers ) { Link Here
84
    );
85
    );
85
}
86
}
86
87
87
my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblionumber });
88
my $biblio = Koha::Biblios->find( $biblionumber );
88
is( scalar(@$reserves), $borrowers_count, "Test GetReserves()" );
89
my $holds = $biblio->holds;
89
90
is( $holds->count, $borrowers_count, 'Test GetReserves()' );
90
is( $reserves->[0]->{priority}, 1, "Reserve 1 has a priority of 1" );
91
is( $holds->next->priority, 1, "Reserve 1 has a priority of 1" );
91
is( $reserves->[1]->{priority}, 2, "Reserve 2 has a priority of 2" );
92
is( $holds->next->priority, 2, "Reserve 2 has a priority of 2" );
92
is( $reserves->[2]->{priority}, 3, "Reserve 3 has a priority of 3" );
93
is( $holds->next->priority, 3, "Reserve 3 has a priority of 3" );
93
is( $reserves->[3]->{priority}, 4, "Reserve 4 has a priority of 4" );
94
is( $holds->next->priority, 4, "Reserve 4 has a priority of 4" );
94
is( $reserves->[4]->{priority}, 5, "Reserve 5 has a priority of 5" );
95
is( $holds->next->priority, 5, "Reserve 5 has a priority of 5" );
95
96
96
my ( $reservedate, $borrowernumber, $branch_1code, $reserve_id ) = GetReservesFromItemnumber($itemnumber);
97
my ( $reservedate, $borrowernumber, $branch_1code, $reserve_id ) = GetReservesFromItemnumber($itemnumber);
97
is( $reservedate, output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }), "GetReservesFromItemnumber should return a valid reserve date");
98
is( $reservedate, output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }), "GetReservesFromItemnumber should return a valid reserve date");
Lines 122-129 ok( GetReserveCount( $borrowernumbers[0] ), "Test GetReserveCount()" ); Link Here
122
123
123
124
124
CancelReserve({ 'reserve_id' => $reserve_id });
125
CancelReserve({ 'reserve_id' => $reserve_id });
125
$reserves = GetReservesFromBiblionumber({ biblionumber => $biblionumber });
126
$holds = $biblio->holds;
126
is( scalar(@$reserves), $borrowers_count - 1, "Test CancelReserve()" );
127
is( $holds->count, $borrowers_count - 1, "Test CancelReserve()" );
127
128
128
129
129
( $reservedate, $borrowernumber, $branch_1code, $reserve_id ) = GetReservesFromItemnumber($itemnumber);
130
( $reservedate, $borrowernumber, $branch_1code, $reserve_id ) = GetReservesFromItemnumber($itemnumber);
Lines 202-210 my $reserve2 = GetReserveInfo( $reserve->{'reserve_id'} ); Link Here
202
ok( $reserve->{'reserve_id'} eq $reserve2->{'reserve_id'}, "Test GetReserveInfo()" );
203
ok( $reserve->{'reserve_id'} eq $reserve2->{'reserve_id'}, "Test GetReserveInfo()" );
203
204
204
205
205
$reserves = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
206
$holds = $biblio->holds;
206
$reserve = $reserves->[1];
207
my $hold = $holds->next;
207
AlterPriority( 'top', $reserve->{'reserve_id'} );
208
AlterPriority( 'top', $hold->reserve_id );
208
$reserve = GetReserve( $reserve->{'reserve_id'} );
209
$reserve = GetReserve( $reserve->{'reserve_id'} );
209
is( $reserve->{'priority'}, '1', "Test AlterPriority(), move to top" );
210
is( $reserve->{'priority'}, '1', "Test AlterPriority(), move to top" );
210
211
Lines 429-435 t::lib::Mocks::mock_preference('ReservesMaxPickUpDelay', 1); Link Here
429
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime(time);
430
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime(time);
430
$year += 1900;
431
$year += 1900;
431
$mon += 1;
432
$mon += 1;
432
$reserves = $dbh->selectall_arrayref('SELECT * FROM reserves', { Slice => {} });
433
my $reserves = $dbh->selectall_arrayref('SELECT * FROM reserves', { Slice => {} });
433
$reserve = $reserves->[0];
434
$reserve = $reserves->[0];
434
my $calendar = C4::Calendar->new(branchcode => $reserve->{branchcode});
435
my $calendar = C4::Calendar->new(branchcode => $reserve->{branchcode});
435
$calendar->insert_single_holiday(
436
$calendar->insert_single_holiday(
(-)a/t/db_dependent/Reserves.t (-13 / +12 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 72;
20
use Test::More tests => 71;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 260-273 AddReserve($branch_1, $requesters{$branch_1}, $bibnum2, Link Here
260
ModReserveAffect($itemnum_cpl, $requesters{$branch_3}, 0);
260
ModReserveAffect($itemnum_cpl, $requesters{$branch_3}, 0);
261
261
262
# Now it should have different priorities.
262
# Now it should have different priorities.
263
my $title_reserves = GetReservesFromBiblionumber({biblionumber => $bibnum2});
263
my $biblio = Koha::Biblios->find( $bibnum2 );
264
# Sort by reserve number in case the database gives us oddly ordered results
264
my $holds = $biblio->holds({}, { order_by => 'reserve_id' });;
265
my @reserves = sort { $a->{reserve_id} <=> $b->{reserve_id} } @$title_reserves;
265
is($holds->next->priority, 0, 'Item is correctly waiting');
266
is($reserves[0]{priority}, 0, 'Item is correctly waiting');
266
is($holds->next->priority, 1, 'Item is correctly priority 1');
267
is($reserves[1]{priority}, 1, 'Item is correctly priority 1');
267
is($holds->next->priority, 2, 'Item is correctly priority 2');
268
is($reserves[2]{priority}, 2, 'Item is correctly priority 2');
268
269
269
my @reserves = Koha::Holds->search({ borrowernumber => $requesters{$branch_3} })->waiting();
270
@reserves = Koha::Holds->search({ borrowernumber => $requesters{$branch_3} })->waiting();
271
is( @reserves, 1, 'GetWaiting got only the waiting reserve' );
270
is( @reserves, 1, 'GetWaiting got only the waiting reserve' );
272
is( $reserves[0]->borrowernumber(), $requesters{$branch_3}, 'GetWaiting got the reserve for the correct borrower' );
271
is( $reserves[0]->borrowernumber(), $requesters{$branch_3}, 'GetWaiting got the reserve for the correct borrower' );
273
272
Lines 307-316 is( $messages->{ResFound}->{borrowernumber}, Link Here
307
    $requesters{$branch_3},
306
    $requesters{$branch_3},
308
    'for generous library, its items fill first hold request in line (bug 10272)');
307
    'for generous library, its items fill first hold request in line (bug 10272)');
309
308
310
my $reserves = GetReservesFromBiblionumber({biblionumber => $biblionumber});
309
$biblio = Koha::Biblios->find( $biblionumber );
311
isa_ok($reserves, 'ARRAY');
310
$holds = $biblio->holds;
312
is(scalar @$reserves, 1, "Only one reserves for this biblio");
311
is($holds->count, 1, "Only one reserves for this biblio");
313
my $reserve_id = $reserves->[0]->{reserve_id};
312
my $reserve_id = $holds->next->reserve_id;
314
313
315
$reserve = GetReserve($reserve_id);
314
$reserve = GetReserve($reserve_id);
316
isa_ok($reserve, 'HASH', "GetReserve return");
315
isa_ok($reserve, 'HASH', "GetReserve return");
(-)a/t/db_dependent/UsageStats.t (-3 / +4 lines)
Lines 19-24 use Test::More tests => 57; Link Here
19
use t::lib::Mocks qw(mock_preference);
19
use t::lib::Mocks qw(mock_preference);
20
use POSIX qw(strftime);
20
use POSIX qw(strftime);
21
use Data::Dumper;
21
use Data::Dumper;
22
use Koha::Biblios;
22
23
23
BEGIN {
24
BEGIN {
24
    use_ok('C4::UsageStats');
25
    use_ok('C4::UsageStats');
Lines 290-298 sub construct_objects_needed { Link Here
290
291
291
    # ---------- Add 1 old_reserves
292
    # ---------- Add 1 old_reserves
292
    AddReserve( $branchcode, $borrowernumber1, $biblionumber1, '', 1, undef, undef, '', 'Title', undef, undef );
293
    AddReserve( $branchcode, $borrowernumber1, $biblionumber1, '', 1, undef, undef, '', 'Title', undef, undef );
293
    my $reserves1   = GetReservesFromBiblionumber( { biblionumber => $biblionumber1 } );
294
    my $biblio = Koha::Biblios->find( $biblionumber1 );
294
    my $reserve_id1 = $reserves1->[0]->{reserve_id};
295
    my $holds = $biblio->holds;
295
    my $reserve1    = CancelReserve( { reserve_id => $reserve_id1 } );
296
    CancelReserve( { reserve_id => $holds->next->reserve_id } );
296
297
297
    # ---------- Add 1 aqbudgets
298
    # ---------- Add 1 aqbudgets
298
    $query = '
299
    $query = '
(-)a/tools/batch_delete_records.pl (-7 / +13 lines)
Lines 28-33 use C4::Output; Link Here
28
use C4::AuthoritiesMarc;
28
use C4::AuthoritiesMarc;
29
use C4::Biblio;
29
use C4::Biblio;
30
30
31
use Koha::Biblios;
32
31
my $input = new CGI;
33
my $input = new CGI;
32
my $dbh = C4::Context->dbh;
34
my $dbh = C4::Context->dbh;
33
my $op = $input->param('op') // q|form|;
35
my $op = $input->param('op') // q|form|;
Lines 68-74 if ( $op eq 'form' ) { Link Here
68
    for my $record_id ( uniq @record_ids ) {
70
    for my $record_id ( uniq @record_ids ) {
69
        if ( $recordtype eq 'biblio' ) {
71
        if ( $recordtype eq 'biblio' ) {
70
            # Retrieve biblio information
72
            # Retrieve biblio information
71
            my $biblio = C4::Biblio::GetBiblio( $record_id );
73
            my $biblio = Koha::Biblios->find( $record_id );
72
            unless ( $biblio ) {
74
            unless ( $biblio ) {
73
                push @messages, {
75
                push @messages, {
74
                    type => 'warning',
76
                    type => 'warning',
Lines 77-86 if ( $op eq 'form' ) { Link Here
77
                };
79
                };
78
                next;
80
                next;
79
            }
81
            }
82
            my $holds_count = $biblio->holds->count;
83
            $biblio = $biblio->unblessed;
80
            my $record = &GetMarcBiblio( $record_id );
84
            my $record = &GetMarcBiblio( $record_id );
81
            $biblio->{subtitle} = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $record_id ) );
85
            $biblio->{subtitle} = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $record_id ) );
82
            $biblio->{itemnumbers} = C4::Items::GetItemnumbersForBiblio( $record_id );
86
            $biblio->{itemnumbers} = C4::Items::GetItemnumbersForBiblio( $record_id );
83
            $biblio->{reserves} = C4::Reserves::GetReservesFromBiblionumber({ biblionumber => $record_id });
87
            $biblio->{holds_count} = $holds_count;
84
            $biblio->{issues_count} = C4::Biblio::CountItemsIssued( $record_id );
88
            $biblio->{issues_count} = C4::Biblio::CountItemsIssued( $record_id );
85
            push @records, $biblio;
89
            push @records, $biblio;
86
        } else {
90
        } else {
Lines 127-132 if ( $op eq 'form' ) { Link Here
127
            my $biblionumber = $record_id;
131
            my $biblionumber = $record_id;
128
            # First, checking if issues exist.
132
            # First, checking if issues exist.
129
            # If yes, nothing to do
133
            # If yes, nothing to do
134
            my $biblio = Koha::Biblios->find( $biblionumber );
135
136
            # TODO Replace with $biblio->get_issues->count
130
            if ( C4::Biblio::CountItemsIssued( $biblionumber ) ) {
137
            if ( C4::Biblio::CountItemsIssued( $biblionumber ) ) {
131
                push @messages, {
138
                push @messages, {
132
                    type => 'warning',
139
                    type => 'warning',
Lines 138-154 if ( $op eq 'form' ) { Link Here
138
            }
145
            }
139
146
140
            # Cancel reserves
147
            # Cancel reserves
141
            my $reserves = C4::Reserves::GetReservesFromBiblionumber({ biblionumber => $biblionumber });
148
            my $holds = $biblio->holds;
142
            for my $reserve ( @$reserves ) {
149
            while ( my $hold = $holds->next ) {
143
                eval{
150
                eval{
144
                    C4::Reserves::CancelReserve( { reserve_id => $reserve->{reserve_id} } );
151
                    C4::Reserves::CancelReserve( { reserve_id => $hold->reserve_id } );
145
                };
152
                };
146
                if ( $@ ) {
153
                if ( $@ ) {
147
                    push @messages, {
154
                    push @messages, {
148
                        type => 'error',
155
                        type => 'error',
149
                        code => 'reserve_not_cancelled',
156
                        code => 'reserve_not_cancelled',
150
                        biblionumber => $biblionumber,
157
                        biblionumber => $biblionumber,
151
                        reserve_id => $reserve->{reserve_id},
158
                        reserve_id => $hold->reserve_id,
152
                        error => $@,
159
                        error => $@,
153
                    };
160
                    };
154
                    $dbh->rollback;
161
                    $dbh->rollback;
155
- 

Return to bug 17736