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 $error = $input->param('error');
66 for (@failedrenews) { $renew_failed[$_] = 1; }
70 if ($print eq "page") { $template_name = "members/moremember-print.tmpl"; }
71 elsif ($print eq "slip") { $template_name = "members/moremember-receipt.tmpl"; }
72 else { $template_name = "members/moremember.tmpl"; }
74 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
76 template_name => $template_name,
80 flagsrequired => { borrowers => 1 },
84 my $borrowernumber = $input->param('borrowernumber');
86 #start the page and read in includes
87 my $data = GetMember( $borrowernumber ,'borrowernumber');
88 my $reregistration = $input->param('reregistration');
90 if ( not defined $data ) {
91 $template->param (unknowuser => 1);
92 output_html_with_http_headers $input, $cookie, $template->output;
96 # re-reregistration function to automatic calcul of date expiry
97 if ( $reregistration eq 'y' ) {
98 $data->{'dateexpiry'} = ExtendMemberSubscriptionTo( $borrowernumber );
101 my $borrowercategory = GetBorrowercategory( $data->{'categorycode'} );
102 my $category_type = $borrowercategory->{'category_type'};
106 # in template <TMPL_IF name="I"> => instutitional (A for Adult& C for children)
107 $template->param( $data->{'categorycode'} => 1 );
109 $debug and printf STDERR "dates (enrolled,expiry,birthdate) raw: (%s, %s, %s)\n", map {$data->{$_}} qw(dateenrolled dateexpiry dateofbirth);
110 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
111 my $userdate = $data->{$_};
113 $debug and warn sprintf "Empty \$data{%12s}", $_;
117 $userdate = C4::Dates->new($userdate,'iso')->output('syspref');
118 $data->{$_} = $userdate || '';
119 $template->param( $_ => $userdate );
121 $data->{'IS_ADULT'} = ( $data->{'categorycode'} ne 'I' );
123 for (qw(debarred gonenoaddress lost borrowernotes)) {
124 $data->{$_} and $template->param(flagged => 1) and last;
127 $data->{'ethnicity'} = fixEthnicity( $data->{'ethnicity'} );
128 $data->{ "sex_".$data->{'sex'}."_p" } = 1;
131 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);
141 $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
142 $template->param( 'catcode' => $catcodes->[0]) if $cnt == 1;
146 if ( $data->{'ethnicity'} || $data->{'ethnotes'} ) {
147 $template->param( printethnicityline => 1 );
149 if ( $category_type eq 'A' ) {
150 $template->param( isguarantee => 1 );
153 # It looks like the $i is only being returned to handle walking through
154 # the array, which is probably better done as a foreach loop.
156 my ( $count, $guarantees ) = GetGuarantees( $data->{'borrowernumber'} );
158 for ( my $i = 0 ; $i < $count ; $i++ ) {
161 borrowernumber => $guarantees->[$i]->{'borrowernumber'},
162 cardnumber => $guarantees->[$i]->{'cardnumber'},
163 name => $guarantees->[$i]->{'firstname'} . " "
164 . $guarantees->[$i]->{'surname'}
168 $template->param( guaranteeloop => \@guaranteedata );
169 ( $template->param( adultborrower => 1 ) ) if ( $category_type eq 'A' );
172 if ($data->{'guarantorid'}){
173 my ($guarantor) = GetMember( $data->{'guarantorid'},'biblionumber');
174 $template->param(guarantor => 1);
175 foreach (qw(borrowernumber cardnumber firstname surname)) {
176 $template->param("guarantor$_" => $guarantor->{$_});
181 #Independant branches management
182 my $unvalidlibrarian =
183 ( ( C4::Context->preference("IndependantBranches") )
184 && ( C4::Context->userenv->{flags} != 1 )
185 && ( $data->{'branchcode'} ne C4::Context->userenv->{branch} ) );
188 $bor{'borrowernumber'} = $borrowernumber;
190 # Converts the branchcode to the branch name
192 if ( C4::Context->preference("IndependantBranches") ) {
193 my $userenv = C4::Context->userenv;
194 unless ( $userenv->{flags} == 1 ) {
195 $samebranch = ( $data->{'branchcode'} eq $userenv->{branch} );
197 $samebranch = 1 if ( $userenv->{flags} == 1 );
199 my $branchdetail = GetBranchDetail( $data->{'branchcode'});
200 $data->{'branchname'} = $branchdetail->{branchname};
203 my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
204 my $lib1 = &GetSortDetails( "Bsort1", $data->{'sort1'} );
205 my $lib2 = &GetSortDetails( "Bsort2", $data->{'sort2'} );
206 ( $template->param( lib1 => $lib1 ) ) if ($lib1);
207 ( $template->param( lib2 => $lib2 ) ) if ($lib2);
211 my ( $count, $issue ) = GetPendingIssues($borrowernumber);
212 my $roaddetails = &GetRoadTypeDetails( $data->{'streettype'} );
213 my $today = POSIX::strftime("%Y%m%d", localtime); # iso format
217 for ( my $i = 0 ; $i < $count ; $i++ ) {
218 my $datedue = $issue->[$i]{'date_due'};
219 $issue->[$i]{'date_due'} = C4::Dates->new($issue->[$i]{'date_due'},'iso')->output('syspref');
220 my %row = %{ $issue->[$i] };
221 $totalprice += $issue->[$i]{'replacementprice'};
222 $row{'replacementprice'} = $issue->[$i]{'replacementprice'};
223 if ( $datedue < $today ) {
224 $row{'red'} = 1; #print "<font color=red>";
226 $row{toggle} = $toggle++ % 2;
228 #find the charge for an item
229 my ( $charge, $itemtype ) =
230 GetIssuingCharges( $issue->[$i]{'itemnumber'}, $borrowernumber );
232 my $itemtypeinfo = getitemtypeinfo($itemtype);
233 $row{'itemtype_description'} = $itemtypeinfo->{description};
234 $row{'itemtype_image'} = $itemtypeinfo->{imageurl};
236 $row{'charge'} = sprintf( "%.2f", $charge );
238 #check item is not reserved
239 my ( $restype, $reserves ) = CheckReserves( $issue->[$i]{'itemnumber'} );
240 $row{'norenew'} = ($restype) ? 1 : 0;
241 $row{'renew_failed'} = $renew_failed[$issue->[$i]{'itemnumber'}];
242 push( @issuedata, \%row );
245 ### ###############################################################################
247 # show all reserves of this borrower, and the position of the reservation ....
248 if ($borrowernumber) {
251 # now we show the status of the borrower's reservations
252 my @borrowerreserv = GetReservesFromBorrowernumber($borrowernumber );
254 foreach my $num_res (@borrowerreserv) {
256 my $getiteminfo = GetBiblioFromItemNumber( $num_res->{'itemnumber'} );
257 my $itemtypeinfo = getitemtypeinfo( $getiteminfo->{'itemtype'} );
258 my ( $transfertwhen, $transfertfrom, $transfertto ) =
259 GetTransfers( $num_res->{'itemnumber'} );
261 foreach (qw(waiting transfered nottransfered)) {
264 $getreserv{reservedate} = C4::Dates->new($num_res->{'reservedate'},'iso')->output('syspref');
265 foreach (qw(biblionumber title author barcodereserv itemcallnumber )) {
266 $getreserv{$_} = $getiteminfo->{$_};
268 $getreserv{itemtype} = $itemtypeinfo->{'description'};
270 # check if we have a waitin status for reservations
271 if ( $num_res->{'found'} eq 'W' ) {
272 $getreserv{color} = 'reserved';
273 $getreserv{waiting} = 1;
276 # check transfers with the itemnumber foud in th reservation loop
277 if ($transfertwhen) {
278 $getreserv{color} = 'transfered';
279 $getreserv{transfered} = 1;
280 $getreserv{datesent} = C4::Dates->new($transfertwhen, 'iso')->output('syspref') or die "Cannot get new($transfertwhen, 'iso') from C4::Dates";
281 $getreserv{frombranch} = GetBranchName($transfertfrom);
284 if ( ( $getiteminfo->{'holdingbranch'} ne $num_res->{'branchcode'} )
285 and not $transfertwhen )
287 $getreserv{nottransfered} = 1;
288 $getreserv{nottransferedby} =
289 GetBranchName( $getiteminfo->{'holdingbranch'} );
292 # if we don't have a reserv on item, we put the biblio infos and the waiting position
293 if ( $getiteminfo->{'title'} eq '' ) {
294 my $getbibinfo = GetBiblioItemData( $num_res->{'biblionumber'} );
295 my $getbibtype = getitemtypeinfo( $getbibinfo->{'itemtype'} );
296 $getreserv{color} = 'inwait';
297 $getreserv{title} = $getbibinfo->{'title'};
298 $getreserv{waitingposition} = $num_res->{'priority'};
299 $getreserv{nottransfered} = 0;
300 $getreserv{itemtype} = $getbibtype->{'description'};
301 $getreserv{author} = $getbibinfo->{'author'};
302 $getreserv{itemcallnumber} = '----------';
303 $getreserv{biblionumber} = $num_res->{'biblionumber'};
306 push( @reservloop, \%getreserv );
309 # return result to the template
310 $template->param( reservloop => \@reservloop );
313 # current alert subscriptions
314 my $alerts = getalert($borrowernumber);
316 $_->{ $_->{type} } = 1;
317 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
320 my $htdocs = C4::Context->config('intrahtdocs');
321 $picture = "/borrowerimages/" . $borrowernumber . ".jpg";
322 if ( -e $htdocs . "$picture" ) {
323 $template->param( picture => $picture );
325 my $branch=C4::Context->userenv->{'branch'};
327 $template->param($data);
331 roaddetails => $roaddetails,
332 borrowernumber => $borrowernumber,
333 reregistration => $reregistration,
335 totalprice => sprintf( "%.2f", $totalprice ),
336 totaldue => sprintf( "%.2f", $total ),
337 issueloop => \@issuedata,
338 unvalidlibrarian => $unvalidlibrarian,
341 StaffMember => ($category_type eq 'S'),
342 is_child => ($category_type eq 'C'),
343 # reserveloop => \@reservedata,
346 output_html_with_http_headers $input, $cookie, $template->output;