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

(-)a/C4/Circulation.pm (-5 / +13 lines)
Lines 250-261 sub decode { Link Here
250
250
251
=head2 transferbook
251
=head2 transferbook
252
252
253
  ($dotransfer, $messages, $iteminformation) = &transferbook($newbranch, 
253
  ($dotransfer, $messages, $iteminformation) = &transferbook({
254
                                            $barcode, $ignore_reserves);
254
                                                   from_branch => $frombranch
255
                                                   to_branch => $tobranch,
256
                                                   barcode => $barcode,
257
                                                   ignore_reserves => $ignore_reserves
258
                                                });
255
259
256
Transfers an item to a new branch. If the item is currently on loan, it is automatically returned before the actual transfer.
260
Transfers an item to a new branch. If the item is currently on loan, it is automatically returned before the actual transfer.
257
261
258
C<$newbranch> is the code for the branch to which the item should be transferred.
262
C<$fbr> is the code for the branch initiating the transfer.
263
C<$tbr> is the code for the branch to which the item should be transferred.
259
264
260
C<$barcode> is the barcode of the item to be transferred.
265
C<$barcode> is the barcode of the item to be transferred.
261
266
Lines 303-309 The item was eligible to be transferred. Barring problems communicating with the Link Here
303
=cut
308
=cut
304
309
305
sub transferbook {
310
sub transferbook {
306
    my ( $tbr, $barcode, $ignoreRs ) = @_;
311
    my $params = shift;
312
    my $tbr      = $params->{to_branch};
313
    my $fbr      = $params->{from_branch};
314
    my $ignoreRs = $params->{ignore_reserves};
315
    my $barcode  = $params->{barcode};
307
    my $messages;
316
    my $messages;
308
    my $dotransfer      = 1;
317
    my $dotransfer      = 1;
309
    my $item = Koha::Items->find( { barcode => $barcode } );
318
    my $item = Koha::Items->find( { barcode => $barcode } );
Lines 318-324 sub transferbook { Link Here
318
    my $itemnumber = $item->itemnumber;
327
    my $itemnumber = $item->itemnumber;
319
    # get branches of book...
328
    # get branches of book...
320
    my $hbr = $item->homebranch;
329
    my $hbr = $item->homebranch;
321
    my $fbr = $item->holdingbranch;
322
330
323
    # if using Branch Transfer Limits
331
    # if using Branch Transfer Limits
324
    if ( C4::Context->preference("UseBranchTransferLimits") == 1 ) {
332
    if ( C4::Context->preference("UseBranchTransferLimits") == 1 ) {
(-)a/C4/RotatingCollections.pm (-1 / +6 lines)
Lines 446-452 sub TransferCollection { Link Here
446
    while ( my $item = $sth->fetchrow_hashref ) {
446
    while ( my $item = $sth->fetchrow_hashref ) {
447
        my ($status) = CheckReserves( $item->{itemnumber} );
447
        my ($status) = CheckReserves( $item->{itemnumber} );
448
        my @transfers = C4::Circulation::GetTransfers( $item->{itemnumber} );
448
        my @transfers = C4::Circulation::GetTransfers( $item->{itemnumber} );
449
        C4::Circulation::transferbook( $colBranchcode, $item->{barcode}, my $ignore_reserves = 1 ) unless ( $status eq 'Waiting' || @transfers );
449
        C4::Circulation::transferbook({
450
            from_branch => $item->holdingbranch,
451
            to_branch => $colBranchcode,
452
            barcode => $item->{barcode},
453
            ignore_reserves => 1
454
        }) unless ( $status eq 'Waiting' || @transfers );
450
    }
455
    }
451
456
452
    return 1;
457
    return 1;
(-)a/circ/branchtransfers.pl (-4 / +11 lines)
Lines 80-85 my $setwaiting; Link Here
80
80
81
my $request        = $query->param('request')        || '';
81
my $request        = $query->param('request')        || '';
82
my $borrowernumber = $query->param('borrowernumber') ||  0;
82
my $borrowernumber = $query->param('borrowernumber') ||  0;
83
my $frombranchcd   = $query->param('frombranchcd')   || C4::Context->userenv->{'branch'};
83
my $tobranchcd     = $query->param('tobranchcd')     || '';
84
my $tobranchcd     = $query->param('tobranchcd')     || '';
84
85
85
my $ignoreRs = 0;
86
my $ignoreRs = 0;
Lines 126-139 defined $barcode and $barcode =~ s/^\s*|\s*$//g; # FIXME: barcodeInputFilter Link Here
126
# warn "barcode : $barcode";
127
# warn "barcode : $barcode";
127
if ($barcode) {
128
if ($barcode) {
128
129
129
    ( $transferred, $messages ) =
130
      transferbook( $tobranchcd, $barcode, $ignoreRs );
131
    my $item = Koha::Items->find({ barcode => $barcode });
130
    my $item = Koha::Items->find({ barcode => $barcode });
131
    $frombranchcd = $item->holdingbranch if $frombranchcd eq "current_holding";
132
    ( $transferred, $messages ) =
133
        transferbook({
134
            from_branch => $frombranchcd,
135
            to_branch => $tobranchcd,
136
            barcode => $barcode,
137
            ignore_reserves => $ignoreRs
138
        });
132
    $found = $messages->{'ResFound'};
139
    $found = $messages->{'ResFound'};
133
    if ($transferred) {
140
    if ($transferred) {
134
        my %item;
141
        my %item;
135
        my $biblio = $item->biblio;
142
        my $biblio = $item->biblio;
136
        my $frbranchcd =  C4::Context->userenv->{'branch'};
137
        $item{'biblionumber'}          = $item->biblionumber;
143
        $item{'biblionumber'}          = $item->biblionumber;
138
        $item{'itemnumber'}            = $item->itemnumber;
144
        $item{'itemnumber'}            = $item->itemnumber;
139
        $item{'title'}                 = $biblio->title;
145
        $item{'title'}                 = $biblio->title;
Lines 145-151 if ($barcode) { Link Here
145
        $item{'location'}              = $av->count ? $av->next->lib : '';
151
        $item{'location'}              = $av->count ? $av->next->lib : '';
146
        $item{counter}  = 0;
152
        $item{counter}  = 0;
147
        $item{barcode}  = $barcode;
153
        $item{barcode}  = $barcode;
148
        $item{frombrcd} = $frbranchcd;
154
        $item{frombrcd} = $frombranchcd;
149
        $item{tobrcd}   = $tobranchcd;
155
        $item{tobrcd}   = $tobranchcd;
150
        push( @trsfitemloop, \%item );
156
        push( @trsfitemloop, \%item );
151
    }
157
    }
Lines 235-240 $template->param( Link Here
235
    itemnumber              => $itemnumber,
241
    itemnumber              => $itemnumber,
236
    barcode                 => $barcode,
242
    barcode                 => $barcode,
237
    biblionumber            => $biblionumber,
243
    biblionumber            => $biblionumber,
244
    frombranchcd            => $frombranchcd,
238
    tobranchcd              => $tobranchcd,
245
    tobranchcd              => $tobranchcd,
239
    reqmessage              => $reqmessage,
246
    reqmessage              => $reqmessage,
240
    cancelled               => $cancelled,
247
    cancelled               => $cancelled,
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/branchtransfers.tt (+11 lines)
Lines 71-76 Link Here
71
                            <input type="hidden" name="biblionumber" value="[% biblionumber | html %]" />
71
                            <input type="hidden" name="biblionumber" value="[% biblionumber | html %]" />
72
                            <input type="hidden" name="borrowernumber" value="[% borrowernumber | html %]" />
72
                            <input type="hidden" name="borrowernumber" value="[% borrowernumber | html %]" />
73
                            <input type="hidden" name="tobranchcd" value="[% tobranchcd | html %]" />
73
                            <input type="hidden" name="tobranchcd" value="[% tobranchcd | html %]" />
74
                            <input type="hidden" name="frombranchcd" value="[% tobranchcd | html %]" />
74
                            <input type="hidden" name="barcode" value="[% barcode | html %]" />
75
                            <input type="hidden" name="barcode" value="[% barcode | html %]" />
75
                            <input type="hidden" name="request" value="KillReserved" />
76
                            <input type="hidden" name="request" value="KillReserved" />
76
                            <input type="submit" value="Cancel" />
77
                            <input type="submit" value="Cancel" />
Lines 127-132 Link Here
127
                                          [% ELSE %]
128
                                          [% ELSE %]
128
                                              <li>Collection code: <b>[% AuthorisedValues.GetByCode( 'CCODE', errmsgloo.code ) | html %]</b></li>
129
                                              <li>Collection code: <b>[% AuthorisedValues.GetByCode( 'CCODE', errmsgloo.code ) | html %]</b></li>
129
                                          [% END %]
130
                                          [% END %]
131
                                          <li>Originating library: <b>[% Branches.GetName( errmsgloo.fbr ) | html %]</b></li>
130
                                          <li>Destination library: <b>[% Branches.GetName( errmsgloo.tbr ) | html %]</b></li>
132
                                          <li>Destination library: <b>[% Branches.GetName( errmsgloo.tbr ) | html %]</b></li>
131
                                      </ol>
133
                                      </ol>
132
                                  </li>
134
                                  </li>
Lines 150-155 Link Here
150
            <legend>Transfer</legend>
152
            <legend>Transfer</legend>
151
            <ol>
153
            <ol>
152
			<li>
154
			<li>
155
                <label for="frombranchcd">Originating library: </label>
156
                    <select name="frombranchcd" id="frombranchcd">
157
                        <option value="current_holding">Item's holding branch</option>
158
                        [% PROCESS options_for_libraries libraries => Branches.all( selected => '', unfiltered => 1) %]
159
                    </select>
160
            </li>
161
			<li>
153
                <label for="tobranchcd">Destination library: </label>
162
                <label for="tobranchcd">Destination library: </label>
154
                    <select name="tobranchcd" id="tobranchcd">
163
                    <select name="tobranchcd" id="tobranchcd">
155
                        [% PROCESS options_for_libraries libraries => Branches.all( selected => tobranchcd, unfiltered => 1) %]
164
                        [% PROCESS options_for_libraries libraries => Branches.all( selected => tobranchcd, unfiltered => 1) %]
Lines 181-186 Link Here
181
                <th class="tf-itemcallnumber">Call number</th>
190
                <th class="tf-itemcallnumber">Call number</th>
182
                <th class="tf-itemtype">Item type</th>
191
                <th class="tf-itemtype">Item type</th>
183
                <th class="tf-ccode">Collection code</th>
192
                <th class="tf-ccode">Collection code</th>
193
                <th class="tf-origin">Origin</th>
184
                <th class="tf-destination">Destination</th>
194
                <th class="tf-destination">Destination</th>
185
            </tr>
195
            </tr>
186
            [% FOREACH trsfitemloo IN trsfitemloop %]
196
            [% FOREACH trsfitemloo IN trsfitemloop %]
Lines 192-197 Link Here
192
                    <td class="tf-itemcallnumber">[% trsfitemloo.itemcallnumber | html %]</td>
202
                    <td class="tf-itemcallnumber">[% trsfitemloo.itemcallnumber | html %]</td>
193
                    <td class="tf-itemtype">[% ItemTypes.GetDescription( trsfitemloo.itemtype ) | html %]</td>
203
                    <td class="tf-itemtype">[% ItemTypes.GetDescription( trsfitemloo.itemtype ) | html %]</td>
194
                    <td class="tf-ccode">[% AuthorisedValues.GetByCode( 'CCODE', trsfitemloo.ccode ) | html %]</td>
204
                    <td class="tf-ccode">[% AuthorisedValues.GetByCode( 'CCODE', trsfitemloo.ccode ) | html %]</td>
205
                    <td class="tf-origin">[% Branches.GetName( trsfitemloo.frombrcd ) | html %]</td>
195
                    <td class="tf-destination">[% Branches.GetName( trsfitemloo.tobrcd ) | html %]</td>
206
                    <td class="tf-destination">[% Branches.GetName( trsfitemloo.tobrcd ) | html %]</td>
196
                </tr>
207
                </tr>
197
            [% END %]
208
            [% END %]
(-)a/t/db_dependent/Circulation.t (-5 / +36 lines)
Lines 18-24 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
use utf8;
19
use utf8;
20
20
21
use Test::More tests => 46;
21
use Test::More tests => 47;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Deep qw( cmp_deeply );
23
use Test::Deep qw( cmp_deeply );
24
24
Lines 2954-2960 subtest 'Set waiting flag' => sub { Link Here
2954
};
2954
};
2955
2955
2956
subtest 'Cancel transfers on lost items' => sub {
2956
subtest 'Cancel transfers on lost items' => sub {
2957
    plan tests => 5;
2957
    plan tests => 6;
2958
    my $library_1 = $builder->build( { source => 'Branch' } );
2958
    my $library_1 = $builder->build( { source => 'Branch' } );
2959
    my $patron_1 = $builder->build( { source => 'Borrower', value => { branchcode => $library_1->{branchcode}, categorycode => $patron_category->{categorycode} } } );
2959
    my $patron_1 = $builder->build( { source => 'Borrower', value => { branchcode => $library_1->{branchcode}, categorycode => $patron_category->{categorycode} } } );
2960
    my $library_2 = $builder->build( { source => 'Branch' } );
2960
    my $library_2 = $builder->build( { source => 'Branch' } );
Lines 2981-2995 subtest 'Cancel transfers on lost items' => sub { Link Here
2981
    my $do_transfer = 1;
2981
    my $do_transfer = 1;
2982
    my ( $res, $rr ) = AddReturn( $item->barcode, $library_1->{branchcode} );
2982
    my ( $res, $rr ) = AddReturn( $item->barcode, $library_1->{branchcode} );
2983
    ModReserveAffect( $item->itemnumber, undef, $do_transfer, $reserve_id );
2983
    ModReserveAffect( $item->itemnumber, undef, $do_transfer, $reserve_id );
2984
    C4::Circulation::transferbook( $library_2->{branchcode}, $item->barcode );
2984
    C4::Circulation::transferbook({
2985
        from_branch => $library_1->{branchcode},
2986
        to_branch => $library_2->{branchcode},
2987
        barcode   => $item->barcode,
2988
    });
2985
    my $hold = Koha::Holds->find( $reserve_id );
2989
    my $hold = Koha::Holds->find( $reserve_id );
2986
    is( $hold->found, 'T', 'Hold is in transit' );
2990
    is( $hold->found, 'T', 'Hold is in transit' );
2987
2991
2988
    #Check transfer exists and the items holding branch is the transfer destination branch before marking it as lost
2992
    #Check transfer exists and the items holding branch is the transfer destination branch before marking it as lost
2989
    my ($datesent,$frombranch,$tobranch) = GetTransfers($item->itemnumber);
2993
    my ($datesent,$frombranch,$tobranch) = GetTransfers($item->itemnumber);
2990
    is( $tobranch, $library_2->{branchcode}, 'The transfer record exists in the branchtransfers table');
2994
    is( $frombranch, $library_1->{branchcode}, 'The transfer is generated from the correct library');
2995
    is( $tobranch, $library_2->{branchcode}, 'The transfer is generated to the correct library');
2991
    my $itemcheck = Koha::Items->find($item->itemnumber);
2996
    my $itemcheck = Koha::Items->find($item->itemnumber);
2992
    is( $itemcheck->holdingbranch, $library_1->{branchcode}, 'Items holding branch is the transfers origin branch before it is marked as lost' );
2997
    is( $itemcheck->holdingbranch, $library_1->{branchcode}, 'Items holding branch is the transfers origination branch before it is marked as lost' );
2993
2998
2994
    #Simulate item being marked as lost and confirm the transfer is deleted and the items holding branch is the transfers source branch
2999
    #Simulate item being marked as lost and confirm the transfer is deleted and the items holding branch is the transfers source branch
2995
    ModItem( { itemlost => 1 }, $item->biblionumber, $item->itemnumber );
3000
    ModItem( { itemlost => 1 }, $item->biblionumber, $item->itemnumber );
Lines 2998-3003 subtest 'Cancel transfers on lost items' => sub { Link Here
2998
    is( $tobranch, undef, 'The transfer on the lost item has been deleted as the LostItemCancelOutstandingTransfer is enabled');
3003
    is( $tobranch, undef, 'The transfer on the lost item has been deleted as the LostItemCancelOutstandingTransfer is enabled');
2999
    $itemcheck = Koha::Items->find($item->itemnumber);
3004
    $itemcheck = Koha::Items->find($item->itemnumber);
3000
    is( $itemcheck->holdingbranch, $library_1->{branchcode}, 'Lost item with cancelled hold has holding branch equallying the transfers source branch' );
3005
    is( $itemcheck->holdingbranch, $library_1->{branchcode}, 'Lost item with cancelled hold has holding branch equallying the transfers source branch' );
3006
3007
};
3008
3009
subtest 'transferbook test' => sub {
3010
    plan tests => 5;
3011
3012
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
3013
    my $item = $builder->build_sample_item();
3014
    ok( $item->holdingbranch ne $library->branchcode && $item->homebranch ne $library->branchcode, "Item is not held or owned by library");
3015
    C4::Circulation::transferbook({
3016
        from_branch => $library->branchcode,
3017
        to_branch => $item->homebranch,
3018
        barcode   => $item->barcode,
3019
    });
3020
    my ($datesent,$from_branch,$to_branch) = GetTransfers($item->itemnumber);
3021
    is( $from_branch, $library->branchcode, 'The transfer is initiated from the specified branch, not the items home or holdingbranch');
3022
    is( $to_branch, $item->homebranch, 'The transfer is initiated to the specified branch');
3023
    C4::Circulation::transferbook({
3024
        from_branch => $item->homebranch,
3025
        to_branch => $library->branchcode,
3026
        barcode   => $item->barcode,
3027
    });
3028
    ($datesent,$from_branch,$to_branch) = GetTransfers($item->itemnumber);
3029
    is( $from_branch, $item->homebranch, 'The transfer is initiated from the specified branch');
3030
    is( $to_branch, $library->branchcode, 'The transfer is initiated to the specified branch');
3031
3001
};
3032
};
3002
3033
3003
subtest 'CanBookBeIssued | is_overdue' => sub {
3034
subtest 'CanBookBeIssued | is_overdue' => sub {
(-)a/t/db_dependent/Koha/Items.t (-2 / +5 lines)
Lines 69-75 subtest 'get_transfer' => sub { Link Here
69
69
70
    my $library_to = $builder->build( { source => 'Branch' } );
70
    my $library_to = $builder->build( { source => 'Branch' } );
71
71
72
    C4::Circulation::transferbook( $library_to->{branchcode}, $new_item_1->barcode );
72
    C4::Circulation::transferbook({
73
        from_branch => $new_item_1->holdingbranch,
74
        to_branch => $library_to->{branchcode},
75
        barcode => $new_item_1->barcode,
76
    });
73
77
74
    $transfer = $new_item_1->get_transfer();
78
    $transfer = $new_item_1->get_transfer();
75
    is( ref($transfer), 'Koha::Item::Transfer', 'Koha::Item->get_transfer should return a Koha::Item::Transfers object' );
79
    is( ref($transfer), 'Koha::Item::Transfer', 'Koha::Item->get_transfer should return a Koha::Item::Transfers object' );
76
- 

Return to bug 23695