There is no item in the catalog with the given barcode. The value is C<$barcode>.
-=item C<IsPermanent>
-
-The item's home branch is permanent. This doesn't prevent the item from being transferred, though. The value is the code of the item's home branch.
-
=item C<DestinationEqualsHolding>
The item is already at the branch to which it is being transferred. The transfer is nonetheless considered to have failed. The value should be ignored.
}
}
- # if is permanent...
- # FIXME Is this still used by someone?
- # See other FIXME in AddReturn
- my $library = Koha::Libraries->find($hbr);
- if ( $library and $library->get_categories->search({'me.categorycode' => 'PE'})->count ) {
- $messages->{'IsPermanent'} = $hbr;
- $dotransfer = 0;
- }
-
# can't transfer book if is already there....
if ( $fbr eq $tbr ) {
$messages->{'DestinationEqualsHolding'} = 1;
=head2 CanBookBeIssued
- ( $issuingimpossible, $needsconfirmation, [ $alerts ] ) = CanBookBeIssued( $borrower,
+ ( $issuingimpossible, $needsconfirmation, [ $alerts ] ) = CanBookBeIssued( $patron,
$barcode, $duedate, $inprocess, $ignore_reserves, $params );
Check if a book can be issued.
=over 4
-=item C<$borrower> hash with borrower informations (from Koha::Patron->unblessed)
+=item C<$patron> is a Koha::Patron
=item C<$barcode> is the bar code of the book being issued.
=cut
sub CanBookBeIssued {
- my ( $borrower, $barcode, $duedate, $inprocess, $ignore_reserves, $params ) = @_;
+ my ( $patron, $barcode, $duedate, $inprocess, $ignore_reserves, $params ) = @_;
my %needsconfirmation; # filled with problems that needs confirmations
my %issuingimpossible; # filled with problems that causes the issue to be IMPOSSIBLE
my %alerts; # filled with messages that shouldn't stop issuing, but the librarian should be aware of.
my $biblioitem = GetBiblioItemData($item->{biblioitemnumber});
$item->{'itemtype'}=$item->{'itype'};
my $dbh = C4::Context->dbh;
+ my $patron_unblessed = $patron->unblessed;
# MANDATORY CHECKS - unless item exists, nothing else matters
unless ( $item->{barcode} ) {
unless ( $duedate ) {
my $issuedate = $now->clone();
- my $branch = _GetCircControlBranch($item,$borrower);
+ my $branch = _GetCircControlBranch($item, $patron_unblessed);
my $itype = ( C4::Context->preference('item-level_itypes') ) ? $item->{'itype'} : $biblioitem->{'itemtype'};
- $duedate = CalcDateDue( $issuedate, $itype, $branch, $borrower );
+ $duedate = CalcDateDue( $issuedate, $itype, $branch, $patron_unblessed );
# Offline circ calls AddIssue directly, doesn't run through here
# So issuingimpossible should be ok.
#
# BORROWER STATUS
#
- my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
if ( $patron->category->category_type eq 'X' && ( $item->{barcode} )) {
# stats only borrower -- add entry to statistics table, and return issuingimpossible{STATS} = 1 .
&UpdateStats({
type => 'localuse',
itemnumber => $item->{'itemnumber'},
itemtype => $item->{'itype'},
- borrowernumber => $borrower->{'borrowernumber'},
+ borrowernumber => $patron->borrowernumber,
ccode => $item->{'ccode'}}
);
ModDateLastSeen( $item->{'itemnumber'} );
return( { STATS => 1 }, {});
}
- my $flags = C4::Members::patronflags( $borrower );
+ my $flags = C4::Members::patronflags( $patron_unblessed );
if ( ref $flags ) {
if ( $flags->{GNA} ) {
$issuingimpossible{GNA} = 1;
$issuingimpossible{DEBARRED} = 1;
}
}
- if ( !defined $borrower->{dateexpiry} || $borrower->{'dateexpiry'} eq '0000-00-00') {
+
+ if ( $patron->is_expired ) {
$issuingimpossible{EXPIRED} = 1;
- } else {
- my $expiry_dt = dt_from_string( $borrower->{dateexpiry}, 'sql', 'floating' );
- $expiry_dt->truncate( to => 'day');
- my $today = $now->clone()->truncate(to => 'day');
- $today->set_time_zone( 'floating' );
- if ( DateTime->compare($today, $expiry_dt) == 1 ) {
- $issuingimpossible{EXPIRED} = 1;
- }
}
#
#
# DEBTS
- my ($balance, $non_issue_charges, $other_charges) =
- C4::Members::GetMemberAccountBalance( $borrower->{'borrowernumber'} );
+ my $account = $patron->account;
+ my $balance = $account->balance;
+ my $non_issues_charges = $account->non_issues_charges;
+ my $other_charges = $balance - $non_issues_charges;
my $amountlimit = C4::Context->preference("noissuescharge");
my $allowfineoverride = C4::Context->preference("AllowFineOverride");
my $no_issues_charge_guarantees = C4::Context->preference("NoIssuesChargeGuarantees");
$no_issues_charge_guarantees = undef unless looks_like_number( $no_issues_charge_guarantees );
if ( defined $no_issues_charge_guarantees ) {
- my $p = Koha::Patrons->find( $borrower->{borrowernumber} );
- my @guarantees = $p->guarantees();
+ my @guarantees = $patron->guarantees();
my $guarantees_non_issues_charges;
foreach my $g ( @guarantees ) {
- my ( $b, $n, $o ) = C4::Members::GetMemberAccountBalance( $g->id );
- $guarantees_non_issues_charges += $n;
+ $guarantees_non_issues_charges += $g->account->non_issues_charges;
}
if ( $guarantees_non_issues_charges > $no_issues_charge_guarantees && !$inprocess && !$allowfineoverride) {
}
if ( C4::Context->preference("IssuingInProcess") ) {
- 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 );
+ if ( $non_issues_charges > $amountlimit && !$inprocess && !$allowfineoverride) {
+ $issuingimpossible{DEBT} = $non_issues_charges;
+ } elsif ( $non_issues_charges > $amountlimit && !$inprocess && $allowfineoverride) {
+ $needsconfirmation{DEBT} = $non_issues_charges;
+ } elsif ( $allfinesneedoverride && $non_issues_charges > 0 && $non_issues_charges <= $amountlimit && !$inprocess ) {
+ $needsconfirmation{DEBT} = $non_issues_charges;
}
}
else {
- 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 ( $non_issues_charges > $amountlimit && $allowfineoverride ) {
+ $needsconfirmation{DEBT} = $non_issues_charges;
+ } elsif ( $non_issues_charges > $amountlimit && !$allowfineoverride) {
+ $issuingimpossible{DEBT} = $non_issues_charges;
+ } elsif ( $non_issues_charges > 0 && $allfinesneedoverride ) {
+ $needsconfirmation{DEBT} = $non_issues_charges;
}
}
$alerts{OTHER_CHARGES} = sprintf( "%.2f", $other_charges );
}
- $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
+ $patron = Koha::Patrons->find( $patron->borrowernumber ); # FIXME Refetch just in case, to avoid regressions. But must not be needed
+ $patron_unblessed = $patron->unblessed;
+
if ( my $debarred_date = $patron->is_debarred ) {
# patron has accrued fine days or has a restriction. $count is a date
if ($debarred_date eq '9999-12-31') {
#
# CHECK IF BOOK ALREADY ISSUED TO THIS BORROWER
#
- if ( $issue && $issue->borrowernumber eq $borrower->{'borrowernumber'} ){
+ if ( $issue && $issue->borrowernumber eq $patron->borrowernumber ){
# Already issued to current borrower.
# If it is an on-site checkout if it can be switched to a normal checkout
$messages{ONSITE_CHECKOUT_WILL_BE_SWITCHED} = 1;
} else {
my ($CanBookBeRenewed,$renewerror) = CanBookBeRenewed(
- $borrower->{'borrowernumber'},
+ $patron->borrowernumber,
$item->{'itemnumber'},
);
if ( $CanBookBeRenewed == 0 ) { # no more renewals allowed
C4::Context->preference('SwitchOnSiteCheckouts')
and $issue
and $issue->onsite_checkout
- and $issue->borrowernumber == $borrower->{'borrowernumber'} ? 1 : 0 );
- my $toomany = TooMany( $borrower, $item->{biblionumber}, $item, { onsite_checkout => $onsite_checkout, switch_onsite_checkout => $switch_onsite_checkout, } );
+ and $issue->borrowernumber == $patron->borrowernumber ? 1 : 0 );
+ my $toomany = TooMany( $patron_unblessed, $item->{biblionumber}, $item, { onsite_checkout => $onsite_checkout, switch_onsite_checkout => $switch_onsite_checkout, } );
# if TooMany max_allowed returns 0 the user doesn't have permission to check out this book
if ( $toomany && not exists $needsconfirmation{RENEW_ISSUE} ) {
if ( $toomany->{max_allowed} == 0 ) {
#
# CHECKPREVCHECKOUT: CHECK IF ITEM HAS EVER BEEN LENT TO PATRON
#
- $patron = Koha::Patrons->find($borrower->{borrowernumber});
+ $patron = Koha::Patrons->find( $patron->borrowernumber ); # FIXME Refetch just in case, to avoid regressions. But must not be needed
my $wants_check = $patron->wants_check_for_previous_checkout;
$needsconfirmation{PREVISSUE} = 1
if ($wants_check and $patron->do_check_for_previous_checkout($item));
$issuingimpossible{ITEMNOTSAMEBRANCH} = 1;
$issuingimpossible{'itemhomebranch'} = $item->{C4::Context->preference("HomeOrHoldingBranch")};
}
- $needsconfirmation{BORRNOTSAMEBRANCH} = $borrower->{'branchcode'}
- if ( $borrower->{'branchcode'} ne $userenv->{branch} );
+ $needsconfirmation{BORRNOTSAMEBRANCH} = $patron->branchcode
+ if ( $patron->branchcode ne $userenv->{branch} );
}
}
#
my $rentalConfirmation = C4::Context->preference("RentalFeesCheckoutConfirmation");
if ( $rentalConfirmation ){
- my ($rentalCharge) = GetIssuingCharges( $item->{'itemnumber'}, $borrower->{'borrowernumber'} );
+ my ($rentalCharge) = GetIssuingCharges( $item->{'itemnumber'}, $patron->borrowernumber );
if ( $rentalCharge > 0 ){
$needsconfirmation{RENTALCHARGE} = $rentalCharge;
}
my ( $restype, $res ) = C4::Reserves::CheckReserves( $item->{'itemnumber'} );
if ($restype) {
my $resbor = $res->{'borrowernumber'};
- if ( $resbor ne $borrower->{'borrowernumber'} ) {
+ if ( $resbor ne $patron->borrowernumber ) {
my $patron = Koha::Patrons->find( $resbor );
if ( $restype eq "Waiting" )
{
## CHECK AGE RESTRICTION
my $agerestriction = $biblioitem->{'agerestriction'};
- my ($restriction_age, $daysToAgeRestriction) = GetAgeRestriction( $agerestriction, $borrower );
+ my ($restriction_age, $daysToAgeRestriction) = GetAgeRestriction( $agerestriction, $patron->unblessed );
if ( $daysToAgeRestriction && $daysToAgeRestriction > 0 ) {
if ( C4::Context->preference('AgeRestrictionOverride') ) {
$needsconfirmation{AGE_RESTRICTION} = "$agerestriction";
## check for high holds decreasing loan period
if ( C4::Context->preference('decreaseLoanHighHolds') ) {
- my $check = checkHighHolds( $item, $borrower );
+ my $check = checkHighHolds( $item, $patron_unblessed );
if ( $check->{exceeded} ) {
if ($override_high_holds) {
require C4::Serials;
my $is_a_subscription = C4::Serials::CountSubscriptionFromBiblionumber($biblionumber);
unless ($is_a_subscription) {
+ # FIXME Should be $patron->checkouts($args);
my $checkouts = Koha::Checkouts->search(
{
- borrowernumber => $borrower->{borrowernumber},
+ borrowernumber => $patron->borrowernumber,
biblionumber => $biblionumber,
},
{
The book is not currently on loan. The value is C<$barcode>.
-=item C<IsPermanent>
-
-The book's home branch is a permanent collection. If you have borrowed
-this book, you are not allowed to return it. The value is the code for
-the book's home branch.
-
=item C<withdrawn>
This book has been withdrawn/cancelled. The value should be ignored.
}
}
-
- # check if the book is in a permanent collection....
- # FIXME -- This 'PE' attribute is largely undocumented. afaict, there's no user interface that reflects this functionality.
- if ( $returnbranch ) {
- my $library = Koha::Libraries->find($returnbranch);
- if ( $library and $library->get_categories->search({'me.categorycode' => 'PE'})->count ) {
- $messages->{'IsPermanent'} = $returnbranch;
- }
- }
-
# check if the return is allowed at this branch
my ($returnallowed, $message) = CanBookBeReturned($item, $branch);
unless ($returnallowed){
my $dbh = C4::Context->dbh;
my $statement = <<END_SQL;
-SELECT issues.*, items.itype as itemtype, items.homebranch, TO_DAYS( date_due )-TO_DAYS( NOW() ) as days_until_due, branches.branchemail
-FROM issues
-LEFT JOIN items USING (itemnumber)
-LEFT OUTER JOIN branches USING (branchcode)
-WHERE returndate is NULL
-HAVING days_until_due >= 0 AND days_until_due <= ?
+SELECT *
+FROM (
+ SELECT issues.*, items.itype as itemtype, items.homebranch, TO_DAYS( date_due )-TO_DAYS( NOW() ) as days_until_due, branches.branchemail
+ FROM issues
+ LEFT JOIN items USING (itemnumber)
+ LEFT OUTER JOIN branches USING (branchcode)
+ WHERE returndate is NULL
+) tmp
+WHERE days_until_due >= 0 AND days_until_due <= ?
END_SQL
my @bind_parameters = ( $params->{'days_in_advance'} );
if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) {
my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals");
- my ( $amountoutstanding ) = C4::Members::GetMemberAccountRecords($patron->borrowernumber);
+ my $amountoutstanding = $patron->account->balance;
if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) {
return ( 0, "auto_too_much_oweing" );
}
my $dbh = C4::Context->dbh;
my $query = q{
+ SELECT * FROM (
SELECT b.biblionumber, b.title, b.author, bi.itemtype, bi.publishercode,
bi.place, bi.publicationyear, b.copyrightdate, bi.pages, bi.size,
i.ccode, SUM(i.issues) AS count
}
$query .= q{
- GROUP BY b.biblionumber
- HAVING count > 0
+ GROUP BY b.biblionumber, b.title, b.author, bi.itemtype, bi.publishercode,
+ bi.place, bi.publicationyear, b.copyrightdate, bi.pages, bi.size,
+ i.ccode
ORDER BY count DESC
};
+ $query .= q{ ) xxx WHERE count > 0 };
$count = int($count);
if ($count > 0) {
$query .= "LIMIT $count";