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
47 use C4::Branch; # GetBranchName
55 $debug = $ENV{DEBUG} || 0;
58 my $dbh = C4::Context->dbh;
61 $debug or $debug = $input->param('debug') || 0;
62 my $print = $input->param('print');
63 my @failedrenews = $input->param('failedrenew');
64 my @failedreturns = $input->param('failedreturn');
65 my $error = $input->param('error');
67 for my $renew (@failedrenews) { $renew_failed[$renew] = 1; }
69 for my $failedret (@failedreturns) { $return_failed[$failedret] = 1; }
73 if ($print eq "page") { $template_name = "members/moremember-print.tmpl"; }
74 elsif ($print eq "slip") { $template_name = "members/moremember-receipt.tmpl"; }
75 else { $template_name = "members/moremember.tmpl"; }
77 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
79 template_name => $template_name,
83 flagsrequired => { borrowers => 1 },
87 my $borrowernumber = $input->param('borrowernumber');
89 #start the page and read in includes
90 my $data = GetMember( $borrowernumber ,'borrowernumber');
91 my $reregistration = $input->param('reregistration');
93 if ( not defined $data ) {
94 $template->param (unknowuser => 1);
95 output_html_with_http_headers $input, $cookie, $template->output;
99 # re-reregistration function to automatic calcul of date expiry
100 if ( $reregistration eq 'y' ) {
101 $data->{'dateexpiry'} = ExtendMemberSubscriptionTo( $borrowernumber );
104 my $borrowercategory = GetBorrowercategory( $data->{'categorycode'} );
105 my $category_type = $borrowercategory->{'category_type'};
109 # in template <TMPL_IF name="I"> => instutitional (A for Adult& C for children)
110 $template->param( $data->{'categorycode'} => 1 );
112 $debug and printf STDERR "dates (enrolled,expiry,birthdate) raw: (%s, %s, %s)\n", map {$data->{$_}} qw(dateenrolled dateexpiry dateofbirth);
113 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
114 my $userdate = $data->{$_};
116 $debug and warn sprintf "Empty \$data{%12s}", $_;
120 $userdate = C4::Dates->new($userdate,'iso')->output('syspref');
121 $data->{$_} = $userdate || '';
122 $template->param( $_ => $userdate );
124 $data->{'IS_ADULT'} = ( $data->{'categorycode'} ne 'I' );
126 for (qw(debarred gonenoaddress lost borrowernotes)) {
127 $data->{$_} and $template->param(flagged => 1) and last;
130 $data->{'ethnicity'} = fixEthnicity( $data->{'ethnicity'} );
131 $data->{ "sex_".$data->{'sex'}."_p" } = 1;
134 if ( $category_type eq 'C' and $data->{'guarantorid'} ne '0' ) {
135 my $data2 = GetMember( $data->{'guarantorid'} ,'borrowernumber');
136 foreach (qw(address city B_address B_city phone mobile zipcode)) {
137 $data->{$_} = $data2->{$_};
139 my ( $catcodes, $labels ) =
140 GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
141 my $cnt = scalar(@$catcodes);
144 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
146 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
150 if ( $data->{'ethnicity'} || $data->{'ethnotes'} ) {
151 $template->param( printethnicityline => 1 );
153 if ( $category_type eq 'A' ) {
154 $template->param( isguarantee => 1 );
157 # It looks like the $i is only being returned to handle walking through
158 # the array, which is probably better done as a foreach loop.
160 my ( $count, $guarantees ) = GetGuarantees( $data->{'borrowernumber'} );
162 for ( my $i = 0 ; $i < $count ; $i++ ) {
165 borrowernumber => $guarantees->[$i]->{'borrowernumber'},
166 cardnumber => $guarantees->[$i]->{'cardnumber'},
167 name => $guarantees->[$i]->{'firstname'} . " "
168 . $guarantees->[$i]->{'surname'}
172 $template->param( guaranteeloop => \@guaranteedata );
173 ( $template->param( adultborrower => 1 ) ) if ( $category_type eq 'A' );
176 if ($data->{'guarantorid'}){
177 my ($guarantor) = GetMember( $data->{'guarantorid'},'biblionumber');
178 $template->param(guarantor => 1);
179 foreach (qw(borrowernumber cardnumber firstname surname)) {
180 $template->param("guarantor$_" => $guarantor->{$_});
183 if ($category_type eq 'C'){
184 $template->param('C' => 1);
188 #Independant branches management
189 my $unvalidlibrarian =
190 ( ( C4::Context->preference("IndependantBranches") )
191 && ( C4::Context->userenv->{flags} != 1 )
192 && ( $data->{'branchcode'} ne C4::Context->userenv->{branch} ) );
195 $bor{'borrowernumber'} = $borrowernumber;
197 # Converts the branchcode to the branch name
199 if ( C4::Context->preference("IndependantBranches") ) {
200 my $userenv = C4::Context->userenv;
201 unless ( $userenv->{flags} == 1 ) {
202 $samebranch = ( $data->{'branchcode'} eq $userenv->{branch} );
204 $samebranch = 1 if ( $userenv->{flags} == 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 ( $count, $issue ) = GetPendingIssues($borrowernumber);
219 my $roaddetails = &GetRoadTypeDetails( $data->{'streettype'} );
220 my $today = POSIX::strftime("%Y-%m-%d", localtime); # iso format
224 for ( my $i = 0 ; $i < $count ; $i++ ) {
225 my $datedue = $issue->[$i]{'date_due'};
226 $issue->[$i]{'date_due'} = C4::Dates->new($issue->[$i]{'date_due'},'iso')->output('syspref');
227 $issue->[$i]{'issuedate'} = C4::Dates->new($issue->[$i]{'issuedate'},'iso')->output('syspref');
228 my %row = %{ $issue->[$i] };
229 $totalprice += $issue->[$i]{'replacementprice'};
230 $row{'replacementprice'} = $issue->[$i]{'replacementprice'};
231 if ( $datedue lt $today ) {
232 $row{'red'} = 1; #print "<font color=red>";
234 $row{toggle} = $toggle++ % 2;
236 #find the charge for an item
237 my ( $charge, $itemtype ) =
238 GetIssuingCharges( $issue->[$i]{'itemnumber'}, $borrowernumber );
240 my $itemtypeinfo = getitemtypeinfo($itemtype);
241 $row{'itemtype_description'} = $itemtypeinfo->{description};
242 $row{'itemtype_image'} = $itemtypeinfo->{imageurl};
244 $row{'charge'} = sprintf( "%.2f", $charge );
246 my ( $renewokay,$renewerror ) = CanBookBeRenewed( $borrowernumber, $issue->[$i]{'itemnumber'});
247 $row{'norenew'} = !$renewokay;
248 $row{"norenew_reason_$renewerror"} = 1 if $renewerror;
249 $row{'renew_failed'} = $renew_failed[$issue->[$i]{'itemnumber'}];
250 $row{'return_failed'} = $return_failed[$issue->[$i]{'barcode'}];
251 push( @issuedata, \%row );
254 ### ###############################################################################
256 # show all reserves of this borrower, and the position of the reservation ....
257 if ($borrowernumber) {
260 # now we show the status of the borrower's reservations
261 my @borrowerreserv = GetReservesFromBorrowernumber($borrowernumber );
263 foreach my $num_res (@borrowerreserv) {
265 my $getiteminfo = GetBiblioFromItemNumber( $num_res->{'itemnumber'} );
266 my $itemtypeinfo = getitemtypeinfo( $getiteminfo->{'itemtype'} );
267 my ( $transfertwhen, $transfertfrom, $transfertto ) =
268 GetTransfers( $num_res->{'itemnumber'} );
270 foreach (qw(waiting transfered nottransfered)) {
273 $getreserv{reservedate} = C4::Dates->new($num_res->{'reservedate'},'iso')->output('syspref');
274 foreach (qw(biblionumber title author barcodereserv itemcallnumber )) {
275 $getreserv{$_} = $getiteminfo->{$_};
277 $getreserv{itemtype} = $itemtypeinfo->{'description'};
279 # check if we have a waitin status for reservations
280 if ( $num_res->{'found'} eq 'W' ) {
281 $getreserv{color} = 'reserved';
282 $getreserv{waiting} = 1;
285 # check transfers with the itemnumber foud in th reservation loop
286 if ($transfertwhen) {
287 $getreserv{color} = 'transfered';
288 $getreserv{transfered} = 1;
289 $getreserv{datesent} = C4::Dates->new($transfertwhen, 'iso')->output('syspref') or die "Cannot get new($transfertwhen, 'iso') from C4::Dates";
290 $getreserv{frombranch} = GetBranchName($transfertfrom);
293 if ( ( $getiteminfo->{'holdingbranch'} ne $num_res->{'branchcode'} )
294 and not $transfertwhen )
296 $getreserv{nottransfered} = 1;
297 $getreserv{nottransferedby} =
298 GetBranchName( $getiteminfo->{'holdingbranch'} );
301 # if we don't have a reserv on item, we put the biblio infos and the waiting position
302 if ( $getiteminfo->{'title'} eq '' ) {
303 my $getbibinfo = GetBiblioItemData( $num_res->{'biblionumber'} );
304 my $getbibtype = getitemtypeinfo( $getbibinfo->{'itemtype'} );
305 $getreserv{color} = 'inwait';
306 $getreserv{title} = $getbibinfo->{'title'};
307 $getreserv{waitingposition} = $num_res->{'priority'};
308 $getreserv{nottransfered} = 0;
309 $getreserv{itemtype} = $getbibtype->{'description'};
310 $getreserv{author} = $getbibinfo->{'author'};
311 $getreserv{biblionumber} = $num_res->{'biblionumber'};
314 push( @reservloop, \%getreserv );
317 # return result to the template
318 $template->param( reservloop => \@reservloop );
321 # current alert subscriptions
322 my $alerts = getalert($borrowernumber);
324 $_->{ $_->{type} } = 1;
325 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
328 # check to see if patron's image exists in the database
329 # basically this gives us a template var to condition the display of
330 # patronimage related interface on
331 my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
332 $template->param( picture => 1 ) if $picture;
334 my $branch=C4::Context->userenv->{'branch'};
336 $template->param($data);
340 DHTMLcalendar_dateformat=>C4::Dates->DHTMLcalendar(),
341 roaddetails => $roaddetails,
342 borrowernumber => $borrowernumber,
343 reregistration => $reregistration,
345 totalprice => sprintf( "%.2f", $totalprice ),
346 totaldue => sprintf( "%.2f", $total ),
347 issueloop => \@issuedata,
348 unvalidlibrarian => $unvalidlibrarian,
351 StaffMember => ($category_type eq 'S'),
352 is_child => ($category_type eq 'C'),
353 # reserveloop => \@reservedata,
356 output_html_with_http_headers $input, $cookie, $template->output;