3 # Copyright 2000-2002 Katipo Communications
4 # Copyright 2010 BibLibre
5 # Copyright 2014 ByWater Solutions
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
25 script to do a borrower enquiry/bring up borrower details etc
26 Displays all the details about a borrower
27 written 20/12/99 by chris@katipo.co.nz
28 last modified 21/1/2000 by chris@katipo.co.nz
29 modified 31/1/2001 by chris@katipo.co.nz
30 to not allow items on request to be renewed
32 needs html removed and to use the C4::Output more, but its tricky
37 #use warnings; FIXME - Bug 2505
43 use C4
::Members
::Attributes
;
44 use C4
::Members
::AttributeTypes
;
50 use C4
::Branch
; # GetBranchName
51 use C4
::Form
::MessagingPreferences
;
52 use List
::MoreUtils qw
/uniq/;
53 use C4
::Members
::Attributes
qw(GetBorrowerAttributes);
54 use Koha
::Patron
::Debarments
qw(GetDebarments);
55 use Koha
::Patron
::Images
;
57 if ( C4
::Context
->preference('NorwegianPatronDBEnable') && C4
::Context
->preference('NorwegianPatronDBEnable') == 1 ) {
58 load Koha
::NorwegianPatronDB
, qw( NLGetSyncDataFromBorrowernumber );
65 use Koha
::Patron
::Categories
;
70 $debug = $ENV{DEBUG} || 0;
73 my $dbh = C4::Context->dbh;
76 $debug or $debug = $input->param('debug') || 0;
77 my $print = $input->param('print');
83 if (defined $print and $print eq "page") {
84 $template_name = "members/moremember-print.tt";
85 # circ staff who process checkouts but can't edit
86 # patrons still need to be able to access print view
87 $flagsrequired = { circulate => "circulate_remaining_permissions" };
88 } elsif (defined $print and $print eq "slip") {
89 $template_name = "members/moremember-receipt.tt";
90 # circ staff who process checkouts but can't edit
91 # patrons still need to be able to print receipts
92 $flagsrequired = { circulate => "circulate_remaining_permissions" };
93 } elsif (defined $print and $print eq "qslip") {
94 $template_name = "members/moremember-receipt.tt";
96 $flagsrequired = { circulate => "circulate_remaining_permissions" };
97 } elsif (defined $print and $print eq "brief") {
98 $template_name = "members/moremember-brief.tt";
99 $flagsrequired = { borrowers => 1 };
101 $template_name = "members/moremember.tt";
102 $flagsrequired = { borrowers => 1 };
105 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
107 template_name => $template_name,
110 authnotrequired => 0,
111 flagsrequired => $flagsrequired,
115 my $borrowernumber = $input->param('borrowernumber');
116 my $error = $input->param('error');
117 $template->param( error => $error ) if ( $error );
119 my ( $od, $issue, $fines ) = GetMemberIssuesAndFines($borrowernumber);
120 $template->param( issuecount => $issue, fines => $fines );
122 my $data = GetMember( 'borrowernumber' => $borrowernumber );
124 if ( not defined $data ) {
125 $template->param (unknowuser => 1);
126 output_html_with_http_headers $input, $cookie, $template->output;
130 my $category_type = $data->{'category_type'};
132 $debug and printf STDERR "dates (enrolled,expiry,birthdate) raw: (%s, %s, %s)\n", map {$data->{$_}} qw(dateenrolled dateexpiry dateofbirth);
133 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
134 my $userdate = $data->{$_};
136 $debug and warn sprintf "Empty \$data{%12s}", $_;
140 $template->param( $_ => dt_from_string
( $userdate ) );
142 $data->{'IS_ADULT'} = ( $data->{'categorycode'} ne 'I' );
144 for (qw(gonenoaddress lost borrowernotes)) {
145 $data->{$_} and $template->param(flagged
=> 1) and last;
148 if ( Koha
::Patrons
->find( $borrowernumber )->is_debarred ) {
149 $template->param( 'userdebarred' => 1, 'flagged' => 1 );
150 my $debar = $data->{'debarred'};
151 if ( $debar ne "9999-12-31" ) {
152 $template->param( 'userdebarreddate' => output_pref
( { dt
=> dt_from_string
( $debar ), dateonly
=> 1 } ) );
153 $template->param( 'debarredcomment' => $data->{debarredcomment
} );
157 $data->{ "sex_".$data->{'sex'}."_p" } = 1 if defined $data->{sex
};
159 if ( $category_type eq 'C') {
160 my $patron_categories = Koha
::Patron
::Categories
->search_limited({ category_type
=> 'A' }, {order_by
=> ['categorycode']});
161 $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
162 $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1;
165 my $patron = Koha
::Patrons
->find($data->{borrowernumber
});
167 if ( my $guarantor = $patron->guarantor ) {
168 $template->param( guarantor
=> $guarantor );
169 push @relatives, $guarantor->borrowernumber;
170 push @relatives, $_->borrowernumber for $patron->siblings;
171 } elsif ( $patron->contactname || $patron->contactfirstname ) {
174 firstname
=> $patron->contactfirstname,
175 surname
=> $patron->contactname,
179 my @guarantees = $patron->guarantees;
180 $template->param( guarantees
=> \
@guarantees );
181 push @relatives, $_->borrowernumber for @guarantees;
184 my $relatives_issues_count =
185 Koha
::Database
->new()->schema()->resultset('Issue')
186 ->count( { borrowernumber
=> \
@relatives } );
188 $template->param( adultborrower
=> 1 ) if ( $category_type eq 'A' || $category_type eq 'I' );
191 $bor{'borrowernumber'} = $borrowernumber;
193 # Converts the branchcode to the branch name
195 if ( C4
::Context
->preference("IndependentBranches") ) {
196 my $userenv = C4
::Context
->userenv;
197 if ( C4
::Context
->IsSuperLibrarian() ) {
201 $samebranch = ( $data->{'branchcode'} eq $userenv->{branch
} );
207 my $library = Koha
::Libraries
->find( $data->{branchcode
})->unblessed;
208 @
{$data}{keys %$library} = values %$library; # merge in all branch columns
210 my ( $total, $accts, $numaccts) = GetMemberAccountRecords
( $borrowernumber );
211 my $lib1 = &GetSortDetails
( "Bsort1", $data->{'sort1'} );
212 my $lib2 = &GetSortDetails
( "Bsort2", $data->{'sort2'} );
213 $template->param( lib1
=> $lib1 ) if ($lib1);
214 $template->param( lib2
=> $lib2 ) if ($lib2);
216 # If printing a page, send the account informations to the template
217 if ($print eq "page") {
218 foreach my $accountline (@
$accts) {
219 $accountline->{amount
} = sprintf '%.2f', $accountline->{amount
};
220 $accountline->{amountoutstanding
} = sprintf '%.2f', $accountline->{amountoutstanding
};
222 if ($accountline->{accounttype
} ne 'F' && $accountline->{accounttype
} ne 'FU'){
223 $accountline->{printtitle
} = 1;
226 $template->param( accounts
=> $accts );
229 # Show OPAC privacy preference is system preference is set
230 if ( C4
::Context
->preference('OPACPrivacy') ) {
231 $template->param( OPACPrivacy
=> 1);
232 $template->param( "privacy".$data->{'privacy'} => 1);
235 my $today = DateTime
->now( time_zone
=> C4
::Context
->tz);
236 $today->truncate(to
=> 'day');
237 my $overdues_exist = 0;
240 # Calculate and display patron's age
241 my $dateofbirth = $data->{ 'dateofbirth' };
242 my $age = GetAge
($dateofbirth);
243 $template->param( age
=> $age );
245 ### ###############################################################################
247 # show all reserves of this borrower, and the position of the reservation ....
248 if ($borrowernumber) {
250 holds_count
=> Koha
::Database
->new()->schema()->resultset('Reserve')
251 ->count( { borrowernumber
=> $borrowernumber } ) );
254 # current alert subscriptions
255 my $alerts = getalert
($borrowernumber);
257 $_->{ $_->{type
} } = 1;
258 $_->{relatedto
} = findrelatedto
( $_->{type
}, $_->{externalid
} );
261 # Add sync data to the user data
262 if ( C4
::Context
->preference('NorwegianPatronDBEnable') && C4
::Context
->preference('NorwegianPatronDBEnable') == 1 ) {
263 my $sync = NLGetSyncDataFromBorrowernumber
( $borrowernumber );
265 $data->{'sync'} = $sync->sync;
266 $data->{'syncstatus'} = $sync->syncstatus;
267 $data->{'lastsync'} = $sync->lastsync;
271 # check to see if patron's image exists in the database
272 # basically this gives us a template var to condition the display of
273 # patronimage related interface on
274 my $patron_image = Koha
::Patron
::Images
->find($data->{borrowernumber
});
275 $template->param( picture
=> 1 ) if $patron_image;
277 my $branch=C4
::Context
->userenv->{'branch'};
279 $template->param(%$data);
281 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
282 my $attributes = C4
::Members
::Attributes
::GetBorrowerAttributes
($borrowernumber);
283 my @classes = uniq
( map {$_->{class}} @
$attributes );
284 @classes = sort @classes;
287 for my $class (@classes) {
289 for my $attr (@
$attributes) {
290 push @items, $attr if $attr->{class} eq $class
292 my $lib = GetAuthorisedValueByCode
( 'PA_CLASS', $class ) || $class;
293 push @attributes_loop, {
301 ExtendedPatronAttributes
=> 1,
302 attributes_loop
=> \
@attributes_loop
305 my @types = C4
::Members
::AttributeTypes
::GetAttributeTypes
();
306 if (scalar(@types) == 0) {
307 $template->param(no_patron_attribute_types
=> 1);
311 if (C4
::Context
->preference('EnhancedMessagingPreferences')) {
312 C4
::Form
::MessagingPreferences
::set_form_values
({ borrowernumber
=> $borrowernumber }, $template);
313 $template->param(messaging_form_inactive
=> 1);
314 $template->param(SMSSendDriver
=> C4
::Context
->preference("SMSSendDriver"));
315 $template->param(SMSnumber
=> defined $data->{'smsalertnumber'} ?
$data->{'smsalertnumber'} : $data->{'mobile'});
316 $template->param(TalkingTechItivaPhone
=> C4
::Context
->preference("TalkingTechItivaPhoneNotification"));
319 # in template <TMPL_IF name="I"> => instutitional (A for Adult, C for children)
320 $template->param( $data->{'categorycode'} => 1 );
323 borrowernumber
=> $borrowernumber,
324 othernames
=> $data->{'othernames'},
325 categoryname
=> $data->{'description'},
326 was_renewed
=> scalar $input->param('was_renewed') ?
1 : 0,
328 todaysdate
=> output_pref
({ dt
=> dt_from_string
, dateformat
=> 'iso', dateonly
=> 1 }),
329 totalprice
=> sprintf("%.2f", $totalprice),
330 totaldue
=> sprintf("%.2f", $total),
331 totaldue_raw
=> $total,
332 overdues_exist
=> $overdues_exist,
333 StaffMember
=> ($category_type eq 'S'),
334 is_child
=> ($category_type eq 'C'),
335 samebranch
=> $samebranch,
336 quickslip
=> $quickslip,
337 privacy_guarantor_checkouts
=> $data->{'privacy_guarantor_checkouts'},
338 activeBorrowerRelationship
=> (C4
::Context
->preference('borrowerRelationship') ne ''),
339 AutoResumeSuspendedHolds
=> C4
::Context
->preference('AutoResumeSuspendedHolds'),
340 SuspendHoldsIntranet
=> C4
::Context
->preference('SuspendHoldsIntranet'),
341 RoutingSerials
=> C4
::Context
->preference('RoutingSerials'),
342 debarments
=> GetDebarments
({ borrowernumber
=> $borrowernumber }),
343 PatronsPerPage
=> C4
::Context
->preference("PatronsPerPage") || 20,
344 relatives_issues_count
=> $relatives_issues_count,
345 relatives_borrowernumbers
=> \
@relatives,
348 output_html_with_http_headers
$input, $cookie, $template->output;