From a82c001f478bb08055aec24ff88e540fbe5e53d0 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 2 Aug 2021 14:26:24 -0300 Subject: [PATCH] Bug 25260: Fix pendingreserves.pl --- circ/pendingreserves.pl | 50 +++++++++---------- circ/reserveratios.pl | 31 ++++++------ .../prog/en/modules/circ/pendingreserves.tt | 14 +++--- 3 files changed, 47 insertions(+), 48 deletions(-) diff --git a/circ/pendingreserves.pl b/circ/pendingreserves.pl index 0b2fea2195..6e9032c1fc 100755 --- a/circ/pendingreserves.pl +++ b/circ/pendingreserves.pl @@ -155,13 +155,13 @@ unless ( $enddate ) { # building query parameters my %where = ( - 'reserve.found' => undef, - 'reserve.priority' => 1, - 'reserve.suspend' => 0, - 'itembib.itemlost' => 0, - 'itembib.withdrawn' => 0, - 'itembib.notforloan' => 0, - 'itembib.itemnumber' => { -not_in => \'SELECT itemnumber FROM branchtransfers WHERE datearrived IS NULL' } + 'me.status' => 'placed', + 'me.priority' => 1, + 'me.suspended' => 0, + 'item.itemlost' => 0, + 'item.withdrawn' => 0, + 'item.notforloan' => 0, + 'item.itemnumber' => { -not_in => \'SELECT itemnumber FROM branchtransfers WHERE datearrived IS NULL' } ); # date boundaries @@ -169,28 +169,28 @@ my $dtf = Koha::Database->new->schema->storage->datetime_parser; my $startdate_iso = $dtf->format_date($startdate); my $enddate_iso = $dtf->format_date($enddate); if ( $startdate_iso && $enddate_iso ){ - $where{'reserve.reservedate'} = [ -and => { '>=', $startdate_iso }, { '<=', $enddate_iso } ]; + $where{'me.created_date'} = [ -and => { '>=', $startdate_iso }, { '<=', $enddate_iso } ]; } elsif ( $startdate_iso ){ - $where{'reserve.reservedate'} = { '>=', $startdate_iso }; + $where{'me.created_date'} = { '>=', $startdate_iso }; } elsif ( $enddate_iso ){ - $where{'reserve.reservedate'} = { '<=', $enddate_iso }; + $where{'me.created_date'} = { '<=', $enddate_iso }; } # Bug 21320 if ( !C4::Context->preference('AllowHoldsOnDamagedItems') ){ - $where{'itembib.damaged'} = 0; + $where{'item.damaged'} = 0; } if ( C4::Context->preference('IndependentBranches') ){ - $where{'itembib.holdingbranch'} = C4::Context->userenv->{'branch'}; + $where{'item.holdingbranch'} = C4::Context->userenv->{'branch'}; } # get all distinct unfulfilled reserves my $holds = Koha::Holds->search( { %where }, - { join => 'itembib', alias => 'reserve', distinct => 1, columns => qw[me.biblionumber] } + { join => 'item', distinct => 1, columns => qw[me.biblio_id] } ); -my @biblionumbers = $holds->get_column('biblionumber'); +my @biblionumbers = $holds->get_column('biblio_id'); my $all_items; foreach my $item ( $holds->get_items_that_can_fill ) { @@ -199,35 +199,33 @@ foreach my $item ( $holds->get_items_that_can_fill ) { # patrons count per biblio my $patrons_count = { - map { $_->{biblionumber} => $_->{patrons_count} } @{ Koha::Holds->search( + map { $_->{biblio_id} => $_->{patrons_count} } @{ Koha::Holds->search( {}, { - select => [ 'biblionumber', { count => { distinct => 'borrowernumber' } } ], - as => [qw( biblionumber patrons_count )], - group_by => [qw( biblionumber )] + select => [ 'biblio_id', { count => { distinct => 'patron_id' } } ], + as => [qw( biblio_id patrons_count )], + group_by => [qw( biblio_id )] }, )->unblessed } }; my $holds_biblios_map = { - map { $_->{biblionumber} => $_->{reserve_id} } @{ Koha::Holds->search( + map { $_->{biblio_id} => $_->{hold_id} } @{ Koha::Holds->search( {%where}, { - join => ['itembib', 'biblio'], - alias => 'reserve', - select => ['reserve.biblionumber', 'reserve.reserve_id'], + join => ['item', 'biblio'], + select => ['me.biblio_id', 'me.hold_id'], } )->unblessed } }; my $all_holds = { - map { $_->biblionumber => $_ } @{ Koha::Holds->search( - { reserve_id => [ values %$holds_biblios_map ]}, + map { $_->biblio_id => $_ } @{ Koha::Holds->search( + { hold_id => [ values %$holds_biblios_map ]}, { - prefetch => [ 'borrowernumber', 'itembib', 'biblio' ], - alias => 'reserve', + prefetch => [ 'patron', 'item', 'biblio' ] } )->as_list } diff --git a/circ/reserveratios.pl b/circ/reserveratios.pl index 7311d1e8c9..6fbaa82e78 100755 --- a/circ/reserveratios.pl +++ b/circ/reserveratios.pl @@ -84,9 +84,9 @@ my $dbh = C4::Context->dbh; my $sqldatewhere = ""; my @query_params = (); -$sqldatewhere .= " AND reservedate >= ?"; +$sqldatewhere .= " AND holds.created_date >= ?"; push @query_params, output_pref({ dt => $startdate, dateformat => 'iso' }) ; -$sqldatewhere .= " AND reservedate <= ?"; +$sqldatewhere .= " AND holds.created_date <= ?"; push @query_params, output_pref({ dt => $enddate, dateformat => 'iso' }); my $include_aqorders_qty = @@ -96,16 +96,16 @@ my $include_aqorders_qty = my $include_aqorders_qty_join = $effective_create_items eq 'receiving' - ? 'LEFT JOIN aqorders ON reserves.biblionumber=aqorders.biblionumber' + ? 'LEFT JOIN aqorders ON holds.biblio_id=aqorders.biblionumber' : q{}; my $nfl_comparison = $include_ordered ? '<=' : '='; my $sus_comparison = $include_suspended ? '<=' : '<'; my $strsth = -"SELECT reservedate, - reserves.borrowernumber as borrowernumber, - reserves.biblionumber, - reserves.branchcode as branch, +"SELECT created_date, + holds.patron_id, + holds.biblio_id, + holds.pickup_library_id as branch, items.holdingbranch, items.itemcallnumber, items.itemnumber, @@ -120,22 +120,23 @@ my $strsth = GROUP_CONCAT(DISTINCT items.itype ORDER BY items.itemnumber SEPARATOR '|') as l_itype, - reserves.found, + holds.status, biblio.title, biblio.subtitle, biblio.medium, biblio.part_number, biblio.part_name, biblio.author, - count(DISTINCT reserves.borrowernumber) as reservecount, + count(DISTINCT holds.patron_id) as reservecount, count(DISTINCT items.itemnumber) $include_aqorders_qty as itemcount - FROM reserves - LEFT JOIN items ON items.biblionumber=reserves.biblionumber - LEFT JOIN biblio ON reserves.biblionumber=biblio.biblionumber + FROM holds + LEFT JOIN items ON items.biblionumber=holds.biblio_id + LEFT JOIN biblio ON biblio.biblionumber=holds.biblio_id $include_aqorders_qty_join WHERE notforloan $nfl_comparison 0 AND damaged = 0 AND itemlost = 0 AND withdrawn = 0 - AND suspend $sus_comparison 1 + AND holds.completed=0 + AND suspended $sus_comparison 1 $sqldatewhere "; @@ -144,7 +145,7 @@ if (C4::Context->preference('IndependentBranches')){ push @query_params, C4::Context->userenv->{'branch'}; } -$strsth .= " GROUP BY reserves.biblionumber ORDER BY reservecount DESC"; +$strsth .= " GROUP BY holds.biblio_id ORDER BY reservecount DESC"; $template->param(sql => $strsth); my $sth = $dbh->prepare($strsth); @@ -158,7 +159,7 @@ while ( my $data = $sth->fetchrow_hashref ) { push( @reservedata, { - reservedate => $data->{reservedate}, + reservedate => $data->{created_date}, priority => $data->{priority}, name => $data->{borrower}, title => $data->{title}, diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt index fb90eeacdd..491b9d8bad 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt @@ -176,17 +176,17 @@ [% END %] - - [% hold.reservedate | $KohaDates %] in [% Branches.GetName ( hold.branchcode ) | html %] + + [% hold.created_date | $KohaDates %] in [% Branches.GetName ( hold.pickup_library_id ) | html %] - [% hold.reservenotes | html %] + [% hold.notes | html %] - [% Branches.GetName ( hold.branchcode ) | html %] + [% Branches.GetName ( hold.pickup_library_id ) | html %]
- + [% SET hold_cancellation = AuthorisedValues.GetAuthValueDropbox('HOLD_CANCELLATION') %] [% IF hold_cancellation %] @@ -209,9 +209,9 @@
[% IF Koha.Preference('CanMarkHoldsToPullAsLost') != 'do_not_allow' %] - [% IF hold.itemnumber %] + [% IF hold.item_id %]
- + [% IF Koha.Preference('CanMarkHoldsToPullAsLost') == 'allow' %] -- 2.32.0