View | Details | Raw Unified | Return to bug 20517
Collapse All | Expand All

(-)a/C4/SIP/ILS.pm (+103 lines)
Lines 7-12 package C4::SIP::ILS; Link Here
7
use warnings;
7
use warnings;
8
use strict;
8
use strict;
9
use Sys::Syslog qw(syslog);
9
use Sys::Syslog qw(syslog);
10
use YAML qw(LoadFile Dump);
11
use MARC::Record;
12
use MARC::Transform;
10
use Data::Dumper;
13
use Data::Dumper;
11
14
12
use C4::SIP::ILS::Item;
15
use C4::SIP::ILS::Item;
Lines 18-23 use C4::SIP::ILS::Transaction::FeePayment; Link Here
18
use C4::SIP::ILS::Transaction::Hold;
21
use C4::SIP::ILS::Transaction::Hold;
19
use C4::SIP::ILS::Transaction::Renew;
22
use C4::SIP::ILS::Transaction::Renew;
20
use C4::SIP::ILS::Transaction::RenewAll;
23
use C4::SIP::ILS::Transaction::RenewAll;
24
use C4::Biblio qw(GetMarcBiblio);
21
25
22
my $debug = 0;
26
my $debug = 0;
23
27
Lines 206-211 sub checkin { Link Here
206
    $circ->item( $item = C4::SIP::ILS::Item->new($item_id) );
210
    $circ->item( $item = C4::SIP::ILS::Item->new($item_id) );
207
211
208
    if ($item) {
212
    if ($item) {
213
        $self->_sortbin_checkin($item); # Call sorting robot handling
209
        $circ->do_checkin( $current_loc, $return_date );
214
        $circ->do_checkin( $current_loc, $return_date );
210
    }
215
    }
211
    else {
216
    else {
Lines 243-248 sub checkin { Link Here
243
    return $circ;
248
    return $circ;
244
}
249
}
245
250
251
# "SORTING ROBOT" HANDLING
252
sub _sortbin_checkin {
253
    my ( $self, $item ) = @_;
254
    return unless defined $item;
255
256
    # to activate this code, it is necessary to add a few parameters in SIPconfig.xml
257
    # For the institution which will use the robot, add the following parameters
258
    # in the "sortbin" tag:
259
    #  status="1"      -> 1 to activate the module
260
    #  subfield="995z" -> subfield which contains the value of the destination bin
261
    #  transform="1"   -> useful if the destination subfield has to be constructed
262
    #                     by checking the values of other fields, this way you can create a virtual subfield
263
    #                     which doesn't need to be configured in the MARC biblio framework.
264
    #  transform_config_file="/home/koha/etc/sortbin_transform.yaml" -> absolute path to the sortbin config file.
265
    #  reserve_config_file="/home/koha/etc/sortbin_reserves.yaml" -> absolute path to the reserve sortbin config file.
266
267
    my $sortbin_status;
268
    my $sortbin_subfield;
269
    my $sortbin_transform;
270
    my $sortbin_transform_path;
271
    my $sortbin_reserve_path;
272
273
    if ( defined $self->{institution}->{sortbin} ) {
274
        $sortbin_status = $self->{institution}->{sortbin}->{status}
275
          if ( defined $self->{institution}->{sortbin}->{status} );
276
        $sortbin_subfield = $self->{institution}->{sortbin}->{subfield}
277
          if ( defined $self->{institution}->{sortbin}->{subfield} );
278
        $sortbin_transform = $self->{institution}->{sortbin}->{transform}
279
          if ( defined $self->{institution}->{sortbin}->{transform} );
280
        $sortbin_transform_path = $self->{institution}->{sortbin}->{transform_config_file}
281
          if ( defined $self->{institution}->{sortbin}->{transform_config_file} );
282
        $sortbin_reserve_path = $self->{institution}->{sortbin}->{reserve_config_file}
283
          if ( defined $self->{institution}->{sortbin}->{reserve_config_file} );
284
    }
285
286
	# Test feature is turned on
287
    unless ( $sortbin_status == 1 ) {
288
        return;
289
    }
290
291
    unless ( defined $sortbin_subfield ) {
292
        syslog( "LOG_ERR", "sortbin subfield must be defined" );
293
        return;
294
    }
295
    my $marc_record_obj = C4::Biblio::GetMarcBiblio($item->{'biblionumber'});
296
    unless ( defined $marc_record_obj ) {
297
        syslog( "LOG_ERR", "sortbin error calling GetMarcBiblio on biblionumber=%s", $item->{'biblionumber'} );
298
        return;
299
    }
300
301
    # We add the 995 field related to the item, to run marctransform with only this one.
302
    my @itemnumbers = ( $item->{'itemnumber'} );
303
    C4::Biblio::EmbedItemsInMarcBiblio($marc_record_obj, $item->{'biblionumber'}, \@itemnumbers);
304
305
    # We look for the sortbin number
306
    $item->{'sort_bin'} = undef;
307
308
    # priority to holds
309
    # if the document is reserved
310
    # and if the yaml file dedicated to holds contains something else than 0 in "sortbin_reserves"
311
    # then the document goes to the reserves bin
312
    my @reserves = @{ $item->{'hold_queue'} };
313
    if ( scalar @reserves > 0 ) {
314
        my $sortbin_reserves_config = LoadFile($sortbin_reserve_path);
315
        if ( $sortbin_reserves_config->{'sortbin_reserves'} != 0 ) {
316
            $item->{'sort_bin'} = $sortbin_reserves_config->{'sortbin_reserves'};
317
        }
318
    }
319
320
    # if the item is not reserved, proceed to the standard sort
321
    if ( !defined $item->{'sort_bin'} ) {
322
        if ( $sortbin_transform == 1 ) {
323
324
            # In Transform mode, we create a virtuel MARC field,
325
            #  based on the values of other fields
326
            # The conversion is defined in a yaml file,
327
            #  check the MARC::Transform doc for more information
328
            # The goal is to obtain a single MARC subfield containing the
329
            #  value the bin where the document will have to be redirected,
330
            #  with MARC::Transform you can create this subfield by checking
331
            #  the values of several other MARC fields
332
            MARC::Transform->new( $marc_record_obj, $sortbin_transform_path );
333
        }
334
335
        # obtained through Transform mode or already available in DB,
336
        #  the MARC subfield containing the destination bin value is now available
337
        my $field    = substr( $sortbin_subfield, 0, 3 );
338
        my $subfield = substr( $sortbin_subfield, 3, 1 );
339
        if ( defined $marc_record_obj->subfield( $field, $subfield ) ) {
340
            $item->{'sort_bin'} = $marc_record_obj->subfield( $field, $subfield );
341
        }
342
        else {
343
            syslog( "LOG_ERR", "sortbin undefined value in subfield %s", $sortbin_subfield );
344
            return;
345
        }
346
    }
347
}
348
246
# If the ILS caches patron information, this lets it free
349
# If the ILS caches patron information, this lets it free
247
# it up
350
# it up
248
sub end_patron_session {
351
sub end_patron_session {
(-)a/C4/SIP/ILS/Item.pm (+4 lines)
Lines 380-385 sub fill_reserve { Link Here
380
    }
380
    }
381
    return ModReserveFill($hold);
381
    return ModReserveFill($hold);
382
}
382
}
383
sub sort_bin {
384
        my $self = shift;
385
        return $self->{sort_bin} || '';
386
}
383
1;
387
1;
384
__END__
388
__END__
385
389
(-)a/C4/SIP/Sip/MsgType.pm (-5 / +6 lines)
Lines 669-680 sub handle_checkin { Link Here
669
            $resp .= add_field( FID_PATRON_ID, $patron->id );
669
            $resp .= add_field( FID_PATRON_ID, $patron->id );
670
        }
670
        }
