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

(-)a/C4/Circulation.pm (-15 / +20 lines)
Lines 1580-1585 holdallowed => Hold policy for this branch and itemtype. Possible values: Link Here
1580
returnbranch => branch to which to return item.  Possible values:
1580
returnbranch => branch to which to return item.  Possible values:
1581
  noreturn: do not return, let item remain where checked in (floating collections)
1581
  noreturn: do not return, let item remain where checked in (floating collections)
1582
  homebranch: return to item's home branch
1582
  homebranch: return to item's home branch
1583
  holdingbranch: return to issuer branch
1583
1584
1584
This searches branchitemrules in the following order:
1585
This searches branchitemrules in the following order:
1585
1586
Lines 1698-1703 fields from the reserves table of the Koha database, and Link Here
1698
C<biblioitemnumber>. It also has the key C<ResFound>, whose value is
1699
C<biblioitemnumber>. It also has the key C<ResFound>, whose value is
1699
either C<Waiting>, C<Reserved>, or 0.
1700
either C<Waiting>, C<Reserved>, or 0.
1700
1701
1702
=item C<WasReturned>
1703
1704
Value 1 if return is successful.
1705
1706
=item C<NeedsTransfer>
1707
1708
If AutomaticItemReturn is disabled, return branch is given as value of NeedsTransfer.
1709
1701
=back
1710
=back
1702
1711
1703
C<$iteminformation> is a reference-to-hash, giving information about the
1712
C<$iteminformation> is a reference-to-hash, giving information about the
Lines 1729-1735 sub AddReturn { Link Here
1729
        return (0, { BadBarcode => $barcode }); # no barcode means no item or borrower.  bail out.
1738
        return (0, { BadBarcode => $barcode }); # no barcode means no item or borrower.  bail out.
1730
    }
1739
    }
1731
    my $issue  = GetItemIssue($itemnumber);
1740
    my $issue  = GetItemIssue($itemnumber);
