updated fine processor to use billing_type in addition to note
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Storage / Publisher / action.pm
1 package OpenILS::Application::Storage::Publisher::action;
2 use base qw/OpenILS::Application::Storage/;
3 use OpenSRF::Utils::Logger qw/:level/;
4 use OpenSRF::Utils qw/:datetime/;
5 use OpenSRF::AppSession;
6 use OpenSRF::EX qw/:try/;
7 use OpenILS::Utils::Fieldmapper;
8 use DateTime;
9 use DateTime::Format::ISO8601;
10
11 my $parser = DateTime::Format::ISO8601->new;
12 my $log = 'OpenSRF::Utils::Logger';
13
14 sub overdue_circs {
15         my $grace = shift;
16
17         my $c_t = action::circulation->table;
18
19         $grace = " - ($grace * (fine_interval))" if ($grace);
20
21         my $sql = <<"   SQL";
22                 SELECT  *
23                   FROM  $c_t
24                   WHERE stop_fines IS NULL
25                         AND due_date < ( CURRENT_TIMESTAMP $grace)
26         SQL
27
28         my $sth = action::circulation->db_Main->prepare_cached($sql);
29         $sth->execute;
30
31         return ( map { action::circulation->construct($_) } $sth->fetchall_hash );
32
33 }
34
35 sub grab_overdue {
36         my $self = shift;
37         my $client = shift;
38         my $grace = shift || '';
39
40         $client->respond( $_->to_fieldmapper ) for ( overdue_circs($grace) );
41
42         return undef;
43
44 }
45 __PACKAGE__->register_method(
46         api_name        => 'open-ils.storage.action.circulation.overdue',
47         api_level       => 1,
48         stream          => 1,
49         method          => 'grab_overdue',
50 );
51
52 sub nearest_hold {
53         my $self = shift;
54         my $client = shift;
55         my $pl = shift;
56         my $cp = shift;
57
58         my ($id) = action::hold_request->db_Main->selectrow_array(<<"   SQL", {}, $pl,$cp);
59                 SELECT  h.id
60                   FROM  action.hold_request h
61                         JOIN action.hold_copy_map hm ON (hm.hold = h.id)
62                   WHERE h.pickup_lib = ?
63                         AND hm.target_copy = ?
64                         AND h.capture_time IS NULL
65                 ORDER BY h.pickup_lib - (SELECT home_ou FROM actor.usr a WHERE a.id = h.usr), h.request_time
66                 LIMIT 1
67         SQL
68         return $id;
69 }
70 __PACKAGE__->register_method(
71         api_name        => 'open-ils.storage.action.hold_request.nearest_hold',
72         api_level       => 1,
73         method          => 'nearest_hold',
74 );
75
76 sub next_resp_group_id {
77         my $self = shift;
78         my $client = shift;
79
80         # XXX This is not replication safe!!!
81
82         my ($id) = action::survey->db_Main->selectrow_array(<<" SQL");
83                 SELECT NEXTVAL('action.survey_response_group_id_seq'::TEXT)
84         SQL
85         return $id;
86 }
87 __PACKAGE__->register_method(
88         api_name        => 'open-ils.storage.action.survey_response.next_group_id',
89         api_level       => 1,
90         method          => 'next_resp_group_id',
91 );
92
93 sub patron_circ_summary {
94         my $self = shift;
95         my $client = shift;
96         my $id = ''.shift();
97
98         return undef unless ($id);
99         my $c_table = action::circulation->table;
100         my $b_table = money::billing->table;
101
102         my $select = <<"        SQL";
103                 SELECT  COUNT(DISTINCT c.id), SUM( COALESCE(b.amount,0) )
104                   FROM  $c_table c
105                         LEFT OUTER JOIN $b_table b ON (c.id = b.xact)
106                   WHERE c.usr = ?
107                         AND c.xact_finish IS NULL
108                         AND c.stop_fines NOT IN ('CLAIMSRETURNED','LOST')
109         SQL
110
111         return action::survey->db_Main->selectrow_arrayref($select, {}, $id);
112 }
113 __PACKAGE__->register_method(
114         api_name        => 'open-ils.storage.action.circulation.patron_summary',
115         api_level       => 1,
116         method          => 'patron_circ_summary',
117 );
118
119 #XXX Fix stored proc calls
120 sub find_local_surveys {
121         my $self = shift;
122         my $client = shift;
123         my $ou = ''.shift();
124
125         return undef unless ($ou);
126         my $s_table = action::survey->table;
127
128         my $select = <<"        SQL";
129                 SELECT  s.*
130                   FROM  $s_table s
131                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
132                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
133         SQL
134
135         my $sth = action::survey->db_Main->prepare_cached($select);
136         $sth->execute($ou);
137
138         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
139
140         return undef;
141 }
142 __PACKAGE__->register_method(
143         api_name        => 'open-ils.storage.action.survey.all',
144         api_level       => 1,
145         stream          => 1,
146         method          => 'find_local_surveys',
147 );
148
149 #XXX Fix stored proc calls
150 sub find_opac_surveys {
151         my $self = shift;
152         my $client = shift;
153         my $ou = ''.shift();
154
155         return undef unless ($ou);
156         my $s_table = action::survey->table;
157
158         my $select = <<"        SQL";
159                 SELECT  s.*
160                   FROM  $s_table s
161                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
162                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
163                         AND s.opac IS TRUE;
164         SQL
165
166         my $sth = action::survey->db_Main->prepare_cached($select);
167         $sth->execute($ou);
168
169         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
170
171         return undef;
172 }
173 __PACKAGE__->register_method(
174         api_name        => 'open-ils.storage.action.survey.opac',
175         api_level       => 1,
176         stream          => 1,
177         method          => 'find_opac_surveys',
178 );
179
180 sub find_optional_surveys {
181         my $self = shift;
182         my $client = shift;
183         my $ou = ''.shift();
184
185         return undef unless ($ou);
186         my $s_table = action::survey->table;
187
188         my $select = <<"        SQL";
189                 SELECT  s.*
190                   FROM  $s_table s
191                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
192                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
193                         AND s.required IS FALSE;
194         SQL
195
196         my $sth = action::survey->db_Main->prepare_cached($select);
197         $sth->execute($ou);
198
199         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
200
201         return undef;
202 }
203 __PACKAGE__->register_method(
204         api_name        => 'open-ils.storage.action.survey.optional',
205         api_level       => 1,
206         stream          => 1,
207         method          => 'find_optional_surveys',
208 );
209
210 sub find_required_surveys {
211         my $self = shift;
212         my $client = shift;
213         my $ou = ''.shift();
214
215         return undef unless ($ou);
216         my $s_table = action::survey->table;
217
218         my $select = <<"        SQL";
219                 SELECT  s.*
220                   FROM  $s_table s
221                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
222                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
223                         AND s.required IS TRUE;
224         SQL
225
226         my $sth = action::survey->db_Main->prepare_cached($select);
227         $sth->execute($ou);
228
229         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
230
231         return undef;
232 }
233 __PACKAGE__->register_method(
234         api_name        => 'open-ils.storage.action.survey.required',
235         api_level       => 1,
236         stream          => 1,
237         method          => 'find_required_surveys',
238 );
239
240 sub find_usr_summary_surveys {
241         my $self = shift;
242         my $client = shift;
243         my $ou = ''.shift();
244
245         return undef unless ($ou);
246         my $s_table = action::survey->table;
247
248         my $select = <<"        SQL";
249                 SELECT  s.*
250                   FROM  $s_table s
251                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
252                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
253                         AND s.usr_summary IS TRUE;
254         SQL
255
256         my $sth = action::survey->db_Main->prepare_cached($select);
257         $sth->execute($ou);
258
259         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
260
261         return undef;
262 }
263 __PACKAGE__->register_method(
264         api_name        => 'open-ils.storage.action.survey.usr_summary',
265         api_level       => 1,
266         stream          => 1,
267         method          => 'find_usr_summary_surveys',
268 );
269
270
271 sub generate_fines {
272         my $self = shift;
273         my $client = shift;
274         my $grace = shift;
275         my $circ = shift;
276         
277         
278         my @circs;
279         if ($circ) {
280                 push @circs, action::circulation->search_where( { id => $circ, stop_fines => undef } );
281         } else {
282                 push @circs, overdue_circs($grace);
283         }
284
285         for my $c (@circs) {
286         
287                 try {
288                         my $due_dt = $parser->parse_datetime( clense_ISO8601( $c->due_date ) );
289         
290                         my $due = $due_dt->epoch;
291                         my $now = time;
292                         my $fine_interval = interval_to_seconds( $c->fine_interval );
293         
294                         if ( interval_to_seconds( $c->fine_interval ) >= interval_to_seconds('1d') ) {  
295                                 my $tz_offset_s = 0;;
296                                 if ($due_dt->strftime('%z') =~ /(-|\+)(\d{2}):?(\d{2})/) {
297                                         $tz_offset_s = $1 . interval_to_seconds( "${2}h ${3}m"); 
298                                 }
299         
300                                 $due -= ($due % $fine_interval) + $tz_offset_s;
301                                 $now -= ($now % $fine_interval) + $tz_offset_s;
302                         }
303         
304                         $client->respond(
305                                 "ARG! Overdue circulation ".$c->id.
306                                 " for item ".$c->target_copy.
307                                 " (user ".$c->usr.").\n".
308                                 "\tItem was due on or before: ".localtime($due)."\n");
309         
310                         my ($fine) = money::billing->search(
311                                 xact => $c->id, voided => 'f',
312                                 { order_by => 'billing_ts DESC', limit => '1' }
313                         );
314         
315                         my $last_fine;
316                         if ($fine) {
317                                 $last_fine = $parser->parse_datetime( clense_ISO8601( $fine->billing_ts ) )->epoch;
318                         } else {
319                                 $last_fine = $due;
320                                 $last_fine += $fine_interval * $grace;
321                         }
322         
323                         my $pending_fine_count = int( ($now - $last_fine) / $fine_interval ); 
324                         unless($pending_fine_count) {
325                                 $client->respond( "\tNo fines to create.  " );
326                                 if ($grace && $now < $due + $fine_interval * $grace) {
327                                         $client->respond( "Still inside grace period of: ". seconds_to_interval( $fine_interval * $grace)."\n" );
328                                 } else {
329                                         $client->respond( "Last fine generated for: ".localtime($last_fine)."\n" );
330                                 }
331                                 next;
332                         }
333         
334                         $client->respond( "\t$pending_fine_count pending fine(s)\n" );
335         
336                         for my $bill (1 .. $pending_fine_count) {
337         
338                                 my ($total) = money::billable_transaction_summary->retrieve( $c->id );
339         
340                                 if ($total && $total->balance_owed > $c->max_fine) {
341                                         $c->update({stop_fines => 'MAXFINES'});
342                                         $client->respond(
343                                                 "\tMaximum fine level of ".$c->max_fine.
344                                                 " reached for this circulation.\n".
345                                                 "\tNo more fines will be generated.\n" );
346                                         last;
347                                 }
348         
349                                 my $billing = money::billing->create(
350                                         { xact          => ''.$c->id,
351                                           note          => "Overdue Fine",
352                                           billing_type  => "Overdue materials",
353                                           amount        => ''.$c->recuring_fine,
354                                           billing_ts    => DateTime->from_epoch( epoch => $last_fine + $fine_interval * $bill )->strftime('%FT%T%z')
355                                         }
356                                 );
357         
358                                 $client->respond(
359                                         "\t\tCreating fine of ".$billing->amount." for period starting ".
360                                         localtime(
361                                                 $parser->parse_datetime(
362                                                         clense_ISO8601( $billing->billing_ts )
363                                                 )->epoch
364                                         )."\n" );
365                         }
366                 } catch Error with {
367                         my $e = shift;
368                         $client->respond( "Error processing overdue circulation [".$c->id."]:\n\n$e\n" );
369                 };
370         }
371 }
372 __PACKAGE__->register_method(
373         api_name        => 'open-ils.storage.action.circulation.overdue.generate_fines',
374         api_level       => 1,
375         stream          => 1,
376         method          => 'generate_fines',
377 );
378
379
380
381 my $locations;
382 my $statuses;
383 my %cache = (titles => {}, cns => {});
384 sub hold_copy_targeter {
385         my $self = shift;
386         my $client = shift;
387         my $check_expire = shift;
388         my $one_hold = shift;
389
390         $self->{user_filter} = OpenSRF::AppSession->create('open-ils.circ');
391         $self->{user_filter}->connect;
392         $self->{client} = $client;
393
394         my $time = time;
395         $check_expire ||= '12h';
396         $check_expire = interval_to_seconds( $check_expire );
397
398         my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time() - $check_expire);
399         $year += 1900;
400         $mon += 1;
401         my $expire_threshold = sprintf(
402                 '%s-%0.2d-%0.2dT%0.2d:%0.2d:%0.2d-00',
403                 $year, $mon, $mday, $hour, $min, $sec
404         );
405
406
407         $statuses ||= [ config::copy_status->search(holdable => 't') ];
408
409         $locations ||= [ asset::copy_location->search(holdable => 't') ];
410
411         my $holds;
412
413         %cache = (titles => {}, cns => {});
414
415         try {
416                 if ($one_hold) {
417                         $holds = [ action::hold_request->search(id => $one_hold) ];
418                 } else {
419                         $holds = [ action::hold_request->search_where(
420                                                         { capture_time => undef,
421                                                           prev_check_time => { '<=' => $expire_threshold },
422                                                         },
423                                                         { order_by => 'request_time,prev_check_time' } ) ];
424                         push @$holds, action::hold_request->search(
425                                                         capture_time => undef,
426                                                         prev_check_time => undef,
427                                                         { order_by => 'request_time' } );
428                 }
429         } catch Error with {
430                 my $e = shift;
431                 die "Could not retrieve uncaptured hold requests:\n\n$e\n";
432         };
433
434         for my $hold (@$holds) {
435                 action::hold_request->db_Main->begin_work;
436                 try {
437                         $client->respond("Processing hold ".$hold->id."...\n");
438
439                         my $copies;
440
441                         $copies = $self->metarecord_hold_capture($hold) if ($hold->hold_type eq 'M');
442                         $self->{client}->status( new OpenSRF::DomainObject::oilsContinueStatus );
443
444                         $copies = $self->title_hold_capture($hold) if ($hold->hold_type eq 'T');
445                         $self->{client}->status( new OpenSRF::DomainObject::oilsContinueStatus );
446                         
447                         $copies = $self->volume_hold_capture($hold) if ($hold->hold_type eq 'V');
448                         $self->{client}->status( new OpenSRF::DomainObject::oilsContinueStatus );
449                         
450                         $copies = $self->copy_hold_capture($hold) if ($hold->hold_type eq 'C');
451
452                         unless (ref $copies || !@$copies) {
453                                 $client->respond("\tNo copies available for targeting at all!\n");
454                         }
455
456                         my @good_copies;
457                         for my $c (@$copies) {
458                                 next if ( grep {$c->id == $hold->current_copy} @good_copies);
459                                 push @good_copies, $c if ($c);
460                         }
461
462                         $client->respond("\t".scalar(@good_copies)." (non-current) copies available for targeting...\n");
463
464                         my $old_best = $hold->current_copy;
465                         $hold->update({ current_copy => undef });
466         
467                         if (!scalar(@good_copies)) {
468                                 $client->respond("\tNo (non-current) copies available to fill the hold.\n");
469                                 if ( $old_best && grep {$c->id == $hold->current_copy} @$copies ) {
470                                         $client->respond("\tPushing current_copy back onto the targeting list\n");
471                                         push @good_copies, asset::copy->retrieve( $old_best );
472                                 } else {
473                                         $client->respond("\tcurrent_copy is no longer available for targeting... NEXT HOLD, PLEASE!\n");
474                                         next;
475                                 }
476                         }
477
478                         my $prox_list;
479                         $$prox_list[0] = [grep {$_->circ_lib == $hold->pickup_lib } @good_copies];
480                         $copies = [grep {$_->circ_lib != $hold->pickup_lib } @good_copies];
481
482                         my $best = $self->choose_nearest_copy($hold, $prox_list);
483
484                         if (!$best) {
485                                 $prox_list = $self->create_prox_list( $hold->pickup_lib, $copies );
486                                 $best = $self->choose_nearest_copy($hold, $prox_list);
487                         }
488
489                         if ($old_best) {
490                                 # hold wasn't fulfilled, record the fact
491                         
492                                 $client->respond("\tHold was not (but should have been) fulfilled by ".$old_best->id.".\n");
493                                 action::unfulfilled_hold_list->create(
494                                                 { hold => ''.$hold->id,
495                                                   current_copy => ''.$old_best->id,
496                                                   circ_lib => ''.$old_best->circ_lib,
497                                                 });
498                         }
499
500                         if ($best) {
501                                 $hold->update( { current_copy => ''.$best->id } );
502                                 $client->respond("\tTargeting copy ".$best->id." for hold fulfillment.\n");
503                         }
504
505                         $hold->update( { prev_check_time => 'now' } );
506                         $client->respond("\tUpdating hold ".$hold->id." with new 'current_copy' for hold fulfillment.\n");
507
508                         $client->respond("\tProcessing of hold ".$hold->id." complete.\n");
509                         $self->method_lookup('open-ils.storage.transaction.commit')->run;
510
511                         action::hold_request->dbi_commit;
512
513                 } otherwise {
514                         my $e = shift;
515                         $client->respond("\tProcessing of hold ".$hold->id." failed!.\n\t\t$e\n");
516                         action::hold_request->dbi_rollback;
517                 };
518         }
519
520         $self->{user_filter}->disconnect;
521         $self->{user_filter}->finish;
522         delete $$self{user_filter};
523         return undef;
524 }
525 __PACKAGE__->register_method(
526         api_name        => 'open-ils.storage.action.hold_request.copy_targeter',
527         api_level       => 1,
528         stream          => 1,
529         method          => 'hold_copy_targeter',
530 );
531
532
533
534 sub copy_hold_capture {
535         my $self = shift;
536         my $hold = shift;
537         my $cps = shift;
538
539         if (!defined($cps)) {
540                 try {
541                         $cps = [ asset::copy->search( id => $hold->target ) ];
542                 } catch Error with {
543                         my $e = shift;
544                         die "Could not retrieve initial volume list:\n\n$e\n";
545                 };
546         }
547
548         my @copies = grep { $_->holdable and !$_->ref } @$cps;
549
550         for (my $i = 0; $i < @copies; $i++) {
551                 next unless $copies[$i];
552                 
553                 my $cn = $cache{cns}{$copies[$i]->call_number};
554                 my $rec = $cache{titles}{$cn->record};
555                 $copies[$i] = undef if ($copies[$i] && !grep{ $copies[$i]->status eq $_->id}@$statuses);
556                 $copies[$i] = undef if ($copies[$i] && !grep{ $copies[$i]->location eq $_->id}@$locations);
557                 $copies[$i] = undef if (
558                         !$copies[$i] ||
559                         !$self->{user_filter}->request(
560                                 'open-ils.circ.permit_hold',
561                                 $hold->to_fieldmapper, do {
562                                         my $cp_fm = $copies[$i]->to_fieldmapper;
563                                         $cp_fm->circ_lib( $copies[$i]->circ_lib->to_fieldmapper );
564                                         $cp_fm->location( $copies[$i]->location->to_fieldmapper );
565                                         $cp_fm->status( $copies[$i]->status->to_fieldmapper );
566                                         $cp_fm;
567                                 },
568                                 { title => $rec->to_fieldmapper,
569                                   usr => actor::user->retrieve($hold->usr)->to_fieldmapper,
570                                   requestor => actor::user->retrieve($hold->requestor)->to_fieldmapper,
571                                 })->gather(1)
572                 );
573                 $self->{client}->status( new OpenSRF::DomainObject::oilsContinueStatus );
574         }
575
576         @copies = grep { $_ } @copies;
577
578         my $count = @copies;
579
580         return unless ($count);
581         
582         action::hold_copy_map->search( { hold => $hold->id } )->delete_all;
583         
584         my @maps;
585         $self->{client}->respond( "\tMapping ".scalar(@copies)." eligable copies for hold ".$hold->id."\n");
586         for my $c (@copies) {
587                 push @maps, action::hold_copy_map->create( { hold => ''.$hold->id, target_copy => ''.$c->id } );
588         }
589
590         return \@copies;
591 }
592
593
594 sub choose_nearest_copy {
595         my $self = shift;
596         my $hold = shift;
597         my $prox_list = shift;
598
599         for my $p ( 0 .. int( scalar(@$prox_list) - 1) ) {
600                 next unless (ref $$prox_list[$p]);
601                 my @capturable = grep { $_->status == 0 } @{ $$prox_list[$p] };
602                 next unless (@capturable);
603                 return $capturable[rand(scalar(@capturable))];
604         }
605 }
606
607 sub create_prox_list {
608         my $self = shift;
609         my $lib = shift;
610         my $copies = shift;
611
612         my @prox_list;
613         for my $cp (@$copies) {
614                 my ($prox) = $self->method_lookup('open-ils.storage.asset.copy.proximity')->run( $cp->id, $lib );
615                 $prox_list[$prox] = [] unless defined($prox_list[$prox]);
616                 push @{$prox_list[$prox]}, $cp;
617         }
618         return \@prox_list;
619 }
620
621 sub volume_hold_capture {
622         my $self = shift;
623         my $hold = shift;
624         my $vols = shift;
625
626         if (!defined($vols)) {
627                 try {
628                         $vols = [ asset::call_number->search( id => $hold->target ) ];
629                         $cache{cns}{$_->id} = $_ for (@$vols);
630                 } catch Error with {
631                         my $e = shift;
632                         die "Could not retrieve initial volume list:\n\n$e\n";
633                 };
634         }
635
636         my @v_ids = map { $_->id } @$vols;
637
638         my $cp_list;
639         try {
640                 $cp_list = [ asset::copy->search( call_number => \@v_ids ) ];
641         
642         } catch Error with {
643                 my $e = shift;
644                 warn "Could not retrieve copy list:\n\n$e\n";
645         };
646
647         $self->copy_hold_capture($hold,$cp_list) if (ref $cp_list and @$cp_list);
648 }
649
650 sub title_hold_capture {
651         my $self = shift;
652         my $hold = shift;
653         my $titles = shift;
654
655         if (!defined($titles)) {
656                 try {
657                         $titles = [ biblio::record_entry->search( id => $hold->target ) ];
658                         $cache{titles}{$_->id} = $_ for (@$titles);
659                 } catch Error with {
660                         my $e = shift;
661                         die "Could not retrieve initial title list:\n\n$e\n";
662                 };
663         }
664
665         my @t_ids = map { $_->id } @$titles;
666         my $cn_list;
667         try {
668                 ($cn_list) = $self->method_lookup('open-ils.storage.direct.asset.call_number.search.record.atomic')->run( \@t_ids );
669         
670         } catch Error with {
671                 my $e = shift;
672                 warn "Could not retrieve volume list:\n\n$e\n";
673         };
674
675         $cache{cns}{$_->id} = $_ for (@$cn_list);
676
677         $self->volume_hold_capture($hold,$cn_list) if (ref $cn_list and @$cn_list);
678 }
679
680 sub metarecord_hold_capture {
681         my $self = shift;
682         my $hold = shift;
683
684         my $titles;
685         try {
686                 $titles = [ metabib::metarecord_source_map->search( metarecord => $hold->target) ];
687         
688         } catch Error with {
689                 my $e = shift;
690                 die "Could not retrieve initial title list:\n\n$e\n";
691         };
692
693         try {
694                 my @recs = map {$_->record} metabib::record_descriptor->search( record => $titles, item_type => [split '', $hold->holdable_formats] ); 
695
696                 $titles = [ biblio::record_entry->search( id => \@recs ) ];
697         
698         } catch Error with {
699                 my $e = shift;
700                 die "Could not retrieve format-pruned title list:\n\n$e\n";
701         };
702
703
704         $cache{titles}{$_->id} = $_ for (@$titles);
705         $self->title_hold_capture($hold,$titles) if (ref $titles and @$titles);
706 }
707
708 1;