Initial version of server-side changes for SIP fine detail enhancement user/dpearl/fine_detail_SERV
authorDan Pearl <dpearl@cwmars.org>
Thu, 25 May 2017 18:10:01 +0000 (14:10 -0400)
committerDan Pearl <dpearl@cwmars.org>
Thu, 25 May 2017 18:10:01 +0000 (14:10 -0400)
Open-ILS/src/perlmods/lib/OpenILS/SIP/Patron.pm

index 0845084..a0f97c5 100644 (file)
@@ -857,25 +857,70 @@ sub charged_items_impl {
 }
 
 sub fine_items {
-    my ($self, $start, $end, $ids_only) = @_;
+    my ($self, $start, $end, $ids_only, $server) = @_;
     my @fines;
+    my ($AV_format_orig, $AV_format, $line);
+
     eval {
+       $AV_format_orig = $server ? $server->{account}->{AV_format} : undef;
+       $AV_format_orig ||= "3m";
+       $AV_format = lc $AV_format;  # For case-insensitivity
+
+        # Do a prescan for validity and default to 3M 
+       if ($AV_format ne "swyer_a" && 
+           $AV_format ne "swyer_b" && 
+           $AV_format ne "eg_legacy" && 
+           $AV_format ne "3m") {
+           syslog('LOG_WARNING', 
+                   "OILS: Unknown value for AV_format: %s", $AV_format_orig);
+           $AV_format = "3m";
+       }
+
        my $xacts = $U->simplereq('open-ils.actor', 'open-ils.actor.user.transactions.history.have_balance', $self->{authtoken}, $self->{user}->id);
+
        foreach my $xact (@{$xacts}) {
            if ($ids_only) {
-               push @fines, $xact;
-               next;
+                push @fines, $xact;
+                next;
            }
-           my $line = $xact->balance_owed . " " . $xact->last_billing_type . " ";
-           if ($xact->xact_type eq 'circulation') {
-               my $mods = $U->simplereq('open-ils.circ', 'open-ils.circ.circ_transaction.find_title', $self->{authtoken}, $xact->id);
-               $line .= $mods->title . ' / ' . $mods->author;
-           } else {
-               $line .= $xact->last_billing_note;
-           }
-           push @fines, OpenILS::SIP::clean_text($line);
+
+           if ($AV_format eq "eg_legacy") {
+                  $line = $xact->balance_owed . " " . $xact->last_billing_type . " ";
+                  if ($xact->xact_type eq 'circulation') {
+                      my $mods = $U->simplereq('open-ils.circ', 'open-ils.circ.circ_transaction.find_title', $self->{authtoken}, $xact->id);
+                      $line .= $mods->title . ' / ' . $mods->author;
+                  } else {
+                      $line .= $xact->last_billing_note;
+                  }
+                  push @fines, OpenILS::SIP::clean_text($line);
+
+               # For now, swyer_a looks suspiciously like 3m!
+           } elsif ($AV_format eq "3m" or $AV_format eq "swyer_a") {
+                  $line = $xact->id . ' $' . $xact->balance_owed . ' "FINE" ' . $xact->last_billing_type . ' ';
+                  if ($xact->xact_type eq 'circulation') {
+                      my $mods = $U->simplereq('open-ils.circ', 'open-ils.circ.circ_transaction.find_title', $self->{authtoken}, $xact->id);
+                      $line .= $mods->title . ' / ' . $mods->author;
+                  } else {
+                      $line .= $xact->last_billing_note;
+                  }
+
+            } elsif ($AV_format eq "swyer_b") {
+                  $line =   "Charge-Number: " . $xact->id;
+                  $line .=  ", Amount-Due: "  . $xact->balance_owed;
+                  $line .=  ", Fine-Type: FINE";
+
+                  if ($xact->xact_type eq 'circulation') {
+                      my $mods = $U->simplereq('open-ils.circ', 'open-ils.circ.circ_transaction.find_title', $self->{authtoken}, $xact->id);
+                      $line .= ", Title: " . $mods->title;
+                  } else {
+                      $line .= ", Title: " . $xact->last_billing_note;
+                  }
+
+             }
+
        }
     };
+
     my $log_status = $@ ? 'ERROR: ' . $@ : 'OK';
     syslog('LOG_DEBUG', 'OILS: Patron->fine_items() ' . $log_status);
     return (defined $start and defined $end) ?