Lines 1294-1300
sub GetHardDueDate {
Link Here
|
1294 |
|
1294 |
|
1295 |
FIXME - This is a copy-paste of GetLoanLength |
1295 |
FIXME - This is a copy-paste of GetLoanLength |
1296 |
as a stop-gap. Do not wish to change API for GetLoanLength |
1296 |
as a stop-gap. Do not wish to change API for GetLoanLength |
1297 |
this close to release, however, Overdues::GetIssuingRules is broken. |
1297 |
this close to release. |
1298 |
|
1298 |
|
1299 |
Get the issuing rule for an itemtype, a borrower type and a branch |
1299 |
Get the issuing rule for an itemtype, a borrower type and a branch |
1300 |
Returns a hashref from the issuingrules table. |
1300 |
Returns a hashref from the issuingrules table. |
Lines 2307-2371
sub CanBookBeRenewed {
Link Here
|
2307 |
my $dbh = C4::Context->dbh; |
2307 |
my $dbh = C4::Context->dbh; |
2308 |
my $renews = 1; |
2308 |
my $renews = 1; |
2309 |
my $renewokay = 0; |
2309 |
my $renewokay = 0; |
2310 |
my $error; |
2310 |
my $error; |
2311 |
|
2311 |
|
2312 |
# Look in the issues table for this item, lent to this borrower, |
2312 |
my $borrower = C4::Members::GetMemberDetails( $borrowernumber, 0 ) or return; |
2313 |
# and not yet returned. |
2313 |
my $item = GetItem($itemnumber) or return; |
|
|
2314 |
my $itemissue = GetItemIssue($itemnumber) or return; |
2314 |
|
2315 |
|
2315 |
# Look in the issues table for this item, lent to this borrower, |
2316 |
my $branchcode = _GetCircControlBranch($item, $borrower); |
2316 |
# and not yet returned. |
|
|
2317 |
my %branch = ( |
2318 |
'ItemHomeLibrary' => 'items.homebranch', |
2319 |
'PickupLibrary' => 'items.holdingbranch', |
2320 |
'PatronLibrary' => 'borrowers.branchcode' |
2321 |
); |
2322 |
my $controlbranch = $branch{C4::Context->preference('CircControl')}; |
2323 |
my $itype = C4::Context->preference('item-level_itypes') ? 'items.itype' : 'biblioitems.itemtype'; |
2324 |
|
2325 |
my $sthcount = $dbh->prepare(" |
2326 |
SELECT |
2327 |
borrowers.categorycode, biblioitems.itemtype, issues.renewals, renewalsallowed, $controlbranch |
2328 |
FROM issuingrules, |
2329 |
issues |
2330 |
LEFT JOIN items USING (itemnumber) |
2331 |
LEFT JOIN borrowers USING (borrowernumber) |
2332 |
LEFT JOIN biblioitems USING (biblioitemnumber) |
2333 |
|
2334 |
WHERE |
2335 |
(issuingrules.categorycode = borrowers.categorycode OR issuingrules.categorycode = '*') |
2336 |
AND |
2337 |
(issuingrules.itemtype = $itype OR issuingrules.itemtype = '*') |
2338 |
AND |
2339 |
(issuingrules.branchcode = $controlbranch OR issuingrules.branchcode = '*') |
2340 |
AND |
2341 |
borrowernumber = ? |
2342 |
AND |
2343 |
itemnumber = ? |
2344 |
ORDER BY |
2345 |
issuingrules.categorycode desc, |
2346 |
issuingrules.itemtype desc, |
2347 |
issuingrules.branchcode desc |
2348 |
LIMIT 1; |
2349 |
"); |
2350 |
|
2351 |
$sthcount->execute( $borrowernumber, $itemnumber ); |
2352 |
if ( my $data1 = $sthcount->fetchrow_hashref ) { |
2353 |
|
2354 |
if ( ( $data1->{renewalsallowed} && $data1->{renewalsallowed} > $data1->{renewals} ) || $override_limit ) { |
2355 |
$renewokay = 1; |
2356 |
} |
2357 |
else { |
2358 |
$error="too_many"; |
2359 |
} |
2360 |
|
2361 |
my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves($itemnumber); |
2362 |
if ($resfound) { |
2363 |
$renewokay = 0; |
2364 |
$error="on_reserve" |
2365 |
} |
2366 |
|
2317 |
|
|
|
2318 |
my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode); |
2319 |
|
2320 |
if ( ( $issuingrule->{renewalsallowed} > $itemissue->{renewals} ) || $override_limit ) { |
2321 |
$renewokay = 1; |
2322 |
} else { |
2323 |
$error = "too_many"; |
2367 |
} |
2324 |
} |
2368 |
return ($renewokay,$error); |
2325 |
|
|
|
2326 |
my ( $resfound, $resrec ) = C4::Reserves::CheckReserves($itemnumber); |
2327 |
if ( $resfound ) { |
2328 |
$renewokay = 0; |
2329 |
$error = "on_reserve"; |
2330 |
} |
2331 |
|
2332 |
return ( $renewokay, $error ); |
2369 |
} |
2333 |
} |
2370 |
|
2334 |
|
2371 |
=head2 AddRenewal |
2335 |
=head2 AddRenewal |
Lines 2876-2929
sub CalcDateDue {
Link Here
|
2876 |
my ( $startdate, $itemtype, $branch, $borrower ) = @_; |
2840 |
my ( $startdate, $itemtype, $branch, $borrower ) = @_; |
2877 |
|
2841 |
|
2878 |
# loanlength now a href |
2842 |
# loanlength now a href |
2879 |
my $loanlength = |
2843 |
my $issuingrule = GetIssuingRule( $borrower->{'categorycode'}, $itemtype, $branch ); |
2880 |
GetLoanLength( $borrower->{'categorycode'}, $itemtype, $branch ); |
2844 |
my $loanlength = $issuingrule->{renewalperiod} |
|
|
2845 |
? |
2846 |
{ |
2847 |
issuelength => $issuingrule->{renewalperiod}, |
2848 |
lengthunit => 'days', |
2849 |
} |
2850 |
: $issuingrule; |
2881 |
|
2851 |
|
2882 |
my $datedue; |
2852 |
my $datedue; |
2883 |
|
2853 |
|
2884 |
# if globalDueDate ON the datedue is set to that date |
2854 |
# calculate the datedue as normal |
2885 |
if (C4::Context->preference('globalDueDate') |
2855 |
if ( C4::Context->preference('useDaysMode') eq 'Days' ) |
2886 |
&& ( C4::Context->preference('globalDueDate') =~ |
2856 |
{ # ignoring calendar |
2887 |
C4::Dates->regexp('syspref') ) |
2857 |
my $dt = |
2888 |
) { |
2858 |
DateTime->now( time_zone => C4::Context->tz() ) |
2889 |
$datedue = dt_from_string( |
2859 |
->truncate( to => 'minute' ); |
2890 |
C4::Context->preference('globalDueDate'), |
2860 |
if ( $loanlength->{lengthunit} eq 'hours' ) { |
2891 |
C4::Context->preference('dateformat') |
2861 |
$dt->add( hours => $loanlength->{issuelength} ); |
2892 |
); |
2862 |
return $dt; |
|
|
2863 |
} else { # days |
2864 |
$dt->add( days => $loanlength->{issuelength} ); |
2865 |
$dt->set_hour(23); |
2866 |
$dt->set_minute(59); |
2867 |
return $dt; |
2868 |
} |
2893 |
} else { |
2869 |
} else { |
2894 |
|
2870 |
my $dur; |
2895 |
# otherwise, calculate the datedue as normal |
2871 |
if ($loanlength->{lengthunit} eq 'hours') { |
2896 |
if ( C4::Context->preference('useDaysMode') eq 'Days' ) |
2872 |
$dur = DateTime::Duration->new( hours => $loanlength->{issuelength}); |
2897 |
{ # ignoring calendar |
2873 |
} |
2898 |
my $dt = |
2874 |
else { # days |
2899 |
DateTime->now( time_zone => C4::Context->tz() ) |
2875 |
$dur = DateTime::Duration->new( days => $loanlength->{issuelength}); |
2900 |
->truncate( to => 'minute' ); |
2876 |
} |
2901 |
if ( $loanlength->{lengthunit} eq 'hours' ) { |
2877 |
if (ref $startdate ne 'DateTime' ) { |
2902 |
$dt->add( hours => $loanlength->{issuelength} ); |
2878 |
$startdate = dt_from_string($startdate); |
2903 |
return $dt; |
2879 |
} |
2904 |
} else { # days |
2880 |
my $calendar = Koha::Calendar->new( branchcode => $branch ); |
2905 |
$dt->add( days => $loanlength->{issuelength} ); |
2881 |
$datedue = $calendar->addDate( $startdate, $dur, $loanlength->{lengthunit} ); |
2906 |
$dt->set_hour(23); |
2882 |
if ($loanlength->{lengthunit} eq 'days') { |
2907 |
$dt->set_minute(59); |
2883 |
$datedue->set_hour(23); |
2908 |
return $dt; |
2884 |
$datedue->set_minute(59); |
2909 |
} |
|
|
2910 |
} else { |
2911 |
my $dur; |
2912 |
if ($loanlength->{lengthunit} eq 'hours') { |
2913 |
$dur = DateTime::Duration->new( hours => $loanlength->{issuelength}); |
2914 |
} |
2915 |
else { # days |
2916 |
$dur = DateTime::Duration->new( days => $loanlength->{issuelength}); |
2917 |
} |
2918 |
if (ref $startdate ne 'DateTime' ) { |
2919 |
$startdate = dt_from_string($startdate); |
2920 |
} |
2921 |
my $calendar = Koha::Calendar->new( branchcode => $branch ); |
2922 |
$datedue = $calendar->addDate( $startdate, $dur, $loanlength->{lengthunit} ); |
2923 |
if ($loanlength->{lengthunit} eq 'days') { |
2924 |
$datedue->set_hour(23); |
2925 |
$datedue->set_minute(59); |
2926 |
} |
2927 |
} |
2885 |
} |
2928 |
} |
2886 |
} |
2929 |
|
2887 |
|