Lines 684-691
sub CanBookBeIssued {
Link Here
|
684 |
|
684 |
|
685 |
my $branch = _GetCircControlBranch($item,$borrower); |
685 |
my $branch = _GetCircControlBranch($item,$borrower); |
686 |
my $itype = ( C4::Context->preference('item-level_itypes') ) ? $item->{'itype'} : $biblioitem->{'itemtype'}; |
686 |
my $itype = ( C4::Context->preference('item-level_itypes') ) ? $item->{'itype'} : $biblioitem->{'itemtype'}; |
687 |
my $loanlength = GetLoanLength( $borrower->{'categorycode'}, $itype, $branch ); |
687 |
$duedate = CalcDateDue( C4::Dates->new( $issuedate, 'iso' ), $itype, $branch, $borrower ); |
688 |
$duedate = CalcDateDue( C4::Dates->new( $issuedate, 'iso' ), $loanlength, $branch, $borrower ); |
|
|
689 |
|
688 |
|
690 |
# Offline circ calls AddIssue directly, doesn't run through here |
689 |
# Offline circ calls AddIssue directly, doesn't run through here |
691 |
# So issuingimpossible should be ok. |
690 |
# So issuingimpossible should be ok. |
Lines 1042-1049
sub AddIssue {
Link Here
|
1042 |
); |
1041 |
); |
1043 |
unless ($datedue) { |
1042 |
unless ($datedue) { |
1044 |
my $itype = ( C4::Context->preference('item-level_itypes') ) ? $biblio->{'itype'} : $biblio->{'itemtype'}; |
1043 |
my $itype = ( C4::Context->preference('item-level_itypes') ) ? $biblio->{'itype'} : $biblio->{'itemtype'}; |
1045 |
my $loanlength = GetLoanLength( $borrower->{'categorycode'}, $itype, $branch ); |
1044 |
$datedue = CalcDateDue( C4::Dates->new( $issuedate, 'iso' ), $itype, $branch, $borrower ); |
1046 |
$datedue = CalcDateDue( C4::Dates->new( $issuedate, 'iso' ), $loanlength, $branch, $borrower ); |
|
|
1047 |
|
1045 |
|
1048 |
} |
1046 |
} |
1049 |
$sth->execute( |
1047 |
$sth->execute( |
Lines 1173-1178
sub GetLoanLength {
Link Here
|
1173 |
return 21; |
1171 |
return 21; |
1174 |
} |
1172 |
} |
1175 |
|
1173 |
|
|
|
1174 |
|
1175 |
=head2 GetHardDueDate |
1176 |
|
1177 |
my ($hardduedate,$hardduedatecompare) = &GetHardDueDate($borrowertype,$itemtype,branchcode) |
1178 |
|
1179 |
Get the Hard Due Date and it's comparison for an itemtype, a borrower type and a branch |
1180 |
|
1181 |
=cut |
1182 |
|
1183 |
sub GetHardDueDate { |
1184 |
my ( $borrowertype, $itemtype, $branchcode ) = @_; |
1185 |
my $dbh = C4::Context->dbh; |
1186 |
my $sth = |
1187 |
$dbh->prepare( |
1188 |
"select hardduedate, hardduedatecompare from issuingrules where categorycode=? and itemtype=? and branchcode=?" |
1189 |
); |
1190 |
$sth->execute( $borrowertype, $itemtype, $branchcode ); |
1191 |
my $results = $sth->fetchrow_hashref; |
1192 |
return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare}) |
1193 |
if defined($results) && $results->{hardduedate} ne 'NULL'; |
1194 |
|
1195 |
$sth->execute( $borrowertype, "*", $branchcode ); |
1196 |
$results = $sth->fetchrow_hashref; |
1197 |
return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare}) |
1198 |
if defined($results) && $results->{hardduedate} ne 'NULL'; |
1199 |
|
1200 |
$sth->execute( "*", $itemtype, $branchcode ); |
1201 |
$results = $sth->fetchrow_hashref; |
1202 |
return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare}) |
1203 |
if defined($results) && $results->{hardduedate} ne 'NULL'; |
1204 |
|
1205 |
$sth->execute( "*", "*", $branchcode ); |
1206 |
$results = $sth->fetchrow_hashref; |
1207 |
return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare}) |
1208 |
if defined($results) && $results->{hardduedate} ne 'NULL'; |
1209 |
|
1210 |
$sth->execute( $borrowertype, $itemtype, "*" ); |
1211 |
$results = $sth->fetchrow_hashref; |
1212 |
return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare}) |
1213 |
if defined($results) && $results->{hardduedate} ne 'NULL'; |
1214 |
|
1215 |
$sth->execute( $borrowertype, "*", "*" ); |
1216 |
$results = $sth->fetchrow_hashref; |
1217 |
return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare}) |
1218 |
if defined($results) && $results->{hardduedate} ne 'NULL'; |
1219 |
|
1220 |
$sth->execute( "*", $itemtype, "*" ); |
1221 |
$results = $sth->fetchrow_hashref; |
1222 |
return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare}) |
1223 |
if defined($results) && $results->{hardduedate} ne 'NULL'; |
1224 |
|
1225 |
$sth->execute( "*", "*", "*" ); |
1226 |
$results = $sth->fetchrow_hashref; |
1227 |
return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare}) |
1228 |
if defined($results) && $results->{hardduedate} ne 'NULL'; |
1229 |
|
1230 |
# if no rule is set => return undefined |
1231 |
return (undef, undef); |
1232 |
} |
1233 |
|
1176 |
=head2 GetIssuingRule |
1234 |
=head2 GetIssuingRule |
1177 |
|
1235 |
|
1178 |
my $irule = &GetIssuingRule($borrowertype,$itemtype,branchcode) |
1236 |
my $irule = &GetIssuingRule($borrowertype,$itemtype,branchcode) |
Lines 2197-2211
sub AddRenewal {
Link Here
|
2197 |
unless ($datedue) { |
2255 |
unless ($datedue) { |
2198 |
|
2256 |
|
2199 |
my $borrower = C4::Members::GetMemberDetails( $borrowernumber, 0 ) or return undef; |
2257 |
my $borrower = C4::Members::GetMemberDetails( $borrowernumber, 0 ) or return undef; |
2200 |
my $loanlength = GetLoanLength( |
2258 |
my $itemtype = (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'} , |
2201 |
$borrower->{'categorycode'}, |
|
|
2202 |
(C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'} , |
2203 |
$issuedata->{'branchcode'} ); # that's the circ control branch. |
2204 |
|
2259 |
|
2205 |
$datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ? |
2260 |
$datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ? |
2206 |
C4::Dates->new($issuedata->{date_due}, 'iso') : |
2261 |
C4::Dates->new($issuedata->{date_due}, 'iso') : |
2207 |
C4::Dates->new(); |
2262 |
C4::Dates->new(); |
2208 |
$datedue = CalcDateDue($datedue,$loanlength,$issuedata->{'branchcode'},$borrower); |
2263 |
$datedue = CalcDateDue($datedue,$itemtype,$issuedata->{'branchcode'},$borrower); |
2209 |
} |
2264 |
} |
2210 |
|
2265 |
|
2211 |
# Update the issues record to have the new due date, and a new count |
2266 |
# Update the issues record to have the new due date, and a new count |
Lines 2589-2605
sub UpdateHoldingbranch {
Link Here
|
2589 |
|
2644 |
|
2590 |
=head2 CalcDateDue |
2645 |
=head2 CalcDateDue |
2591 |
|
2646 |
|
2592 |
$newdatedue = CalcDateDue($startdate,$loanlength,$branchcode); |
2647 |
$newdatedue = CalcDateDue($startdate,$itemtype,$branchcode,$borrower); |
2593 |
this function calculates the due date given the loan length , |
2648 |
|
|
|
2649 |
this function calculates the due date given the start date and configured circulation rules, |
2594 |
checking against the holidays calendar as per the 'useDaysMode' syspref. |
2650 |
checking against the holidays calendar as per the 'useDaysMode' syspref. |
2595 |
C<$startdate> = C4::Dates object representing start date of loan period (assumed to be today) |
2651 |
C<$startdate> = C4::Dates object representing start date of loan period (assumed to be today) |
|
|
2652 |
C<$itemtype> = itemtype code of item in question |
2596 |
C<$branch> = location whose calendar to use |
2653 |
C<$branch> = location whose calendar to use |
2597 |
C<$loanlength> = loan length prior to adjustment |
2654 |
C<$borrower> = Borrower object |
2598 |
=cut |
2655 |
=cut |
2599 |
|
2656 |
|
2600 |
sub CalcDateDue { |
2657 |
sub CalcDateDue { |
2601 |
my ($startdate,$loanlength,$branch,$borrower) = @_; |
2658 |
my ($startdate,$itemtype,$branch,$borrower) = @_; |
2602 |
my $datedue; |
2659 |
my $datedue; |
|
|
2660 |
my $loanlength = GetLoanLength($borrower->{'categorycode'},$itemtype, $branch); |
2603 |
|
2661 |
|
2604 |
if(C4::Context->preference('useDaysMode') eq 'Days') { # ignoring calendar |
2662 |
if(C4::Context->preference('useDaysMode') eq 'Days') { # ignoring calendar |
2605 |
my $timedue = time + ($loanlength) * 86400; |
2663 |
my $timedue = time + ($loanlength) * 86400; |
Lines 2611-2629
sub CalcDateDue {
Link Here
|
2611 |
$datedue = $calendar->addDate($startdate, $loanlength); |
2669 |
$datedue = $calendar->addDate($startdate, $loanlength); |
2612 |
} |
2670 |
} |
2613 |
|
2671 |
|
|
|
2672 |
# if Hard Due Dates are used, retreive them and apply as necessary |
2673 |
my ($hardduedate, $hardduedatecompare) = GetHardDueDate($borrower->{'categorycode'},$itemtype, $branch); |
2674 |
if ( $hardduedate->output('iso') && $hardduedate->output('iso') ne '0000-00-00') { |
2675 |
# if the calculated due date is after the 'before' Hard Due Date (ceiling), override |
2676 |
if ( $datedue->output( 'iso' ) gt $hardduedate->output( 'iso' ) && $hardduedatecompare == -1) { |
2677 |
$datedue = $hardduedate; |
2678 |
# if the calculated date is before the 'after' Hard Due Date (floor), override |
2679 |
} elsif ( $datedue->output( 'iso' ) lt $hardduedate->output( 'iso' ) && $hardduedatecompare == 1) { |
2680 |
$datedue = $hardduedate; |
2681 |
# if the hard due date is set to 'exactly', overrride |
2682 |
} elsif ( $hardduedatecompare == 0) { |
2683 |
$datedue = $hardduedate; |
2684 |
} |
2685 |
# in all other cases, keep the date due as it is |
2686 |
} |
2687 |
|
2614 |
# if ReturnBeforeExpiry ON the datedue can't be after borrower expirydate |
2688 |
# if ReturnBeforeExpiry ON the datedue can't be after borrower expirydate |
2615 |
if ( C4::Context->preference('ReturnBeforeExpiry') && $datedue->output('iso') gt $borrower->{dateexpiry} ) { |
2689 |
if ( C4::Context->preference('ReturnBeforeExpiry') && $datedue->output('iso') gt $borrower->{dateexpiry} ) { |
2616 |
$datedue = C4::Dates->new( $borrower->{dateexpiry}, 'iso' ); |
2690 |
$datedue = C4::Dates->new( $borrower->{dateexpiry}, 'iso' ); |
2617 |
} |
2691 |
} |
2618 |
|
2692 |
|
2619 |
# if ceilingDueDate ON the datedue can't be after the ceiling date |
|
|
2620 |
if ( C4::Context->preference('ceilingDueDate') |
2621 |
&& ( C4::Context->preference('ceilingDueDate') =~ C4::Dates->regexp('syspref') ) ) { |
2622 |
my $ceilingDate = C4::Dates->new( C4::Context->preference('ceilingDueDate') ); |
2623 |
if ( $datedue->output( 'iso' ) gt $ceilingDate->output( 'iso' ) ) { |
2624 |
$datedue = $ceilingDate; |
2625 |
} |
2626 |
} |
2627 |
|
2693 |
|
2628 |
return $datedue; |
2694 |
return $datedue; |
2629 |
} |
2695 |
} |