Lines 155-167
unless ( $enddate ) {
Link Here
|
155 |
|
155 |
|
156 |
# building query parameters |
156 |
# building query parameters |
157 |
my %where = ( |
157 |
my %where = ( |
158 |
'reserve.found' => undef, |
158 |
'me.status' => 'placed', |
159 |
'reserve.priority' => 1, |
159 |
'me.priority' => 1, |
160 |
'reserve.suspend' => 0, |
160 |
'me.suspended' => 0, |
161 |
'itembib.itemlost' => 0, |
161 |
'item.itemlost' => 0, |
162 |
'itembib.withdrawn' => 0, |
162 |
'item.withdrawn' => 0, |
163 |
'itembib.notforloan' => 0, |
163 |
'item.notforloan' => 0, |
164 |
'itembib.itemnumber' => { -not_in => \'SELECT itemnumber FROM branchtransfers WHERE datearrived IS NULL' } |
164 |
'item.itemnumber' => { -not_in => \'SELECT itemnumber FROM branchtransfers WHERE datearrived IS NULL' } |
165 |
); |
165 |
); |
166 |
|
166 |
|
167 |
# date boundaries |
167 |
# date boundaries |
Lines 169-196
my $dtf = Koha::Database->new->schema->storage->datetime_parser;
Link Here
|
169 |
my $startdate_iso = $dtf->format_date($startdate); |
169 |
my $startdate_iso = $dtf->format_date($startdate); |
170 |
my $enddate_iso = $dtf->format_date($enddate); |
170 |
my $enddate_iso = $dtf->format_date($enddate); |
171 |
if ( $startdate_iso && $enddate_iso ){ |
171 |
if ( $startdate_iso && $enddate_iso ){ |
172 |
$where{'reserve.reservedate'} = [ -and => { '>=', $startdate_iso }, { '<=', $enddate_iso } ]; |
172 |
$where{'me.created_date'} = [ -and => { '>=', $startdate_iso }, { '<=', $enddate_iso } ]; |
173 |
} elsif ( $startdate_iso ){ |
173 |
} elsif ( $startdate_iso ){ |
174 |
$where{'reserve.reservedate'} = { '>=', $startdate_iso }; |
174 |
$where{'me.created_date'} = { '>=', $startdate_iso }; |
175 |
} elsif ( $enddate_iso ){ |
175 |
} elsif ( $enddate_iso ){ |
176 |
$where{'reserve.reservedate'} = { '<=', $enddate_iso }; |
176 |
$where{'me.created_date'} = { '<=', $enddate_iso }; |
177 |
} |
177 |
} |
178 |
|
178 |
|
179 |
# Bug 21320 |
179 |
# Bug 21320 |
180 |
if ( !C4::Context->preference('AllowHoldsOnDamagedItems') ){ |
180 |
if ( !C4::Context->preference('AllowHoldsOnDamagedItems') ){ |
181 |
$where{'itembib.damaged'} = 0; |
181 |
$where{'item.damaged'} = 0; |
182 |
} |
182 |
} |
183 |
|
183 |
|
184 |
if ( C4::Context->preference('IndependentBranches') ){ |
184 |
if ( C4::Context->preference('IndependentBranches') ){ |
185 |
$where{'itembib.holdingbranch'} = C4::Context->userenv->{'branch'}; |
185 |
$where{'item.holdingbranch'} = C4::Context->userenv->{'branch'}; |
186 |
} |
186 |
} |
187 |
|
187 |
|
188 |
# get all distinct unfulfilled reserves |
188 |
# get all distinct unfulfilled reserves |
189 |
my $holds = Koha::Holds->search( |
189 |
my $holds = Koha::Holds->search( |
190 |
{ %where }, |
190 |
{ %where }, |
191 |
{ join => 'itembib', alias => 'reserve', distinct => 1, columns => qw[me.biblionumber] } |
191 |
{ join => 'item', distinct => 1, columns => qw[me.biblio_id] } |
192 |
); |
192 |
); |
193 |
my @biblionumbers = $holds->get_column('biblionumber'); |
193 |
my @biblionumbers = $holds->get_column('biblio_id'); |
194 |
|
194 |
|
195 |
my $all_items; |
195 |
my $all_items; |
196 |
foreach my $item ( $holds->get_items_that_can_fill ) { |
196 |
foreach my $item ( $holds->get_items_that_can_fill ) { |
Lines 199-233
foreach my $item ( $holds->get_items_that_can_fill ) {
Link Here
|
199 |
|
199 |
|
200 |
# patrons count per biblio |
200 |
# patrons count per biblio |
201 |
my $patrons_count = { |
201 |
my $patrons_count = { |
202 |
map { $_->{biblionumber} => $_->{patrons_count} } @{ Koha::Holds->search( |
202 |
map { $_->{biblio_id} => $_->{patrons_count} } @{ Koha::Holds->search( |
203 |
{}, |
203 |
{}, |
204 |
{ |
204 |
{ |
205 |
select => [ 'biblionumber', { count => { distinct => 'borrowernumber' } } ], |
205 |
select => [ 'biblio_id', { count => { distinct => 'patron_id' } } ], |
206 |
as => [qw( biblionumber patrons_count )], |
206 |
as => [qw( biblio_id patrons_count )], |
207 |
group_by => [qw( biblionumber )] |
207 |
group_by => [qw( biblio_id )] |
208 |
}, |
208 |
}, |
209 |
)->unblessed |
209 |
)->unblessed |
210 |
} |
210 |
} |
211 |
}; |
211 |
}; |
212 |
|
212 |
|
213 |
my $holds_biblios_map = { |
213 |
my $holds_biblios_map = { |
214 |
map { $_->{biblionumber} => $_->{reserve_id} } @{ Koha::Holds->search( |
214 |
map { $_->{biblio_id} => $_->{hold_id} } @{ Koha::Holds->search( |
215 |
{%where}, |
215 |
{%where}, |
216 |
{ |
216 |
{ |
217 |
join => ['itembib', 'biblio'], |
217 |
join => ['item', 'biblio'], |
218 |
alias => 'reserve', |
218 |
select => ['me.biblio_id', 'me.hold_id'], |
219 |
select => ['reserve.biblionumber', 'reserve.reserve_id'], |
|
|
220 |
} |
219 |
} |
221 |
)->unblessed |
220 |
)->unblessed |
222 |
} |
221 |
} |
223 |
}; |
222 |
}; |
224 |
|
223 |
|
225 |
my $all_holds = { |
224 |
my $all_holds = { |
226 |
map { $_->biblionumber => $_ } @{ Koha::Holds->search( |
225 |
map { $_->biblio_id => $_ } @{ Koha::Holds->search( |
227 |
{ reserve_id => [ values %$holds_biblios_map ]}, |
226 |
{ hold_id => [ values %$holds_biblios_map ]}, |
228 |
{ |
227 |
{ |
229 |
prefetch => [ 'borrowernumber', 'itembib', 'biblio' ], |
228 |
prefetch => [ 'patron', 'item', 'biblio' ] |
230 |
alias => 'reserve', |
|
|
231 |
} |
229 |
} |
232 |
)->as_list |
230 |
)->as_list |
233 |
} |
231 |
} |