From d4f44e3c8693e53f3e60722ba9858427dba10a0e Mon Sep 17 00:00:00 2001 From: miker Date: Thu, 16 Sep 2010 02:25:57 +0000 Subject: [PATCH] teach open-ils.storage.serial.issuance.ranged_tree about "global" issuances git-svn-id: svn://svn.open-ils.org/ILS/trunk@17718 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Storage/Publisher/asset.pm | 97 ++++++++++++---------- 1 file changed, 55 insertions(+), 42 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/asset.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/asset.pm index c413085a8..8f49f4b94 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/asset.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/asset.pm @@ -799,51 +799,64 @@ __PACKAGE__->register_method( # 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 { -- 2.11.0