added checks for null due_dates and unlimited circ durations
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 7 Aug 2006 20:20:17 +0000 (20:20 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 7 Aug 2006 20:20:17 +0000 (20:20 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@5347 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Open-ILS/src/perlmods/OpenILS/Application/Circ/Circulate.pm

index 2cf0ae7..9b80360 100644 (file)
@@ -1740,10 +1740,14 @@ sub _checked_out {
        # split the circs up into overdue and not-overdue circs
        my (@out,@overdue);
        for my $c (@$circs) {
-               my $due_dt = $parser->parse_datetime( clense_ISO8601( $c->due_date ) );
-               my $due = $due_dt->epoch;
-               if ($due < DateTime->today->epoch) {
-                       push @overdue, $c->id;
+               if( $c->due_date ) {
+                       my $due_dt = $parser->parse_datetime( clense_ISO8601( $c->due_date ) );
+                       my $due = $due_dt->epoch;
+                       if ($due < DateTime->today->epoch) {
+                               push @overdue, $c->id;
+                       } else {
+                               push @out, $c->id;
+                       }
                } else {
                        push @out, $c->id;
                }
index 162fecb..ece57b6 100644 (file)
@@ -880,20 +880,28 @@ sub run_checkout_scripts {
                throw OpenSRF::EX::ERROR ("Circ Duration Script Died: $@");
 
    my $duration   = $result->{durationRule};
-   #my $dur_level  = $result->{durationLevel};
    my $recurring  = $result->{recurringFinesRule};
    my $max_fine   = $result->{maxFine};
-   #my $rec_fines_level = $result->{recurringFinesLevel};
 
-   ($duration, $evt) = $U->fetch_circ_duration_by_name($duration);
-       return $self->bail_on_events($evt) if $evt;
-   ($recurring, $evt) = $U->fetch_recurring_fine_by_name($recurring);
-       return $self->bail_on_events($evt) if $evt;
-   ($max_fine, $evt) = $U->fetch_max_fine_by_name($max_fine);
-       return $self->bail_on_events($evt) if $evt;
+       if( $duration ne OILS_UNLIMITED_CIRC_DURATION ) {
+
+               ($duration, $evt) = $U->fetch_circ_duration_by_name($duration);
+               return $self->bail_on_events($evt) if $evt;
+       
+               ($recurring, $evt) = $U->fetch_recurring_fine_by_name($recurring);
+               return $self->bail_on_events($evt) if $evt;
+       
+               ($max_fine, $evt) = $U->fetch_max_fine_by_name($max_fine);
+               return $self->bail_on_events($evt) if $evt;
+
+       } else {
+
+               # The item circulates with an unlimited duration
+               $duration       = undef;
+               $recurring      = undef;
+               $max_fine       = undef;
+       }
 
-   #$self->duration_level($dur_level);
-   #$self->recurring_fines_level($rec_fines_level);
    $self->duration_rule($duration);
    $self->recurring_fines_rule($recurring);
    $self->max_fine_rule($max_fine);
@@ -909,41 +917,47 @@ sub build_checkout_circ_object {
    my $recurring  = $self->recurring_fines_rule;
    my $copy       = $self->copy;
    my $patron     = $self->patron;
-   #my $dur_level  = $self->duration_level;
-   #my $rec_level  = $self->recurring_fines_level;
-
-       my $dname = $duration->name;
-       my $mname = $max->name;
-       my $rname = $recurring->name;
-
-       $logger->debug("circulator: building circulation ".
-               "with duration=$dname, maxfine=$mname, recurring=$rname");
-
-       #$circ->duration( $duration->shrt ) if ($dur_level == OILS_CIRC_DURATION_SHORT);
-   #$circ->duration( $duration->normal ) if ($dur_level == OILS_CIRC_DURATION_NORMAL);
-   #$circ->duration( $duration->extended ) if ($dur_level == OILS_CIRC_DURATION_EXTENDED);
-
-       $circ->duration( $duration->shrt ) 
-               if $copy->loan_duration == OILS_CIRC_DURATION_SHORT;
-   $circ->duration( $duration->normal ) 
-               if $copy->loan_duration == OILS_CIRC_DURATION_NORMAL;
-   $circ->duration( $duration->extended ) 
-               if $copy->loan_duration ==OILS_CIRC_DURATION_EXTENDED;
-
-   $circ->recuring_fine( $recurring->low ) 
-               if $copy->fine_level == OILS_REC_FINE_LEVEL_LOW;
-   $circ->recuring_fine( $recurring->normal ) 
-               if $copy->fine_level == OILS_REC_FINE_LEVEL_NORMAL;
-   $circ->recuring_fine( $recurring->high ) 
-               if $copy->fine_level == OILS_REC_FINE_LEVEL_HIGH;
-
-   $circ->duration_rule( $duration->name );
-   $circ->recuring_fine_rule( $recurring->name );
-   $circ->max_fine_rule( $max->name );
-   $circ->max_fine( $max->amount );
-
-   $circ->fine_interval($recurring->recurance_interval);
-   $circ->renewal_remaining( $duration->max_renewals );
+
+       if( $duration ) {
+
+               my $dname = $duration->name;
+               my $mname = $max->name;
+               my $rname = $recurring->name;
+       
+               $logger->debug("circulator: building circulation ".
+                       "with duration=$dname, maxfine=$mname, recurring=$rname");
+       
+               $circ->duration( $duration->shrt ) 
+                       if $copy->loan_duration == OILS_CIRC_DURATION_SHORT;
+               $circ->duration( $duration->normal ) 
+                       if $copy->loan_duration == OILS_CIRC_DURATION_NORMAL;
+               $circ->duration( $duration->extended ) 
+                       if $copy->loan_duration == OILS_CIRC_DURATION_EXTENDED;
+       
+               $circ->recuring_fine( $recurring->low ) 
+                       if $copy->fine_level == OILS_REC_FINE_LEVEL_LOW;
+               $circ->recuring_fine( $recurring->normal ) 
+                       if $copy->fine_level == OILS_REC_FINE_LEVEL_NORMAL;
+               $circ->recuring_fine( $recurring->high ) 
+                       if $copy->fine_level == OILS_REC_FINE_LEVEL_HIGH;
+
+               $circ->duration_rule( $duration->name );
+               $circ->recuring_fine_rule( $recurring->name );
+               $circ->max_fine_rule( $max->name );
+               $circ->max_fine( $max->amount );
+
+               $circ->fine_interval($recurring->recurance_interval);
+               $circ->renewal_remaining( $duration->max_renewals );
+
+       } else {
+
+               $logger->info("circulator: copy found with an unlimited circ duration");
+               $circ->duration_rule(OILS_UNLIMITED_CIRC_DURATION);
+               $circ->recuring_fine_rule(OILS_UNLIMITED_CIRC_DURATION);
+               $circ->max_fine_rule(OILS_UNLIMITED_CIRC_DURATION);
+               $circ->renewal_remaining(0);
+       }
+
    $circ->target_copy( $copy->id );
    $circ->usr( $patron->id );
    $circ->circ_lib( $self->circ_lib );
@@ -954,7 +968,6 @@ sub build_checkout_circ_object {
       $circ->circ_staff($self->editor->requestor->id);
    }
 
-
    # if the user provided an overiding checkout time,
    # (e.g. the checkout really happened several hours ago), then
    # we apply that here.  Does this need a perm??
@@ -963,7 +976,7 @@ sub build_checkout_circ_object {
 
    # if a patron is renewing, 'requestor' will be the patron
    $circ->circ_staff($self->editor->requestor->id);
-       $circ->due_date( $self->create_due_date($circ->duration) );
+       $circ->due_date( $self->create_due_date($circ->duration) ) if $circ->duration;
 
        $self->circ($circ);
 }
@@ -984,7 +997,7 @@ sub apply_modified_due_date {
    } else {
 
       # if the due_date lands on a day when the location is closed
-      return unless $copy;
+      return unless $copy and $circ->due_date;
 
                my $org = (ref $copy->circ_lib) ? $copy->circ_lib->id : $copy->circ_lib;