fixed some logic errors in the claims returned backdating
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 16 Oct 2006 17:10:37 +0000 (17:10 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 16 Oct 2006 17:10:37 +0000 (17:10 +0000)
making sure void_time and voider is set for backdated circs

git-svn-id: svn://svn.open-ils.org/ILS/trunk@6473 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

index d562c5e..2d3f4d7 100644 (file)
@@ -356,20 +356,57 @@ sub _set_circ_claims_returned {
        return $evt if $evt;
        $circ->stop_fines("CLAIMSRETURNED");
 
-       $logger->activity("user ".$reqr->id.
-               " marking circ".  $circ->id. " as claims returned");
+       $logger->info("user ".$reqr->id.
+               " marking circ".  $circ->id. " as claims returned with backdate $backdate");
 
        # allow the caller to backdate the circulation and void any fines
        # that occurred after the backdate
        if($backdate) {
-               OpenILS::Application::Circ::Circulate::_checkin_handle_backdate(
-                       $backdate, $circ, $reqr, $session );
+               my $s = cr_handle_backdate($backdate, $circ, $reqr, $session );
+               $logger->debug("backdate method returned $s");
                $circ->stop_fines_time(clense_ISO8601($backdate))
        }
 
        return undef;
 }
 
+sub cr_handle_backdate {
+   my( $backdate, $circ, $requestor, $session, $closecirc ) = @_;
+
+       my $bd = $backdate;
+       $bd =~ s/^(\d{4}-\d{2}-\d{2}).*/$1/og;
+       $bd = "${bd}T23:59:59";
+
+   my $bills = $session->request(
+      "open-ils.storage.direct.money.billing.search_where.atomic",
+               billing_ts => { '>=' => $bd }, 
+               xact => $circ->id,
+               billing_type => OILS_BILLING_TYPE_OVERDUE_MATERIALS
+       )->gather(1);
+
+       $logger->debug("backdate found ".scalar(@$bills)." bills to void");
+
+   if($bills) {
+      for my $bill (@$bills) {
+                       unless( $U->is_true($bill->voided) ) {
+                               $logger->info("voiding bill ".$bill->id);
+                               $bill->voided('t');
+                               $bill->void_time('now');
+                               $bill->voider($requestor->id);
+                               my $n = $bill->note || "";
+                               $bill->note($n . "\nSystem: VOIDED FOR BACKDATE");
+                               my $s = $session->request(
+                                       "open-ils.storage.direct.money.billing.update", $bill)->gather(1);
+                               return $U->DB_UPDATE_FAILED($bill) unless $s;
+                       }
+               }
+   }
+
+       return 100;
+}
+
+
+
 
 
 __PACKAGE__->register_method (
index 6a17237..5e27a84 100644 (file)
@@ -1718,9 +1718,14 @@ sub checkin_handle_backdate {
                }
        );
 
+       $logger->debug("backdate found ".scalar(@$bills)." bills to void");
+
        for my $bill (@$bills) {        
-               if( !$bill->voided or $bill->voided =~ /f/i ) {
+               unless( $U->is_true($bill->voided) ) {
+                       $logger->info("backdate voiding bill ".$bill->id);
                        $bill->voided('t');
+                       $bill->void_time('now');
+                       $bill->voider($self->editor->requestor->id);
                        my $n = $bill->note || "";
                        $bill->note("$n\nSystem: VOIDED FOR BACKDATE");
 
@@ -1732,15 +1737,15 @@ sub checkin_handle_backdate {
 
 
 
+=head
 # XXX Legacy version for Circ.pm support
 sub _checkin_handle_backdate {
-   my( $backdate, $circ, $requestor, $session, $closecirc ) = @_;
+   my( $class, $backdate, $circ, $requestor, $session, $closecirc ) = @_;
 
        my $bd = $backdate;
        $bd =~ s/^(\d{4}-\d{2}-\d{2}).*/$1/og;
        $bd = "${bd}T23:59:59";
 
-
    my $bills = $session->request(
       "open-ils.storage.direct.money.billing.search_where.atomic",
                billing_ts => { '>=' => $bd }, 
@@ -1748,17 +1753,27 @@ sub _checkin_handle_backdate {
                billing_type => OILS_BILLING_TYPE_OVERDUE_MATERIALS
        )->gather(1);
 
+       $logger->debug("backdate found ".scalar(@$bills)." bills to void");
+
    if($bills) {
       for my $bill (@$bills) {
-         $bill->voided('t');
-         my $n = $bill->note || "";
-         $bill->note($n . "\nSystem: VOIDED FOR BACKDATE");
-         my $s = $session->request(
-            "open-ils.storage.direct.money.billing.update", $bill)->gather(1);
-         return $U->DB_UPDATE_FAILED($bill) unless $s;
-      }
+                       unless( $U->is_true($bill->voided) ) {
+                               $logger->debug("voiding bill ".$bill->id);
+                               $bill->voided('t');
+                               $bill->void_time('now');
+                               $bill->voider($requestor->id);
+                               my $n = $bill->note || "";
+                               $bill->note($n . "\nSystem: VOIDED FOR BACKDATE");
+                               my $s = $session->request(
+                                       "open-ils.storage.direct.money.billing.update", $bill)->gather(1);
+                               return $U->DB_UPDATE_FAILED($bill) unless $s;
+                       }
+               }
    }
+
+       return 100;
 }
+=cut