Add the ability to renew via SIP 1 method used by 3M self-checks
authordbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sat, 23 Jan 2010 00:44:06 +0000 (00:44 +0000)
committerdbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sat, 23 Jan 2010 00:44:06 +0000 (00:44 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@15371 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/SIP.pm
Open-ILS/src/perlmods/OpenILS/SIP/Transaction/Checkout.pm

index 855d386..739c646 100644 (file)
@@ -164,13 +164,16 @@ sub format_date {
        my $year = $time[5]+1900;
        my $mon = $time[4]+1;
        my $day = $time[3];
-
-       $mon =~ s/^(\d)$/0$1/;
-       $day =~ s/^(\d)$/0$1/;
-       $date = "$year$mon$day";
-
-       $date = $year.'-'.$mon.'-'.$day .' 00:00:00' if $type eq 'due';
-       #$date = $year.'-'.$mon.'-'.$day if $type eq 'due';
+       my $hour = $time[2];
+       my $minute = $time[1];
+       my $second = $time[0];
+  
+       $date = sprintf("%04d-%02d-%02d", $year, $mon, $day);
+  
+       # Due dates need time of day as well
+       if ($type eq 'due') {
+               $date .= sprintf(" %02d:%02d:%02d", $hour, $minute, $second);
+       }
 
        syslog('LOG_DEBUG', "OILS: formatted date [type=$type]: $date");
        return $date;
@@ -275,6 +278,7 @@ sub offline_ok {
 
 sub checkout {
        my ($self, $patron_id, $item_id, $sc_renew) = @_;
+       $sc_renew = 0;
 
        $self->verify_session;
        
@@ -303,15 +307,18 @@ sub checkout {
        }
 
        syslog('LOG_DEBUG', "OILS: OpenILS::Checkout data loaded OK, checking out...");
-       $xact->do_checkout();
 
-       if ($item->{patron} && ($item->{patron} ne $patron_id)) {
+       if ($item->{patron} && ($item->{patron} eq $patron_id)) {
+               syslog('LOG_INFO', "OILS: OpenILS::Checkout data loaded OK, doing renew...");
+               $sc_renew = 1;
+       } elsif ($item->{patron} && ($item->{patron} ne $patron_id)) {
                # I can't deal with this right now
                # XXX check in then check out?
                $xact->screen_msg("Item checked out to another patron");
                $xact->ok(0);
        } 
 
+       $xact->do_checkout($sc_renew);
        $xact->desensitize(!$item->magnetic);
 
        if( $xact->ok ) {
index 9376723..1b94492 100644 (file)
@@ -51,7 +51,7 @@ sub new {
 # XXX Set $self->ok(0) on any errors
 sub do_checkout {
        my $self = shift;
-       syslog('LOG_DEBUG', "OILS: performing checkout...");
+       my $is_renew = shift || 0;
 
        $self->ok(0); 
 
@@ -60,58 +60,66 @@ sub do_checkout {
                patron_barcode => $self->{patron}->id
        };
 
-       my $resp = $U->simplereq(
-               'open-ils.circ',
-               'open-ils.circ.checkout.permit', 
-               $self->{authtoken}, $args );
+       my $resp;
 
-       $resp = [$resp] unless ref $resp eq 'ARRAY';
+       if ($is_renew) {
+               $resp = $U->simplereq(
+                       'open-ils.circ',
+                       'open-ils.circ.renew', $self->{authtoken},
+                       { barcode => $self->item->id, patron_barcode => $self->patron->id });
+       } else {
+               $resp = $U->simplereq(
+                       'open-ils.circ',
+                       'open-ils.circ.checkout.permit', 
+                       $self->{authtoken}, $args );
 
-       my $key;
+               $resp = [$resp] unless ref $resp eq 'ARRAY';
 
-       syslog('LOG_DEBUG', "OILS: Checkout permit returned event: " . OpenSRF::Utils::JSON->perl2JSON($resp));
+               my $key;
 
-       if( @$resp == 1 and ! $U->event_code($$resp[0]) ) {
-               $key = $$resp[0]->{payload};
-               syslog('LOG_INFO', "OILS: circ permit key => $key");
+               syslog('LOG_DEBUG', "OILS: Checkout permit returned event: " . OpenSRF::Utils::JSON->perl2JSON($resp));
 
-       } else {
+               if( @$resp == 1 and ! $U->event_code($$resp[0]) ) {
+                       $key = $$resp[0]->{payload};
+                       syslog('LOG_INFO', "OILS: circ permit key => $key");
 
-               # We got one or more non-success events
-               $self->screen_msg('');
-               for my $r (@$resp) {
+               } else {
 
-                       if( my $code = $U->event_code($resp) ) {
-                               my $txt = $resp->{textcode};
-                               syslog('LOG_INFO', "OILS: Checkout permit failed with event $code : $txt");
+                       # We got one or more non-success events
+                       $self->screen_msg('');
+                       for my $r (@$resp) {
 
-                               if( $txt eq 'OPEN_CIRCULATION_EXISTS' ) {
-                                       $self->screen_msg(OILS_SIP_MSG_CIRC_EXISTS);
-                                       return 0;
-                               } else {
-                                       $self->screen_msg(OILS_SIP_MSG_CIRC_PERMIT_FAILED);
+                               if( my $code = $U->event_code($resp) ) {
+                                       my $txt = $resp->{textcode};
+                                       syslog('LOG_INFO', "OILS: Checkout permit failed with event $code : $txt");
+
+                                       if( $txt eq 'OPEN_CIRCULATION_EXISTS' ) {
+                                               $self->screen_msg(OILS_SIP_MSG_CIRC_EXISTS);
+                                               return 0;
+                                       } else {
+                                               $self->screen_msg(OILS_SIP_MSG_CIRC_PERMIT_FAILED);
+                                       }
                                }
                        }
+                       return 0;
                }
-               return 0;
-       }
 
-       # --------------------------------------------------------------------
-       # Now do the actual checkout
-       # --------------------------------------------------------------------
+               # --------------------------------------------------------------------
+               # Now do the actual checkout
+               # --------------------------------------------------------------------
 
-       $args = { 
-               permit_key              => $key, 
-               patron_barcode => $self->{patron}->id, 
-               barcode                 => $self->{item}->id
-       };
-
-       $resp = $U->simplereq(
-               'open-ils.circ',
-               'open-ils.circ.checkout', $self->{authtoken}, $args );
+               $args = { 
+                       permit_key              => $key, 
+                       patron_barcode => $self->{patron}->id, 
+                       barcode                 => $self->{item}->id
+               };
 
+               $resp = $U->simplereq(
+                       'open-ils.circ',
+                       'open-ils.circ.checkout', $self->{authtoken}, $args );
+       }
 
-       syslog('LOG_DEBUG', "OILS: Checkout returned event: " . OpenSRF::Utils::JSON->perl2JSON($resp));
+       syslog('LOG_INFO', "OILS: Checkout returned event: " . OpenSRF::Utils::JSON->perl2JSON($resp));
 
        # XXX Check for events
        if( $resp ) {