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

(-)a/C4/RotatingCollections.pm (-17 / +59 lines)
Lines 30-37 use C4::Reserves qw(CheckReserves); Link Here
30
use Koha::Database;
30
use Koha::Database;
31
31
32
use DBI;
32
use DBI;
33
33
use Try::Tiny;
34
use Data::Dumper;
35
34
36
use vars qw(@ISA @EXPORT);
35
use vars qw(@ISA @EXPORT);
37
36
Lines 410-417 Transfers a collection to another branch Link Here
410
409
411
 Output:
410
 Output:
412
   $success: 1 if all database operations were successful, 0 otherwise
411
   $success: 1 if all database operations were successful, 0 otherwise
413
   $errorCode: Code for reason of failure, good for translating errors in templates
412
   $messages: Arrayref of messages for user feedback
414
   $errorMessage: English description of error
415
413
416
=cut
414
=cut
417
415
Lines 435-441 sub TransferCollection { Link Here
435
                        colBranchcode = ? 
433
                        colBranchcode = ? 
436
                        WHERE colId = ?"
434
                        WHERE colId = ?"
437
    );
435
    );
438
    $sth->execute( $colBranchcode, $colId ) or return ( 0, 4, $sth->errstr() );
436
    $sth->execute( $colBranchcode, $colId ) or return 0;
437
    my $to_library = Koha::Libraries->find( $colBranchcode );
439
438
440
    $sth = $dbh->prepare(q{
439
    $sth = $dbh->prepare(q{
441
        SELECT items.itemnumber, items.barcode FROM collections_tracking
440
        SELECT items.itemnumber, items.barcode FROM collections_tracking
Lines 444-464 sub TransferCollection { Link Here
444
        WHERE issues.borrowernumber IS NULL
443
        WHERE issues.borrowernumber IS NULL
445
          AND collections_tracking.colId = ?
444
          AND collections_tracking.colId = ?
446
    });
445
    });
447
    $sth->execute($colId) or return ( 0, 4, $sth->errstr );
446
    $sth->execute($colId) or return 0;
448
    my @results;
447
    my $messages;
449
    while ( my $item = $sth->fetchrow_hashref ) {
448
    while ( my $item = $sth->fetchrow_hashref ) {
450
        my ($status) = CheckReserves( $item->{itemnumber} );
449
        my $item_object = Koha::Items->find( $item->{itemnumber} );
451
        my @transfers = C4::Circulation::GetTransfers( $item->{itemnumber} );
450
        try {
452
        C4::Circulation::transferbook({
451
            $item_object->request_transfer(
453
            from_branch => $item->holdingbranch,
452
                {
454
            to_branch => $colBranchcode,
453
                    to            => $to_library,
455
            barcode => $item->{barcode},
454
                    reason        => 'RotatingCollection',
456
            ignore_reserves => 1,
455
                    ignore_limits => 0
457
            trigger => 'RotatingCollection'
456
                }
458
        }) unless ( $status eq 'Waiting' || $status eq 'Processing' || @transfers );
457
            );    # Request transfer
458
        }
459
        catch {
460
            if ( $_->isa('Koha::Exceptions::Item::Transfer::Found') ) {
461
                my $exception      = $_;
462
                my $found_transfer = $_->transfer;
463
                if (   $found_transfer->in_transit
464
                    || $found_transfer->reason eq 'Reserve' )
465
                {
466
                    my $transfer = $item_object->request_transfer(
467
                        {
468
                            to            => $to_library,
469
                            reason        => "RotatingCollection",
470
                            ignore_limits => 0,
471
                            enqueue       => 1
472
                        }
473
                    );    # Queue transfer
474
                    push @{$messages},
475
                      {
476
                        type           => 'enqueu',
477
                        item           => $item_object,
478
                        found_transfer => $found_transfer
479
                      };
480
                }
481
                else {
482
                    my $transfer = $item_object->request_transfer(
483
                        {
484
                            to            => $to_library,
485
                            reason        => "RotatingCollection",
486
                            ignore_limits => 0,
487
                            replace       => 1
488
                        }
489
                    );    # Replace transfer
490
                    # NOTE: If we just replaced a StockRotationAdvance,
491
                    # it will get enqueued afresh on the next cron run
492
                }
493
            }
494
            elsif ( $_->isa('Koha::Exceptions::Item::Transfer::Limit') ) {
495
                push @{$messages}, { type => 'failure', item => $item_object };
496
            }
497
            else {
498
                $_->rethrow();
499
            }
500
        };
459
    }
501
    }
460
502
461
    return 1;
503
    return (1, $messages);
462
}
504
}
463
505
464
=head2 GetCollectionItemBranches
506
=head2 GetCollectionItemBranches
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/rotating_collections/transferCollection.tt (+15 lines)
Lines 19-24 Link Here
19
19
20
                <h1>Transfer collection <em>[% colTitle | html %]</em></h1>
20
                <h1>Transfer collection <em>[% colTitle | html %]</em></h1>
21
21
22
                [% IF ( messages ) %]
23
                    [% FOREACH message IN messages %]
24
                        [%- SWITCH message.type -%]
25
                            [%- CASE 'failure' %]
26
                            <div class="dialog error">
27
                                <p>Cannot transfer item [% message.item.itemnumber | html %] due to transfer limits</p>
28
                            </div>
29
                            [%- CASE 'enqueu' -%]
30
                            <div class="dialog message">
31
                                <p>Item [% message.item.itemnumber | html %] queued behind [% message.found_transfer.reason | html %] transfer to [% Branches.GetName(message.found_transfer.tobranch) | html %]</p>
32
                            </div>
33
                       [% END %]
34
                    [% END %]
35
                [% END %]
36
22
                [% IF ( transferSuccess ) %]
37
                [% IF ( transferSuccess ) %]
23
                    <div class="dialog message">
38
                    <div class="dialog message">
24
                        <p>Collection transferred successfully</p>
39
                        <p>Collection transferred successfully</p>
(-)a/rotating_collections/transferCollection.pl (-6 / +7 lines)
Lines 41-59 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
41
);
41
);
42
42
43
## Transfer collection
43
## Transfer collection
44
my ( $success, $errorCode, $errorMessage );
44
my ( $success, $messages );
45
if ($toBranch) {
45
if ($toBranch) {
46
    ( $success, $errorCode, $errorMessage ) =
46
    ( $success, $messages) =
47
      TransferCollection( $colId, $toBranch );
47
      TransferCollection( $colId, $toBranch );
48
48
49
    if ($success) {
49
    if ($success) {
50
        $template->param( transferSuccess => 1 );
50
        $template->param(
51
            transferSuccess => 1,
52
            messages        => $messages
53
        );
51
    }
54
    }
52
    else {
55
    else {
53
        $template->param(
56
        $template->param(
54
            transferFailure => 1,
57
            transferFailure => 1,
55
            errorCode       => $errorCode,
58
            messages        => $messages
56
            errorMessage    => $errorMessage
57
        );
59
        );
58
    }
60
    }
59
}
61
}
60
- 

Return to bug 26618