From d69cb82360b98d838f02c56de7a1de405d81529e Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 9 Sep 2020 13:46:53 -0400 Subject: [PATCH] more patron info fields Signed-off-by: Bill Erickson --- .../src/perlmods/lib/OpenILS/Application/SIP2.pm | 10 ++++-- .../lib/OpenILS/Application/SIP2/Common.pm | 41 ++++++++++++++++++++++ .../lib/OpenILS/Application/SIP2/Patron.pm | 2 ++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm index 57fbbfc218..e0ed21b445 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2.pm @@ -302,6 +302,8 @@ sub patron_response_common_data { ] }; } + + my $patron = $pdetails->{patron}; return { fixed_fields => [ @@ -309,7 +311,7 @@ sub patron_response_common_data { $SC->spacebool($pdetails->{renew_denied}), $SC->spacebool($pdetails->{recall_denied}), $SC->spacebool($pdetails->{holds_denied}), - $SC->spacebool($pdetails->{patron}->card->active eq 'f'), + $SC->spacebool($patron->card->active eq 'f'), $SC->spacebool(0), # too many charged $SC->spacebool($pdetails->{too_may_overdue}), $SC->spacebool(0), # too many renewals @@ -327,7 +329,11 @@ sub patron_response_common_data { {AA => $barcode}, {BL => $SC->sipbool(1)}, # valid patron {BV => $pdetails->{balance_owed}}, # fee amount - {CQ => $SC->sipbool($password)} # password verified if exists + {CQ => $SC->sipbool($password)}, # password verified if exists + {PA => $SC->format_date($session, $patron->expire_date)}, + ($patron->dob ? + {PB => $SC->format_date($session, $patron->dob, 'dob')} : ()), + {PC => $patron->profile->name} ] }; } 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 8fc8c014f4..304c647d3a 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Common.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Common.pm @@ -1,5 +1,6 @@ package OpenILS::Application::SIP2::Common; use strict; use warnings; +use OpenILS::Utils::DateTime qw/:datetime/; use constant SIP_DATE_FORMAT => "%Y%m%d %H%M%S"; @@ -9,6 +10,46 @@ sub sipdate { return $date->strftime(SIP_DATE_FORMAT); } +sub format_date { + my ($class, $session, $date, $type) = @_; + $type ||= ''; + + return "" unless $date; + + my $dt = DateTime::Format::ISO8601->new-> parse_datetime(clean_ISO8601($date)); + + # actor.usr.dob stores dates without time/timezone, which causes + # DateTime to assume the date is stored as UTC. Tell DateTime + # to use the local time zone, instead. + # Other dates will have time zones and should be parsed as-is. + $dt->set_time_zone('local') if $type eq 'dob'; + + my @time = localtime($dt->epoch); + + my $year = $time[5]+1900; + my $mon = $time[4]+1; + my $day = $time[3]; + my $hour = $time[2]; + my $minute = $time[1]; + my $second = $time[0]; + + $date = sprintf("%04d%02d%02d", $year, $mon, $day); + + # Due dates need hyphen separators and time of day as well + if ($type eq 'due') { + + if ($session->config->{due_date_use_sip_date_format}) { + $date = $class->sipdate($dt); + + } else { + $date = sprintf("%04d-%02d-%02d %02d:%02d:%02d", + $year, $mon, $day, $hour, $minute, $second); + } + } + + return $date; +} + # False == 'N' sub sipbool { my ($class, $bool) = @_; 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 b619cf9be9..04ec361e50 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Patron.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/SIP2/Patron.pm @@ -328,6 +328,8 @@ sub set_patron_privileges { my $expire = DateTime::Format::ISO8601->new ->parse_datetime(clean_ISO8601($patron->expire_date)); + $details->{expire_date} = $SC->format_date($patron->expire_date); + if ($expire < DateTime->now) { $logger->info("SIP2 Patron account is expired; all privileges blocked"); $details->{charge_denied} = 1; -- 2.11.0