Bug 3638 Self Check Should Capture Hold Items
[koha_fer] / C4 / SIP / ILS / Transaction / Checkin.pm
index 6c4f360..a705f57 100644 (file)
@@ -7,12 +7,14 @@ package ILS::Transaction::Checkin;
 use warnings;
 use strict;
 
-use POSIX qw(strftime);
+use POSIX qw(strftime);
 
 use ILS;
 use ILS::Transaction;
 
 use C4::Circulation;
+use C4::Reserves qw( ModReserveAffect );
+use C4::Debug;
 
 our @ISA = qw(ILS::Transaction);
 
@@ -31,7 +33,7 @@ my %fields = (
 
 sub new {
     my $class = shift;
-    my $self = $class->SUPER::new();
+    my $self = $class->SUPER::new();                # start with an ILS::Transaction object
 
     foreach (keys %fields) {
         $self->{_permitted}->{$_} = $fields{$_};    # overlaying _permitted
@@ -45,40 +47,69 @@ sub do_checkin {
     my $self = shift;
     my $branch = @_ ? shift : 'SIP2' ;
     my $barcode = $self->{item}->id;
+    $debug and warn "do_checkin() calling AddReturn($barcode, $branch)";
     my ($return, $messages, $iteminformation, $borrower) = AddReturn($barcode, $branch);
     $self->alert(!$return);
+    # ignoring messages: NotIssued, IsPermanent, WasLost, WasTransfered
+
+    # biblionumber, biblioitemnumber, itemnumber
+    # borrowernumber, reservedate, branchcode
+    # cancellationdate, found, reservenotes, priority, timestamp
+
     if ($messages->{BadBarcode}) {
         $self->alert_type('99');
     }
-    # ignoring: NotIssued, IsPermanent
     if ($messages->{wthdrawn}) {
         $self->alert_type('99');
     }
+    if ($messages->{Wrongbranch}) {
+        $self->destination_loc($messages->{Wrongbranch}->{Rightbranch});
+        $self->alert_type('04');            # send to other branch
+    }
+    if ($messages->{WrongTransfer}) {
+        $self->destination_loc($messages->{WrongTransfer});
+        $self->alert_type('04');            # send to other branch
+    }
+    if ($messages->{NeedsTransfer}) {
+        $self->destination_loc($iteminformation->{homebranch});
+        $self->alert_type('04');            # send to other branch
+    }
     if ($messages->{ResFound}) {
-        if ($self->hold($messages->{ResFound}->{ResFound})) {
-            $self->alert_type('99');
+        $self->hold($messages->{ResFound});
+        if ($branch eq $messages->{ResFound}->{branchcode}) {
+            $self->alert_type('01');
+            ModReserveAffect( $messages->{ResFound}->{itemnumber},
+                $messages->{ResFound}->{borrowernumber}, 0);
+
+        } else {
+            $self->alert_type('02');
+            ModReserveAffect( $messages->{ResFound}->{itemnumber},
+                $messages->{ResFound}->{borrowernumber}, 1);
+
         }
+        $self->{item}->hold_patron_id( $messages->{ResFound}->{borrowernumber} );
+        $self->{item}->destination_loc( $messages->{ResFound}->{branchcode} );
     }
-    defined $self->alert_type and $self->alert(1);  # alert_type could be "00"
+    $self->alert(1) if defined $self->alert_type;  # alert_type could be "00", hypothetically
     $self->ok($return);
 }
 
 sub resensitize {
        my $self = shift;
        unless ($self->{item}) {
-               warn "no item found in object to resensitize";
+               warn "resensitize(): no item found in object to resensitize";
                return;
        }
-       return !$self->{item}->magnetic;
+       return !$self->{item}->magnetic_media;
 }
 
 sub patron_id {
        my $self = shift;
        unless ($self->{patron}) {
-               warn "no patron found in object";
+               warn "patron_id(): no patron found in object";
                return;
        }
-       return !$self->{patron}->id;
+       return $self->{patron}->id;
 }
 
 1;