Bug 27049: Add /misc/cronjobs/writeoff_debts.pl
[koha-ffzg.git] / misc / sip_cli_emulator.pl
index 687f354..3044b04 100755 (executable)
@@ -40,10 +40,21 @@ my $location_code;
 my $patron_identifier;
 my $patron_password;
 
+my $summary;
+
 my $item_identifier;
 
 my $fee_acknowledged = 0;
 
+my $fee_type;
+my $payment_type;
+my $currency_type;
+my $fee_amount;
+my $fee_identifier;
+my $transaction_id;
+my $pickup_location;
+my $hold_mode;
+
 my $terminator = q{};
 
 my @messages;
@@ -55,13 +66,24 @@ 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,
+
+    "fee-type=s"        => \$fee_type,
+    "payment-type=s"    => \$payment_type,
+    "currency-type=s"   => \$currency_type,
+    "fee-amount=s"      => \$fee_amount,
+    "fee-identifier=s"  => \$fee_identifier,
+    "transaction-id=s"  => \$transaction_id,
+    "pickup-location=s" => \$pickup_location,
+    "hold-mode=s"       => \$hold_mode,
+
     "t|terminator=s" => \$terminator,
 
     "m|message=s" => \@messages,
@@ -84,8 +106,6 @@ $terminator = ( $terminator eq 'CR' ) ? $CR : $CRLF;
 # Set perl to expect the same record terminator it is sending
 $/ = $terminator;
 
-my ( $sec, $min, $hour, $day, $month, $year ) = localtime(time);
-$year += 1900;
 my $transaction_date = C4::SIP::Sip::timestamp();
 
 my $terminal_password = $login_password;
@@ -128,8 +148,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',
@@ -215,6 +236,60 @@ my $handlers = {
             'fee_acknowledged',
         ],
     },
+    fee_paid => {
+        name       => 'Fee Paid',
+        subroutine => \&build_fee_paid_command_message,
+        parameters => {
+            transaction_date  => $transaction_date,
+            fee_type          => $fee_type,
+            payment_type      => $payment_type,
+            currency_type     => $currency_type,
+            fee_amount        => $fee_amount,
+            institution_id    => $location_code,
+            patron_identifier => $patron_identifier,
+            terminal_password => $terminal_password,
+            patron_password   => $patron_password,
+            fee_identifier    => $fee_identifier,
+            transaction_id    => $transaction_id,
+        },
+        optional => [
+            'fee_type', # has default
+            'payment_type', # has default
+            'currency_type', #has default
+            'terminal_password',
+            'patron_password',
+            'fee_identifier',
+            'transaction_id',
+        ],
+    },
+    hold => {
+        name       => 'Hold',
+        subroutine => \&build_hold_command_message,
+        parameters => {
+            hold_mode           => $hold_mode eq '-' ? '-' : '+',
+            transaction_date    => $transaction_date,
+            expiration_date     => undef,
+            pickup_location     => $pickup_location,
+            hold_type           => undef,
+            institution_id      => $location_code,
+            patron_identifier   => $patron_identifier,
+            patron_password     => $patron_password,
+            item_identifier     => $item_identifier,
+            title_identifier    => undef,
+            terminal_password   => $terminal_password,
+            fee_acknowledged    => $fee_acknowledged,
+        },
+        optional => [
+            'expiration_date',
+            'pickup_location',
+            'hold_type',
+            'patron_password',
+            'item_identifier',
+            'title_identifier',
+            'terminal_password',
+            'fee_acknowledged',
+        ],
+    },
 };
 
 my $data = run_command_message('login');
@@ -314,8 +389,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
@@ -415,6 +491,38 @@ sub build_checkin_command_message {
       . build_field( FID_CANCEL,       $cancel, { optional => 1 } );
 }
 
