From 0d09a498c9aa11f1c7a8a76aec715f864498d7db 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! --- C4/SIP/ILS/Patron.pm | 32 +++++++++++++++++++++++++++++++- C4/SIP/Sip/MsgType.pm | 16 ++++++++-------- etc/SIPconfig.xml | 3 ++- misc/sip_cli_emulator.pl | 17 +++++++++++++---- 4 files changed, 54 insertions(+), 14 deletions(-) diff --git a/C4/SIP/ILS/Patron.pm b/C4/SIP/ILS/Patron.pm index 4e9c152..0d2c2f4 100644 --- a/C4/SIP/ILS/Patron.pm +++ b/C4/SIP/ILS/Patron.pm @@ -23,6 +23,7 @@ use C4::Reserves; use C4::Branch qw(GetBranchName); use C4::Items qw( GetBarcodeFromItemnumber GetItemnumbersForBiblio); use C4::Auth qw(checkpw_hash); +use Koha::Database; our $VERSION = 3.07.00.049; @@ -296,7 +297,36 @@ sub charged_items { } sub fine_items { 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') %]"; + + require Template; + 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 6b387cf..c392fa2 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; # @@ -898,11 +898,11 @@ sub summary_info { # message to the corresponding field and handler # my @summary_map = ( - { func => $patron->can( "hold_items"), fid => FID_HOLD_ITEMS }, - { func => $patron->can("overdue_items"), fid => FID_OVERDUE_ITEMS }, - { func => $patron->can("charged_items"), fid => FID_CHARGED_ITEMS }, - { func => $patron->can( "fine_items"), fid => FID_FINE_ITEMS }, - { func => $patron->can( "recall_items"), fid => FID_RECALL_ITEMS }, + { func => $patron->can("hold_items"), fid => FID_HOLD_ITEMS }, + { func => $patron->can("overdue_items"), fid => FID_OVERDUE_ITEMS }, + { func => $patron->can("charged_items"), fid => FID_CHARGED_ITEMS }, + { func => $patron->can("fine_items"), fid => FID_FINE_ITEMS }, + { func => $patron->can("recall_items"), fid => FID_RECALL_ITEMS }, { func => $patron->can("unavail_holds"), fid => FID_UNAVAILABLE_HOLD_ITEMS }, ); @@ -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}) { @@ -991,7 +991,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 8d2d77b..c9a6fc5 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 -- 1.7.2.5