1732
#   warn Dumper($iteminformation);
1733
    if ($issue and $issue->{borrowernumber}) {
1741
    if ($issue and $issue->{borrowernumber}) {
1734
        $borrower = C4::Members::GetMemberDetails($issue->{borrowernumber})
1742
        $borrower = C4::Members::GetMemberDetails($issue->{borrowernumber})
1735
            or die "Data inconsistency: barcode $barcode (itemnumber:$itemnumber) claims to be issued to non-existant borrowernumber '$issue->{borrowernumber}'\n"
1743
            or die "Data inconsistency: barcode $barcode (itemnumber:$itemnumber) claims to be issued to non-existant borrowernumber '$issue->{borrowernumber}'\n"
Lines 1749-1766 sub AddReturn { Link Here
1749
    my $item = GetItem($itemnumber) or die "GetItem($itemnumber) failed";
1757
    my $item = GetItem($itemnumber) or die "GetItem($itemnumber) failed";
1750
        # full item data, but no borrowernumber or checkout info (no issue)
1758
        # full item data, but no borrowernumber or checkout info (no issue)
1751
        # we know GetItem should work because GetItemnumberFromBarcode worked
1759
        # we know GetItem should work because GetItemnumberFromBarcode worked
1752
    my $hbr      = GetBranchItemRule($item->{'homebranch'}, $item->{'itype'})->{'returnbranch'} || "homebranch";
1760
    my $hbr = GetBranchItemRule($item->{'homebranch'}, $item->{'itype'})->{'returnbranch'} || "homebranch";
1753
        # get the proper branch to which to return the item
1761
        # get the proper branch to which to return the item
1754
    $hbr = $item->{$hbr} || $branch ;
1762
    my $returnbranch = $item->{$hbr} || $branch ;
1755
        # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
1763
        # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
1756
1764
1757
    my $borrowernumber = $borrower->{'borrowernumber'} || undef;    # we don't know if we had a borrower or not
1765
    my $borrowernumber = $borrower->{'borrowernumber'} || undef;    # we don't know if we had a borrower or not
1758
1766
1759
    # check if the book is in a permanent collection....
1767
    # check if the book is in a permanent collection....
1760
    # FIXME -- This 'PE' attribute is largely undocumented.  afaict, there's no user interface that reflects this functionality.
1768
    # FIXME -- This 'PE' attribute is largely undocumented.  afaict, there's no user interface that reflects this functionality.
1761
    if ( $hbr ) {
1769
    if ( $returnbranch ) {
1762
        my $branches = GetBranches();    # a potentially expensive call for a non-feature.
1770
        my $branches = GetBranches();    # a potentially expensive call for a non-feature.
1763
        $branches->{$hbr}->{PE} and $messages->{'IsPermanent'} = $hbr;
1771
        $branches->{$returnbranch}->{PE} and $messages->{'IsPermanent'} = $returnbranch;
1764
    }
1772
    }
1765
1773
1766
    # check if the return is allowed at this branch
1774
    # check if the return is allowed at this branch
Lines 1956-1976 sub AddReturn { Link Here
1956
        DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
1964
        DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
1957
    }
1965
    }
1958
1966
1959
    # FIXME: make this comment intelligible.
1967
    # Transfer to returnbranch if Automatic transfer set or append message NeedsTransfer
1960
    #adding message if holdingbranch is non equal a userenv branch to return the document to homebranch
1968
    if (($doreturn or $messages->{'NotIssued'}) and !$resfound and ($branch ne $returnbranch) and not $messages->{'WrongTransfer'}){
1961
    #we check, if we don't have reserv or transfert for this document, if not, return it to homebranch .
1969
        if  (C4::Context->preference("AutomaticItemReturn"    ) or
1962
1963
    if (($doreturn or $messages->{'NotIssued'}) and !$resfound and ($branch ne $hbr) and not $messages->{'WrongTransfer'}){
1964
        if ( C4::Context->preference("AutomaticItemReturn"    ) or
1965
            (C4::Context->preference("UseBranchTransferLimits") and
1970
            (C4::Context->preference("UseBranchTransferLimits") and
1966
             ! IsBranchTransferAllowed($branch, $hbr, $item->{C4::Context->preference("BranchTransferLimitsType")} )
1971
             ! IsBranchTransferAllowed($branch, $returnbranch, $item->{C4::Context->preference("BranchTransferLimitsType")} )
1967
           )) {
1972
           )) {
1968
            $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s)", $item->{'itemnumber'},$branch, $hbr;
1973
            $debug and warn sprintf "about to call ModItemTransfer(%s, %s, %s)", $item->{'itemnumber'},$branch, $returnbranch;
1969
            $debug and warn "item: " . Dumper($item);
1974
            $debug and warn "item: " . Dumper($item);
1970
            ModItemTransfer($item->{'itemnumber'}, $branch, $hbr);
1975
            ModItemTransfer($item->{'itemnumber'}, $branch, $returnbranch);
1971
            $messages->{'WasTransfered'} = 1;
1976
            $messages->{'WasTransfered'} = 1;
1972
        } else {
1977
        } else {
1973
            $messages->{'NeedsTransfer'} = 1;   # TODO: instead of 1, specify branchcode that the transfer SHOULD go to, $item->{homebranch}
1978
            $messages->{'NeedsTransfer'} = $returnbranch;
1974
        }
1979
        }
1975
    }
1980
    }
1976
    return ( $doreturn, $messages, $issue, $borrower );
1981
    return ( $doreturn, $messages, $issue, $borrower );
(-)a/circ/returns.pl (-6 / +12 lines)
Lines 248-257 if ($barcode) { Link Here
248
#
248
#
249
# save the return
249
# save the return
250
#
250
#
251
    ( $returned, $messages, $issueinformation, $borrower ) =
252
      AddReturn( $barcode, $userenv_branch, $exemptfine, $dropboxmode, $return_date_override );
253
    my $homeorholdingbranchreturn = C4::Context->preference('HomeOrHoldingBranchReturn');
254
    $homeorholdingbranchreturn ||= 'homebranch';
255
251
256
    # get biblio description
252
    # get biblio description
257
    my $biblio = GetBiblioFromItemNumber($itemnumber);
253
    my $biblio = GetBiblioFromItemNumber($itemnumber);
Lines 268-277 if ($barcode) { Link Here
268
        );
264
        );
269
    }
265
    }
270
266
267
    # make sure return branch respects home branch circulation rules, default to homebranch
