Browse Source

Bug 17829: Move GetMember to Koha::Patron

GetMember returned a patron given a borrowernumber, cardnumber or
userid.
All of these 3 attributes are defined as a unique key at the DB level
and so we can use Koha::Patrons->find to replace this subroutine.
Additionaly GetMember set category_type and description.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
17.11.x
Jonathan Druart 6 years ago
parent
commit
2b90ea2cb0
  1. 19
      C4/Acquisition.pm
  2. 7
      C4/Auth.pm
  3. 5
      C4/Budgets.pm
  4. 188
      C4/Circulation.pm
  5. 11
      C4/HoldsQueue.pm
  6. 54
      C4/ILSDI/Services.pm
  7. 30
      C4/Letters.pm
  8. 63
      C4/Members.pm
  9. 35
      C4/Reserves.pm
  10. 28
      C4/SIP/ILS/Item.pm
  11. 10
      C4/SIP/ILS/Patron.pm
  12. 20
      C4/SIP/ILS/Transaction/Hold.pm
  13. 6
      C4/SIP/ILS/Transaction/Renew.pm
  14. 4
      C4/SIP/ILS/Transaction/RenewAll.pm
  15. 12
      acqui/acqui-home.pl
  16. 10
      acqui/addorderiso2709.pl
  17. 12
      acqui/basket.pl
  18. 8
      acqui/basketgroup.pl
  19. 14
      acqui/booksellers.pl
  20. 6
      acqui/neworderbiblio.pl
  21. 11
      acqui/neworderempty.pl
  22. 11
      acqui/orderreceive.pl
  23. 5
      acqui/transferorder.pl
  24. 15
      admin/aqbudgets.pl
  25. 10
      catalogue/ISBDdetail.pl
  26. 10
      catalogue/MARCdetail.pl
  27. 18
      catalogue/detail.pl
  28. 10
      catalogue/imageviewer.pl
  29. 10
      catalogue/labeledMARCdetail.pl
  30. 15
      catalogue/moredetail.pl
  31. 12
      catalogue/search.pl
  32. 3
      cataloguing/additem.pl
  33. 13
      circ/branchtransfers.pl
  34. 70
      circ/circulation.pl
  35. 112
      circ/returns.pl
  36. 14
      circ/transferstoreceive.pl
  37. 15
      circ/waitingreserves.pl
  38. 18
      members/boraccount.pl
  39. 54
      members/deletemem.pl
  40. 49
      members/discharge.pl
  41. 11
      members/files.pl
  42. 2
      members/housebound.pl
  43. 18
      members/mancredit.pl
  44. 20
      members/maninvoice.pl
  45. 18
      members/member-flags.pl
  46. 19
      members/member-password.pl
  47. 11
      members/member.pl
  48. 14
      members/memberentry.pl
  49. 21
      members/moremember.pl
  50. 11
      members/notices.pl
  51. 7
      members/pay.pl
  52. 7
      members/paycollect.pl
  53. 12
      members/printfeercpt.pl
  54. 12
      members/printinvoice.pl
  55. 17
      members/purchase-suggestions.pl
  56. 15
      members/readingrec.pl
  57. 29
      members/routing-lists.pl
  58. 14
      members/statistics.pl
  59. 7
      members/summary-print.pl
  60. 4
      members/update-child.pl
  61. 5
      misc/cronjobs/advance_notices.pl
  62. 20
      misc/cronjobs/notice_unprocessed_suggestions.pl
  63. 17
      misc/export_borrowers.pl
  64. 4
      misc/load_testing/benchmark_staff.pl
  65. 9
      offline_circ/list.pl
  66. 30
      offline_circ/process_koc.pl
  67. 6
      opac/opac-ISBDdetail.pl
  68. 5
      opac/opac-MARCdetail.pl
  69. 5
      opac/opac-account-pay-paypal-return.pl
  70. 10
      opac/opac-account.pl
  71. 23
      opac/opac-detail.pl
  72. 6
      opac/opac-discharge.pl
  73. 23
      opac/opac-memberentry.pl
  74. 5
      opac/opac-messaging.pl
  75. 7
      opac/opac-passwd.pl
  76. 4
      opac/opac-readingrecord.pl
  77. 5
      opac/opac-registration-verify.pl
  78. 3
      opac/opac-renew.pl
  79. 30
      opac/opac-reserve.pl
  80. 9
      opac/opac-sendbasket.pl
  81. 7
      opac/opac-sendshelf.pl
  82. 7
      opac/opac-shelves.pl
  83. 4
      opac/opac-showreviews.pl
  84. 8
      opac/opac-suggestions.pl
  85. 2
      opac/opac-user.pl
  86. 8
      opac/sco/sco-main.pl
  87. 4
      patroncards/create-pdf.pl
  88. 5
      patroncards/edit-batch.pl
  89. 6
      reserve/placerequest.pl
  90. 76
      reserve/request.pl
  91. 8
      reviews/reviewswaiting.pl
  92. 3
      serials/routing-preview.pl
  93. 3
      serials/routing.pl
  94. 22
      suggestion/suggestion.pl
  95. 5
      svc/members/search
  96. 2
      t/db_dependent/Acquisition/OrderUsers.t
  97. 23
      t/db_dependent/Circulation.t
  98. 1
      t/db_dependent/Circulation/Branch.t
  99. 5
      t/db_dependent/Circulation/CheckIfIssuedToPatron.t
  100. 4
      t/db_dependent/Circulation/GetPendingOnSiteCheckouts.t

19
C4/Acquisition.pm

