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,
);
# 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).
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;
};
}
-# 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;
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 {
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) = @_;
});
}
+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;