268
    my $hbr = GetBranchItemRule($biblio->{'homebranch'}, $itemtype)->{'returnbranch'} || "homebranch";
269
    my $returnbranch = $biblio->{$hbr} ;
270
271
    $template->param(
271
    $template->param(
272
        title            => $biblio->{'title'},
272
        title            => $biblio->{'title'},
273
        homebranch       => $biblio->{'homebranch'},
273
        homebranch       => $biblio->{'homebranch'},
274
        homebranchname   => GetBranchName( $biblio->{$homeorholdingbranchreturn} ),
274
        homebranchname   => GetBranchName( $biblio->{'homebranch'} ),
275
        returnbranch     => $returnbranch,
276
        returnbranchname => GetBranchName( $returnbranch ),
275
        author           => $biblio->{'author'},
277
        author           => $biblio->{'author'},
276
        itembarcode      => $biblio->{'barcode'},
278
        itembarcode      => $biblio->{'barcode'},
277
        itemtype         => $biblio->{'itemtype'},
279
        itemtype         => $biblio->{'itemtype'},
Lines 287-292 if ($barcode) { Link Here
287
        barcode => $barcode,
289
        barcode => $barcode,
288
    );
290
    );
289
291
292
    # do the return
293
    ( $returned, $messages, $issueinformation, $borrower ) =
294
      AddReturn( $barcode, $userenv_branch, $exemptfine, $dropboxmode, $return_date_override );
295
290
    if ($returned) {
296
    if ($returned) {
291
        my $time_now = DateTime->now( time_zone => C4::Context->tz )->truncate( to => 'minute');
297
        my $time_now = DateTime->now( time_zone => C4::Context->tz )->truncate( to => 'minute');
292
        my $duedate = $issueinformation->{date_due}->strftime('%Y-%m-%d %H:%M');
298
        my $duedate = $issueinformation->{date_due}->strftime('%Y-%m-%d %H:%M');
Lines 352-358 if ( $messages->{'WasTransfered'} ) { Link Here
352
if ( $messages->{'NeedsTransfer'} ){
358
if ( $messages->{'NeedsTransfer'} ){
353
    $template->param(
359
    $template->param(
354
        found          => 1,
360
        found          => 1,
355
        needstransfer  => 1,
361
        needstransfer  => $messages->{'NeedsTransfer'},
356
        itemnumber     => $itemnumber,
362
        itemnumber     => $itemnumber,
357
    );
363
    );
358
}
364
}
(-)a/installer/data/mysql/sysprefs.sql (-1 lines)
Lines 132-138 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
132
('HighlightOwnItemsOnOPACWhich','PatronBranch','PatronBranch|OpacURLBranch','Decides which branch\'s items to emphasize. If PatronBranch, emphasize the logged in user\'s library\'s items. If OpacURLBranch, highlight the items of the Apache var BRANCHCODE defined in Koha\'s Apache configuration file.','Choice'),
132
('HighlightOwnItemsOnOPACWhich','PatronBranch','PatronBranch|OpacURLBranch','Decides which branch\'s items to emphasize. If PatronBranch, emphasize the logged in user\'s library\'s items. If OpacURLBranch, highlight the items of the Apache var BRANCHCODE defined in Koha\'s Apache configuration file.','Choice'),
133
('HoldsToPullStartDate','2',NULL,'Set the default start date for the Holds to pull list to this many days ago','Integer'),
133
('HoldsToPullStartDate','2',NULL,'Set the default start date for the Holds to pull list to this many days ago','Integer'),
134
('HomeOrHoldingBranch','holdingbranch','holdingbranch|homebranch','Used by Circulation to determine which branch of an item to check with independent branches on, and by search to determine which branch to choose for availability ','Choice'),
134
('HomeOrHoldingBranch','holdingbranch','holdingbranch|homebranch','Used by Circulation to determine which branch of an item to check with independent branches on, and by search to determine which branch to choose for availability ','Choice'),
135
('HomeOrHoldingBranchReturn','homebranch','holdingbranch|homebranch','Used by Circulation to determine which branch of an item to check checking-in items','Choice'),
136
('HTML5MediaEnabled','not','not|opac|staff|both','Show a tab with a HTML5 media player for files catalogued in field 856','Choice'),
135
('HTML5MediaEnabled','not','not|opac|staff|both','Show a tab with a HTML5 media player for files catalogued in field 856','Choice'),
137
('HTML5MediaExtensions','webm|ogg|ogv|oga|vtt','','Media file extensions','free'),
136
('HTML5MediaExtensions','webm|ogg|ogv|oga|vtt','','Media file extensions','free'),
138
('IDreamBooksReadometer','0','','Display Readometer from IDreamBooks.com','YesNo'),
137
('IDreamBooksReadometer','0','','Display Readometer from IDreamBooks.com','YesNo'),
(-)a/installer/data/mysql/updatedatabase.pl (+7 lines)
Lines 8456-8461 if ( CheckVersion($DBversion) ) { Link Here
8456
    ");
8456
    ");
8457
8457
8458
    print "Upgrade to $DBversion done (Bug 10500 - Improve isbn matching when importing records)\n";
8458
    print "Upgrade to $DBversion done (Bug 10500 - Improve isbn matching when importing records)\n";
8459
8460
$DBversion = "3.15.00.XXX";
8461
if ( CheckVersion($DBversion) ) {
8462
    $dbh->do(q{
8463
        DELETE FROM systempreferences WHERE variable = 'HomeOrHoldingBranchReturn';
8464
    });
8465
    print "Upgrade to $DBversion done (Bug 7981 - Transfer message on return. HomeOrHoldingBranchReturn syspref removed in favour of circulation rules.)\n";
8459
    SetVersion($DBversion);
8466
    SetVersion($DBversion);
8460
}
8467
}
8461
8468
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (-7 lines)
Lines 329-341 Circulation: Link Here
329
                  confirmation: Ask for confirmation
329
                  confirmation: Ask for confirmation
330
            - when checking out to a borrower that has overdues outstanding	    
330
            - when checking out to a borrower that has overdues outstanding	    
331
        -
331
        -
332
            - On checkin route the returned item to
333
            - pref: HomeOrHoldingBranchReturn
334
              type: choice
335
              choices:
336
                  homebranch: the library the item is from.
337
                  holdingbranch: the library the item was checked out from.
338
        -
339
            - "When issuing an item that has been marked as lost, "
332
            - "When issuing an item that has been marked as lost, "
340
            - pref: IssueLostItem
333
            - pref: IssueLostItem
341
              choices:
334
              choices:
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt (-5 / +5 lines)
Lines 253-261 $(document).ready(function () { Link Here
253
    [% END %]
253
    [% END %]
254
254
255
    [% IF ( transfer ) %]
255
    [% IF ( transfer ) %]
256
    <!-- transfer: item with no reservation, must be returned to its home library -->
256
    <!-- transfer: item with no reservation, must be returned according to home library circulation rules -->
257
	<div id="return1" class="dialog message">
257
	<div id="return1" class="dialog message">
258
            <h3>Please return <a href="/cgi-bin/koha/catalogue/detail.pl?type=intra&amp;biblionumber=[% itembiblionumber %]">[% title or "item" |html %]</a> to [% homebranchname %]<br/>( <a href="#" onclick="Dopop('transfer-slip.pl?transferitem=[% itemnumber %]&amp;branchcode=[% homebranch %]&amp;op=slip'); return true;">Print slip</a> )</h3>
258
            <h3>Please return <a href="/cgi-bin/koha/catalogue/detail.pl?type=intra&amp;biblionumber=[% itembiblionumber %]">[% title or "item" |html %]</a> to [% returnbranchname %]<br/>( <a href="#" onclick="Dopop('transfer-slip.pl?transferitem=[% itemnumber %]&amp;branchcode=[% returnbranch %]&amp;op=slip'); return true;">Print slip</a> )</h3>
259
        </div>
259
        </div>
260
        [% IF ( soundon ) %]
260
        [% IF ( soundon ) %]
261
        <audio src="[% interface %]/[% theme %]/sound/opening.ogg" autoplay="autoplay" autobuffer="autobuffer"></audio>
261
        <audio src="[% interface %]/[% theme %]/sound/opening.ogg" autoplay="autoplay" autobuffer="autobuffer"></audio>
Lines 267-281 $(document).ready(function () { Link Here
267
        [% IF ( soundon ) %]
267
        [% IF ( soundon ) %]
268
        <audio src="[% interface %]/[% theme %]/sound/opening.ogg" autoplay="autoplay" autobuffer="autobuffer"></audio>
268
        <audio src="[% interface %]/[% theme %]/sound/opening.ogg" autoplay="autoplay" autobuffer="autobuffer"></audio>
269
        [% END %]
269
        [% END %]
270
	<div id="item-transfer" class="dialog message"><h3> This item needs to be transferred to [% homebranchname %]</h3>
270
 <div id="item-transfer" class="dialog message"><h3> This item needs to be transferred to [% returnbranchname %]</h3>
271
    Transfer now?<br />
271
    Transfer now?<br />
272
    <form method="post" action="returns.pl" name="mainform" id="mainform">
272
    <form method="post" action="returns.pl" name="mainform" id="mainform">
273
    [% IF itemnumber %]
273
    [% IF itemnumber %]
274
        <input type="submit" name="dotransfer" value="Yes, Print slip" class="print" onclick="Dopop('transfer-slip.pl?transferitem=[% itemnumber %]&amp;&amp;branchcode=[% homebranch %]&amp;op=slip'); return true;" />
274
        <input type="submit" name="dotransfer" value="Yes, Print slip" class="print" onclick="Dopop('transfer-slip.pl?transferitem=[% itemnumber %]&amp;&amp;branchcode=[% returnbranch %]&amp;op=slip'); return true;" />
275
    [% END %]
275
    [% END %]
276
	<input type="submit" name="dotransfer" value="Yes" class="submit" />
276
	<input type="submit" name="dotransfer" value="Yes" class="submit" />
277
	<input type="submit" name="notransfer" value="No" class="submit" />
277
	<input type="submit" name="notransfer" value="No" class="submit" />
278
	<input type="hidden" name="tobranch" value="[% homebranch %]" />
278
    <input type="hidden" name="tobranch" value="[% returnbranch %]" />
279
	<input type="hidden" name="transferitem" value="[% itemnumber %]" />
279
	<input type="hidden" name="transferitem" value="[% itemnumber %]" />
280
        <input type="hidden" name="exemptfine" value="[% exemptfine %]" />
280
        <input type="hidden" name="exemptfine" value="[% exemptfine %]" />
281
        <input type="hidden" name="dropboxmode" value="[% dropboxmode %]" />
281
        <input type="hidden" name="dropboxmode" value="[% dropboxmode %]" />
(-)a/t/db_dependent/Circulation_Branch.t (-18 / +107 lines)
Lines 7-23 use C4::Branch; Link Here
7
use C4::Circulation;
7
use C4::Circulation;
8
use C4::Items;
8
use C4::Items;
9
use C4::Context;
9
use C4::Context;
10
10
use Data::Dumper;
11
use Test::More tests => 10;
11
use Test::More tests => 13;
12
12
13
BEGIN {
13
BEGIN {
14
    use_ok('C4::Circulation');
14
    use_ok('C4::Circulation');
15
}
15
}
16
16
17
can_ok( 'C4::Circulation', qw(
17
can_ok( 'C4::Circulation', qw(
18
                            GetBranchBorrowerCircRule
18
    AddIssue
19
                            GetBranchItemRule
19
    AddReturn
20
                            )
20
    GetBranchBorrowerCircRule
21
    GetBranchItemRule
22
    GetIssuingRule
23
    )
21
);
24
);
22
25
23
#Start transaction
26
#Start transaction
Lines 160-165 $sth->execute( Link Here
160
    $sampleitemtype2->{imageurl},     $sampleitemtype2->{summary}
163
    $sampleitemtype2->{imageurl},     $sampleitemtype2->{summary}
161
);
164
);
162
165
166
#Add biblio and item
167
my $record = MARC::Record->new();
168
$record->append_fields(
169
    MARC::Field->new( '952', '0', '0', a => $samplebranch1->{branchcode} ) );
170
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '' );
171
172
# item 2 has home branch and holding branch samplebranch1
173
my @sampleitem1 = C4::Items::AddItem(
174
    {
175
        barcode        => 'barcode_1',
176
        itemcallnumber => 'callnumber1',
177
        homebranch     => $samplebranch1->{branchcode},
178
        holdingbranch  => $samplebranch1->{branchcode}
179
    },
180
    $biblionumber
181
);
182
my $item_id1    = $sampleitem1[2];
183
184
# item 2 has holding branch samplebranch2
185
my @sampleitem2 = C4::Items::AddItem(
186
    {
187
        barcode        => 'barcode_2',
188
        itemcallnumber => 'callnumber2',
189
        homebranch     => $samplebranch2->{branchcode},
190
        holdingbranch  => $samplebranch1->{branchcode}
191
    },
192
    $biblionumber
193
);
194
my $item_id2 = $sampleitem2[2];
195
196
# item 3 has item type sampleitemtype2 with noreturn policy
197
my @sampleitem3 = C4::Items::AddItem(
198
    {
199
        barcode        => 'barcode_3',
200
        itemcallnumber => 'callnumber3',
201
        homebranch     => $samplebranch2->{branchcode},
202
        holdingbranch  => $samplebranch2->{branchcode},
203
        itype          => $sampleitemtype2->{itemtype}
204
    },
205
    $biblionumber
206
);
207
my $item_id3 = $sampleitem3[2];
208
209
#Add borrower
210
my $borrower_id1 = C4::Members::AddMember(
211
    firstname    => 'firstname1',
212
    surname      => 'surname1 ',
213
    categorycode => $samplecat->{categorycode},
214
    branchcode   => $samplebranch1->{branchcode},
215
);
216
my $borrower_1 = C4::Members::GetMember(borrowernumber => $borrower_id1);
217
163
$query =
218
$query =
164
"INSERT INTO branch_borrower_circ_rules (branchcode,categorycode,maxissueqty) VALUES( ?,?,?)";
219
"INSERT INTO branch_borrower_circ_rules (branchcode,categorycode,maxissueqty) VALUES( ?,?,?)";
165
$dbh->do(
220
$dbh->do(
Lines 167-179 $dbh->do( Link Here
167
    $samplebranch1->{branchcode},
222
    $samplebranch1->{branchcode},
168
    $samplecat->{categorycode}, 5
223
    $samplecat->{categorycode}, 5
169
);
224
);
170
$query =
225
171
"INSERT INTO default_branch_circ_rules (branchcode,maxissueqty,holdallowed,returnbranch) VALUES( ?,?,?,?)";
172
$dbh->do( $query, {}, $samplebranch2->{branchcode},
173
    3, 1, $samplebranch2->{branchcode} );
174
$query =
226
$query =
175
"INSERT INTO default_circ_rules (singleton,maxissueqty,holdallowed,returnbranch) VALUES( ?,?,?,?)";
227
"INSERT INTO default_circ_rules (singleton,maxissueqty,holdallowed,returnbranch) VALUES( ?,?,?,?)";
176
$dbh->do( $query, {}, 'singleton', 4, 3, $samplebranch1->{branchcode} );
228
$dbh->do( $query, {}, 'singleton', 4, 3, 'homebranch' );
229
230
$query =
231
"INSERT INTO default_branch_circ_rules (branchcode,maxissueqty,holdallowed,returnbranch) VALUES( ?,?,?,?)";
232
$dbh->do( $query, {}, $samplebranch2->{branchcode}, 3, 1, 'holdingbranch' );
177
233
178
$query =
234
$query =
179
"INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)";
235
"INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)";
Lines 181-192 $sth = $dbh->prepare($query); Link Here
181
$sth->execute(
237
$sth->execute(
182
    $samplebranch1->{branchcode},
238
    $samplebranch1->{branchcode},
183
    $sampleitemtype1->{itemtype},
239
    $sampleitemtype1->{itemtype},
184
    5, $samplebranch1->{branchcode}
240
    5, 'homebranch'
241
);
242
$sth->execute(
243
    $samplebranch2->{branchcode},
244
    $sampleitemtype1->{itemtype},
245
    5, 'holdingbranch'
185
);
246
);
186
$sth->execute(
247
$sth->execute(
187
    $samplebranch2->{branchcode},
248
    $samplebranch2->{branchcode},
188
    $sampleitemtype2->{itemtype},
249
    $sampleitemtype2->{itemtype},
189
    5, $samplebranch1->{branchcode}
250
    5, 'noreturn'
190
);
251
);
191
252
192
#Test GetBranchBorrowerCircRule
253
#Test GetBranchBorrowerCircRule
Lines 220-242 is_deeply( Link Here
220
        $samplebranch1->{branchcode},
281
        $samplebranch1->{branchcode},
221
        $sampleitemtype1->{itemtype}
282
        $sampleitemtype1->{itemtype}
222
    ),
283
    ),
223
    { returnbranch => $samplebranch1->{branchcode}, holdallowed => 5 },
284
    { returnbranch => 'homebranch', holdallowed => 5 },
224
    "GetBranchitem returns holdallowed and return branch"
285
    "GetBranchitem returns holdallowed and return branch"
225
);
286
);
226
is_deeply(
287
is_deeply(
227
    GetBranchItemRule(),
288
    GetBranchItemRule(),
228
    { returnbranch => $samplebranch1->{branchcode}, holdallowed => 3 },
289
    { returnbranch => 'homebranch', holdallowed => 3 },
229
"Without parameters GetBranchItemRule returns the values in default_circ_rules"
290
"Without parameters GetBranchItemRule returns the values in default_circ_rules"
230
);
291
);
231
is_deeply(
292
is_deeply(
232
    GetBranchItemRule( $samplebranch1->{branchcode} ),
293
    GetBranchItemRule( $samplebranch2->{branchcode} ),
233
    { returnbranch => $samplebranch1->{branchcode}, holdallowed => 3 },
294
    { returnbranch => 'holdingbranch', holdallowed => 1 },
234
"With only a branchcode GetBranchItemRule returns values in default_branch_circ_rules"
295
"With only a branchcode GetBranchItemRule returns values in default_branch_circ_rules"
235
);
296
);
236
is_deeply(
297
is_deeply(
237
    GetBranchItemRule( -1, -1 ),
298
    GetBranchItemRule( -1, -1 ),
238
    { returnbranch => $samplebranch1->{branchcode}, holdallowed => 3 },
299
    { returnbranch => 'homebranch', holdallowed => 3 },
239
    "With only one parametern GetBranchItemRule returns default values"
300
    "With only one parametern GetBranchItemRule returns default values"
240
);
301
);
241
302
303
# Test return policies
304
C4::Context->set_preference('AutomaticItemReturn','0');
305
306
# item1 returned at branch2 should trigger transfer to homebranch
307
$query =
308
"INSERT INTO issues (borrowernumber,itemnumber,branchcode) VALUES( ?,?,? )";
309
$dbh->do( $query, {}, $borrower_id1, $item_id1, $samplebranch1->{branchcode} );
310
311
my ($doreturn, $messages, $iteminformation, $borrower) = AddReturn('barcode_1', 
312
    $samplebranch2->{branchcode});
313
is( $messages->{NeedsTransfer}, $samplebranch1->{branchcode}, "AddReturn respects default return policy - return to homebranch" );
314
315
# item2 returned at branch2 should trigger transfer to holding branch 
316
$query =
317
"INSERT INTO issues (borrowernumber,itemnumber,branchcode) VALUES( ?,?,? )";
318
$dbh->do( $query, {}, $borrower_id1, $item_id2, $samplebranch2->{branchcode} );
319
($doreturn, $messages, $iteminformation, $borrower) = AddReturn('barcode_2', 
320
    $samplebranch2->{branchcode});
321
is( $messages->{NeedsTransfer}, $samplebranch1->{branchcode}, "AddReturn respects branch return policy - item2->homebranch policy = 'holdingbranch'" );
322
323
# item3 should not trigger transfer - floating collection 
324
$query =
325
"INSERT INTO issues (borrowernumber,itemnumber,branchcode) VALUES( ?,?,? )";
326
$dbh->do( $query, {}, $borrower_id1, $item_id3, $samplebranch1->{branchcode} );
327
($doreturn, $messages, $iteminformation, $borrower) = AddReturn('barcode_3', 
328
    $samplebranch1->{branchcode});
329
is($messages->{NeedsTransfer},undef,"AddReturn respects branch item return policy - noreturn");
330
331
242
$dbh->rollback;
332
$dbh->rollback;
243
- 

Return to bug 7981