@ -35,6 +35,7 @@ use Koha::Items;
use Koha::Number::Price;
use Koha::Libraries;
use Koha::CsvProfiles;
use Koha::Patrons;
use C4::Koha;
@ -805,7 +806,7 @@ AcqViewBaskets, user permissions and basket properties (creator, users list,
branch).
First parameter can be either a borrowernumber or a hashref as returned by
C4::Members::GetMember.
Koha::Patron->unblessed
Second parameter can be either a basketno or a hashref as returned by
C4::Acquisition::GetBasket.
@ -822,7 +823,7 @@ sub CanUserManageBasket {
my ($borrower, $basket, $userflags) = @_;
if (!ref $borrower) {
$borrower = C4::Members::GetMember(borrowernumber => $borrower);
$borrower = Koha::Patrons->find( $borrower );
}
if (!ref $basket) {
$basket = GetBasket($basket);
@ -830,7 +831,7 @@ sub CanUserManageBasket {
return 0 unless ($basket and $borrower);
my $borrowernumber = $borrower->{borrowernumber};
my $borrowernumber = $borrower->borrowernumber;
my $basketno = $basket->{basketno};
my $AcqViewBaskets = C4::Context->preference('AcqViewBaskets');
@ -842,7 +843,7 @@ sub CanUserManageBasket {
my ($flags) = $sth->fetchrow_array;
$sth->finish;
$userflags = C4::Auth::getuserflags($flags, $borrower->{userid}, $dbh);
$userflags = C4::Auth::getuserflags($flags, $borrower->userid, $dbh);
}
unless ($userflags->{superlibrarian}
@ -865,7 +866,7 @@ sub CanUserManageBasket {
}
if ($AcqViewBaskets eq 'branch' && defined $basket->{branch}
&& $basket->{branch} ne $borrower->{branchcode}) {
&& $basket->{branch} ne $borrower->branchcode) {
return 0;
}
}
@ -3082,17 +3083,17 @@ sub NotifyOrderUsers {
my $order = GetOrder( $ordernumber );
for my $borrowernumber (@borrowernumbers) {
my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber );
my $library = Koha::Libraries->find( $borrower->{branchcode} )->unblessed;
my $patron = Koha::Patrons->find( $borrowernumber );
my $library = $patron->library->unblessed;
my $biblio = Koha::Biblios->find( $order->{biblionumber} )->unblessed;
my $letter = C4::Letters::GetPreparedLetter(
module => 'acquisition',
letter_code => 'ACQ_NOTIF_ON_RECEIV',
branchcode => $library->{branchcode},
lang => $borrower->{lang},
lang => $patron->lang,
tables => {
'branches' => $library,
'borrowers' => $borrower,
'borrowers' => $patron->unblessed,
'biblio' => $biblio,
'aqorders' => $order,
},

7
C4/Auth.pm

@ -211,7 +211,6 @@ sub get_template_and_user {
my $borrowernumber;
if ($user) {
require C4::Members;
# It's possible for $user to be the borrowernumber if they don't have a
# userid defined (and are logging in through some other method, such
@ -219,8 +218,9 @@ sub get_template_and_user {
my $borrower;
$borrowernumber = getborrowernumber($user) if defined($user);
if ( !defined($borrowernumber) && defined($user) ) {
$borrower = C4::Members::GetMember( borrowernumber => $user );
$borrower = Koha::Patrons->find( $user );
if ($borrower) {
$borrower = $borrower->unblessed;
$borrowernumber = $user;
# A bit of a hack, but I don't know there's a nicer way
@ -228,7 +228,8 @@ sub get_template_and_user {
$user = $borrower->{firstname} . ' ' . $borrower->{surname};
}
} else {
$borrower = C4::Members::GetMember( borrowernumber => $borrowernumber );
$borrower = Koha::Patrons->find( $borrowernumber );
$borrower->unblessed if $borrower; # FIXME Otherwise, what to do?
}
# user info

5
C4/Budgets.pm

@ -21,6 +21,7 @@ use strict;
#use warnings; FIXME - Bug 2505
use C4::Context;
use Koha::Database;
use Koha::Patrons;
use C4::Debug;
use vars qw(@ISA @EXPORT);
@ -915,7 +916,7 @@ sub CanUserUseBudget {
my ($borrower, $budget, $userflags) = @_;
if (not ref $borrower) {
$borrower = C4::Members::GetMember(borrowernumber => $borrower);
$borrower = Koha::Patrons->find( $borrower )->unblessed;
}
if (not ref $budget) {
$budget = GetBudget($budget);
@ -998,7 +999,7 @@ sub CanUserModifyBudget {
my ($borrower, $budget, $userflags) = @_;
if (not ref $borrower) {
$borrower = C4::Members::GetMember(borrowernumber => $borrower);
$borrower = Koha::Patrons->find( $borrower )->unblessed;
}
if (not ref $budget) {
$budget = GetBudget($budget);

188
C4/Circulation.pm

@ -573,7 +573,7 @@ C<$issuingimpossible> and C<$needsconfirmation> are some hashref.
=over 4
=item C<$borrower> hash with borrower informations (from GetMember)
=item C<$borrower> hash with borrower informations (from Koha::Patron->unblessed)
=item C<$barcode> is the bar code of the book being issued.
@ -971,8 +971,8 @@ sub CanBookBeIssued {
elsif ( $issue ) {
# issued to someone else
my $currborinfo = C4::Members::GetMember( borrowernumber => $issue->borrowernumber );
my $patron = Koha::Patrons->find( $issue->borrowernumber );
my ( $can_be_returned, $message ) = CanBookBeReturned( $item, C4::Context->userenv->{branch} );
@ -981,10 +981,10 @@ sub CanBookBeIssued {
$issuingimpossible{branch_to_return} = $message;
} else {
$needsconfirmation{ISSUED_TO_ANOTHER} = 1;
$needsconfirmation{issued_firstname} = $currborinfo->{'firstname'};
$needsconfirmation{issued_surname} = $currborinfo->{'surname'};
$needsconfirmation{issued_cardnumber} = $currborinfo->{'cardnumber'};
$needsconfirmation{issued_borrowernumber} = $currborinfo->{'borrowernumber'};
$needsconfirmation{issued_firstname} = $patron->firstname;
$needsconfirmation{issued_surname} = $patron->surname;
$needsconfirmation{issued_cardnumber} = $patron->cardnumber;
$needsconfirmation{issued_borrowernumber} = $patron->borrowernumber;
}
}
@ -994,28 +994,28 @@ sub CanBookBeIssued {
if ($restype) {
my $resbor = $res->{'borrowernumber'};
if ( $resbor ne $borrower->{'borrowernumber'} ) {
my ( $resborrower ) = C4::Members::GetMember( borrowernumber => $resbor );
my $patron = Koha::Patrons->find( $resbor );
if ( $restype eq "Waiting" )
{
# The item is on reserve and waiting, but has been
# reserved by some other patron.
$needsconfirmation{RESERVE_WAITING} = 1;
$needsconfirmation{'resfirstname'} = $resborrower->{'firstname'};
$needsconfirmation{'ressurname'} = $resborrower->{'surname'};
$needsconfirmation{'rescardnumber'} = $resborrower->{'cardnumber'};
$needsconfirmation{'resborrowernumber'} = $resborrower->{'borrowernumber'};
$needsconfirmation{'resfirstname'} = $patron->firstname;
$needsconfirmation{'ressurname'} = $patron->surname;
$needsconfirmation{'rescardnumber'} = $patron->cardnumber;
$needsconfirmation{'resborrowernumber'} = $patron->borrowernumber;
$needsconfirmation{'resbranchcode'} = $res->{branchcode};
$needsconfirmation{'reswaitingdate'} = $res->{'waitingdate'};
}
elsif ( $restype eq "Reserved" ) {
# The item is on reserve for someone else.
$needsconfirmation{RESERVED} = 1;
$needsconfirmation{'resfirstname'} = $resborrower->{'firstname'};
$needsconfirmation{'ressurname'} = $resborrower->{'surname'};
$needsconfirmation{'rescardnumber'} = $resborrower->{'cardnumber'};
$needsconfirmation{'resborrowernumber'} = $resborrower->{'borrowernumber'};
$needsconfirmation{'resbranchcode'} = $res->{branchcode};
$needsconfirmation{'resreservedate'} = $res->{'reservedate'};
$needsconfirmation{'resfirstname'} = $patron->firstname;
$needsconfirmation{'ressurname'} = $patron->surname;
$needsconfirmation{'rescardnumber'} = $patron->cardnumber;
$needsconfirmation{'resborrowernumber'} = $patron->borrowernumber;
$needsconfirmation{'resbranchcode'} = $patron->branchcode;
$needsconfirmation{'resreservedate'} = $res->{reservedate};
}
}
}
@ -1235,7 +1235,7 @@ Issue a book. Does no check, they are done in CanBookBeIssued. If we reach this
=over 4
=item C<$borrower> is a hash with borrower informations (from GetMember).
=item C<$borrower> is a hash with borrower informations (from Koha::Patron->unblessed).
=item C<$barcode> is the barcode of the item being issued.
@ -1808,7 +1808,7 @@ sub AddReturn {
}
$branch = C4::Context->userenv->{'branch'} unless $branch; # we trust userenv to be a safe fallback/default
my $messages;
my $borrower;
my $patron;
my $doreturn = 1;
my $validTransfert = 0;
my $stat_type = 'return';
@ -1827,7 +1827,7 @@ sub AddReturn {
my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } );
if ( $issue ) {
$borrower = C4::Members::GetMember( borrowernumber => $issue->borrowernumber )
$patron = Koha::Patrons->find( $issue->borrowernumber )
or die "Data inconsistency: barcode $barcode (itemnumber:$itemnumber) claims to be issued to non-existent borrowernumber '" . $issue->borrowernumber . "'\n"
. Dumper($issue->unblessed) . "\n";
} else {
@ -1859,7 +1859,8 @@ sub AddReturn {
my $returnbranch = $item->{$hbr} || $branch ;
# if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
my $borrowernumber = $borrower->{'borrowernumber'} || undef; # we don't know if we had a borrower or not
my $borrowernumber = $patron ? $patron->borrowernumber : undef; # we don't know if we had a borrower or not
my $patron_unblessed = $patron ? $patron->unblessed : {};
my $yaml = C4::Context->preference('UpdateNotForLoanStatusOnCheckin');
if ($yaml) {
@ -1898,7 +1899,7 @@ sub AddReturn {
Rightbranch => $message
};
$doreturn = 0;
return ( $doreturn, $messages, $issue, $borrower );
return ( $doreturn, $messages, $issue, $patron_unblessed);
}
if ( $item->{'withdrawn'} ) { # book has been cancelled
@ -1912,28 +1913,28 @@ sub AddReturn {
if ($doreturn) {
my $is_overdue;
die "The item is not issed and cannot be returned" unless $issue; # Just in case...
$borrower or warn "AddReturn without current borrower";
$patron or warn "AddReturn without current borrower";
my $circControlBranch;
if ($dropbox) {
# define circControlBranch only if dropbox mode is set
# don't allow dropbox mode to create an invalid entry in issues (issuedate > today)
# FIXME: check issuedate > returndate, factoring in holidays
$circControlBranch = _GetCircControlBranch($item,$borrower);
$circControlBranch = _GetCircControlBranch($item,$patron_unblessed);
$is_overdue = $issue->is_overdue( $dropboxdate );
} else {
$is_overdue = $issue->is_overdue;
}
if ($borrowernumber) {
if ($patron) {
eval {
my $issue_id = MarkIssueReturned( $borrowernumber, $item->{'itemnumber'},
$circControlBranch, $return_date, $borrower->{'privacy'} );
$circControlBranch, $return_date, $patron->privacy );
$issue->issue_id($issue_id);
};
unless ( $@ ) {
if ( ( C4::Context->preference('CalculateFinesOnReturn') && $is_overdue ) || $return_date ) {
_CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $borrower, return_date => $return_date } );
_CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $patron_unblessed, return_date => $return_date } );
}
} else {
$messages->{'Wrongbranch'} = {
@ -1941,7 +1942,7 @@ sub AddReturn {
Rightbranch => $message
};
carp $@;
return ( 0, { WasReturned => 0 }, $issue, $borrower );
return ( 0, { WasReturned => 0 }, $issue, $patron_unblessed );
}
# FIXME is the "= 1" right? This could be the borrower hash.
@ -2013,22 +2014,22 @@ sub AddReturn {
if ( $issue and $issue->is_overdue ) {
# fix fine days
$today = $dropboxdate if $dropbox;
my ($debardate,$reminder) = _debar_user_on_return( $borrower, $item, dt_from_string($issue->date_due), $today );
my ($debardate,$reminder) = _debar_user_on_return( $patron_unblessed, $item, dt_from_string($issue->date_due), $today );
if ($reminder){
$messages->{'PrevDebarred'} = $debardate;
} else {
$messages->{'Debarred'} = $debardate if $debardate;
}
# there's no overdue on the item but borrower had been previously debarred
} elsif ( $issue->date_due and $borrower->{'debarred'} ) {
if ( $borrower->{debarred} eq "9999-12-31") {
$messages->{'ForeverDebarred'} = $borrower->{'debarred'};
} elsif ( $issue->date_due and $patron->debarred ) {
if ( $patron->debarred eq "9999-12-31") {
$messages->{'ForeverDebarred'} = $patron->debarred;
} else {
my $borrower_debar_dt = dt_from_string( $borrower->{debarred} );
my $borrower_debar_dt = dt_from_string( $patron->debarred );
$borrower_debar_dt->truncate(to => 'day');
my $today_dt = $today->clone()->truncate(to => 'day');
if ( DateTime->compare( $borrower_debar_dt, $today_dt ) != -1 ) {
$messages->{'PrevDebarred'} = $borrower->{'debarred'};
$messages->{'PrevDebarred'} = $patron->debarred;
}
}
}
@ -2054,29 +2055,31 @@ sub AddReturn {
ccode => $item->{ ccode }
});
# Send a check-in slip. # NOTE: borrower may be undef. probably shouldn't try to send messages then.
my $circulation_alert = 'C4::ItemCirculationAlertPreference';
my %conditions = (
branchcode => $branch,
categorycode => $borrower->{categorycode},
item_type => $item->{itype},
notification => 'CHECKIN',
);
if ($doreturn && $circulation_alert->is_enabled_for(\%conditions)) {
SendCirculationAlert({
type => 'CHECKIN',
item => $item,
borrower => $borrower,
branch => $branch,
});
}
logaction("CIRCULATION", "RETURN", $borrowernumber, $item->{'itemnumber'})
if C4::Context->preference("ReturnLog");
# Send a check-in slip. # NOTE: borrower may be undef. Do not try to send messages then.
if ( $patron ) {
my $circulation_alert = 'C4::ItemCirculationAlertPreference';
my %conditions = (
branchcode => $branch,
categorycode => $patron->categorycode,
item_type => $item->{itype},
notification => 'CHECKIN',
);
if ($doreturn && $circulation_alert->is_enabled_for(\%conditions)) {
SendCirculationAlert({
type => 'CHECKIN',
item => $item,
borrower => $patron->unblessed,
branch => $branch,
});
}
logaction("CIRCULATION", "RETURN", $borrowernumber, $item->{'itemnumber'})
if C4::Context->preference("ReturnLog");
}
# Remove any OVERDUES related debarment if the borrower has no overdues
if ( $borrowernumber
&& $borrower->{'debarred'}
&& $patron->debarred
&& C4::Context->preference('AutoRemoveOverduesRestrictions')
&& !Koha::Patrons->find( $borrowernumber )->has_overdues
&& @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) }
@ -2099,7 +2102,7 @@ sub AddReturn {
}
}
return ( $doreturn, $messages, $issue, $borrower );
return ( $doreturn, $messages, $issue, ( $patron ? $patron->unblessed : {} ));
}
=head2 MarkIssueReturned
@ -2136,7 +2139,7 @@ sub MarkIssueReturned {
# Note that a warning should appear on the about page (System information tab).
$anonymouspatron = C4::Context->preference('AnonymousPatron');
die "Fatal error: the patron ($borrowernumber) has requested their circulation history be anonymized on check-in, but the AnonymousPatron system preference is empty or not set correctly."
unless C4::Members::GetMember( borrowernumber => $anonymouspatron );
unless Koha::Patrons->find( $anonymouspatron );
}
my $database = Koha::Database->new();
my $schema = $database->schema;
@ -2619,7 +2622,7 @@ sub CanBookBeRenewed {
return ( 0, 'onsite_checkout' ) if $issue->onsite_checkout;
$borrowernumber ||= $issue->borrowernumber;
my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber )
my $patron = Koha::Patrons->find( $borrowernumber )
or return;
my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves($itemnumber);
@ -2673,7 +2676,7 @@ sub CanBookBeRenewed {
my $item = GetItem($i);
next if IsItemOnHoldAndFound($i);
for my $b (@borrowernumbers) {
my $borr = $borrowers{$b}//= C4::Members::GetMember(borrowernumber => $b);
my $borr = $borrowers{$b} //= Koha::Patrons->find( $b )->unblessed;
next unless IsAvailableForItemLevelRequest($item, $borr);
next unless CanItemBeReserved($b,$i);
@ -2691,9 +2694,9 @@ sub CanBookBeRenewed {
return ( 1, undef ) if $override_limit;
my $branchcode = _GetCircControlBranch( $item, $borrower );
my $branchcode = _GetCircControlBranch( $item, $patron->unblessed );
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
{ categorycode => $borrower->{categorycode},
{ categorycode => $patron->categorycode,
itemtype => $item->{itype},
branchcode => $branchcode
}
@ -2704,7 +2707,7 @@ sub CanBookBeRenewed {
my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
my $patron = Koha::Patrons->find($borrowernumber);
$patron = Koha::Patrons->find($borrowernumber); # FIXME Is this really useful?
my $restricted = $patron->is_debarred;
my $hasoverdues = $patron->has_overdues;
@ -2738,7 +2741,7 @@ sub CanBookBeRenewed {
if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) {
my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals");
my ( $amountoutstanding ) = C4::Members::GetMemberAccountRecords($borrower->{borrowernumber});
my ( $amountoutstanding ) = C4::Members::GetMemberAccountRecords($patron->borrowernumber);
if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) {
return ( 0, "auto_too_much_oweing" );
}
@ -2831,10 +2834,11 @@ sub AddRenewal {
return;
}
my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ) or return;
my $patron = Koha::Patrons->find( $borrowernumber ) or return; # FIXME Should do more than just return
my $patron_unblessed = $patron->unblessed;
if ( C4::Context->preference('CalculateFinesOnReturn') && $issue->is_overdue ) {
_CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $borrower } );
_CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $patron_unblessed } );
}
_FixOverduesOnReturn( $borrowernumber, $itemnumber );
@ -2847,7 +2851,7 @@ sub AddRenewal {
$datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
dt_from_string( $issue->date_due, 'sql' ) :
DateTime->now( time_zone => C4::Context->tz());
$datedue = CalcDateDue($datedue, $itemtype, _GetCircControlBranch($item, $borrower), $borrower, 'is a renewal');
$datedue = CalcDateDue($datedue, $itemtype, _GetCircControlBranch($item, $patron_unblessed), $patron_unblessed, 'is a renewal');
}
# Update the issues record to have the new due date, and a new count
@ -2883,11 +2887,10 @@ sub AddRenewal {
# Send a renewal slip according to checkout alert preferencei
if ( C4::Context->preference('RenewalSendNotice') eq '1' ) {
$borrower = C4::Members::GetMember( borrowernumber => $borrowernumber );
my $circulation_alert = 'C4::ItemCirculationAlertPreference';
my %conditions = (
branchcode => $branch,
categorycode => $borrower->{categorycode},
categorycode => $patron->categorycode,
item_type => $item->{itype},
notification => 'CHECKOUT',
);
@ -2896,7 +2899,7 @@ sub AddRenewal {
{
type => 'RENEWAL',
item => $item,
borrower => $borrower,
borrower => $patron->unblessed,
branch => $branch,
}
);
@ -2904,10 +2907,9 @@ sub AddRenewal {
}
# Remove any OVERDUES related debarment if the borrower has no overdues
$borrower = C4::Members::GetMember( borrowernumber => $borrowernumber );
if ( $borrowernumber
&& $borrower->{'debarred'}
&& !Koha::Patrons->find( $borrowernumber )->has_overdues
if ( $patron
&& $patron->is_debarred
&& ! $patron->has_overdues
&& @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) }
) {
DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
@ -2939,8 +2941,10 @@ sub GetRenewCount {
my $renewsallowed = 0;
my $renewsleft = 0;
my $borrower = C4::Members::GetMember( borrowernumber => $bornum);
my $item = GetItem($itemno);
my $patron = Koha::Patrons->find( $bornum );
my $item = GetItem($itemno);
return (0, 0, 0) unless $patron or $item; # Wrong call, no renewal allowed
# Look in the issues table for this item, lent to this borrower,
# and not yet returned.
@ -2955,16 +2959,16 @@ sub GetRenewCount {
my $data = $sth->fetchrow_hashref;
$renewcount = $data->{'renewals'} if $data->{'renewals'};
# $item and $borrower should be calculated
my $branchcode = _GetCircControlBranch($item, $borrower);
my $branchcode = _GetCircControlBranch($item, $patron->unblessed);
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
{ categorycode => $borrower->{categorycode},
{ categorycode => $patron->categorycode,
itemtype => $item->{itype},
branchcode => $branchcode
}
);
$renewsallowed = $issuing_rule ? $issuing_rule->renewalsallowed : undef; # FIXME Just replace undef with 0 to get what we expected. But what about the side-effects? TODO LATER
$renewsallowed = $issuing_rule ? $issuing_rule->renewalsallowed : 0;
$renewsleft = $renewsallowed - $renewcount;
if($renewsleft < 0){ $renewsleft = 0; }
return ( $renewcount, $renewsallowed, $renewsleft );
@ -2998,12 +3002,12 @@ sub GetSoonestRenewDate {
my $itemissue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return;
$borrowernumber ||= $itemissue->borrowernumber;
my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber )
my $patron = Koha::Patrons->find( $borrowernumber )
or return;
my $branchcode = _GetCircControlBranch( $item, $borrower );
my $branchcode = _GetCircControlBranch( $item, $patron->unblessed );
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
{ categorycode => $borrower->{categorycode},
{ categorycode => $patron->categorycode,
itemtype => $item->{itype},
branchcode => $branchcode
}
@ -3057,12 +3061,12 @@ sub GetLatestAutoRenewDate {
my $itemissue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return;
$borrowernumber ||= $itemissue->borrowernumber;
my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber )
my $patron = Koha::Patrons->find( $borrowernumber )
or return;
my $branchcode = _GetCircControlBranch( $item, $borrower );
my $branchcode = _GetCircControlBranch( $item, $patron->unblessed );
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
{ categorycode => $borrower->{categorycode},
{ categorycode => $patron->categorycode,
itemtype => $item->{itype},
branchcode => $branchcode
}
@ -3606,12 +3610,12 @@ sub ReturnLostItem{
my ( $borrowernumber, $itemnum ) = @_;
MarkIssueReturned( $borrowernumber, $itemnum );
my $borrower = C4::Members::GetMember( 'borrowernumber'=>$borrowernumber );
my $patron = Koha::Patrons->find( $borrowernumber );
my $item = C4::Items::GetItem( $itemnum );
my $old_note = ($item->{'paidfor'} && ($item->{'paidfor'} ne q{})) ? $item->{'paidfor'}.' / ' : q{};
my @datearr = localtime(time);
my $date = ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
my $bor = "$borrower->{'firstname'} $borrower->{'surname'} $borrower->{'cardnumber'}";
my $bor = $patron->firstname . ' ' . $patron->surname . ' ' . $patron->cardnumber;
ModItem({ paidfor => $old_note."Paid for by $bor $date" }, undef, $itemnum);
}
@ -3630,7 +3634,7 @@ sub LostItem{
# If a borrower lost the item, add a replacement cost to the their record
if ( my $borrowernumber = $issues->{borrowernumber} ){
my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber );
my $patron = Koha::Patrons->find( $borrowernumber );
if (C4::Context->preference('WhenLostForgiveFine')){
my $fix = _FixOverduesOnReturn($borrowernumber, $itemnumber, 1, 0); # 1, 0 = exemptfine, no-dropbox
@ -3642,7 +3646,7 @@ sub LostItem{
#warn " $issues->{'borrowernumber'} / $itemnumber ";
}
MarkIssueReturned($borrowernumber,$itemnumber,undef,undef,$borrower->{'privacy'}) if $mark_returned;
MarkIssueReturned($borrowernumber,$itemnumber,undef,undef,$patron->privacy) if $mark_returned;
}
}
@ -3727,9 +3731,9 @@ sub ProcessOfflineReturn {
sub ProcessOfflineIssue {
my $operation = shift;
my $borrower = C4::Members::GetMember( cardnumber => $operation->{cardnumber} );
my $patron = Koha::Patrons->find( { cardnumber => $operation->{cardnumber} } );
if ( $borrower->{borrowernumber} ) {
if ( $patron ) {
my $item = Koha::Items->find({ barcode => $operation->{barcode} });
unless ($item) {
return "Barcode not found.";
@ -3737,7 +3741,7 @@ sub ProcessOfflineIssue {
my $itemnumber = $item->itemnumber;
my $issue = GetOpenIssue( $itemnumber );
if ( $issue and ( $issue->{borrowernumber} ne $borrower->{borrowernumber} ) ) { # Item already issued to another borrower, mark it returned
if ( $issue and ( $issue->{borrowernumber} ne $patron->borrowernumber ) ) { # Item already issued to another patron mark it returned
MarkIssueReturned(
$issue->{borrowernumber},
$itemnumber,
@ -3746,7 +3750,7 @@ sub ProcessOfflineIssue {
);
}
AddIssue(
$borrower,
$patron->unblessed,
$operation->{'barcode'},
undef,
1,

11
C4/HoldsQueue.pm

@ -29,6 +29,7 @@ use C4::Circulation;
use C4::Members;
use C4::Biblio;
use Koha::DateUtils;
use Koha::Patrons;
use List::Util qw(shuffle);
use List::MoreUtils qw(any);
@ -677,11 +678,11 @@ sub CreatePicklistFromItemMap {
my $barcode = $item->{barcode};
my $itemcallnumber = $item->{itemcallnumber};
my $borrower = GetMember('borrowernumber'=>$borrowernumber);
my $cardnumber = $borrower->{'cardnumber'};
my $surname = $borrower->{'surname'};
my $firstname = $borrower->{'firstname'};
my $phone = $borrower->{'phone'};
my $patron = Koha::Patrons->find( $borrowernumber );
my $cardnumber = $patron->cardnumber;
my $surname = $patron->surname;
my $firstname = $patron->firstname;
my $phone = $patron->phone;
my $bib = GetBiblioData($biblionumber);
my $title = $bib->{title};

54
C4/ILSDI/Services.pm

@ -306,18 +306,12 @@ Parameters:
sub LookupPatron {
my ($cgi) = @_;
# Get the borrower...
my $borrower = GetMember($cgi->param('id_type') => $cgi->param('id'));
if ( not $borrower->{'borrowernumber'} ) {
my $patrons = Koha::Patrons->search( { $cgi->param('id_type') => $cgi->param('id') } );
unless ( $patrons->count ) {
return { message => 'PatronNotFound' };
}
# Build the hashref
my $patron->{'id'} = $borrower->{'borrowernumber'};
return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
# ...and return his ID
return $patron;
return { id => $patrons->next->borrowernumber };
}
=head2 AuthenticatePatron
@ -341,9 +335,8 @@ sub AuthenticatePatron {
my ($status, $cardnumber, $userid) = C4::Auth::checkpw( C4::Context->dbh, $username, $password );
if ( $status ) {
# Get the borrower
my $borrower = GetMember( cardnumber => $cardnumber );
my $patron->{'id'} = $borrower->{'borrowernumber'};
return $patron;
my $patron = Koha::Patrons->find( { cardnumber => $cardnumber } );
return { id => $patron->borrowernumber };
}
else {
return { code => 'PatronNotFound' };
@ -376,11 +369,11 @@ sub GetPatronInfo {
# Get Member details
my $borrowernumber = $cgi->param('patron_id');
my $borrower = GetMember( borrowernumber => $borrowernumber );
return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
my $patron = Koha::Patrons->find( $borrowernumber );
return { code => 'PatronNotFound' } unless $patron;
# Cleaning the borrower hashref
my $borrower = $patron->unblessed;
my $flags = C4::Members::patronflags( $borrower );
$borrower->{'charges'} = $flags->{'CHARGES'}->{'amount'};
my $library = Koha::Libraries->find( $borrower->{branchcode} );
@ -483,14 +476,14 @@ sub GetPatronStatus {
# Get Member details
my $borrowernumber = $cgi->param('patron_id');
my $borrower = GetMember( borrowernumber => $borrowernumber );
return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
my $patron = Koha::Patrons->find( $borrowernumber );
return { code => 'PatronNotFound' } unless $patron;
# Return the results
return {
type => $$borrower{categorycode},
type => $patron->categorycode,
status => 0, # TODO
expiry => $$borrower{dateexpiry},
expiry => $patron->dateexpiry,
};
}
@ -513,11 +506,10 @@ sub GetServices {
# Get the member, or return an error code if not found
my $borrowernumber = $cgi->param('patron_id');
my $borrower = GetMember( borrowernumber => $borrowernumber );
return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
my $patron = Koha::Patrons->find( $borrowernumber );
return { code => 'PatronNotFound' } unless $patron;
my $borrower = $patron->unblessed;
# Get the item, or return an error code if not found
my $itemnumber = $cgi->param('item_id');
my $item = GetItem( $itemnumber );
@ -587,8 +579,8 @@ sub RenewLoan {
# Get borrower infos or return an error code
my $borrowernumber = $cgi->param('patron_id');
my $borrower = GetMember( borrowernumber => $borrowernumber );
return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
my $patron = Koha::Patrons->find( $borrowernumber );
return { code => 'PatronNotFound' } unless $patron;
# Get the item, or return an error code
my $itemnumber = $cgi->param('item_id');
@ -637,8 +629,8 @@ sub HoldTitle {
# Get the borrower or return an error code
my $borrowernumber = $cgi->param('patron_id');
my $borrower = GetMember( borrowernumber => $borrowernumber );
return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
my $patron = Koha::Patrons->find( $borrowernumber );
return { code => 'PatronNotFound' } unless $patron;
# Get the biblio record, or return an error code
my $biblionumber = $cgi->param('bib_id');
@ -657,7 +649,7 @@ sub HoldTitle {
$branch = $cgi->param('pickup_location');
return { code => 'LocationNotFound' } unless Koha::Libraries->find($branch);
} else { # if the request provide no branch, use the borrower's branch
$branch = $$borrower{branchcode};
$branch = $patron->branchcode;
}
# Add the reserve
@ -705,8 +697,8 @@ sub HoldItem {
# Get the borrower or return an error code
my $borrowernumber = $cgi->param('patron_id');
my $borrower = GetMember( borrowernumber => $borrowernumber );
return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
my $patron = Koha::Patrons->find( $borrowernumber );
return { code => 'PatronNotFound' } unless $patron;
# Get the biblio or return an error code
my $biblionumber = $cgi->param('bib_id');
@ -734,7 +726,7 @@ sub HoldItem {
$branch = $cgi->param('pickup_location');
return { code => 'LocationNotFound' } unless Koha::Libraries->find($branch);
} else { # if the request provide no branch, use the borrower's branch
$branch = $$borrower{branchcode};
$branch = $patron->branchcode;
}
# Add the reserve
@ -772,8 +764,8 @@ sub CancelHold {
# Get the borrower or return an error code
my $borrowernumber = $cgi->param('patron_id');
my $borrower = GetMember( borrowernumber => $borrowernumber );
return { code => 'PatronNotFound' } unless $$borrower{borrowernumber};
my $patron = Koha::Patrons->find( $borrowernumber );
return { code => 'PatronNotFound' } unless $patron;
# Get the reserve or return an error code
my $reserve_id = $cgi->param('item_id');

30
C4/Letters.pm

@ -37,6 +37,7 @@ use Koha::SMS::Providers;
use Koha::Email;
use Koha::DateUtils qw( format_sqldatetime dt_from_string );
use Koha::Patrons;
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
@ -416,8 +417,9 @@ sub SendAlerts {
# find the list of borrowers to alert
my $alerts = getalert( '', 'issue', $subscriptionid );
foreach (@$alerts) {
my $borinfo = C4::Members::GetMember('borrowernumber' => $_->{'borrowernumber'});
my $email = $borinfo->{email} or next;
my $patron = Koha::Patrons->find( $_->{borrowernumber} );
next unless $patron; # Just in case
my $email = $patron->email or next;
# warn "sending issues...";
my $userenv = C4::Context->userenv;
@ -430,7 +432,7 @@ sub SendAlerts {
'branches' => $_->{branchcode},
'biblio' => $biblionumber,
'biblioitems' => $biblionumber,
'borrowers' => $borinfo,
'borrowers' => $patron->unblessed,
'subscription' => $subscriptionid,
'serial' => $externalid,
},
@ -1048,15 +1050,15 @@ sub SendQueuedMessages {
}
elsif ( lc( $message->{'message_transport_type'} ) eq 'sms' ) {
if ( C4::Context->preference('SMSSendDriver') eq 'Email' ) {
my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
my $sms_provider = Koha::SMS::Providers->find( $member->{'sms_provider_id'} );
my $patron = Koha::Patrons->find( $message->{borrowernumber} );
my $sms_provider = Koha::SMS::Providers->find( $patron->sms_provider_id );
unless ( $sms_provider ) {
warn sprintf( "Patron %s has no sms provider id set!", $message->{'borrowernumber'} ) if $params->{'verbose'} or $debug;
_set_message_status( { message_id => $message->{'message_id'}, status => 'failed' } );
next MESSAGE;
}
$message->{to_address} ||= $member->{'smsalertnumber'};
unless ( $message->{to_address} && $member->{'smsalertnumber'} ) {
$message->{to_address} ||= $patron->smsalertnumber;
unless ( $message->{to_address} && $patron->smsalertnumber ) {
_set_message_status( { message_id => $message->{'message_id'}, status => 'failed' } );
warn sprintf( "No smsalertnumber found for patron %s!", $message->{'borrowernumber'} ) if $params->{'verbose'} or $debug;
next MESSAGE;
@ -1302,10 +1304,10 @@ sub _send_message_by_email {
my $message = shift or return;
my ($username, $password, $method) = @_;
my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
my $patron = Koha::Patrons->find( $message->{borrowernumber} );
my $to_address = $message->{'to_address'};
unless ($to_address) {
unless ($member) {
unless ($patron) {
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
_set_message_status( { message_id => $message->{'message_id'},
status => 'failed' } );
@ -1330,8 +1332,8 @@ sub _send_message_by_email {
my $branch_email = undef;
my $branch_replyto = undef;
my $branch_returnpath = undef;
if ($member) {
my $library = Koha::Libraries->find( $member->{branchcode} );
if ($patron) {
my $library = $patron->library;
$branch_email = $library->branchemail;
$branch_replyto = $library->branchreplyto;
$branch_returnpath = $library->branchreturnpath;
@ -1407,9 +1409,9 @@ sub _is_duplicate {
sub _send_message_by_sms {
my $message = shift or return;
my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
my $patron = Koha::Patrons->find( $message->{borrowernumber} );
unless ( $member->{smsalertnumber} ) {
unless ( $patron and $patron->smsalertnumber ) {
_set_message_status( { message_id => $message->{'message_id'},
status => 'failed' } );
return;
@ -1421,7 +1423,7 @@ sub _send_message_by_sms {
return;
}
my $success = C4::SMS->send_sms( { destination => $member->{'smsalertnumber'},
my $success = C4::SMS->send_sms( { destination => $patron->smsalertnumber,
message => $message->{'content'},
} );
_set_message_status( { message_id => $message->{'message_id'},

63
C4/Members.pm

@ -60,7 +60,6 @@ BEGIN {
@ISA = qw(Exporter);
#Get data
push @EXPORT, qw(
&GetMember
&GetPendingIssues
&GetAllIssues
@ -280,68 +279,6 @@ sub patronflags {
}
=head2 GetMember
$borrower = &GetMember(%information);
Retrieve the first patron record meeting on criteria listed in the
C<%information> hash, which should contain one or more
pairs of borrowers column names and values, e.g.,
$borrower = GetMember(borrowernumber => id);
C<&GetBorrower> returns a reference-to-hash whose keys are the fields of
the C<borrowers> table in the Koha database.
FIXME: GetMember() is used throughout the code as a lookup
on a unique key such as the borrowernumber, but this meaning is not
enforced in the routine itself.
=cut
#'
sub GetMember {
my ( %information ) = @_;
if (exists $information{borrowernumber} && !defined $information{borrowernumber}) {
#passing mysql's kohaadmin?? Makes no sense as a query
return;
}
my $dbh = C4::Context->dbh;
my $select =
q{SELECT borrowers.*, categories.category_type, categories.description
FROM borrowers
LEFT JOIN categories on borrowers.categorycode=categories.categorycode WHERE };
my $more_p = 0;
my @values = ();
for (keys %information ) {
if ($more_p) {
$select .= ' AND ';
}
else {
$more_p++;
}
if (defined $information{$_}) {
$select .= "$_ = ?";
push @values, $information{$_};
}
else {
$select .= "$_ IS NULL";
}
}
$debug && warn $select, " ",values %information;
my $sth = $dbh->prepare("$select");
$sth->execute(@values);
my $data = $sth->fetchall_arrayref({});
#FIXME interface to this routine now allows generation of a result set
#so whole array should be returned but bowhere in the current code expects this
if (@{$data} ) {
return $data->[0];
}
return;
}
=head2 ModMember
my $success = ModMember(borrowernumber => $borrowernumber,

35
C4/Reserves.pm

@ -226,16 +226,16 @@ sub AddReserve {
# Send e-mail to librarian if syspref is active
if(C4::Context->preference("emailLibrarianWhenHoldIsPlaced")){
my $borrower = C4::Members::GetMember(borrowernumber => $borrowernumber);
my $library = Koha::Libraries->find($borrower->{branchcode})->unblessed;
my $patron = Koha::Patrons->find( $borrowernumber );
my $library = $patron->library;
if ( my $letter = C4::Letters::GetPreparedLetter (
module => 'reserves',
letter_code => 'HOLDPLACED',
branchcode => $branch,
lang => $borrower->{lang},
lang => $patron->lang,
tables => {
'branches' => $library,
'borrowers' => $borrower,
'branches' => $library->unblessed,
'borrowers' => $patron->unblessed,
'biblio' => $biblionumber,
'biblioitems' => $biblionumber,
'items' => $checkitem,
@ -243,7 +243,7 @@ sub AddReserve {
},
) ) {
my $admin_email_address = $library->{'branchemail'} || C4::Context->preference('KohaAdminEmailAddress');
my $admin_email_address = $library->branchemail || C4::Context->preference('KohaAdminEmailAddress');
C4::Letters::EnqueueLetter(
{ letter => $letter,
@ -331,7 +331,8 @@ sub CanItemBeReserved {
# item->{itype} will come for biblioitems if necessery
my $item = GetItem($itemnumber);
my $biblioData = C4::Biblio::GetBiblioData( $item->{biblionumber} );
my $borrower = C4::Members::GetMember( 'borrowernumber' => $borrowernumber );
my $patron = Koha::Patrons->find( $borrowernumber );
my $borrower = $patron->unblessed;
# If an item is damaged and we don't allow holds on damaged items, we can stop right here
return 'damaged'
@ -807,12 +808,12 @@ sub CheckReserves {
if ( $res->{'itemnumber'} == $itemnumber && $res->{'priority'} == 0) {
return ( "Waiting", $res, \@reserves ); # Found it
} else {
my $borrowerinfo;
my $patron;
my $iteminfo;
my $local_hold_match;
if ($LocalHoldsPriority) {
$borrowerinfo = C4::Members::GetMember( borrowernumber => $res->{'borrowernumber'} );
$patron = Koha::Patrons->find( $res->{borrowernumber} );
$iteminfo = C4::Items::GetItem($itemnumber);
my $local_holds_priority_item_branchcode =
@ -821,7 +822,7 @@ sub CheckReserves {
( $LocalHoldsPriorityPatronControl eq 'PickupLibrary' )
? $res->{branchcode}
: ( $LocalHoldsPriorityPatronControl eq 'HomeLibrary' )
? $borrowerinfo->{branchcode}
? $patron->branchcode
: undef;
$local_hold_match =
$local_holds_priority_item_branchcode eq
@ -832,11 +833,11 @@ sub CheckReserves {
if ( ( $res->{'priority'} && $res->{'priority'} < $priority ) || $local_hold_match ) {
$iteminfo ||= C4::Items::GetItem($itemnumber);
next if $res->{itemtype} && $res->{itemtype} ne _get_itype( $iteminfo );
$borrowerinfo ||= C4::Members::GetMember( borrowernumber => $res->{'borrowernumber'} );
my $branch = GetReservesControlBranch( $iteminfo, $borrowerinfo );
$patron ||= Koha::Patrons->find( $res->{borrowernumber} );
my $branch = GetReservesControlBranch( $iteminfo, $patron->unblessed );
my $branchitemrule = C4::Circulation::GetBranchItemRule($branch,$iteminfo->{'itype'});
next if ($branchitemrule->{'holdallowed'} == 0);
next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $borrowerinfo->{'branchcode'}));
next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $patron->branchcode));
next if ( ($branchitemrule->{hold_fulfillment_policy} ne 'any') && ($res->{branchcode} ne $iteminfo->{ $branchitemrule->{hold_fulfillment_policy} }) );
$priority = $res->{'priority'};
$highest = $res;
@ -1808,7 +1809,7 @@ sub _koha_notify_reserve {
my $hold = Koha::Holds->find($reserve_id);
my $borrowernumber = $hold->borrowernumber;
my $borrower = C4::Members::GetMember(borrowernumber => $borrowernumber);
my $patron = Koha::Patrons->find( $borrowernumber );
# Try to get the borrower's email address
my $to_address = C4::Members::GetNoticeEmailAddress($borrowernumber);
@ -1825,10 +1826,10 @@ sub _koha_notify_reserve {
my %letter_params = (
module => 'reserves',
branchcode => $hold->branchcode,
lang => $borrower->{lang},
lang => $patron->lang,
tables => {
'branches' => $library,
'borrowers' => $borrower,
'borrowers' => $patron->unblessed,
'biblio' => $hold->biblionumber,
'biblioitems' => $hold->biblionumber,
'reserves' => $hold->unblessed,
@ -1859,7 +1860,7 @@ sub _koha_notify_reserve {
while ( my ( $mtt, $letter_code ) = each %{ $messagingprefs->{transports} } ) {
next if (
( $mtt eq 'email' and not $to_address ) # No email address
or ( $mtt eq 'sms' and not $borrower->{smsalertnumber} ) # No SMS number
or ( $mtt eq 'sms' and not $patron->smsalertnumber ) # No SMS number
or ( $mtt eq 'phone' and C4::Context->preference('TalkingTechItivaPhoneNotification') ) # Notice is handled by TalkingTech_itiva_outbound.pl
);

28
C4/SIP/ILS/Item.pm

@ -93,9 +93,9 @@ sub new {
my $issue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } );
if ($issue) {
$self->{due_date} = dt_from_string( $issue->date_due, 'sql' )->truncate( to => 'minute' );
my $patron = Koha::Patrons->find( $issue->borrowernumber );
$self->{patron} = $patron->cardnumber;
}
my $borrower = $issue ? GetMember( borrowernumber => $issue->borrowernumber ) : {};
$self->{patron} = $borrower->{'cardnumber'};
my $biblio = Koha::Biblios->find( $self->{biblionumber} );
my $holds = $biblio->current_holds->unblessed;
$self->{hold_queue} = $holds;
@ -175,29 +175,27 @@ sub hold_patron_name {
return $output;
}
my $holder = GetMember(borrowernumber=>$borrowernumber);
my $holder = Koha::Patrons->find( $borrowernumber );
unless ($holder) {
syslog("LOG_ERR", "While checking hold, GetMember failed for borrowernumber '$borrowernumber'");
syslog("LOG_ERR", "While checking hold, failed to retrieve the patron with borrowernumber '$borrowernumber'");
return;
}
my $email = $holder->{email} || '';
my $phone = $holder-