+sub build_hold_command_message {
+    my ($params) = @_;
+
+    my $hold_mode         = $params->{hold_mode};
+    my $transaction_date  = $params->{transaction_date};
+    my $expiration_date   = $params->{expiration_date};
+    my $pickup_location   = $params->{pickup_location};
+    my $hold_type         = $params->{hold_type};
+    my $institution_id    = $params->{institution_id};
+    my $patron_identifier = $params->{patron_identifier};
+    my $patron_password   = $params->{patron_password};
+    my $item_identifier   = $params->{item_identifier};
+    my $title_identifier  = $params->{title_identifier};
+    my $terminal_password = $params->{terminal_password};
+    my $fee_acknowledged  = $params->{fee_acknowledged} || 'N';
+
+    return
+        HOLD
+      . $hold_mode
+      . $transaction_date
+      . build_field( FID_EXPIRATION,   $expiration_date,   { optional => 1 } )
+      . build_field( FID_PICKUP_LOCN,  $pickup_location,   { optional => 1 } )
+      . build_field( FID_HOLD_TYPE,    $hold_type,         { optional => 1 } )
+      . build_field( FID_INST_ID,      $institution_id                       )
+      . build_field( FID_PATRON_ID,    $patron_identifier                    )
+      . build_field( FID_PATRON_PWD,   $patron_password,   { optional => 1 } )
+      . build_field( FID_ITEM_ID,      $item_identifier,   { optional => 1 } )
+      . build_field( FID_TITLE_ID,     $title_identifier,  { optional => 1 } )
+      . build_field( FID_TERMINAL_PWD, $terminal_password, { optional => 1 } )
+      . build_field( FID_FEE_ACK,      $fee_acknowledged,  { optional => 1 } );
+}
+
 sub build_renew_command_message {
     my ($params) = @_;
 
@@ -453,6 +561,36 @@ sub build_renew_command_message {
       . build_field( FID_FEE_ACK,      $fee_acknowledged, { optional => 1 } );
 }
 
+sub build_fee_paid_command_message {
+    my ($params) = @_;
+
+    my $transaction_date  = $params->{transaction_date};
+    my $fee_type          = $params->{fee_type} || '01';
+    my $payment_type      = $params->{payment_type} || '00';
+    my $currency_type     = $params->{currency_type} || 'USD';
+    my $fee_amount        = $params->{fee_amount};
+    my $institution_id    = $params->{location_code};
+    my $patron_identifier = $params->{patron_identifier};
+    my $terminal_password = $params->{terminal_password};
+    my $patron_password   = $params->{patron_password};
+    my $fee_identifier    = $params->{fee_identifier};
+    my $transaction_id    = $params->{transaction_id};
+
+    return
+        FEE_PAID
+      . $transaction_date
+      . $fee_type
+      . $payment_type
+      . $currency_type
+      . build_field( FID_FEE_AMT,        $fee_amount )
+      . build_field( FID_INST_ID,        $institution_id )
+      . build_field( FID_PATRON_ID,      $patron_identifier )
+      . build_field( FID_TERMINAL_PWD,   $terminal_password, { optional => 1 } )
+      . build_field( FID_PATRON_PWD,     $patron_password, { optional => 1 } )
+      . build_field( FID_FEE_ID,         $fee_identifier, { optional => 1 } )
+      . build_field( FID_TRANSACTION_ID, $transaction_id, { optional => 1 } );
+}
+
 sub build_field {
     my ( $field_identifier, $value, $params ) = @_;
 
@@ -486,6 +624,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
@@ -493,15 +634,25 @@ Options:
 
   -fa --fee-acknowledged Sends a confirmation of checkout fee
 
+  --fee-type        Fee type for Fee Paid message, defaults to '01'
+  --payment-type    Payment type for Fee Paid message, default to '00'
+  --currency-type   Currency type for Fee Paid message, defaults to 'USD'
+  --fee-amount      Fee amount for Fee Paid message, required
+  --fee-identifier  Fee identifier for Fee Paid message, optional
+  --transaction-id  Transaction id for Fee Paid message, optional
+  --pickup-location Pickup location (branchcode) for Hold message, optional
+  --hold-mode       Accepts "+" to add hold or "-" to cancel hold, defaults to +
+
   -m --message     SIP2 message to execute
 
   Implemented Messages:
-    patron_status_request
-    patron_information
-    item_information
-    checkout
     checkin
+    checkout
+    fee_paid
+    hold
+    item_information
+    patron_information
+    patron_status_request
     renew
-
 /
 }