671
        if ($item) {
671
        if ($item) {
672
            $resp .= maybe_add( FID_MEDIA_TYPE,           $item->sip_media_type );
672
            $resp .= maybe_add( FID_SORT_BIN,             $item->sort_bin            );
673
            $resp .= maybe_add( FID_MEDIA_TYPE,           $item->sip_media_type      );
673
            $resp .= maybe_add( FID_ITEM_PROPS,           $item->sip_item_properties );
674
            $resp .= maybe_add( FID_ITEM_PROPS,           $item->sip_item_properties );
674
            $resp .= maybe_add( FID_COLLECTION_CODE,      $item->collection_code );
675
            $resp .= maybe_add( FID_COLLECTION_CODE,      $item->collection_code     );
675
            $resp .= maybe_add( FID_CALL_NUMBER,          $item->call_number );
676
            $resp .= maybe_add( FID_CALL_NUMBER,          $item->call_number         );
676
            $resp .= maybe_add( FID_DESTINATION_LOCATION, $item->destination_loc );
677
            $resp .= maybe_add( FID_DESTINATION_LOCATION, $item->destination_loc     );
677
            $resp .= maybe_add( FID_HOLD_PATRON_ID,       $item->hold_patron_bcode );
678
            $resp .= maybe_add( FID_HOLD_PATRON_ID,       $item->hold_patron_bcode   );
678
            $resp .= maybe_add( FID_HOLD_PATRON_NAME,     $item->hold_patron_name( $server->{account}->{da_field_template} ) );
679
            $resp .= maybe_add( FID_HOLD_PATRON_NAME,     $item->hold_patron_name( $server->{account}->{da_field_template} ) );
679
            if ( $status->hold and $status->hold->{branchcode} ne $item->destination_loc ) {
680
            if ( $status->hold and $status->hold->{branchcode} ne $item->destination_loc ) {
680
                warn 'SIP hold mismatch: $status->hold->{branchcode}=' . $status->hold->{branchcode} . '; $item->destination_loc=' . $item->destination_loc;
681
                warn 'SIP hold mismatch: $status->hold->{branchcode}=' . $status->hold->{branchcode} . '; $item->destination_loc=' . $item->destination_loc;
(-)a/etc/SIPconfig.xml (-3 / +8 lines)
Lines 70-78 in our case "ILS". Link Here
70
<institutions>
70
<institutions>
71
    <institution id="MAIN" implementation="ILS" parms="">
71
    <institution id="MAIN" implementation="ILS" parms="">
72
          <policy checkin="true" renewal="true" checkout="true"
72
          <policy checkin="true" renewal="true" checkout="true"
73
            status_update="false" offline="false"
73
	  	  status_update="false" offline="false"
74
          timeout="100"
74
		  timeout="100"
75
            retries="5" />
75
	  	  retries="5" />
76
          <sortbin status="1"
77
                   subfield="995z"
78
                   transform="1"
79
                   transform_config_file="/home/koha/etc/sortbin_transform.yaml"
80
                   reserve_config_file="/home/koha/etc/sortbin_reserves.yaml" />
76
    </institution>
81
    </institution>
77
    <institution id="CPL" implementation="ILS" parms="">
82
    <institution id="CPL" implementation="ILS" parms="">
78
          <policy checkin="true" renewal="true" checkout="true"
83
          <policy checkin="true" renewal="true" checkout="true"
(-)a/etc/sortbin_reserves.yaml (+6 lines)
Line 0 Link Here
1
---
2
# Paramétrage du bac accueillant les documents réservés
3
# Mettre la valeur 0 désactive le tri des réservations
4
# Un nombre supérieur à zéro indique le bac ciblé
5
sortbin_reserves: 2
6
(-)a/etc/sortbin_transform.yaml (-1 / +40 lines)
Line 0 Link Here
0
- 
1
---
2
# ATTENTION : Il faut renseigner à l'identique le sous-champ défini dans SIP_config.xml institutions / institution / sortbin / subfield (dans notre cas 995$z)
3
# le bac destiné aux réservations est à définir dans le fichier sortbin_reserves.yaml
4
#-
5
# si homebranch n'est pas site memo, bac pb
6
# condition : $f995b ne "MED"
7
# forceupdate :
8
#  f995z : "2"
9
-
10
# notices avec 995$3 vers bac à problème
11
 condition : $f9953 eq "oui"
12
 forceupdate :
13
  f995z : "2"
14
-
15
 # RDC vers bac numéro 1, situé juste à gauche de l'entrée carrousel
16
 condition : $f995s eq "4"
17
 forceupdate :
18
  f995z : "1"
19
-
20
 # 1er étage multimédia vers bac 3
21
 condition : $f995s eq "1" and ( $f995j eq "BLU" or $f995j eq "CD" or $f995j eq "CD-ROM" or $f995j eq "DIS" or $f995j eq "MUL" or $f995j eq "DVD" or $f995j eq "MUS-DVD" or $f995j eq "LIV-CD" )
22
 forceupdate :
23
  f995z : "3"
24
-
25
 # 1er étage, notices non multimédia, vers bac 4
26
 condition : $f995s eq "1"
27
 forceupdate :
28
  f995z : "4"
29
-
30
 # 2ème étage vers bac 5, situé juste à droite de l'entrée carrousel
31
 condition : $f995s eq "2"
32
 forceupdate :
33
  f995z : "5"
34
-
35
 # pour les docs ne remplissant aucun des critères ci-dessus
36
 # on envoie vers le bac 2
37
 condition :
38
 forceupdate :
39
  f995z : "2"
40

Return to bug 20517