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 under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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;
51 use C4::Branch; # GetBranchName
52 use C4::Form::MessagingPreferences;
53 use List::MoreUtils qw/uniq/;
54 use C4::Members::Attributes qw(GetBorrowerAttributes);
55 use Koha::Borrower::Debarments qw(GetDebarments IsDebarred);
65 $debug = $ENV{DEBUG} || 0;
68 my $dbh = C4::Context->dbh;
71 $debug or $debug = $input->param('debug') || 0;
72 my $print = $input->param('print');
78 if ($print eq "page") {
79 $template_name = "members/moremember-print.tmpl";
80 # circ staff who process checkouts but can't edit
81 # patrons still need to be able to access print view
82 $flagsrequired = { circulate => "circulate_remaining_permissions" };
83 } elsif ($print eq "slip") {
84 $template_name = "members/moremember-receipt.tmpl";
85 # circ staff who process checkouts but can't edit
86 # patrons still need to be able to print receipts
87 $flagsrequired = { circulate => "circulate_remaining_permissions" };
88 } elsif ($print eq "qslip") {
89 $template_name = "members/moremember-receipt.tmpl";
91 $flagsrequired = { circulate => "circulate_remaining_permissions" };
92 } elsif ($print eq "brief") {
93 $template_name = "members/moremember-brief.tmpl";
94 $flagsrequired = { borrowers => 1 };
96 $template_name = "members/moremember.tmpl";
97 $flagsrequired = { borrowers => 1 };
100 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
102 template_name => $template_name,
105 authnotrequired => 0,
106 flagsrequired => $flagsrequired,
110 my $borrowernumber = $input->param('borrowernumber');
112 my ( $od, $issue, $fines ) = GetMemberIssuesAndFines($borrowernumber);
113 $template->param( issuecount => $issue );
115 my $data = GetMember( 'borrowernumber' => $borrowernumber );
117 if ( not defined $data ) {
118 $template->param (unknowuser => 1);
119 output_html_with_http_headers $input, $cookie, $template->output;
123 my $category_type = $data->{'category_type'};
125 $debug and printf STDERR "dates (enrolled,expiry,birthdate) raw: (%s, %s, %s)\n", map {$data->{$_}} qw(dateenrolled dateexpiry dateofbirth);
126 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
127 my $userdate = $data->{$_};
129 $debug and warn sprintf "Empty \$data{%12s}", $_;
133 $userdate = C4::Dates->new($userdate,'iso')->output('syspref');
134 $data->{$_} = $userdate || '';
135 $template->param( $_ => $userdate );
137 $data->{'IS_ADULT'} = ( $data->{'categorycode'} ne 'I' );
139 for (qw(gonenoaddress lost borrowernotes)) {
140 $data->{$_} and $template->param(flagged => 1) and last;
143 if ( IsDebarred($borrowernumber) ) {
144 $template->param( 'userdebarred' => 1, 'flagged' => 1 );
145 my $debar = $data->{'debarred'};
146 if ( $debar ne "9999-12-31" ) {
147 $template->param( 'userdebarreddate' => C4::Dates::format_date($debar) );
148 $template->param( 'debarredcomment' => $data->{debarredcomment} );
152 $data->{'ethnicity'} = fixEthnicity( $data->{'ethnicity'} );
153 $data->{ "sex_".$data->{'sex'}."_p" } = 1;
156 if ( $category_type eq 'C') {
157 my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
158 my $cnt = scalar(@$catcodes);
160 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
161 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
165 if ( $data->{'ethnicity'} || $data->{'ethnotes'} ) {
166 $template->param( printethnicityline => 1 );
168 if ( $category_type eq 'A' || $category_type eq 'I') {
169 $template->param( isguarantee => 1 );
172 # It looks like the $i is only being returned to handle walking through
173 # the array, which is probably better done as a foreach loop.
175 my ( $count, $guarantees ) = GetGuarantees( $data->{'borrowernumber'} );
177 for ( my $i = 0 ; $i < $count ; $i++ ) {
180 borrowernumber => $guarantees->[$i]->{'borrowernumber'},
181 cardnumber => $guarantees->[$i]->{'cardnumber'},
182 name => $guarantees->[$i]->{'firstname'} . " "
183 . $guarantees->[$i]->{'surname'}
187 $template->param( guaranteeloop => \@guaranteedata );
190 if ($data->{'guarantorid'}){
191 my ($guarantor) = GetMember( 'borrowernumber' =>$data->{'guarantorid'});
192 $template->param(guarantor => 1);
193 foreach (qw(borrowernumber cardnumber firstname surname)) {
194 $template->param("guarantor$_" => $guarantor->{$_});
197 if ($category_type eq 'C'){
198 $template->param('C' => 1);
202 $template->param( adultborrower => 1 ) if ( $category_type eq 'A' || $category_type eq 'I' );
205 $bor{'borrowernumber'} = $borrowernumber;
207 # Converts the branchcode to the branch name
209 if ( C4::Context->preference("IndependentBranches") ) {
210 my $userenv = C4::Context->userenv;
211 if ( C4::Context->IsSuperLibrarian() ) {
215 $samebranch = ( $data->{'branchcode'} eq $userenv->{branch} );
221 my $branchdetail = GetBranchDetail( $data->{'branchcode'});
222 @{$data}{keys %$branchdetail} = values %$branchdetail; # merge in all branch columns
224 my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
225 my $lib1 = &GetSortDetails( "Bsort1", $data->{'sort1'} );
226 my $lib2 = &GetSortDetails( "Bsort2", $data->{'sort2'} );
227 $template->param( lib1 => $lib1 ) if ($lib1);
228 $template->param( lib2 => $lib2 ) if ($lib2);
230 # If printing a page, send the account informations to the template
231 if ($print eq "page") {
232 foreach my $accountline (@$accts) {
233 $accountline->{amount} = sprintf '%.2f', $accountline->{amount};
234 $accountline->{amountoutstanding} = sprintf '%.2f', $accountline->{amountoutstanding};
236 if ($accountline->{accounttype} ne 'F' && $accountline->{accounttype} ne 'FU'){
237 $accountline->{printtitle} = 1;
240 $template->param( accounts => $accts );
243 # Show OPAC privacy preference is system preference is set
244 if ( C4::Context->preference('OPACPrivacy') ) {
245 $template->param( OPACPrivacy => 1);
246 $template->param( "privacy".$data->{'privacy'} => 1);
249 my @relatives = GetMemberRelatives($borrowernumber);
250 my $relatives_issues_count =
251 Koha::Database->new()->schema()->resultset('Issue')
252 ->count( { borrowernumber => \@relatives } );
254 my $roadtype = C4::Koha::GetAuthorisedValueByCode( 'ROADTYPE', $data->{streettype} );
255 my $today = DateTime->now( time_zone => C4::Context->tz);
256 $today->truncate(to => 'day');
257 my @borrowers_with_issues;
258 my $overdues_exist = 0;
261 ### ###############################################################################
263 # show all reserves of this borrower, and the position of the reservation ....
264 if ($borrowernumber) {
266 holds_count => Koha::Database->new()->schema()->resultset('Reserve')
267 ->count( { borrowernumber => $borrowernumber } ) );
270 # current alert subscriptions
271 my $alerts = getalert($borrowernumber);
273 $_->{ $_->{type} } = 1;
274 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
278 my $userenv = C4::Context->userenv;
279 if ( C4::Context->IsSuperLibrarian() ) {
282 elsif ( C4::Context->preference("IndependentBranches") ) {
283 $candeleteuser = ( $data->{'branchcode'} eq $userenv->{branch} );
286 if ( C4::Auth::getuserflags( $userenv->{flags}, $userenv->{number} )->{borrowers} ) {
294 # check to see if patron's image exists in the database
295 # basically this gives us a template var to condition the display of
296 # patronimage related interface on
297 my ($picture, $dberror) = GetPatronImage($data->{'borrowernumber'});
298 $template->param( picture => 1 ) if $picture;
300 my $branch=C4::Context->userenv->{'branch'};
302 $template->param(%$data);
304 if (C4::Context->preference('ExtendedPatronAttributes')) {
305 my $attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
306 my @classes = uniq( map {$_->{class}} @$attributes );
307 @classes = sort @classes;
310 for my $class (@classes) {
312 for my $attr (@$attributes) {
313 push @items, $attr if $attr->{class} eq $class
315 my $lib = GetAuthorisedValueByCode( 'PA_CLASS', $class ) || $class;
316 push @attributes_loop, {
324 ExtendedPatronAttributes => 1,
325 attributes_loop => \@attributes_loop
328 my @types = C4::Members::AttributeTypes::GetAttributeTypes();
329 if (scalar(@types) == 0) {
330 $template->param(no_patron_attribute_types => 1);
334 if (C4::Context->preference('EnhancedMessagingPreferences')) {
335 C4::Form::MessagingPreferences::set_form_values({ borrowernumber => $borrowernumber }, $template);
336 $template->param(messaging_form_inactive => 1);
337 $template->param(SMSSendDriver => C4::Context->preference("SMSSendDriver"));
338 $template->param(SMSnumber => defined $data->{'smsalertnumber'} ? $data->{'smsalertnumber'} : $data->{'mobile'});
339 $template->param(TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification"));
342 # in template <TMPL_IF name="I"> => instutitional (A for Adult, C for children)
343 $template->param( $data->{'categorycode'} => 1 );
346 AllowRenewalLimitOverride => C4::Context->preference("AllowRenewalLimitOverride"),
347 CANDELETEUSER => $candeleteuser,
348 roadtype => $roadtype,
349 borrowernumber => $borrowernumber,
350 othernames => $data->{'othernames'},
351 categoryname => $data->{'description'},
352 was_renewed => $input->param('was_renewed') ? 1 : 0,
354 todaysdate => C4::Dates->today(),
355 totalprice => sprintf("%.2f", $totalprice),
356 totaldue => sprintf("%.2f", $total),
357 totaldue_raw => $total,
358 overdues_exist => $overdues_exist,
359 StaffMember => ($category_type eq 'S'),
360 is_child => ($category_type eq 'C'),
361 samebranch => $samebranch,
362 quickslip => $quickslip,
363 activeBorrowerRelationship => (C4::Context->preference('borrowerRelationship') ne ''),
364 AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
365 SuspendHoldsIntranet => C4::Context->preference('SuspendHoldsIntranet'),
366 RoutingSerials => C4::Context->preference('RoutingSerials'),
367 debarments => GetDebarments({ borrowernumber => $borrowernumber }),
368 PatronsPerPage => C4::Context->preference("PatronsPerPage") || 20,
369 relatives_issues_count => $relatives_issues_count,
370 relatives_borrowernumbers => \@relatives,
373 output_html_with_http_headers $input, $cookie, $template->output;