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

(-)a/C4/RotatingCollections.pm (-15 / +57 lines)
Lines 407-414 Transfers a collection to another branch Link Here
407
407
408
 Output:
408
 Output:
409
   $success: 1 if all database operations were successful, 0 otherwise
409
   $success: 1 if all database operations were successful, 0 otherwise
410
   $errorCode: Code for reason of failure, good for translating errors in templates
410
   $messages: Arrayref of messages for user feedback
411
   $errorMessage: English description of error
412
411
413
=cut
412
=cut
414
413
Lines 432-438 sub TransferCollection { Link Here
432
                        colBranchcode = ? 
431
                        colBranchcode = ? 
433
                        WHERE colId = ?"
432
                        WHERE colId = ?"
434
    );
433
    );
435
    $sth->execute( $colBranchcode, $colId ) or return ( 0, 4, $sth->errstr() );
434
    $sth->execute( $colBranchcode, $colId ) or return 0;
436
435
437
    $sth = $dbh->prepare(q{
436
    $sth = $dbh->prepare(q{
438
        SELECT items.itemnumber, items.barcode FROM collections_tracking
437
        SELECT items.itemnumber, items.barcode FROM collections_tracking
Lines 441-461 sub TransferCollection { Link Here
441
        WHERE issues.borrowernumber IS NULL
440
        WHERE issues.borrowernumber IS NULL
442
          AND collections_tracking.colId = ?
441
          AND collections_tracking.colId = ?
443
    });
442
    });
444
    $sth->execute($colId) or return ( 0, 4, $sth->errstr );
443
    $sth->execute($colId) or return 0;
445
    my @results;
444
    my $messages;
446
    while ( my $item = $sth->fetchrow_hashref ) {
445
    while ( my $item = $sth->fetchrow_hashref ) {
447
        my ($status) = CheckReserves( $item->{itemnumber} );
446
        my $item_object = Koha::Items->find( $item->{itemnumber} );
448
        my @transfers = C4::Circulation::GetTransfers( $item->{itemnumber} );
447
        try {
449
        C4::Circulation::transferbook({
448
            $item_object->request_transfer(
450
            from_branch => $item->holdingbranch,
449
                {
451
            to_branch => $colBranchcode,
450
                    to            => $colBranchcode,
452
            barcode => $item->{barcode},
451
                    reason        => 'RotatingCollection',
453
            ignore_reserves => 1,
452
                    ignore_limits => 0
454
            trigger => 'RotatingCollection'
453
                }
455
        }) unless ( $status eq 'Waiting' || @transfers );
454
            );    # Request transfer
455
        }
456
        catch {
457
            if ( $_->isa('Koha::Exceptions::Item::Transfer::Found') ) {
458
                my $exception      = $_;
459
                my $found_transfer = $_->transfer;
460
                if (   $found_transfer->in_transit
461
                    || $found_transfer->reason eq 'Reserve' )
462
                {
463
                    my $transfer = $item_object->request_transfer(
464
                        {
465
                            to            => $colBranchcode,
466
                            reason        => "RotatingCollection",
467
                            ignore_limits => 0,
468
                            enqueue       => 1
469
                        }
470
                    );    # Queue transfer
471
                    push @{$messages},
472
                      {
473
                        type           => 'enqueu',
474
                        item           => $item_object,
475
                        found_transfer => $found_transfer
476
                      };
477
                }
478
                else {
479
                    my $transfer = $item->request_transfer(
480
                        {
481
                            to            => $colBranchcode,
482
                            reason        => "RotatingCollection",
483
                            ignore_limits => 0,
484
                            replace       => 1
485
                        }
486
                    );    # Replace transfer
487
                    # NOTE: If we just replaced a StockRotationAdvance, 
488
                    # it will get enqueued afresh on the next cron run
489
                }
490
            }
491
            elsif ( $_->isa('Koha::Exceptions::Item::Transfer::Limit') ) {
492
                push @{$messages}, { type => 'failure', item => $item_object };
493
            }
494
            else {
495
                $_->rethrow();
496
            }
497
        };
456
    }
498
    }
457
499
458
    return 1;
500
    return (1, $messages);
459
}
501
}
460
502
461
=head2 GetCollectionItemBranches
503
=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 %] queued behind transfer to [% message.found_transfer.to | 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 (-7 / +4 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 =
47
      TransferCollection( $colId, $toBranch );
47
      TransferCollection( $colId, $toBranch );
48
48
49
    if ($success) {
49
    if ($success) {
50
        $template->param( transferSuccess => 1 );
50
        $template->param( transferSuccess => 1, messages => $messages );
51
    }
51
    }
52
    else {
52
    else {
53
        $template->param(
53
        $template->param(
54
            transferFailure => 1,
54
            transferFailure => 1
55
            errorCode       => $errorCode,
56
            errorMessage    => $errorMessage
57
        );
55
        );
58
    }
56
    }
59
}
57
}
60
- 

Return to bug 26618