From caba6f285ee1830ffafd3a6452a77ea999a77a72 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 4 Sep 2020 17:58:58 -0400 Subject: [PATCH] fine items; testing pending Signed-off-by: Bill Erickson --- .../src/perlmods/lib/OpenILS/Application/SIP2.pm | 24 +-- .../lib/OpenILS/Application/SIP2/Common.pm | 16 ++ .../lib/OpenILS/Application/SIP2/Patron.pm | 198 +++++++++++++++++---- 3 files changed, 188 insertions(+), 50 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm index 813fe0cd3d..4f8bda3fad 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm @@ -198,7 +198,7 @@ sub handle_patron_info { my $summary = ref $message->{fixed_fields} ? $message->{fixed_fields}->[2] : ''; - my $list_items = patron_summary_list_items($summary); + my $list_items = $SC->patron_summary_list_items($summary); my $pdetails = OpenILS::Application::SIP2::Patron->get_patron_details( $session, @@ -227,8 +227,6 @@ sub handle_patron_info { ); # TODO: Add - # overdue items AT variable-length optional field (this field should be sent for each overdue item). - # charged items AU variable-length optional field (this field should be sent for each charged item). # fine items AV variable-length optional field (this field should be sent for each fine item). # recall items BU variable-length optional field (this field should be sent for each recall item). # unavailable hold items CD variable-length optional field (this field should be sent for each unavailable hold item). @@ -241,6 +239,10 @@ sub handle_patron_info { for my $item (@{$pdetails->{items_out}}) { push(@{$response->{fields}}, {AU => $item}); } + } elsif ($list_items eq 'overdue_items') { + for my $item (@{$pdetails->{overdue_items}}) { + push(@{$response->{fields}}, {AT => $item}); + } } return $response; @@ -325,21 +327,5 @@ sub patron_response_common_data { }; } -# Determines which class of data the SIP client wants detailed -# information on in the patron info request. -sub patron_summary_list_items { - my $summary = shift; - - my $idx = index($summary, 'Y'); - - return 'hold_items' if $idx == 0; - return 'overdue_items' if $idx == 1; - return 'charged_items' if $idx == 2; - return 'fine_items' if $idx == 3; - return 'recall_items' if $idx == 4; - return 'unavailable_holds' if $idx == 5; - return ''; -} - 1; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Common.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Common.pm index 6ac3908718..8fc8c014f4 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Common.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Common.pm @@ -39,4 +39,20 @@ sub get_field_value { return undef; } +# Determines which class of data the SIP client wants detailed +# information on in the patron info request. +sub patron_summary_list_items { + my ($class, $summary) = @_; + + my $idx = index($summary, 'Y'); + + return 'hold_items' if $idx == 0; + return 'overdue_items' if $idx == 1; + return 'charged_items' if $idx == 2; + return 'fine_items' if $idx == 3; + return 'recall_items' if $idx == 4; + return 'unavailable_holds' if $idx == 5; + return ''; +} + 1; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Patron.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Patron.pm index 30b8618e46..104a20f951 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Patron.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Patron.pm @@ -164,6 +164,13 @@ sub set_patron_summary_list_items { add_items_out($session, $details, $offset, $limit) if $list_items eq 'charged_items'; + + add_items_out($session, $details, $offset, $limit) + if $list_items eq 'charged_items'; + + add_fine_items($session, $details, $offset, $limit) + if $list_items eq 'fine_items'; + } sub add_hold_items { @@ -193,50 +200,71 @@ sub add_items_out { my ($session, $details, $offset, $limit) = @_; my $patron = $details->{patron}; - my $format = $session->config->{settings}->{msg64_summary_datatype} || ''; - my @circ_ids = (@{$details->{items_out_ids}}, @{$details->{items_overdue_ids}}); @circ_ids = grep { $_ } @circ_ids[$offset .. ($offset + $limit - 1)]; $details->{items_out} = []; for my $circ_id (@circ_ids) { - my $value; + my $value = circ_id_to_value($session, $circ_id); + push(@{$details->{items_out}}, $value); + } +} - if ($format eq 'barcode') { - my $circ = $session->editor->retrieve_action_circulation([ - $circ_id, { - flesh => 1, - flesh_fields => {circ => ['target_copy']} - }]); - - $value = $circ->target_copy->barcode; - - } else { # title - - my $circ = $session->editor->retrieve_action_circulation([ - $circ_id, { - flesh => 4, - flesh_fields => { - circ => ['target_copy'], - acp => ['call_number'], - acn => ['record'], - bre => ['simple_record'] - } - }]); +sub add_overdue_items { + my ($session, $details, $offset, $limit) = @_; + my $patron = $details->{patron}; - if ($circ->target_copy->call_number == -1) { - $value = $circ->target_copy->dummy_title; - } else { - $value = - $circ->target_copy->call_number->record->simple_record->title; - } - } + my @circ_ids = @{$details->{items_overdue_ids}}; + @circ_ids = grep { $_ } @circ_ids[$offset .. ($offset + $limit - 1)]; + + $details->{overdue_items} = []; + for my $circ_id (@circ_ids) { + my $value = circ_id_to_value($session, $circ_id); push(@{$details->{items_out}}, $value); } } +sub circ_id_to_value { + my ($session, $circ_id) = @_; + + my $value = ''; + my $format = $session->config->{settings}->{msg64_summary_datatype} || ''; + + if ($format eq 'barcode') { + my $circ = $session->editor->retrieve_action_circulation([ + $circ_id, { + flesh => 1, + flesh_fields => {circ => ['target_copy']} + }]); + + $value = $circ->target_copy->barcode; + + } else { # title + + my $circ = $session->editor->retrieve_action_circulation([ + $circ_id, { + flesh => 4, + flesh_fields => { + circ => ['target_copy'], + acp => ['call_number'], + acn => ['record'], + bre => ['simple_record'] + } + }]); + + if ($circ->target_copy->call_number == -1) { + $value = $circ->target_copy->dummy_title; + } else { + $value = + $circ->target_copy->call_number->record->simple_record->title; + } + } + + return $value; +} + # Hold -> reporter.hold_request_record -> display field for title. sub find_title_for_hold { my ($session, $hold) = @_; @@ -356,5 +384,113 @@ sub get_patron_penalties { }); } +sub add_fine_items { + my ($session, $details, $offset, $limit) = @_; + my $patron = $details->{patron}; + my $e = $session->editor; + + my @fines; + my $AV_format = lc($session->sip_account->av_format) || 'eg_legacy'; + + # Do a prescan for validity and default to eg_legacy + if ($AV_format ne "swyer_a" && + $AV_format ne "swyer_b" && + $AV_format ne "eg_legacy" && + $AV_format ne "3m") { + + syslog(LOG_WARNING => "SIP2 Unknown value for AV_format: $AV_format"); + $AV_format = "eg_legacy"; + } + + my $xacts = $U->simplereq( + 'open-ils.actor', + 'open-ils.actor.user.transactions.history.have_balance', + $e->authtoken, $patron->id + ); + + foreach my $xact (@{$xacts}) { + my ($title, $author, $line, $fee_type); + + if ($xact->last_billing_type =~ /^Lost/) { + $fee_type = 'LOST'; + } elsif ($xact->last_billing_type =~ /^Overdue/) { + $fee_type = 'FINE'; + } else { + $fee_type = 'FEE'; + } + + if ($xact->xact_type eq 'circulation') { + my $circ = $e->retrieve_action_circulation([ + $xact->id, { + flesh => 2, + flesh_fields => { + circ => ['target_copy'], + acp => ['call_number'] + } + } + ]); + + my $displays = $e->search_metabib_flat_display_entry({ + source => $circ->target_copy->call_number->record, + name => ['title', 'author'] + }); + + ($title) = map {$_->value} grep {$_->name eq 'title'} @$displays; + ($author) = map {$_->value} grep {$_->name eq 'author'} @$displays; + + # Scrub "/" chars since they are used in some cases + # to delineate title/author. + if ($title) { + $title =~ s/\///g; + } else { + $title = ''; + } + + if ($author) { + $author =~ s/\///g; + } else { + $author = ''; + } + } + + if ($AV_format eq "eg_legacy") { + + $line = $xact->balance_owed . " " . $xact->last_billing_type . " "; + + if ($xact->xact_type eq 'circulation') { + $line .= "$title / $author"; + } else { + $line .= $xact->last_billing_note; + } + + } elsif ($AV_format eq "3m" or $AV_format eq "swyer_a") { + + $line = $xact->id . ' $' . $xact->balance_owed . " \"$fee_type\" "; + + if ($xact->xact_type eq 'circulation') { + $line .= "$title"; + } 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: $fee_type"; + + if ($xact->xact_type eq 'circulation') { + $line .= ", Title: $title"; + } else { + $line .= ", Title: " . $xact->last_billing_note; + } + } + + push @fines, $line; + } + + $details->{fine_items} = \@fines; +} + 1; -- 2.11.0