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
54 $debug = $ENV{DEBUG} || 0;
57 my $dbh = C4::Context->dbh;
60 $debug or $debug = $input->param('debug') || 0;
61 my $print = $input->param('print');
62 my @failedrenews = $input->param('failedrenew');
63 my $error = $input->param('error');
65 for (@failedrenews) { $renew_failed[$_] = 1; }
69 if ($print eq "page") { $template_name = "members/moremember-print.tmpl"; }
70 elsif ($print eq "slip") { $template_name = "members/moremember-receipt.tmpl"; }
71 else { $template_name = "members/moremember.tmpl"; }
73 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
75 template_name => $template_name,
79 flagsrequired => { borrowers => 1 },
83 my $borrowernumber = $input->param('borrowernumber');
85 #start the page and read in includes
86 my $data = GetMember( $borrowernumber ,'borrowernumber');
87 my $reregistration = $input->param('reregistration');
89 if ( not defined $data ) {
90 $template->param (unknowuser => 1);
91 output_html_with_http_headers $input, $cookie, $template->output;
95 # re-reregistration function to automatic calcul of date expiry
96 if ( $reregistration eq 'y' ) {
97 $data->{'dateexpiry'} = ExtendMemberSubscriptionTo( $borrowernumber );
100 my $borrowercategory = GetBorrowercategory( $data->{'categorycode'} );
101 my $category_type = $borrowercategory->{'category_type'};
105 # in template <TMPL_IF name="I"> => instutitional (A for Adult& C for children)
106 $template->param( $data->{'categorycode'} => 1 );
108 $debug and printf STDERR "dates (enrolled,expiry,birthdate) raw: (%s, %s, %s)\n", map {$data->{$_}} qw(dateenrolled dateexpiry dateofbirth);
109 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
110 my $userdate = $data->{$_};
112 $debug and warn sprintf "Empty \$data{%12s}", $_;
116 $userdate = C4::Dates->new($userdate,'iso')->output('syspref');
117 $data->{$_} = $userdate || '';
118 $template->param( $_ => $userdate );
120 $data->{'IS_ADULT'} = ( $data->{'categorycode'} ne 'I' );
122 for (qw(debarred gonenoaddress lost borrowernotes)) {
123 $data->{$_} and $template->param(flagged => 1) and last;
126 $data->{'ethnicity'} = fixEthnicity( $data->{'ethnicity'} );
128 $data->{ "sex_".$data->{'sex'}."_p" } = 1;
130 if ( $category_type eq 'C' and $data->{'guarantorid'} ne '0' ) {
132 my $data2 = GetMember( $data->{'guarantorid'} ,'borrowernumber');
133 foreach (qw(address city B_address B_city phone mobile zipcode)) {
134 $data->{$_} = $data2->{$_};
136 my ( $catcodes, $labels ) =
137 GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
138 my $cnt = scalar(@$catcodes);
139 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
140 $template->param( 'IS_CHILD' => 1 );
143 if ( $data->{'ethnicity'} || $data->{'ethnotes'} ) {
144 $template->param( printethnicityline => 1 );
146 if ( $category_type eq 'A' ) {
147 $template->param( isguarantee => 1 );
150 # It looks like the $i is only being returned to handle walking through
151 # the array, which is probably better done as a foreach loop.
153 my ( $count, $guarantees ) = GetGuarantees( $data->{'borrowernumber'} );
155 for ( my $i = 0 ; $i < $count ; $i++ ) {
158 borrowernumber => $guarantees->[$i]->{'borrowernumber'},
159 cardnumber => $guarantees->[$i]->{'cardnumber'},
160 name => $guarantees->[$i]->{'firstname'} . " "
161 . $guarantees->[$i]->{'surname'}
165 $template->param( guaranteeloop => \@guaranteedata );
166 ( $template->param( adultborrower => 1 ) ) if ( $category_type eq 'A' );
169 if ($data->{'guarantorid'}){
170 my ($guarantor) = GetMember( $data->{'guarantorid'},'biblionumber');
171 $template->param(guarantor => 1);
172 foreach (qw(borrowernumber cardnumber firstname surname)) {
173 $template->param("guarantor$_" => $guarantor->{$_});
178 #Independant branches management
179 my $unvalidlibrarian =
180 ( ( C4::Context->preference("IndependantBranches") )
181 && ( C4::Context->userenv->{flags} != 1 )
182 && ( $data->{'branchcode'} ne C4::Context->userenv->{branch} ) );
185 $bor{'borrowernumber'} = $borrowernumber;
187 # Converts the branchcode to the branch name
189 if ( C4::Context->preference("IndependantBranches") ) {
190 my $userenv = C4::Context->userenv;
191 unless ( $userenv->{flags} == 1 ) {
192 $samebranch = ( $data->{'branchcode'} eq $userenv->{branch} );
194 $samebranch = 1 if ( $userenv->{flags} == 1 );
196 my $branchdetail = GetBranchDetail( $data->{'branchcode'});
197 $data->{'branchname'} = $branchdetail->{branchname};
200 my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
201 my $lib1 = &GetSortDetails( "Bsort1", $data->{'sort1'} );
202 my $lib2 = &GetSortDetails( "Bsort2", $data->{'sort2'} );
203 ( $template->param( lib1 => $lib1 ) ) if ($lib1);
204 ( $template->param( lib2 => $lib2 ) ) if ($lib2);
208 my ( $count, $issue ) = GetPendingIssues($borrowernumber);
209 my $roaddetails = &GetRoadTypeDetails( $data->{'streettype'} );
210 my $today = POSIX::strftime("%Y%m%d", localtime); # iso format
214 for ( my $i = 0 ; $i < $count ; $i++ ) {
215 my $datedue = $issue->[$i]{'date_due'};
216 $issue->[$i]{'date_due'} = C4::Dates->new($issue->[$i]{'date_due'},'iso')->output('syspref');
217 my %row = %{ $issue->[$i] };
218 $totalprice += $issue->[$i]{'replacementprice'};
219 $row{'replacementprice'} = $issue->[$i]{'replacementprice'};
220 if ( $datedue < $today ) {
221 $row{'red'} = 1; #print "<font color=red>";
223 $row{toggle} = $toggle++ % 2;
225 #find the charge for an item
226 my ( $charge, $itemtype ) =
227 GetIssuingCharges( $issue->[$i]{'itemnumber'}, $borrowernumber );
229 my $itemtypeinfo = getitemtypeinfo($itemtype);
230 $row{'itemtype_description'} = $itemtypeinfo->{description};
231 $row{'itemtype_image'} = $itemtypeinfo->{imageurl};
233 $row{'charge'} = sprintf( "%.2f", $charge );
235 #check item is not reserved
236 my ( $restype, $reserves ) = CheckReserves( $issue->[$i]{'itemnumber'} );
237 $row{'norenew'} = ($restype) ? 1 : 0;
238 $row{'renew_failed'} = $renew_failed[$issue->[$i]{'itemnumber'}];
239 push( @issuedata, \%row );
242 ##################################################################################
244 # show all reserves of this borrower, and the position of the reservation ....
245 if ($borrowernumber) {
248 # now we show the status of the borrower's reservations
249 my @borrowerreserv = GetReservesFromBorrowernumber($borrowernumber );
251 foreach my $num_res (@borrowerreserv) {
253 my $getiteminfo = GetBiblioFromItemNumber( $num_res->{'itemnumber'} );
254 my $itemtypeinfo = getitemtypeinfo( $getiteminfo->{'itemtype'} );
255 my ( $transfertwhen, $transfertfrom, $transfertto ) =
256 GetTransfers( $num_res->{'itemnumber'} );
258 foreach (qw(waiting transfered nottransfered)) {
261 $getreserv{reservedate} = C4::Dates->new($num_res->{'reservedate'},'iso')->output('syspref');
262 foreach (qw(biblionumber title author barcodereserv itemcallnumber )) {
263 $getreserv{$_} = $getiteminfo->{$_};
265 $getreserv{itemtype} = $itemtypeinfo->{'description'};
267 # check if we have a waitin status for reservations
268 if ( $num_res->{'found'} eq 'W' ) {
269 $getreserv{color} = 'reserved';
270 $getreserv{waiting} = 1;
273 # check transfers with the itemnumber foud in th reservation loop
274 if ($transfertwhen) {
275 $getreserv{color} = 'transfered';
276 $getreserv{transfered} = 1;
277 $getreserv{datesent} = C4::Dates->new($transfertwhen, 'iso')->output('syspref') or die "Cannot get new($transfertwhen, 'iso') from C4::Dates";
278 $getreserv{frombranch} = GetBranchName($transfertfrom);
281 if ( ( $getiteminfo->{'holdingbranch'} ne $num_res->{'branchcode'} )
282 and not $transfertwhen )
284 $getreserv{nottransfered} = 1;
285 $getreserv{nottransferedby} =
286 GetBranchName( $getiteminfo->{'holdingbranch'} );
289 # if we don't have a reserv on item, we put the biblio infos and the waiting position
290 if ( $getiteminfo->{'title'} eq '' ) {
291 my $getbibinfo = GetBiblioItemData( $num_res->{'biblionumber'} );
292 my $getbibtype = getitemtypeinfo( $getbibinfo->{'itemtype'} );
293 $getreserv{color} = 'inwait';
294 $getreserv{title} = $getbibinfo->{'title'};
295 $getreserv{waitingposition} = $num_res->{'priority'};
296 $getreserv{nottransfered} = 0;
297 $getreserv{itemtype} = $getbibtype->{'description'};
298 $getreserv{author} = $getbibinfo->{'author'};
299 $getreserv{itemcallnumber} = '----------';
300 $getreserv{biblionumber} = $num_res->{'biblionumber'};
303 push( @reservloop, \%getreserv );
306 # return result to the template
307 $template->param( reservloop => \@reservloop );
310 # current alert subscriptions
311 my $alerts = getalert($borrowernumber);
313 $_->{ $_->{type} } = 1;
314 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
317 my $htdocs = C4::Context->config('intrahtdocs');
318 $picture = "/borrowerimages/" . $borrowernumber . ".jpg";
319 if ( -e $htdocs . "$picture" ) {
320 $template->param( picture => $picture );
322 my $branch=C4::Context->userenv->{'branch'};
324 $template->param($data);
328 roaddetails => $roaddetails,
329 borrowernumber => $borrowernumber,
330 reregistration => $reregistration,
332 totalprice => sprintf( "%.2f", $totalprice ),
333 totaldue => sprintf( "%.2f", $total ),
334 issueloop => \@issuedata,
335 unvalidlibrarian => $unvalidlibrarian,
338 StaffMember => ($category_type eq 'S'),
339 is_child => ($category_type eq 'C'),
340 # reserveloop => \@reservedata,
343 output_html_with_http_headers $input, $cookie, $template->output;