From d71bc9f4469dd16e1a9c309f4658940b504101fb Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Mon, 9 Mar 2020 14:53:05 +0000
Subject: [PATCH] Bug 24828: Add ability to specify cash register in SIP config

This patch adds the ablity to specify a cash register id to link to
payments taken via SIP2 clients.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
---
 C4/SIP/ILS.pm                        |  4 ++--
 C4/SIP/ILS/Transaction/FeePayment.pm | 10 ++++++----
 C4/SIP/Sip/MsgType.pm                |  3 ++-
 etc/SIPconfig.xml                    |  3 ++-
 4 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/C4/SIP/ILS.pm b/C4/SIP/ILS.pm
index 785ab1b0cf..822a6d3aaf 100644
--- a/C4/SIP/ILS.pm
+++ b/C4/SIP/ILS.pm
@@ -260,7 +260,7 @@ sub end_patron_session {
 }
 
 sub pay_fee {
-    my ($self, $patron_id, $patron_pwd, $fee_amt, $fee_type, $pay_type, $fee_id, $trans_id, $currency, $is_writeoff, $disallow_overpayment ) = @_;
+    my ($self, $patron_id, $patron_pwd, $fee_amt, $fee_type, $pay_type, $fee_id, $trans_id, $currency, $is_writeoff, $disallow_overpayment, $register_id) = @_;
 
     my $trans = C4::SIP::ILS::Transaction::FeePayment->new();
 
@@ -271,7 +271,7 @@ sub pay_fee {
         $trans->screen_msg('Invalid patron barcode.');
         return $trans;
     }
-    my $trans_result = $trans->pay( $patron->{borrowernumber}, $fee_amt, $pay_type, $fee_id, $is_writeoff, $disallow_overpayment );
+    my $trans_result = $trans->pay( $patron->{borrowernumber}, $fee_amt, $pay_type, $fee_id, $is_writeoff, $disallow_overpayment, $register_id );
     my $ok = $trans_result->{ok};
     $trans->ok($ok);
 
diff --git a/C4/SIP/ILS/Transaction/FeePayment.pm b/C4/SIP/ILS/Transaction/FeePayment.pm
index 152c17610e..355145cb49 100644
--- a/C4/SIP/ILS/Transaction/FeePayment.pm
+++ b/C4/SIP/ILS/Transaction/FeePayment.pm
@@ -49,6 +49,7 @@ sub pay {
     my $fee_id               = shift;
     my $is_writeoff          = shift;
     my $disallow_overpayment = shift;
+    my $register_id          = shift;
 
     my $type = $is_writeoff ? 'WRITEOFF' : 'PAYMENT';
 
@@ -86,10 +87,11 @@ sub pay {
     else {
         my $pay_response = $account->pay(
             {
-                amount       => $amt,
-                type         => $type,
-                payment_type => 'SIP' . $sip_type,
-                interface    => C4::Context->interface
+                amount        => $amt,
+                type          => $type,
+                payment_type  => 'SIP' . $sip_type,
+                interface     => C4::Context->interface,
+                cash_register => $register_id
             }
         );
         return {
diff --git a/C4/SIP/Sip/MsgType.pm b/C4/SIP/Sip/MsgType.pm
index eb5b645a67..3a3ea840a4 100644
--- a/C4/SIP/Sip/MsgType.pm
+++ b/C4/SIP/Sip/MsgType.pm
@@ -1092,6 +1092,7 @@ sub handle_fee_paid {
 
     my $disallow_overpayment  = $server->{account}->{disallow_overpayment};
     my $payment_type_writeoff = $server->{account}->{payment_type_writeoff} || q{};
+    my $register_id           = $server->{account}->{register_id};
 
     my $is_writeoff = $pay_type eq $payment_type_writeoff;
 
@@ -1104,7 +1105,7 @@ sub handle_fee_paid {
 
     $ils->check_inst_id( $inst_id, "handle_fee_paid" );
 
-    my $pay_result = $ils->pay_fee( $patron_id, $patron_pwd, $fee_amt, $fee_type, $pay_type, $fee_id, $trans_id, $currency, $is_writeoff, $disallow_overpayment );
+    my $pay_result = $ils->pay_fee( $patron_id, $patron_pwd, $fee_amt, $fee_type, $pay_type, $fee_id, $trans_id, $currency, $is_writeoff, $disallow_overpayment, $register_id );
     $status = $pay_result->{status};
     my $pay_response = $pay_result->{pay_response};
 
diff --git a/etc/SIPconfig.xml b/etc/SIPconfig.xml
index 1e5c2314a2..f1c516f8f2 100644
--- a/etc/SIPconfig.xml
+++ b/etc/SIPconfig.xml
@@ -58,7 +58,8 @@
              ae_field_template="[% patron.surname %][% IF patron.firstname %], [% patron.firstname %][% END %]"
              da_field_template="[% patron.surname %][% IF patron.firstname %], [% patron.firstname %][% END %]"
              av_field_template="[% accountline.description %] [% accountline.amountoutstanding | format('%.2f') %]"
-             hide_fields="BD,BE,BF,PB">
+             hide_fields="BD,BE,BF,PB"
+             register_id=''>
           <screen_msg_regex find="Greetings from Koha." replace="Welcome to your library!" />
           <screen_msg_regex find="Invalid patron barcode." replace="Barcode not found, are you sure this is your library card?" />
           <patron_attribute field="XY" code="CODE" />
-- 
2.20.1