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 (defined $print and $print eq "page") {
79 $template_name = "members/moremember-print.tt";
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 (defined $print and $print eq "slip") {
84 $template_name = "members/moremember-receipt.tt";
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 (defined $print and $print eq "qslip") {
89 $template_name = "members/moremember-receipt.tt";
91 $flagsrequired = { circulate => "circulate_remaining_permissions" };
92 } elsif (defined $print and $print eq "brief") {
93 $template_name = "members/moremember-brief.tt";
94 $flagsrequired = { borrowers => 1 };
96 $template_name = "members/moremember.tt";
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 if defined $data->{sex
};
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 );
188 ( $template->param( adultborrower
=> 1 ) ) if ( $category_type eq 'A' || $category_type eq 'I' );
191 if ($data->{'guarantorid'}){
192 my ($guarantor) = GetMember
( 'borrowernumber' =>$data->{'guarantorid'});
193 $template->param(guarantor
=> 1);
194 foreach (qw(borrowernumber cardnumber firstname surname)) {
195 $template->param("guarantor$_" => $guarantor->{$_});
198 if ($category_type eq 'C'){
199 $template->param('C' => 1);
204 $bor{'borrowernumber'} = $borrowernumber;
206 # Converts the branchcode to the branch name
208 if ( C4
::Context
->preference("IndependentBranches") ) {
209 my $userenv = C4
::Context
->userenv;
210 if ( C4
::Context
->IsSuperLibrarian() ) {
214 $samebranch = ( $data->{'branchcode'} eq $userenv->{branch
} );
220 my $branchdetail = GetBranchDetail
( $data->{'branchcode'});
221 @
{$data}{keys %$branchdetail} = values %$branchdetail; # merge in all branch columns
223 my ( $total, $accts, $numaccts) = GetMemberAccountRecords
( $borrowernumber );
224 my $lib1 = &GetSortDetails
( "Bsort1", $data->{'sort1'} );
225 my $lib2 = &GetSortDetails
( "Bsort2", $data->{'sort2'} );
226 $template->param( lib1
=> $lib1 ) if ($lib1);
227 $template->param( lib2
=> $lib2 ) if ($lib2);
229 # If printing a page, send the account informations to the template
230 if ($print eq "page") {
231 foreach my $accountline (@
$accts) {
232 $accountline->{amount
} = sprintf '%.2f', $accountline->{amount
};
233 $accountline->{amountoutstanding
} = sprintf '%.2f', $accountline->{amountoutstanding
};
235 if ($accountline->{accounttype
} ne 'F' && $accountline->{accounttype
} ne 'FU'){
236 $accountline->{printtitle
} = 1;
239 $template->param( accounts
=> $accts );
242 # Show OPAC privacy preference is system preference is set
243 if ( C4
::Context
->preference('OPACPrivacy') ) {
244 $template->param( OPACPrivacy
=> 1);
245 $template->param( "privacy".$data->{'privacy'} => 1);
248 my @relatives = GetMemberRelatives
($borrowernumber);
249 my $relatives_issues_count =
250 Koha
::Database
->new()->schema()->resultset('Issue')
251 ->count( { borrowernumber
=> \
@relatives } );
253 my $roadtype = C4
::Koha
::GetAuthorisedValueByCode
( 'ROADTYPE', $data->{streettype
} );
254 my $today = DateTime
->now( time_zone
=> C4
::Context
->tz);
255 $today->truncate(to
=> 'day');
256 my @borrowers_with_issues;
257 my $overdues_exist = 0;
260 ### ###############################################################################
262 # show all reserves of this borrower, and the position of the reservation ....
263 if ($borrowernumber) {
265 holds_count
=> Koha
::Database
->new()->schema()->resultset('Reserve')
266 ->count( { borrowernumber
=> $borrowernumber } ) );
269 # current alert subscriptions
270 my $alerts = getalert
($borrowernumber);
272 $_->{ $_->{type
} } = 1;
273 $_->{relatedto
} = findrelatedto
( $_->{type
}, $_->{externalid
} );
277 my $userenv = C4
::Context
->userenv;
278 if ( C4
::Context
->IsSuperLibrarian() ) {
281 elsif ( C4
::Context
->preference("IndependentBranches") ) {
282 $candeleteuser = ( $data->{'branchcode'} eq $userenv->{branch
} );
285 if ( C4
::Auth
::getuserflags
( $userenv->{flags
}, $userenv->{number
} )->{borrowers
} ) {
293 # check to see if patron's image exists in the database
294 # basically this gives us a template var to condition the display of
295 # patronimage related interface on
296 my ($picture, $dberror) = GetPatronImage
($data->{'borrowernumber'});
297 $template->param( picture
=> 1 ) if $picture;
299 my $branch=C4
::Context
->userenv->{'branch'};
301 $template->param(%$data);
303 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
304 my $attributes = C4
::Members
::Attributes
::GetBorrowerAttributes
($borrowernumber);
305 my @classes = uniq
( map {$_->{class}} @
$attributes );
306 @classes = sort @classes;
309 for my $class (@classes) {
311 for my $attr (@
$attributes) {
312 push @items, $attr if $attr->{class} eq $class
314 my $lib = GetAuthorisedValueByCode
( 'PA_CLASS', $class ) || $class;
315 push @attributes_loop, {
323 ExtendedPatronAttributes
=> 1,
324 attributes_loop
=> \
@attributes_loop
327 my @types = C4
::Members
::AttributeTypes
::GetAttributeTypes
();
328 if (scalar(@types) == 0) {
329 $template->param(no_patron_attribute_types
=> 1);
333 if (C4
::Context
->preference('EnhancedMessagingPreferences')) {
334 C4
::Form
::MessagingPreferences
::set_form_values
({ borrowernumber
=> $borrowernumber }, $template);
335 $template->param(messaging_form_inactive
=> 1);
336 $template->param(SMSSendDriver
=> C4
::Context
->preference("SMSSendDriver"));
337 $template->param(SMSnumber
=> defined $data->{'smsalertnumber'} ?
$data->{'smsalertnumber'} : $data->{'mobile'});
338 $template->param(TalkingTechItivaPhone
=> C4
::Context
->preference("TalkingTechItivaPhoneNotification"));
341 # Computes full borrower address
342 my $address = $data->{'streetnumber'} . " $roadtype " . $data->{'address'};
344 # in template <TMPL_IF name="I"> => instutitional (A for Adult, C for children)
345 $template->param( $data->{'categorycode'} => 1 );
348 AllowRenewalLimitOverride
=> C4
::Context
->preference("AllowRenewalLimitOverride"),
349 CANDELETEUSER
=> $candeleteuser,
350 roadtype
=> $roadtype,
351 borrowernumber
=> $borrowernumber,
352 othernames
=> $data->{'othernames'},
353 categoryname
=> $data->{'description'},
354 was_renewed
=> $input->param('was_renewed') ?
1 : 0,
356 todaysdate
=> C4
::Dates
->today(),
357 totalprice
=> sprintf("%.2f", $totalprice),
358 totaldue
=> sprintf("%.2f", $total),
359 totaldue_raw
=> $total,
360 overdues_exist
=> $overdues_exist,
361 StaffMember
=> ($category_type eq 'S'),
362 is_child
=> ($category_type eq 'C'),
363 samebranch
=> $samebranch,
364 quickslip
=> $quickslip,
365 activeBorrowerRelationship
=> (C4
::Context
->preference('borrowerRelationship') ne ''),
366 AutoResumeSuspendedHolds
=> C4
::Context
->preference('AutoResumeSuspendedHolds'),
367 SuspendHoldsIntranet
=> C4
::Context
->preference('SuspendHoldsIntranet'),
368 RoutingSerials
=> C4
::Context
->preference('RoutingSerials'),
369 debarments
=> GetDebarments
({ borrowernumber
=> $borrowernumber }),
370 PatronsPerPage
=> C4
::Context
->preference("PatronsPerPage") || 20,
371 relatives_issues_count
=> $relatives_issues_count,
372 relatives_borrowernumbers
=> \
@relatives,
376 output_html_with_http_headers
$input, $cookie, $template->output;