Bug 26591: SIP option prevcheckout_block_checkout to block checkout of previously...
[koha-ffzg.git] / C4 / SIP / Sip / MsgType.pm
index a61cd7b..62d3d5f 100644 (file)
@@ -433,7 +433,7 @@ sub build_patron_status {
             $password_rc = $patron->check_password($patron_pwd);
         }
 
-        $resp .= patron_status_string($patron);
+        $resp .= patron_status_string( $patron, $server );
         $resp .= $lang . timestamp();
         if ( defined $server->{account}->{ae_field_template} ) {
             $resp .= add_field( FID_PERSONAL_NAME, $patron->format( $server->{account}->{ae_field_template}, $server ) );
@@ -533,7 +533,7 @@ sub handle_checkout {
 
         # 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, $fee_ack );
+        $status = $ils->checkout( $patron_id, $item_id, $sc_renewal_policy, $fee_ack, $account );
     }
 
     $item   = $status->item;
@@ -613,6 +613,8 @@ sub handle_checkout {
         }
     }
 
+    $resp .= $item->build_additional_item_fields_string( $server ) if $item;
+
     if ( $protocol_version >= 2 ) {
 
         # Financials : return irrespective of ok status
@@ -656,7 +658,7 @@ sub handle_checkin {
         siplog( "LOG_WARNING", "received no-block checkin from terminal '%s'", $account->{id} );
         $status = $ils->checkin_no_block( $item_id, $trans_date, $return_date, $item_props, $cancel );
     } else {
-        $status = $ils->checkin( $item_id, $trans_date, $return_date, $my_branch, $item_props, $cancel, $account->{checked_in_ok}, $account->{cv_triggers_alert} );
+        $status = $ils->checkin( $item_id, $trans_date, $return_date, $my_branch, $item_props, $cancel, $account );
     }
 
     $patron = $status->patron;
@@ -680,6 +682,7 @@ sub handle_checkin {
     if ($item) {
         $resp .= add_field( FID_PERM_LOCN, $item->permanent_location, $server );
         $resp .= maybe_add( FID_TITLE_ID, $item->title_id, $server );
+        $resp .= $item->build_additional_item_fields_string( $server );
     }
 
     if ( $protocol_version >= 2 ) {
@@ -688,13 +691,18 @@ sub handle_checkin {
             $resp .= add_field( FID_PATRON_ID, $patron->id, $server );
         }
         if ($item) {
-$resp .= maybe_add( FID_MEDIA_TYPE,           $item->sip_media_type,      $server );
-$resp .= maybe_add( FID_ITEM_PROPS,           $item->sip_item_properties, $server );
-$resp .= maybe_add( FID_COLLECTION_CODE,      $item->collection_code,     $server );
-$resp .= maybe_add( FID_CALL_NUMBER,          $item->call_number,         $server );
-$resp .= maybe_add( FID_HOLD_PATRON_ID,       $item->hold_patron_bcode,   $server );
-$resp .= add_field( FID_DESTINATION_LOCATION, $item->destination_loc,     $server ) if ( $item->destination_loc || $server->{account}->{ct_always_send} );
-$resp .= maybe_add( FID_HOLD_PATRON_NAME,     $item->hold_patron_name( $server->{account}->{da_field_template} ), $server );
+            $resp .= maybe_add( FID_MEDIA_TYPE,           $item->sip_media_type,      $server );
+            $resp .= maybe_add( FID_ITEM_PROPS,           $item->sip_item_properties, $server );
+            $resp .= maybe_add( FID_CALL_NUMBER,          $item->call_number,         $server );
+            $resp .= maybe_add( FID_HOLD_PATRON_ID,       $item->hold_patron_bcode,   $server );
+            $resp .= add_field( FID_DESTINATION_LOCATION, $item->destination_loc,     $server ) if ( $item->destination_loc || $server->{account}->{ct_always_send} );
+            $resp .= maybe_add( FID_HOLD_PATRON_NAME,     $item->hold_patron_name( $server->{account}->{da_field_template} ), $server );
+
+            if ( my $CR = $server->{account}->{cr_item_field} ) {
+                $resp .= maybe_add( FID_COLLECTION_CODE, $item->{$CR}, $server );
+            } else {
+                $resp .= maybe_add( FID_COLLECTION_CODE, $item->collection_code, $server );
+            }
 
             if ( $status->hold and $status->hold->{branchcode} ne $item->destination_loc ) {
                 warn 'SIP hold mismatch: $status->hold->{branchcode}=' . $status->hold->{branchcode} . '; $item->destination_loc=' . $item->destination_loc;
@@ -908,7 +916,6 @@ sub handle_login {
 sub summary_info {
     my ( $ils, $patron, $summary, $start, $end, $server ) = @_;
     my $resp = '';
-    my $summary_type;
 
     #
     # Map from offsets in the "summary" field of the Patron Information
@@ -923,9 +930,10 @@ sub summary_info {
         { func => $patron->can("unavail_holds"), fid => FID_UNAVAILABLE_HOLD_ITEMS },
     );
 
-    if ( ( $summary_type = index( $summary, 'Y' ) ) == -1 ) {
-        return '';    # No detailed information required
-    }
+    my $summary_type = index( $summary, 'Y' );
+    return q{} if $summary_type == -1;    # No detailed information required.
+    return q{} if $summary_type > 5;      # Positions 6-9 are not defined in the sip spec,
+                                          # and we have no extensions to handle them.
 
     siplog( "LOG_DEBUG", "Summary_info: index == '%d', field '%s'", $summary_type, $summary_map[$summary_type]->{fid} );
 
@@ -961,7 +969,7 @@ sub handle_patron_info {
     $resp = (PATRON_INFO_RESP);
     if ($patron) {
         $patron->update_lastseen();
-        $resp .= patron_status_string($patron);
+        $resp .= patron_status_string( $patron, $server );
         $resp .= ( defined($lang) and length($lang) == 3 ) ? $lang : $patron->language;
         $resp .= timestamp();
 
@@ -1211,6 +1219,12 @@ sub handle_item_information {
         $resp .= maybe_add( FID_CURRENT_LOCN, $item->current_location, $server );
         $resp .= maybe_add( FID_ITEM_PROPS,   $item->sip_item_properties, $server );
 
+        if ( my $CR = $server->{account}->{cr_item_field} ) {
+                $resp .= maybe_add( FID_COLLECTION_CODE, $item->{$CR}, $server );
+        } else {
+          $resp .= maybe_add( FID_COLLECTION_CODE, $item->collection_code, $server );
+        }
+
         if ( ( $i = $item->fee ) != 0 ) {
             $resp .= add_field( FID_CURRENCY, $item->fee_currency, $server );
             $resp .= add_field( FID_FEE_AMT,  $i, $server );
@@ -1232,6 +1246,8 @@ sub handle_item_information {
 
         $resp .= maybe_add( FID_SCREEN_MSG, $item->screen_msg, $server );
         $resp .= maybe_add( FID_PRINT_LINE, $item->print_line, $server );
+
+        $resp .= $item->build_additional_item_fields_string( $server );
     }
 
     $self->write_msg( $resp, undef, $server->{account}->{terminator}, $server->{account}->{encoding} );
@@ -1321,7 +1337,7 @@ sub handle_patron_enable {
             # Don't enable the patron if there was an invalid password
             $status = $patron->enable;
         }
-        $resp .= patron_status_string($patron);
+        $resp .= patron_status_string( $patron, $server );
         $resp .= $patron->language . timestamp();
 
         $resp .= add_field( FID_PATRON_ID,     $patron->id, $server );
@@ -1647,6 +1663,8 @@ sub send_acs_status {
 #
 sub patron_status_string {
     my $patron = shift;
+    my $server = shift;
+
     my $patron_status;
 
     siplog( "LOG_DEBUG", "patron_status_string: %s charge_ok: %s", $patron->id, $patron->charge_ok );
@@ -1658,7 +1676,7 @@ sub patron_status_string {
         denied( $patron->hold_ok ),
         boolspace( $patron->card_lost ),
         boolspace( $patron->too_many_charged ),
-        boolspace( $patron->too_many_overdue ),
+        $server->{account}->{overdues_block_checkout} ? boolspace( $patron->too_many_overdue ) : q{ },
         boolspace( $patron->too_many_renewal ),
         boolspace( $patron->too_many_claim_return ),
         boolspace( $patron->too_many_lost ),