3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
23 script to do a borrower enquiry/bring up borrower details etc
24 Displays all the details about a borrower
25 written 20/12/99 by chris@katipo.co.nz
26 last modified 21/1/2000 by chris@katipo.co.nz
27 modified 31/1/2001 by chris@katipo.co.nz
28 to not allow items on request to be renewed
30 needs html removed and to use the C4::Output more, but its tricky
40 use C4
::Members
::Attributes
;
41 use C4
::Members
::AttributeTypes
;
49 use C4
::Branch
; # GetBranchName
50 use C4
::Form
::MessagingPreferences
;
58 $debug = $ENV{DEBUG} || 0;
61 my $dbh = C4::Context->dbh;
64 $debug or $debug = $input->param('debug') || 0;
65 my $print = $input->param('print');
66 my $override_limit = $input->param("override_limit") || 0;
67 my @failedrenews = $input->param('failedrenew');
68 my @failedreturns = $input->param('failedreturn');
69 my $error = $input->param('error');
71 for my $renew (@failedrenews) { $renew_failed{$renew} = 1; }
73 for my $failedret (@failedreturns) { $return_failed{$failedret} = 1; }
78 if ($print eq "page") { $template_name = "members/moremember-print.tmpl"; }
79 elsif ($print eq "slip") { $template_name = "members/moremember-receipt.tmpl"; }
80 elsif ($print eq "qslip") { $template_name = "members/moremember-receipt.tmpl"; $quickslip = 1; }
81 else { $template_name = "members/moremember.tmpl"; }
83 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
85 template_name => $template_name,
89 flagsrequired => { borrowers => 1 },
93 my $borrowernumber = $input->param('borrowernumber');
95 #start the page and read in includes
96 my $data = GetMember( 'borrowernumber' => $borrowernumber );
97 my $reregistration = $input->param('reregistration');
99 if ( not defined $data ) {
100 $template->param (unknowuser => 1);
101 output_html_with_http_headers $input, $cookie, $template->output;
105 # re-reregistration function to automatic calcul of date expiry
106 if ( $reregistration eq 'y' ) {
107 $data->{'dateexpiry'} = ExtendMemberSubscriptionTo( $borrowernumber );
110 my $category_type = $data->{'category_type'};
114 # in template <TMPL_IF name="I"> => instutitional (A for Adult& C for children)
115 $template->param( $data->{'categorycode'} => 1 );
117 $debug and printf STDERR "dates (enrolled,expiry,birthdate) raw: (%s, %s, %s)\n", map {$data->{$_}} qw(dateenrolled dateexpiry dateofbirth);
118 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
119 my $userdate = $data->{$_};
121 $debug and warn sprintf "Empty \$data{%12s}", $_;
125 $userdate = C4
::Dates
->new($userdate,'iso')->output('syspref');
126 $data->{$_} = $userdate || '';
127 $template->param( $_ => $userdate );
129 $data->{'IS_ADULT'} = ( $data->{'categorycode'} ne 'I' );
131 for (qw(debarred gonenoaddress lost borrowernotes)) {
132 $data->{$_} and $template->param(flagged
=> 1) and last;
135 $data->{'ethnicity'} = fixEthnicity
( $data->{'ethnicity'} );
136 $data->{ "sex_".$data->{'sex'}."_p" } = 1;
139 if ( $category_type eq 'C') {
140 if ($data->{'guarantorid'} ne '0' ) {
141 my $data2 = GetMember
( 'borrowernumber' => $data->{'guarantorid'} );
142 foreach (qw(address city B_address B_city phone mobile zipcode country B_country)) {
143 $data->{$_} = $data2->{$_};
146 my ( $catcodes, $labels ) = GetborCatFromCatType
( 'A', 'WHERE category_type = ?' );
147 my $cnt = scalar(@
$catcodes);
149 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
150 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
154 if ( $data->{'ethnicity'} || $data->{'ethnotes'} ) {
155 $template->param( printethnicityline
=> 1 );
157 if ( $category_type eq 'A' ) {
158 $template->param( isguarantee
=> 1 );
161 # It looks like the $i is only being returned to handle walking through
162 # the array, which is probably better done as a foreach loop.
164 my ( $count, $guarantees ) = GetGuarantees
( $data->{'borrowernumber'} );
166 for ( my $i = 0 ; $i < $count ; $i++ ) {
169 borrowernumber
=> $guarantees->[$i]->{'borrowernumber'},
170 cardnumber
=> $guarantees->[$i]->{'cardnumber'},
171 name
=> $guarantees->[$i]->{'firstname'} . " "
172 . $guarantees->[$i]->{'surname'}
176 $template->param( guaranteeloop
=> \
@guaranteedata );
177 ( $template->param( adultborrower
=> 1 ) ) if ( $category_type eq 'A' );
180 if ($data->{'guarantorid'}){
181 my ($guarantor) = GetMember
( 'borrowernumber' =>$data->{'guarantorid'});
182 $template->param(guarantor
=> 1);
183 foreach (qw(borrowernumber cardnumber firstname surname)) {
184 $template->param("guarantor$_" => $guarantor->{$_});
187 if ($category_type eq 'C'){
188 $template->param('C' => 1);
193 $bor{'borrowernumber'} = $borrowernumber;
195 # Converts the branchcode to the branch name
197 if ( C4
::Context
->preference("IndependantBranches") ) {
198 my $userenv = C4
::Context
->userenv;
199 unless ( $userenv->{flags
} % 2 == 1 ) {
200 $samebranch = ( $data->{'branchcode'} eq $userenv->{branch
} );
202 $samebranch = 1 if ( $userenv->{flags
} % 2 == 1 );
206 my $branchdetail = GetBranchDetail
( $data->{'branchcode'});
207 $data->{'branchname'} = $branchdetail->{branchname
};
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);
218 my $issue = GetPendingIssues
($borrowernumber);
219 my $issuecount = scalar(@
$issue);
220 my $roaddetails = &GetRoadTypeDetails
( $data->{'streettype'} );
221 my $today = POSIX
::strftime
("%Y-%m-%d", localtime); # iso format
223 my $overdues_exist = 0;
225 for ( my $i = 0 ; $i < $issuecount ; $i++ ) {
226 my $datedue = $issue->[$i]{'date_due'};
227 my $issuedate = $issue->[$i]{'issuedate'};
228 $issue->[$i]{'date_due'} = C4
::Dates
->new($issue->[$i]{'date_due'}, 'iso')->output('syspref');
229 $issue->[$i]{'issuedate'} = C4
::Dates
->new($issue->[$i]{'issuedate'},'iso')->output('syspref');
230 my $biblionumber = $issue->[$i]{'biblionumber'};
231 my %row = %{ $issue->[$i] };
232 $totalprice += $issue->[$i]{'replacementprice'};
233 $row{'replacementprice'} = $issue->[$i]{'replacementprice'};
234 # item lost, damaged loops
235 if ($row{'itemlost'}) {
236 my $fw = GetFrameworkCode
($issue->[$i]{'biblionumber'});
237 my $category = GetAuthValCode
('items.itemlost',$fw);
238 my $lostdbh = C4
::Context
->dbh;
239 my $sth = $lostdbh->prepare("select lib from authorised_values where category=? and authorised_value =? ");
240 $sth->execute($category, $row{'itemlost'});
241 my $loststat = $sth->fetchrow;
243 $row{'itemlost'} = $loststat;
246 if ($row{'damaged'}) {
247 my $fw = GetFrameworkCode
($issue->[$i]{'biblionumber'});
248 my $category = GetAuthValCode
('items.damaged',$fw);
249 my $damageddbh = C4
::Context
->dbh;
250 my $sth = $damageddbh->prepare("select lib from authorised_values where category=? and authorised_value =? ");
251 $sth->execute($category, $row{'damaged'});
252 my $damagedstat = $sth->fetchrow;
254 $row{'itemdamaged'} = $damagedstat;
258 if ( $datedue lt $today ) {
262 if ( $issuedate eq $today ) {
266 #find the charge for an item
267 my ( $charge, $itemtype ) =
268 GetIssuingCharges
( $issue->[$i]{'itemnumber'}, $borrowernumber );
270 my $itemtypeinfo = getitemtypeinfo
($itemtype);
271 $row{'itemtype_description'} = $itemtypeinfo->{description
};
272 $row{'itemtype_image'} = $itemtypeinfo->{imageurl
};
274 $row{'charge'} = sprintf( "%.2f", $charge );
276 my ( $renewokay,$renewerror ) = CanBookBeRenewed
( $borrowernumber, $issue->[$i]{'itemnumber'}, $override_limit );
277 $row{'norenew'} = !$renewokay;
278 $row{'can_confirm'} = ( !$renewokay && $renewerror ne 'on_reserve' );
279 $row{"norenew_reason_$renewerror"} = 1 if $renewerror;
280 $row{'renew_failed'} = $renew_failed{ $issue->[$i]{'itemnumber'} };
281 $row{'return_failed'} = $return_failed{$issue->[$i]{'barcode'}};
282 push( @issuedata, \
%row );
285 ### ###############################################################################
287 # show all reserves of this borrower, and the position of the reservation ....
288 if ($borrowernumber) {
291 # now we show the status of the borrower's reservations
292 my @borrowerreserv = GetReservesFromBorrowernumber
($borrowernumber );
294 foreach my $num_res (@borrowerreserv) {
296 my $getiteminfo = GetBiblioFromItemNumber
( $num_res->{'itemnumber'} );
297 my $itemtypeinfo = getitemtypeinfo
( $getiteminfo->{'itemtype'} );
298 my ( $transfertwhen, $transfertfrom, $transfertto ) =
299 GetTransfers
( $num_res->{'itemnumber'} );
301 foreach (qw(waiting transfered nottransfered)) {
304 $getreserv{reservedate
} = C4
::Dates
->new($num_res->{'reservedate'},'iso')->output('syspref');
305 foreach (qw(biblionumber title author itemcallnumber )) {
306 $getreserv{$_} = $getiteminfo->{$_};
308 $getreserv{barcodereserv
} = $getiteminfo->{'barcode'};
309 $getreserv{itemtype
} = $itemtypeinfo->{'description'};
311 # check if we have a waitin status for reservations
312 if ( $num_res->{'found'} eq 'W' ) {
313 $getreserv{color
} = 'reserved';
314 $getreserv{waiting
} = 1;
317 # check transfers with the itemnumber foud in th reservation loop
318 if ($transfertwhen) {
319 $getreserv{color
} = 'transfered';
320 $getreserv{transfered
} = 1;
321 $getreserv{datesent
} = C4
::Dates
->new($transfertwhen, 'iso')->output('syspref') or die "Cannot get new($transfertwhen, 'iso') from C4::Dates";
322 $getreserv{frombranch
} = GetBranchName
($transfertfrom);
325 if ( ( $getiteminfo->{'holdingbranch'} ne $num_res->{'branchcode'} )
326 and not $transfertwhen )
328 $getreserv{nottransfered
} = 1;
329 $getreserv{nottransferedby
} =
330 GetBranchName
( $getiteminfo->{'holdingbranch'} );
333 # if we don't have a reserv on item, we put the biblio infos and the waiting position
334 if ( $getiteminfo->{'title'} eq '' ) {
335 my $getbibinfo = GetBiblioData
( $num_res->{'biblionumber'} );
336 my $getbibtype = getitemtypeinfo
( $getbibinfo->{'itemtype'} );
337 $getreserv{color
} = 'inwait';
338 $getreserv{title
} = $getbibinfo->{'title'};
339 $getreserv{nottransfered
} = 0;
340 $getreserv{itemtype
} = $getbibtype->{'description'};
341 $getreserv{author
} = $getbibinfo->{'author'};
342 $getreserv{biblionumber
} = $num_res->{'biblionumber'};
344 $getreserv{waitingposition
} = $num_res->{'priority'};
346 push( @reservloop, \
%getreserv );
349 # return result to the template
350 $template->param( reservloop
=> \
@reservloop,
351 countreserv
=> scalar @reservloop,
355 # current alert subscriptions
356 my $alerts = getalert
($borrowernumber);
358 $_->{ $_->{type
} } = 1;
359 $_->{relatedto
} = findrelatedto
( $_->{type
}, $_->{externalid
} );
362 # check to see if patron's image exists in the database
363 # basically this gives us a template var to condition the display of
364 # patronimage related interface on
365 my ($picture, $dberror) = GetPatronImage
($data->{'cardnumber'});
366 $template->param( picture
=> 1 ) if $picture;
368 my $branch=C4
::Context
->userenv->{'branch'};
370 $template->param($data);
372 if (C4
::Context
->preference('ExtendedPatronAttributes')) {
373 $template->param(ExtendedPatronAttributes
=> 1);
374 $template->param(patron_attributes
=> C4
::Members
::Attributes
::GetBorrowerAttributes
($borrowernumber));
375 my @types = C4
::Members
::AttributeTypes
::GetAttributeTypes
();
376 if (scalar(@types) == 0) {
377 $template->param(no_patron_attribute_types
=> 1);
381 if (C4
::Context
->preference('EnhancedMessagingPreferences')) {
382 C4
::Form
::MessagingPreferences
::set_form_values
({ borrowernumber
=> $borrowernumber }, $template);
383 $template->param(messaging_form_inactive
=> 1);
384 $template->param(SMSSendDriver
=> C4
::Context
->preference("SMSSendDriver"));
385 $template->param(SMSnumber
=> defined $data->{'smsalertnumber'} ?
$data->{'smsalertnumber'} : $data->{'mobile'});
390 AllowRenewalLimitOverride
=> C4
::Context
->preference("AllowRenewalLimitOverride"),
391 DHTMLcalendar_dateformat
=> C4
::Dates
->DHTMLcalendar(),
392 roaddetails
=> $roaddetails,
393 borrowernumber
=> $borrowernumber,
394 categoryname
=> $data->{'description'},
395 reregistration
=> $reregistration,
397 totalprice
=> sprintf("%.2f", $totalprice),
398 totaldue
=> sprintf("%.2f", $total),
399 totaldue_raw
=> $total,
400 issueloop
=> \
@issuedata,
401 issuecount
=> $issuecount,
402 overdues_exist
=> $overdues_exist,
405 StaffMember
=> ($category_type eq 'S'),
406 is_child
=> ($category_type eq 'C'),
407 # reserveloop => \@reservedata,
408 dateformat
=> C4
::Context
->preference("dateformat"),
409 "dateformat_" . (C4
::Context
->preference("dateformat") || '') => 1,
410 samebranch
=> $samebranch,
411 quickslip
=> $quickslip,
414 output_html_with_http_headers
$input, $cookie, $template->output;