# XXX Since this is all we need in open-ils.storage for serial stuff ATM, just
# XXX putting it here instead of creating a whole new file.
sub issuance_ranged_tree {
- my $self = shift;
- my $client = shift;
- my $iss = shift;
- my $ou = shift;
- my $depth = shift || 0;
-
- my $ou_list =
- actor::org_unit
- ->db_Main
- ->selectcol_arrayref(
- 'SELECT id FROM actor.org_unit_descendants(?,?)',
- {},
- $ou,
- $depth
- );
-
- return undef unless ($ou_list and @$ou_list);
-
- $iss = serial::issuance->retrieve( $iss );
- return undef unless ($iss);
-
- my $issuance = $iss->to_fieldmapper;
- $issuance->items([]);
-
- for my $it ( $iss->items() ) {
- my $item = $it->to_fieldmapper;
-
- next if ($it->unit->deleted);
- next unless (grep { $it->unit->circ_lib eq $_ } @$ou_list);
-
- my $unit = $it->unit->to_fieldmapper;
- $unit->status( $it->unit->status->to_fieldmapper );
- $unit->location( $it->unit->location->to_fieldmapper );
- $item->unit( $unit );
-
- push @{ $issuance->items }, $item;
- }
+ my $self = shift;
+ my $client = shift;
+ my $iss = shift;
+ my $ou = shift;
+ my $depth = shift || 0;
+
+ my $ou_list =
+ actor::org_unit
+ ->db_Main
+ ->selectcol_arrayref(
+ 'SELECT id FROM actor.org_unit_descendants(?,?)',
+ {},
+ $ou,
+ $depth
+ );
+
+ return undef unless ($ou_list and @$ou_list);
+
+ $iss = serial::issuance->retrieve( $iss );
+ return undef unless ($iss);
+
+ my $issuance = $iss->to_fieldmapper;
+ $issuance->items([]);
+
+ # Now, gather issuances on the same bib, with the same label and date_published ...
+ my @subs = map { $_->id } serial::subscription->search( record_entry => $iss->subscription->record_entry->id );
+
+ my @similar_iss = serial::issuance->search_where(
+ subscription => \@subs,
+ label => $iss->label,
+ date_published => $iss->date_published
+ );
+
+ # ... and add all /their/ items to the target issuance
+ for my $i ( @similar_iss ) {
+ for my $it ( $i->items() ) {
+
+ next if ($it->unit->deleted);
+ next unless (grep { $it->unit->circ_lib eq $_ } @$ou_list);
+
+ my $unit = $it->unit->to_fieldmapper;
+ $unit->status( $it->unit->status->to_fieldmapper );
+ $unit->location( $it->unit->location->to_fieldmapper );
+
+ my $item = $it->to_fieldmapper;
+ $item->unit( $unit );
+
+ push @{ $issuance->items }, $item;
+ }
+ }
- return $issuance;
+ return $issuance;
}
__PACKAGE__->register_method(
- api_name => 'open-ils.storage.serial.issuance.ranged_tree',
- method => 'issuance_ranged_tree',
- argc => 1,
- api_level => 1,
+ api_name => 'open-ils.storage.serial.issuance.ranged_tree',
+ method => 'issuance_ranged_tree',
+ argc => 1,
+ api_level => 1,
);
sub merge_record_assets {