From eff6644c8b152820b47402d1ad0777a8cf843290 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 25 Aug 2014 08:30:09 -0400 Subject: [PATCH] Bug 12820 - SIP2 does not send rental charge fee! Koha's SIP2 implementation has facilities to send the fee amount ( BV ) for checking out a given item, but in our code, the fee amount is never set! It's even more complicated than that. If there is a fee, the sip server checks to see if BO ( fee acknowledged ) is set to Y. If it is not, the SIP server is supposed to block the checkout and send a screen message with the fee amount. If it is, the checkout proceeds as usual. Test Plan: 1) Apply the patch for bug 13159 2) Set a checkout fee for an itemtype 3) Find an item of the itemtype 4) Run the SIP cli utility: sip_cli_emulator.pl -a
-p -su -sp -l --patron -m checkout --item 5) Note the server returns an AF field describing the fee and doesn't check out the item. 6) Rerun step 4 with the addition of the -fa flag 7) Note the item checks out to the patron this time --- C4/SIP/ILS.pm | 6 +++++- C4/SIP/ILS/Item.pm | 5 ++++- C4/SIP/ILS/Patron.pm | 2 ++ C4/SIP/ILS/Transaction/Checkout.pm | 13 +++++++++++++ C4/SIP/Sip/MsgType.pm | 5 +++-- 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/C4/SIP/ILS.pm b/C4/SIP/ILS.pm index 8086bc6..68a9ada 100644 --- a/C4/SIP/ILS.pm +++ b/C4/SIP/ILS.pm @@ -126,7 +126,7 @@ sub offline_ok { # the response. # sub checkout { - my ($self, $patron_id, $item_id, $sc_renew) = @_; + my ( $self, $patron_id, $item_id, $sc_renew, $sc_fee_acknowledged ) = @_; my ($patron, $item, $circ); $circ = new ILS::Transaction::Checkout; @@ -134,6 +134,8 @@ sub checkout { $circ->patron($patron = new ILS::Patron $patron_id); $circ->item($item = new ILS::Item $item_id); + my $charge = $circ->fee(); + if (!$patron) { $circ->screen_msg("Invalid Patron"); } elsif (!$patron->charge_ok) { @@ -146,6 +148,8 @@ sub checkout { } elsif ($item->{patron} && ($item->{patron} ne $patron_id)) { # I can't deal with this right now $circ->screen_msg("Item checked out to another patron"); + } elsif ( !$sc_fee_acknowledged && $charge ) { + $circ->screen_msg( sprintf("There is a charge of %.2f to check out this item. Please confirm.", $charge ) ); } else { $circ->do_checkout(); if ($circ->ok){ diff --git a/C4/SIP/ILS/Item.pm b/C4/SIP/ILS/Item.pm index 7f144a8..991ac1d 100644 --- a/C4/SIP/ILS/Item.pm +++ b/C4/SIP/ILS/Item.pm @@ -92,7 +92,10 @@ sub new { my $it = C4::Context->preference('item-level_itypes') ? $item->{itype} : $item->{itemtype}; my $itemtype = Koha::Database->new()->schema()->resultset('Itemtype')->find( $it ); - $item->{sip_media_type} = $itemtype->sip_media_type() if $itemtype; + if ($itemtype) { + $item->{sip_media_type} = $itemtype->sip_media_type(); + $item->{fee} = $itemtype->rentalcharge(); + } # check if its on issue and if so get the borrower my $issue = GetItemIssue($item->{'itemnumber'}); diff --git a/C4/SIP/ILS/Patron.pm b/C4/SIP/ILS/Patron.pm index d326f89..1dc9cea 100644 --- a/C4/SIP/ILS/Patron.pm +++ b/C4/SIP/ILS/Patron.pm @@ -68,6 +68,7 @@ sub new { %ilspatron = ( getmemberdetails_object => $kp, name => $kp->{firstname} . " " . $kp->{surname}, + ils_id => $kp->{borrowernumber}, id => $kp->{cardnumber}, # to SIP, the id is the BARCODE, not userid password => $pw, ptype => $kp->{categorycode}, # 'A'dult. Whatever. @@ -132,6 +133,7 @@ sub new { # 1 means read/write my %fields = ( + ils_id => 0, id => 0, name => 0, address => 0, diff --git a/C4/SIP/ILS/Transaction/Checkout.pm b/C4/SIP/ILS/Transaction/Checkout.pm index edc1d04..3ffbce2 100644 --- a/C4/SIP/ILS/Transaction/Checkout.pm +++ b/C4/SIP/ILS/Transaction/Checkout.pm @@ -20,6 +20,8 @@ use C4::Circulation; use C4::Members; use C4::Reserves qw(ModReserveFill); use C4::Debug; +use C4::Circulation qw( GetIssuingCharges ); + use parent qw(ILS::Transaction); our $debug; @@ -125,6 +127,7 @@ sub do_checkout { $debug and warn "do_checkout: calling AddIssue(\$borrower,$barcode, $overridden_duedate, 0)\n" # . "w/ \$borrower: " . Dumper($borrower) . "w/ C4::Context->userenv: " . Dumper(C4::Context->userenv); + $self->{fee_amount} = GetIssuingCharges($itemnumber, $borrower); my $due_dt = AddIssue($borrower, $barcode, $overridden_duedate, 0); if ($due_dt) { $self->{due} = $due_dt->clone(); @@ -137,5 +140,15 @@ sub do_checkout { return $self; } +sub fee { + my ($self) = @_; + + my ($charge) = GetIssuingCharges( $self->{item}->{itemnumber}, $self->{patron}->{ils_id} ); + + if ($charge > 0 ) { + return sprintf( "%.2f", $charge ); + } +} + 1; __END__ diff --git a/C4/SIP/Sip/MsgType.pm b/C4/SIP/Sip/MsgType.pm index 2aca72f..6ecac03 100644 --- a/C4/SIP/Sip/MsgType.pm +++ b/C4/SIP/Sip/MsgType.pm @@ -511,7 +511,7 @@ sub handle_checkout { $patron_id = $fields->{(FID_PATRON_ID)}; $item_id = $fields->{(FID_ITEM_ID)}; - + my $sc_fee_acknowledged = $fields->{ (FID_FEE_ACK) } eq 'Y'; if ($no_block eq 'Y') { # Off-line transactions need to be recorded, but there's @@ -525,7 +525,7 @@ sub handle_checkout { } else { # Does the transaction date really matter for items that are # checkout out while the terminal is online? I'm guessing 'no' - $status = $ils->checkout($patron_id, $item_id, $sc_renewal_policy); + $status = $ils->checkout( $patron_id, $item_id, $sc_renewal_policy, $sc_fee_acknowledged ); } $item = $status->item; @@ -585,6 +585,7 @@ sub handle_checkout { $resp .= add_field(FID_INST_ID, $inst); $resp .= add_field(FID_PATRON_ID, $patron_id); $resp .= add_field(FID_ITEM_ID, $item_id); + $resp .= maybe_add( FID_FEE_AMT, $status->fee() ); # If the item is valid, provide the title, otherwise # leave it blank -- 1.7.2.5