use C4::Debug;
use C4::Branch; # GetBranches
use C4::Log; # logaction
-use C4::Koha qw(GetAuthorisedValueByCode);
+use C4::Koha qw(
+ GetAuthorisedValueByCode
+ GetAuthValCode
+ GetKohaAuthorisedValueLib
+);
use C4::Overdues qw(CalcFine UpdateFine);
use Algorithm::CheckDigits;
&GetBiblioIssues
&GetOpenIssue
&AnonymiseIssueHistory
- &CheckIfIssuedToPatron
+ &CheckIfIssuedToPatron
);
# subs to deal with returns
#
# DEBTS
- my ($amount) =
- C4::Members::GetMemberAccountRecords( $borrower->{'borrowernumber'}, '' && $duedate->ymd() );
+ my ($balance, $non_issue_charges, $other_charges) =
+ C4::Members::GetMemberAccountBalance( $borrower->{'borrowernumber'} );
my $amountlimit = C4::Context->preference("noissuescharge");
my $allowfineoverride = C4::Context->preference("AllowFineOverride");
my $allfinesneedoverride = C4::Context->preference("AllFinesNeedOverride");
if ( C4::Context->preference("IssuingInProcess") ) {
- if ( $amount > $amountlimit && !$inprocess && !$allowfineoverride) {
- $issuingimpossible{DEBT} = sprintf( "%.2f", $amount );
- } elsif ( $amount > $amountlimit && !$inprocess && $allowfineoverride) {
- $needsconfirmation{DEBT} = sprintf( "%.2f", $amount );
- } elsif ( $allfinesneedoverride && $amount > 0 && $amount <= $amountlimit && !$inprocess ) {
- $needsconfirmation{DEBT} = sprintf( "%.2f", $amount );
+ if ( $non_issue_charges > $amountlimit && !$inprocess && !$allowfineoverride) {
+ $issuingimpossible{DEBT} = sprintf( "%.2f", $non_issue_charges );
+ } elsif ( $non_issue_charges > $amountlimit && !$inprocess && $allowfineoverride) {
+ $needsconfirmation{DEBT} = sprintf( "%.2f", $non_issue_charges );
+ } elsif ( $allfinesneedoverride && $non_issue_charges > 0 && $non_issue_charges <= $amountlimit && !$inprocess ) {
+ $needsconfirmation{DEBT} = sprintf( "%.2f", $non_issue_charges );
}
}
else {
- if ( $amount > $amountlimit && $allowfineoverride ) {
- $needsconfirmation{DEBT} = sprintf( "%.2f", $amount );
- } elsif ( $amount > $amountlimit && !$allowfineoverride) {
- $issuingimpossible{DEBT} = sprintf( "%.2f", $amount );
- } elsif ( $amount > 0 && $allfinesneedoverride ) {
- $needsconfirmation{DEBT} = sprintf( "%.2f", $amount );
+ if ( $non_issue_charges > $amountlimit && $allowfineoverride ) {
+ $needsconfirmation{DEBT} = sprintf( "%.2f", $non_issue_charges );
+ } elsif ( $non_issue_charges > $amountlimit && !$allowfineoverride) {
+ $issuingimpossible{DEBT} = sprintf( "%.2f", $non_issue_charges );
+ } elsif ( $non_issue_charges > 0 && $allfinesneedoverride ) {
+ $needsconfirmation{DEBT} = sprintf( "%.2f", $non_issue_charges );
}
}
+ if ($balance > 0 && $other_charges > 0) {
+ $alerts{OTHER_CHARGES} = sprintf( "%.2f", $other_charges );
+ }
my ($blocktype, $count) = C4::Members::IsMemberBlocked($borrower->{'borrowernumber'});
if ($blocktype == -1) {
#
# ITEM CHECKING
#
- if ( $item->{'notforloan'}
- && $item->{'notforloan'} > 0 )
+ if ( $item->{'notforloan'} )
{
if(!C4::Context->preference("AllowNotForLoanOverride")){
$issuingimpossible{NOT_FOR_LOAN} = 1;
+ $issuingimpossible{item_notforloan} = $item->{'notforloan'};
}else{
$needsconfirmation{NOT_FOR_LOAN_FORCING} = 1;
+ $needsconfirmation{item_notforloan} = $item->{'notforloan'};
}
}
- elsif ( !$item->{'notforloan'} ){
+ else {
# we have to check itemtypes.notforloan also
if (C4::Context->preference('item-level_itypes')){
# this should probably be a subroutine
if ($notforloan->{'notforloan'}) {
if (!C4::Context->preference("AllowNotForLoanOverride")) {
$issuingimpossible{NOT_FOR_LOAN} = 1;
+ $issuingimpossible{itemtype_notforloan} = $item->{'itype'};
} else {
$needsconfirmation{NOT_FOR_LOAN_FORCING} = 1;
+ $needsconfirmation{itemtype_notforloan} = $item->{'itype'};
}
}
}
elsif ($biblioitem->{'notforloan'} == 1){
if (!C4::Context->preference("AllowNotForLoanOverride")) {
$issuingimpossible{NOT_FOR_LOAN} = 1;
+ $issuingimpossible{itemtype_notforloan} = $biblioitem->{'itemtype'};
} else {
$needsconfirmation{NOT_FOR_LOAN_FORCING} = 1;
+ $needsconfirmation{itemtype_notforloan} = $biblioitem->{'itemtype'};
}
}
}
}
}
- logaction("CIRCULATION", "ISSUE", $borrower->{'borrowernumber'}, $biblio->{'biblionumber'})
+ logaction("CIRCULATION", "ISSUE", $borrower->{'borrowernumber'}, $biblio->{'itemnumber'})
if C4::Context->preference("IssueLog");
}
return ($datedue); # not necessarily the same as when it came in!
sub GetLoanLength {
my ( $borrowertype, $itemtype, $branchcode ) = @_;
my $dbh = C4::Context->dbh;
- my $sth =
- $dbh->prepare(
-'select issuelength, lengthunit from issuingrules where categorycode=? and itemtype=? and branchcode=? and issuelength is not null'
- );
-# warn "in get loan lenght $borrowertype $itemtype $branchcode ";
-# try to find issuelength & return the 1st available.
-# check with borrowertype, itemtype and branchcode, then without one of those parameters
+ my $sth = $dbh->prepare(qq{
+ SELECT issuelength, lengthunit, renewalperiod
+ FROM issuingrules
+ WHERE categorycode=?
+ AND itemtype=?
+ AND branchcode=?
+ AND issuelength IS NOT NULL
+ });
+
+ # try to find issuelength & return the 1st available.
+ # check with borrowertype, itemtype and branchcode, then without one of those parameters
$sth->execute( $borrowertype, $itemtype, $branchcode );
my $loanlength = $sth->fetchrow_hashref;
+
return $loanlength
if defined($loanlength) && $loanlength->{issuelength};
# if no rule is set => 21 days (hardcoded)
return {
issuelength => 21,
+ renewalperiod => 21,
lengthunit => 'days',
};
FIXME - This is a copy-paste of GetLoanLength
as a stop-gap. Do not wish to change API for GetLoanLength
-this close to release, however, Overdues::GetIssuingRules is broken.
+this close to release.
Get the issuing rule for an itemtype, a borrower type and a branch
Returns a hashref from the issuingrules table.
});
}
- logaction("CIRCULATION", "RETURN", $borrowernumber, $item->{'biblionumber'})
+ logaction("CIRCULATION", "RETURN", $borrowernumber, $item->{'itemnumber'})
if C4::Context->preference("ReturnLog");
# FIXME: make this comment intelligible.
Find out whether a borrowed item may be renewed.
-C<$dbh> is a DBI handle to the Koha database.
-
C<$borrowernumber> is the borrower number of the patron who currently
has the item on loan.
the limit on the number of times that the loan can be renewed
(as controlled by the item type) to be ignored.
-C<$CanBookBeRenewed> returns a true value iff the item may be renewed. The
+C<$CanBookBeRenewed> returns a true value if the item may be renewed. The
item must currently be on loan to the specified borrower; renewals
must be allowed for the item's type; and the borrower must not have
already renewed the loan. $error will contain the reason the renewal can not proceed
my $dbh = C4::Context->dbh;
my $renews = 1;
my $renewokay = 0;
- my $error;
+ my $error;
- # Look in the issues table for this item, lent to this borrower,
- # and not yet returned.
+ my $borrower = C4::Members::GetMemberDetails( $borrowernumber, 0 ) or return;
+ my $item = GetItem($itemnumber) or return;
+ my $itemissue = GetItemIssue($itemnumber) or return;
- # Look in the issues table for this item, lent to this borrower,
- # and not yet returned.
- my %branch = (
- 'ItemHomeLibrary' => 'items.homebranch',
- 'PickupLibrary' => 'items.holdingbranch',
- 'PatronLibrary' => 'borrowers.branchcode'
- );
- my $controlbranch = $branch{C4::Context->preference('CircControl')};
- my $itype = C4::Context->preference('item-level_itypes') ? 'items.itype' : 'biblioitems.itemtype';
-
- my $sthcount = $dbh->prepare("
- SELECT
- borrowers.categorycode, biblioitems.itemtype, issues.renewals, renewalsallowed, $controlbranch
- FROM issuingrules,
- issues
- LEFT JOIN items USING (itemnumber)
- LEFT JOIN borrowers USING (borrowernumber)
- LEFT JOIN biblioitems USING (biblioitemnumber)
-
- WHERE
- (issuingrules.categorycode = borrowers.categorycode OR issuingrules.categorycode = '*')
- AND
- (issuingrules.itemtype = $itype OR issuingrules.itemtype = '*')
- AND
- (issuingrules.branchcode = $controlbranch OR issuingrules.branchcode = '*')
- AND
- borrowernumber = ?
- AND
- itemnumber = ?
- ORDER BY
- issuingrules.categorycode desc,
- issuingrules.itemtype desc,
- issuingrules.branchcode desc
- LIMIT 1;
- ");
-
- $sthcount->execute( $borrowernumber, $itemnumber );
- if ( my $data1 = $sthcount->fetchrow_hashref ) {
-
- if ( ( $data1->{renewalsallowed} && $data1->{renewalsallowed} > $data1->{renewals} ) || $override_limit ) {
- $renewokay = 1;
- }
- else {
- $error="too_many";
- }
-
- my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves($itemnumber);
- if ($resfound) {
- $renewokay = 0;
- $error="on_reserve"
- }
+ my $branchcode = _GetCircControlBranch($item, $borrower);
+ my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode);
+
+ if ( ( $issuingrule->{renewalsallowed} > $itemissue->{renewals} ) || $override_limit ) {
+ $renewokay = 1;
+ } else {
+ $error = "too_many";
}
- return ($renewokay,$error);
+
+ my $resstatus = C4::Reserves::GetReserveStatus($itemnumber);
+ if ( $resstatus eq "Waiting" or $resstatus eq "Reserved" ) {
+ $renewokay = 0;
+ $error = "on_reserve";
+ }
+
+ return ( $renewokay, $error );
}
=head2 AddRenewal
my $itemtype = (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'};
$datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
- $issuedata->{date_due} :
+ dt_from_string( $issuedata->{date_due} ) :
DateTime->now( time_zone => C4::Context->tz());
- $datedue = CalcDateDue($datedue,$itemtype,$issuedata->{'branchcode'},$borrower);
+ $datedue = CalcDateDue($datedue, $itemtype, $issuedata->{'branchcode'}, $borrower, 'is a renewal');
}
# Update the issues record to have the new due date, and a new count
C<$itemtype> = itemtype code of item in question
C<$branch> = location whose calendar to use
C<$borrower> = Borrower object
+C<$isrenewal> = Boolean: is true if we want to calculate the date due for a renewal. Else is false.
=cut
sub CalcDateDue {
- my ( $startdate, $itemtype, $branch, $borrower ) = @_;
+ my ( $startdate, $itemtype, $branch, $borrower, $isrenewal ) = @_;
+
+ $isrenewal ||= 0;
# loanlength now a href
my $loanlength =
- GetLoanLength( $borrower->{'categorycode'}, $itemtype, $branch );
+ GetLoanLength( $borrower->{'categorycode'}, $itemtype, $branch );
- my $datedue;
+ my $length_key = ( $isrenewal and defined $loanlength->{renewalperiod} )
+ ? qq{renewalperiod}
+ : qq{issuelength};
- # if globalDueDate ON the datedue is set to that date
- if (C4::Context->preference('globalDueDate')
- && ( C4::Context->preference('globalDueDate') =~
- C4::Dates->regexp('syspref') )
- ) {
- $datedue = dt_from_string(
- C4::Context->preference('globalDueDate'),
- C4::Context->preference('dateformat')
- );
+ my $datedue;
+ if ( $startdate ) {
+ if (ref $startdate ne 'DateTime' ) {
+ $datedue = dt_from_string($datedue);
+ } else {
+ $datedue = $startdate->clone;
+ }
} else {
+ $datedue =
+ DateTime->now( time_zone => C4::Context->tz() )
+ ->truncate( to => 'minute' );
+ }
- # otherwise, calculate the datedue as normal
- if ( C4::Context->preference('useDaysMode') eq 'Days' )
- { # ignoring calendar
- my $dt =
- DateTime->now( time_zone => C4::Context->tz() )
- ->truncate( to => 'minute' );
- if ( $loanlength->{lengthunit} eq 'hours' ) {
- $dt->add( hours => $loanlength->{issuelength} );
- } else { # days
- $dt->add( days => $loanlength->{issuelength} );
- $dt->set_hour(23);
- $dt->set_minute(59);
- }
- # break
- return $dt;
- } else {
- my $dur;
- if ($loanlength->{lengthunit} eq 'hours') {
- $dur = DateTime::Duration->new( hours => $loanlength->{issuelength});
- }
- else { # days
- $dur = DateTime::Duration->new( days => $loanlength->{issuelength});
- }
- if (ref $startdate ne 'DateTime' ) {
- $startdate = dt_from_string($startdate);
- }
- my $calendar = Koha::Calendar->new( branchcode => $branch );
- $datedue = $calendar->addDate( $startdate, $dur, $loanlength->{lengthunit} );
- if ($loanlength->{lengthunit} eq 'days') {
- $datedue->set_hour(23);
- $datedue->set_minute(59);
- }
+ # calculate the datedue as normal
+ if ( C4::Context->preference('useDaysMode') eq 'Days' )
+ { # ignoring calendar
+ if ( $loanlength->{lengthunit} eq 'hours' ) {
+ $datedue->add( hours => $loanlength->{$length_key} );
+ } else { # days
+ $datedue->add( days => $loanlength->{$length_key} );
+ $datedue->set_hour(23);
+ $datedue->set_minute(59);
+ }
+ } else {
+ my $dur;
+ if ($loanlength->{lengthunit} eq 'hours') {
+ $dur = DateTime::Duration->new( hours => $loanlength->{$length_key});
+ }
+ else { # days
+ $dur = DateTime::Duration->new( days => $loanlength->{$length_key});
+ }
+ my $calendar = Koha::Calendar->new( branchcode => $branch );
+ $datedue = $calendar->addDate( $datedue, $dur, $loanlength->{lengthunit} );
+ if ($loanlength->{lengthunit} eq 'days') {
+ $datedue->set_hour(23);
+ $datedue->set_minute(59);
}
}
}
# in all other cases, keep the date due as it is
+
}
# if ReturnBeforeExpiry ON the datedue can't be after borrower expirydate
}
sub AddOfflineOperation {
+ my ( $userid, $branchcode, $timestamp, $action, $barcode, $cardnumber, $amount ) = @_;
my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("INSERT INTO pending_offline_operations (userid, branchcode, timestamp, action, barcode, cardnumber) VALUES(?,?,?,?,?,?)");
- $sth->execute( @_ );
+ my $sth = $dbh->prepare("INSERT INTO pending_offline_operations (userid, branchcode, timestamp, action, barcode, cardnumber, amount) VALUES(?,?,?,?,?,?,?)");
+ $sth->execute( $userid, $branchcode, $timestamp, $action, $barcode, $cardnumber, $amount );
return "Added.";
}
$report = ProcessOfflineReturn( $operation );
} elsif ( $operation->{action} eq 'issue' ) {
$report = ProcessOfflineIssue( $operation );
+ } elsif ( $operation->{action} eq 'payment' ) {
+ $report = ProcessOfflinePayment( $operation );
}
DeleteOfflineOperation( $operation->{operationid} ) if $operation->{operationid};
}
}
+sub ProcessOfflinePayment {
+ my $operation = shift;
+
+ my $borrower = C4::Members::GetMemberDetails( undef, $operation->{cardnumber} ); # Get borrower from operation cardnumber
+ my $amount = $operation->{amount};
+
+ recordpayment( $borrower->{borrowernumber}, $amount );
+
+ return "Success."
+}
=head2 TransferSlip
=cut
sub CheckIfIssuedToPatron {
- my ($borrowernumber, $biblionumber) = @_;
- my $isissued = 0;
+ my ($borrowernumber, $biblionumber) = @_;
- my $items = GetItemsByBiblioitemnumber($biblionumber);
+ my $items = GetItemsByBiblioitemnumber($biblionumber);
- foreach my $item (@{$items}) {
- $isissued = 1 if ($item->{borrowernumber} && $item->{borrowernumber} eq $borrowernumber);
- }
+ foreach my $item (@{$items}) {
+ return 1 if ($item->{borrowernumber} && $item->{borrowernumber} eq $borrowernumber);
+ }
- return $isissued;
+ return;
}