Bug 25690: SIP2: Don't allow checking out attached hold that is being transferred
[srvgit] / C4 / SIP / ILS / Item.pm
index 0950864..4a6c098 100644 (file)
@@ -89,6 +89,8 @@ sub new {
     $self->{permanent_location} = $item->homebranch;
     $self->{collection_code}    = $item->ccode;
     $self->{call_number}        = $item->itemcallnumber;
+    $self->{'shelving_location'}           = $item->location;
+    $self->{'permanent_shelving_location'} = $item->permanent_location;
 
     $self->{object} = $item;
 
@@ -106,8 +108,8 @@ sub new {
     my $biblio = Koha::Biblios->find( $self->{biblionumber} );
     my $holds = $biblio->current_holds->unblessed;
     $self->{hold_queue} = $holds;
-    $self->{hold_shelf}    = [( grep {   defined $_->{found}  and $_->{found} eq 'W' } @{$self->{hold_queue}} )];
-    $self->{pending_queue} = [( grep {(! defined $_->{found}) or  $_->{found} ne 'W' } @{$self->{hold_queue}} )];
+    $self->{hold_attached} = [( grep { defined $_->{found}  and ( $_->{found} eq 'W' or $_->{found} eq 'P' or $_->{found} eq 'T' ) } @{$self->{hold_queue}} )];
+    $self->{pending_queue} = [( grep {(! defined $_->{found}) or ( $_->{found} ne 'W' and $_->{found} ne 'P' and $_->{found} ne 'T' ) } @{$self->{hold_queue}} )];
     $self->{title} = $biblio->title;
     $self->{author} = $biblio->author;
     bless $self, $type;
@@ -135,6 +137,8 @@ my %fields = (
     barcode             => 0,
     onloan              => 0,
     collection_code     => 0,
+    shelving_location   => 0,
+    permanent_shelving_location   => 0,
     call_number         => 0,
     enumchron           => 0,
     location            => 0,
@@ -144,8 +148,8 @@ my %fields = (
 
 sub next_hold {
     my $self = shift;
-    # use Data::Dumper; warn "next_hold() hold_shelf: " . Dumper($self->{hold_shelf}); warn "next_hold() pending_queue: " . $self->{pending_queue};
-    foreach (@{$self->hold_shelf}) {    # If this item was taken from the hold shelf, then that reserve still governs
+    # use Data::Dumper; warn "next_hold() hold_attached: " . Dumper($self->{hold_attached}); warn "next_hold() pending_queue: " . $self->{pending_queue};
+    foreach (@{$self->hold_attached}) {    # If this item was taken from the hold shelf, then that reserve still governs
         next unless ($_->{itemnumber} and $_->{itemnumber} == $self->{itemnumber});
         return $_;
     }
@@ -265,10 +269,13 @@ sub sip_circulation_status {
     elsif ( Koha::Checkouts::ReturnClaims->search({ itemnumber => $self->{_object}->id, resolution => undef })->count ) {
         return '11';    # claimed returned
     }
+    elsif ( $self->{itemlost} ) {
+        return '12';    # lost
+    }
     elsif ( $self->{borrowernumber} ) {
         return '04';    # charged
     }
-    elsif ( grep { $_->{itemnumber} == $self->{itemnumber}  } @{ $self->{hold_shelf} } ) {
+    elsif ( grep { $_->{itemnumber} == $self->{itemnumber}  } @{ $self->{hold_attached} } ) {
         return '08';    # waiting on hold shelf
     }
     else {
@@ -307,10 +314,10 @@ sub pending_queue {
        (defined $self->{pending_queue}) or return [];
     return $self->{pending_queue};
 }
-sub hold_shelf {
+sub hold_attached {
     my $self = shift;
-       (defined $self->{hold_shelf}) or return [];
-    return $self->{hold_shelf};
+    (defined $self->{hold_attached}) or return [];
+    return $self->{hold_attached};
 }
 
 sub hold_queue_position {
@@ -352,7 +359,7 @@ sub hold_pickup_date {
 #    AND no pending (i.e. non-W) hold queue
 # OR
 # 2) not checked out
-#    AND (not on hold_shelf OR is on hold_shelf for patron)
+#    AND (not on hold_attached OR is on hold_attached for patron)
 #
 # What this means is we are consciously allowing the patron to checkout (but not renew) an item that DOES
 # have non-W holds on it, but has not been "picked" from the stacks.  That is to say, the
@@ -364,13 +371,13 @@ sub hold_pickup_date {
 sub available {
        my ($self, $for_patron) = @_;
        my $count  = (defined $self->{pending_queue}) ? scalar @{$self->{pending_queue}} : 0;
-       my $count2 = (defined $self->{hold_shelf}   ) ? scalar @{$self->{hold_shelf}   } : 0;
-       $debug and print STDERR "availability check: pending_queue size $count, hold_shelf size $count2\n";
+    my $count2 = (defined $self->{hold_attached}   ) ? scalar @{$self->{hold_attached}   } : 0;
+    $debug and print STDERR "availability check: pending_queue size $count, hold_attached size $count2\n";
     if (defined($self->{borrowernumber})) {
         ($self->{borrowernumber} eq $for_patron) or return 0;
                return ($count ? 0 : 1);
        } else {        # not checked out
-        ($count2) and return $self->barcode_is_borrowernumber($for_patron, $self->{hold_shelf}[0]->{borrowernumber});
+        ($count2) and return $self->barcode_is_borrowernumber($for_patron, $self->{hold_attached}[0]->{borrowernumber});
        }
        return 0;
 }