From d2cd8cd95773f57a6bb9e1752724874f1e9418b9 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 9 Jul 2015 09:53:31 -0400 Subject: [PATCH] Bug 14512 - Add support for AV field to Koha's SIP2 Server Koha's SIP2 server should have support for the AV field ( field items ). The biggest problem with this field is that its' contents are not really defined in SIP2 protocol specification. All it says is "this field should be sent for each fine item". Due to this, I think the contents of the field need to be configurable at the login level, so that the contents can be defined based on the SIP2 devices requirements for the AV field. Test Plan: 1) Apply this patch 2) Find a patron with outstanding fines 3) Run a patron information request using misc/sip_cli_emulator.pl using the new -s option with the value " Y " 4) Note there is an AV field for each fee containing the description and amount 5) Edit your sip config, add an av_field_template parameter to the login you are using such as av_field_template="TEST [% accountline.description %] [% accountline.amountoutstanding | format('%.2f') %]" 6) Restart your SIP server 7) Repeat the patron information request 8) Note your custom AV field is being used! Signed-off-by: Chris Davis Signed-off-by: Jesse Weaver --- C4/SIP/ILS/Patron.pm | 33 ++++++++++++++++++++++++++++++++- C4/SIP/Sip/MsgType.pm | 6 +++--- etc/SIPconfig.xml | 3 ++- misc/sip_cli_emulator.pl | 17 +++++++++++++---- 4 files changed, 50 insertions(+), 9 deletions(-) diff --git a/C4/SIP/ILS/Patron.pm b/C4/SIP/ILS/Patron.pm index 7d99ad6..d61b097 100644 --- a/C4/SIP/ILS/Patron.pm +++ b/C4/SIP/ILS/Patron.pm @@ -299,8 +299,39 @@ sub charged_items { return $self->x_items('items', @_); } sub fine_items { + require Koha::Database; + require Template; + my $self = shift; - return $self->x_items('fine_items', @_); + my $start = shift; + my $end = shift; + my $server = shift; + + my @fees = Koha::Database->new()->schema()->resultset('Accountline')->search( + { + borrowernumber => $self->{borrowernumber}, + amountoutstanding => { '>' => '0' }, + } + ); + + $start = $start ? $start - 1 : 0; + $end = $end ? $end : scalar @fees - 1; + + my $av_field_template = $server ? $server->{account}->{av_field_template} : undef; + $av_field_template ||= "[% accountline.description %] [% accountline.amountoutstanding | format('%.2f') %]"; + + my $tt = Template->new(); + + my @return_values; + for ( my $i = $start; $i <= $end; $i++ ) { + my $fee = $fees[$i]; + + my $output; + $tt->process( \$av_field_template, { accountline => $fee }, \$output ); + push( @return_values, { barcode => $output } ); + } + + return \@return_values; } sub recall_items { my $self = shift; diff --git a/C4/SIP/Sip/MsgType.pm b/C4/SIP/Sip/MsgType.pm index 14d64d7..7728ed4 100644 --- a/C4/SIP/Sip/MsgType.pm +++ b/C4/SIP/Sip/MsgType.pm @@ -890,7 +890,7 @@ sub handle_login { # and we're going to believe it. # sub summary_info { - my ( $ils, $patron, $summary, $start, $end ) = @_; + my ( $ils, $patron, $summary, $start, $end, $server ) = @_; my $resp = ''; my $summary_type; @@ -915,7 +915,7 @@ sub summary_info { my $func = $summary_map[$summary_type]->{func}; my $fid = $summary_map[$summary_type]->{fid}; - my $itemlist = &$func( $patron, $start, $end ); + my $itemlist = &$func( $patron, $start, $end, $server ); syslog( "LOG_DEBUG", "summary_info: list = (%s)", join( ", ", @{$itemlist} ) ); foreach my $i ( @{$itemlist} ) { @@ -987,7 +987,7 @@ sub handle_patron_info { # fine_items # recall_items - $resp .= summary_info( $ils, $patron, $summary, $start, $end ); + $resp .= summary_info( $ils, $patron, $summary, $start, $end, $server ); $resp .= maybe_add( FID_HOME_ADDR, $patron->address ); $resp .= maybe_add( FID_EMAIL, $patron->email_addr ); diff --git a/etc/SIPconfig.xml b/etc/SIPconfig.xml index 141bc4f..fc7635e 100644 --- a/etc/SIPconfig.xml +++ b/etc/SIPconfig.xml @@ -42,7 +42,8 @@ + send_patron_home_library_in_af="1" + av_field_template="[% accountline.description %] [% accountline.amountoutstanding | format('%.2f') %]" > diff --git a/misc/sip_cli_emulator.pl b/misc/sip_cli_emulator.pl index ca8ba07..f1799ee 100755 --- a/misc/sip_cli_emulator.pl +++ b/misc/sip_cli_emulator.pl @@ -40,6 +40,8 @@ my $location_code; my $patron_identifier; my $patron_password; +my $summary; + my $item_identifier; my $fee_acknowledged = 0; @@ -55,13 +57,15 @@ GetOptions( "sp|sip_pass=s" => \$login_password, # sip password "l|location|location_code=s" => \$location_code, # sip location code - "patron=s" => \$patron_identifier, # patron cardnumber or login - "password=s" => \$patron_password, # patron's password + "patron=s" => \$patron_identifier, # patron cardnumber or login + "password=s" => \$patron_password, # patron's password "i|item=s" => \$item_identifier, "fa|fee-acknowledged" => \$fee_acknowledged, + "s|summary=s" => \$summary, + "t|terminator=s" => \$terminator, "m|message=s" => \@messages, @@ -126,8 +130,9 @@ my $handlers = { patron_identifier => $patron_identifier, terminal_password => $terminal_password, patron_password => $patron_password, + summary => $summary, }, - optional => [ 'patron_password', ], + optional => [ 'patron_password', 'summary' ], }, item_information => { name => 'Item Information', @@ -312,8 +317,9 @@ sub build_patron_information_command_message { my $patron_identifier = $params->{patron_identifier}; my $terminal_password = $params->{terminal_password}; my $patron_password = $params->{patron_password}; + my $summary = $params->{summary}; - my $summary = " "; + $summary //= " "; return PATRON_INFO @@ -484,6 +490,9 @@ Options: --patron ILS patron cardnumber or username --password ILS patron password + -s --summary Optionally define the patron information request summary field. + Please refer to the SIP2 protocol specification for details + --item ILS item identifier ( item barcode ) -t --terminator SIP2 message terminator, either CR, or CRLF -- 2.7.0