Lines 94-99
BEGIN {
Link Here
|
94 |
push @EXPORT, qw( |
94 |
push @EXPORT, qw( |
95 |
&AddReturn |
95 |
&AddReturn |
96 |
&MarkIssueReturned |
96 |
&MarkIssueReturned |
|
|
97 |
&GetCircControlBranch |
97 |
); |
98 |
); |
98 |
|
99 |
|
99 |
# subs to deal with transfers |
100 |
# subs to deal with transfers |
Lines 375-381
sub TooMany {
Link Here
|
375 |
my $dbh = C4::Context->dbh; |
376 |
my $dbh = C4::Context->dbh; |
376 |
my $branch; |
377 |
my $branch; |
377 |
# Get which branchcode we need |
378 |
# Get which branchcode we need |
378 |
$branch = _GetCircControlBranch($item,$borrower); |
379 |
$branch = GetCircControlBranch($item,$borrower); |
379 |
my $type = (C4::Context->preference('item-level_itypes')) |
380 |
my $type = (C4::Context->preference('item-level_itypes')) |
380 |
? $item->{'itype'} # item-level |
381 |
? $item->{'itype'} # item-level |
381 |
: $item->{'itemtype'}; # biblio-level |
382 |
: $item->{'itemtype'}; # biblio-level |
Lines 432-444
sub TooMany {
Link Here
|
432 |
push @bind_params, $borrower->{'borrowernumber'}; |
433 |
push @bind_params, $borrower->{'borrowernumber'}; |
433 |
my $rule_branch = $issuing_rule->{branchcode}; |
434 |
my $rule_branch = $issuing_rule->{branchcode}; |
434 |
if ($rule_branch ne "*") { |
435 |
if ($rule_branch ne "*") { |
|
|
436 |
# FIXME: This code replicates the behavior of GetCircControlBranch, |
437 |
# but returns only the relevent field, rather than the value. It would be better |
438 |
# to allow GetCircControl to be able to return the revelent field so we aren't repeating |
439 |
# ourselves here. Or, possibly create GetCircControlBranchField which GetCircControlBranch |
440 |
# would then use, and we could also call here. |
435 |
if (C4::Context->preference('CircControl') eq 'PickupLibrary') { |
441 |
if (C4::Context->preference('CircControl') eq 'PickupLibrary') { |
436 |
$count_query .= " AND issues.branchcode = ? "; |
442 |
$count_query .= " AND issues.branchcode = ? "; |
437 |
push @bind_params, $branch; |
443 |
push @bind_params, $branch; |
438 |
} elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') { |
444 |
} elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') { |
439 |
; # if branch is the patron's home branch, then count all loans by patron |
445 |
; # if branch is the patron's home branch, then count all loans by patron |
440 |
} else { |
446 |
} else { |
441 |
$count_query .= " AND items.homebranch = ? "; |
447 |
my $branchfield = C4::Context->preference('HomeOrHoldingBranch') || 'homebranch'; |
|
|
448 |
$count_query .= " AND items.$branchfield = ? "; |
442 |
push @bind_params, $branch; |
449 |
push @bind_params, $branch; |
443 |
} |
450 |
} |
444 |
} |
451 |
} |
Lines 462-474
sub TooMany {
Link Here
|
462 |
WHERE borrowernumber = ? "; |
469 |
WHERE borrowernumber = ? "; |
463 |
push @bind_params, $borrower->{borrowernumber}; |
470 |
push @bind_params, $borrower->{borrowernumber}; |
464 |
|
471 |
|
|
|
472 |
# FIXME: As above, this code replicates the behavior of GetCircControlBranch. |
465 |
if (C4::Context->preference('CircControl') eq 'PickupLibrary') { |
473 |
if (C4::Context->preference('CircControl') eq 'PickupLibrary') { |
466 |
$branch_count_query .= " AND issues.branchcode = ? "; |
474 |
$branch_count_query .= " AND issues.branchcode = ? "; |
467 |
push @bind_params, $branch; |
475 |
push @bind_params, $branch; |
468 |
} elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') { |
476 |
} elsif (C4::Context->preference('CircControl') eq 'PatronLibrary') { |
469 |
; # if branch is the patron's home branch, then count all loans by patron |
477 |
; # if branch is the patron's home branch, then count all loans by patron |
470 |
} else { |
478 |
} else { |
471 |
$branch_count_query .= " AND items.homebranch = ? "; |
479 |
my $branchfield = C4::Context->preference('HomeOrHoldingBranch') || 'homebranch'; |
|
|
480 |
$count_query .= " AND items.$branchfield = ? "; |
472 |
push @bind_params, $branch; |
481 |
push @bind_params, $branch; |
473 |
} |
482 |
} |
474 |
my $branch_count_sth = $dbh->prepare($branch_count_query); |
483 |
my $branch_count_sth = $dbh->prepare($branch_count_query); |
Lines 715-721
sub CanBookBeIssued {
Link Here
|
715 |
unless ( $duedate ) { |
724 |
unless ( $duedate ) { |
716 |
my $issuedate = $now->clone(); |
725 |
my $issuedate = $now->clone(); |
717 |
|
726 |
|
718 |
my $branch = _GetCircControlBranch($item,$borrower); |
727 |
my $branch = GetCircControlBranch($item,$borrower); |
719 |
my $itype = ( C4::Context->preference('item-level_itypes') ) ? $item->{'itype'} : $biblioitem->{'itemtype'}; |
728 |
my $itype = ( C4::Context->preference('item-level_itypes') ) ? $item->{'itype'} : $biblioitem->{'itemtype'}; |
720 |
$duedate = CalcDateDue( $issuedate, $itype, $branch, $borrower ); |
729 |
$duedate = CalcDateDue( $issuedate, $itype, $branch, $borrower ); |
721 |
|
730 |
|
Lines 1097-1103
sub CanBookBeReturned {
Link Here
|
1097 |
sub checkHighHolds { |
1106 |
sub checkHighHolds { |
1098 |
my ( $item, $borrower ) = @_; |
1107 |
my ( $item, $borrower ) = @_; |
1099 |
my $biblio = GetBiblioFromItemNumber( $item->{itemnumber} ); |
1108 |
my $biblio = GetBiblioFromItemNumber( $item->{itemnumber} ); |
1100 |
my $branch = _GetCircControlBranch( $item, $borrower ); |
1109 |
my $branch = GetCircControlBranch( $item, $borrower ); |
1101 |
my $dbh = C4::Context->dbh; |
1110 |
my $dbh = C4::Context->dbh; |
1102 |
my $sth = $dbh->prepare( |
1111 |
my $sth = $dbh->prepare( |
1103 |
'select count(borrowernumber) as num_holds from reserves where biblionumber=?' |
1112 |
'select count(borrowernumber) as num_holds from reserves where biblionumber=?' |
Lines 1188-1194
sub AddIssue {
Link Here
|
1188 |
if ($borrower and $barcode and $barcodecheck ne '0'){#??? wtf |
1197 |
if ($borrower and $barcode and $barcodecheck ne '0'){#??? wtf |
1189 |
# find which item we issue |
1198 |
# find which item we issue |
1190 |
my $item = GetItem('', $barcode) or return; # if we don't get an Item, abort. |
1199 |
my $item = GetItem('', $barcode) or return; # if we don't get an Item, abort. |
1191 |
my $branch = _GetCircControlBranch($item,$borrower); |
1200 |
my $branch = GetCircControlBranch($item,$borrower); |
1192 |
|
1201 |
|
1193 |
# get actual issuing if there is one |
1202 |
# get actual issuing if there is one |
1194 |
my $actualissue = GetItemIssue( $item->{itemnumber}); |
1203 |
my $actualissue = GetItemIssue( $item->{itemnumber}); |
Lines 1774-1802
sub AddReturn {
Link Here
|
1774 |
if ($doreturn) { |
1783 |
if ($doreturn) { |
1775 |
my $datedue = $issue->{date_due}; |
1784 |
my $datedue = $issue->{date_due}; |
1776 |
$borrower or warn "AddReturn without current borrower"; |
1785 |
$borrower or warn "AddReturn without current borrower"; |
1777 |
my $circControlBranch; |
|
|
1778 |
if ($dropbox) { |
1786 |
if ($dropbox) { |
1779 |
# define circControlBranch only if dropbox mode is set |
|
|
1780 |
# don't allow dropbox mode to create an invalid entry in issues (issuedate > today) |
1787 |
# don't allow dropbox mode to create an invalid entry in issues (issuedate > today) |
1781 |
# FIXME: check issuedate > returndate, factoring in holidays |
1788 |
# FIXME: check issuedate > returndate, factoring in holidays |
1782 |
#$circControlBranch = _GetCircControlBranch($item,$borrower) unless ( $item->{'issuedate'} eq C4::Dates->today('iso') );; |
1789 |
$issue->{'overdue'} = DateTime->compare($issue->{'date_due'}, $today ) == -1 ? 1 : 0; |
1783 |
$circControlBranch = _GetCircControlBranch($item,$borrower); |
|
|
1784 |
$issue->{'overdue'} = DateTime->compare($issue->{'date_due'}, $today ) == -1 ? 1 : 0; |
1785 |
} |
1790 |
} |
1786 |
|
1791 |
|
1787 |
if ($borrowernumber) { |
1792 |
if ($borrowernumber) { |
1788 |
if( C4::Context->preference('CalculateFinesOnReturn') && $issue->{'overdue'}){ |
1793 |
my $circ_control_branchcode = |
1789 |
# we only need to calculate and change the fines if we want to do that on return |
1794 |
GetCircControlBranch( $item, $borrower, $issue ); |
1790 |
# Should be on for hourly loans |
1795 |
|
1791 |
my $control = C4::Context->preference('CircControl'); |
1796 |
if ( $issue->{'overdue'} ) { |
1792 |
my $control_branchcode = |
|
|
1793 |
( $control eq 'ItemHomeLibrary' ) ? $item->{homebranch} |
1794 |
: ( $control eq 'PatronLibrary' ) ? $borrower->{branchcode} |
1795 |
: $issue->{branchcode}; |
1796 |
|
1797 |
|
1797 |
my ( $amount, $type, $unitcounttotal ) = |
1798 |
my ( $amount, $type, $unitcounttotal ) = |
1798 |
C4::Overdues::CalcFine( $item, $borrower->{categorycode}, |
1799 |
C4::Overdues::CalcFine( $item, $borrower->{categorycode}, |
1799 |
$control_branchcode, $datedue, $today ); |
1800 |
$circ_control_branchcode, $datedue, $today ); |
1800 |
|
1801 |
|
1801 |
$type ||= q{}; |
1802 |
$type ||= q{}; |
1802 |
|
1803 |
|
Lines 1810-1816
sub AddReturn {
Link Here
|
1810 |
} |
1811 |
} |
1811 |
|
1812 |
|
1812 |
MarkIssueReturned( $borrowernumber, $item->{'itemnumber'}, |
1813 |
MarkIssueReturned( $borrowernumber, $item->{'itemnumber'}, |
1813 |
$circControlBranch, '', $borrower->{'privacy'} ); |
1814 |
$circ_control_branchcode, '', $borrower->{'privacy'} ); |
1814 |
|
1815 |
|
1815 |
# FIXME is the "= 1" right? This could be the borrower hash. |
1816 |
# FIXME is the "= 1" right? This could be the borrower hash. |
1816 |
$messages->{'WasReturned'} = 1; |
1817 |
$messages->{'WasReturned'} = 1; |
Lines 2019-2025
Should only be called for overdue returns
Link Here
|
2019 |
sub _debar_user_on_return { |
2020 |
sub _debar_user_on_return { |
2020 |
my ( $borrower, $item, $dt_due, $dt_today ) = @_; |
2021 |
my ( $borrower, $item, $dt_due, $dt_today ) = @_; |
2021 |
|
2022 |
|
2022 |
my $branchcode = _GetCircControlBranch( $item, $borrower ); |
2023 |
my $branchcode = GetCircControlBranch( $item, $borrower ); |
2023 |
my $calendar = Koha::Calendar->new( branchcode => $branchcode ); |
2024 |
my $calendar = Koha::Calendar->new( branchcode => $branchcode ); |
2024 |
|
2025 |
|
2025 |
# $deltadays is a DateTime::Duration object |
2026 |
# $deltadays is a DateTime::Duration object |
Lines 2215-2254
sub _FixAccountForLostAndReturned {
Link Here
|
2215 |
return; |
2216 |
return; |
2216 |
} |
2217 |
} |
2217 |
|
2218 |
|
2218 |
=head2 _GetCircControlBranch |
2219 |
=head2 GetCircControlBranch |
2219 |
|
|
|
2220 |
my $circ_control_branch = _GetCircControlBranch($iteminfos, $borrower); |
2221 |
|
2220 |
|
2222 |
Internal function : |
2221 |
my $circ_control_branch = GetCircControlBranch( $item, $borrower[, $issue ] ); |
2223 |
|
2222 |
|
2224 |
Return the library code to be used to determine which circulation |
2223 |
Return the library code to be used to determine which circulation |
2225 |
policy applies to a transaction. Looks up the CircControl and |
2224 |
policy applies to a transaction. Looks up the CircControl and |
2226 |
HomeOrHoldingBranch system preferences. |
2225 |
HomeOrHoldingBranch system preferences. |
2227 |
|
2226 |
|
2228 |
C<$iteminfos> is a hashref to iteminfo. Only {homebranch or holdingbranch} is used. |
2227 |
C<$item> is a hashref for an item. Only {homebranch or holdingbranch} is used. |
|
|
2228 |
|
2229 |
C<$borrower> is a hashref for a borrower. Only {branchcode} is used. |
2230 |
|
2231 |
C<$issue> is a hashref for an issue. Only {branchcode} is used. |
2229 |
|
2232 |
|
2230 |
C<$borrower> is a hashref to borrower. Only {branchcode} is used. |
2233 |
If CircControl is set to "PickupLibrary", GetCircControlBranch returns the currently logged in library branchcode. |
|
|
2234 |
|
2235 |
If CircControl is set to 'PatronLibrary', GetCircControlBranch returns the patron's home library branchcode. |
2236 |
|
2237 |
If CircControl is set to 'ItemHomeLibrary', and $issue is defined, it will return the branchcode for the issue, |
2238 |
othereise it uses the system preference HomeOrHoldingBranch to return either the item's homebranch or its holdingbranch. |
2231 |
|
2239 |
|
2232 |
=cut |
2240 |
=cut |
2233 |
|
2241 |
|
2234 |
sub _GetCircControlBranch { |
2242 |
sub GetCircControlBranch { |
2235 |
my ($item, $borrower) = @_; |
2243 |
my ( $item, $borrower, $issue ) = @_; |
2236 |
my $circcontrol = C4::Context->preference('CircControl'); |
2244 |
my $circcontrol = C4::Context->preference('CircControl'); |
2237 |
my $branch; |
2245 |
my $branch; |
2238 |
|
2246 |
|
2239 |
if ($circcontrol eq 'PickupLibrary' and (C4::Context->userenv and C4::Context->userenv->{'branch'}) ) { |
2247 |
if ( $circcontrol eq 'PickupLibrary' |
2240 |
$branch= C4::Context->userenv->{'branch'}; |
2248 |
&& C4::Context->userenv |
2241 |
} elsif ($circcontrol eq 'PatronLibrary') { |
2249 |
&& C4::Context->userenv->{branch} ) |
2242 |
$branch=$borrower->{branchcode}; |
2250 |
{ |
2243 |
} else { |
2251 |
$branch = C4::Context->userenv->{branch}; |
2244 |
my $branchfield = C4::Context->preference('HomeOrHoldingBranch') || 'homebranch'; |
2252 |
} |
2245 |
$branch = $item->{$branchfield}; |
2253 |
elsif ( $circcontrol eq 'PatronLibrary' ) { |
2246 |
# default to item home branch if holdingbranch is used |
2254 |
$branch = $borrower->{branchcode}; |
2247 |
# and is not defined |
2255 |
} |
2248 |
if (!defined($branch) && $branchfield eq 'holdingbranch') { |
2256 |
elsif ( $circcontrol eq 'ItemHomeLibrary' ) { |
2249 |
$branch = $item->{homebranch}; |
2257 |
if ($issue) { |
|
|
2258 |
$branch = $issue->{branchcode}; |
2259 |
} |
2260 |
else { |
2261 |
my $branch_field = C4::Context->preference('HomeOrHoldingBranch'); |
2262 |
$branch_field ||= 'homebranch'; |
2263 |
|
2264 |
$branch = $item->{$branch_field} || $item->{homebranch}; |
2250 |
} |
2265 |
} |
2251 |
} |
2266 |
} |
|
|
2267 |
|
2252 |
return $branch; |
2268 |
return $branch; |
2253 |
} |
2269 |
} |
2254 |
|
2270 |
|
Lines 2468-2474
sub CanBookBeRenewed {
Link Here
|
2468 |
my $item = GetItem($itemnumber) or return; |
2484 |
my $item = GetItem($itemnumber) or return; |
2469 |
my $itemissue = GetItemIssue($itemnumber) or return; |
2485 |
my $itemissue = GetItemIssue($itemnumber) or return; |
2470 |
|
2486 |
|
2471 |
my $branchcode = _GetCircControlBranch($item, $borrower); |
2487 |
my $branchcode = GetCircControlBranch( $item, $borrower ); |
2472 |
|
2488 |
|
2473 |
my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode); |
2489 |
my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode); |
2474 |
|
2490 |
|
Lines 2631-2637
sub GetRenewCount {
Link Here
|
2631 |
$renewcount = $data->{'renewals'} if $data->{'renewals'}; |
2647 |
$renewcount = $data->{'renewals'} if $data->{'renewals'}; |
2632 |
$sth->finish; |
2648 |
$sth->finish; |
2633 |
# $item and $borrower should be calculated |
2649 |
# $item and $borrower should be calculated |
2634 |
my $branchcode = _GetCircControlBranch($item, $borrower); |
2650 |
my $branchcode = GetCircControlBranch($item, $borrower); |
2635 |
|
2651 |
|
2636 |
my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode); |
2652 |
my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode); |
2637 |
|
2653 |
|