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
49 my $dbh = C4::Context->dbh;
52 my $print = $input->param('print');
53 my @failedrenews = $input->param('failedrenew');
55 for (@failedrenews) { $renew_failed[$_] = 1; }
59 if ($print eq "page") { $template_name = "members/moremember-print.tmpl"; }
60 elsif ($print eq "slip") { $template_name = "members/moremember-receipt.tmpl"; }
61 else { $template_name = "members/moremember.tmpl"; }
63 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
65 template_name => $template_name,
69 flagsrequired => { borrowers => 1 },
73 my $borrowernumber = $input->param('borrowernumber');
75 #start the page and read in includes
76 my $data = GetMember( $borrowernumber ,'borrowernumber');
77 my $reregistration = $input->param('reregistration');
79 if ( not defined $data ) {
80 $template->param (unknowuser => 1);
84 # re-reregistration function to automatic calcul of date expiry
86 # $data->{'dateexpiry'} = GetMembeReregistration(
87 $data->{'dateexpiry'} = ExtendMemberSubscriptionTo(
88 $data->{'categorycode'},
89 $borrowernumber, $data->{'dateenrolled'}
91 ) if ( $reregistration eq 'y' );
92 my $borrowercategory = GetBorrowercategory( $data->{'categorycode'} );
93 my $category_type = $borrowercategory->{'category_type'};
95 # in template <TMPL_IF name="I"> => instutitional (A for Adult& C for children)
96 $template->param( $data->{'categorycode'} => 1 );
98 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
99 my $tempdate = C4::Dates->new($data->{$_})->output('iso')
100 or warn ("Invalid $_ = " . $data->{$_});
101 $data->{$_} = $tempdate || '';
103 $data->{'IS_ADULT'} = ( $data->{'categorycode'} ne 'I' );
105 for (qw(debarred gonenoaddress lost borrowernotes)) {
106 $data->{$_} and $template->param(flagged => 1) and last;
109 $data->{'ethnicity'} = fixEthnicity( $data->{'ethnicity'} );
111 $data->{ "sex_".$data->{'sex'}."_p" } = 1;
113 if ( $category_type eq 'C' and $data->{'guarantorid'} ne '0' ) {
114 my $data2 = GetMember( $data->{'guarantorid'} ,'borrowernumber');
115 foreach (qw(address city B_address B_city phone mobilezipcode)) {
116 $data->{$_} = $data2->{$_};
120 if ( $data->{'ethnicity'} || $data->{'ethnotes'} ) {
121 $template->param( printethnicityline => 1 );
123 if ( $category_type eq 'A' ) {
124 $template->param( isguarantee => 1 );
127 # It looks like the $i is only being returned to handle walking through
128 # the array, which is probably better done as a foreach loop.
130 my ( $count, $guarantees ) = GetGuarantees( $data->{'borrowernumber'} );
132 for ( my $i = 0 ; $i < $count ; $i++ ) {
135 borrowernumber => $guarantees->[$i]->{'borrowernumber'},
136 cardnumber => $guarantees->[$i]->{'cardnumber'},
137 name => $guarantees->[$i]->{'firstname'} . " "
138 . $guarantees->[$i]->{'surname'}
142 $template->param( guaranteeloop => \@guaranteedata );
143 ( $template->param( adultborrower => 1 ) ) if ( $category_type eq 'A' );
146 if ($data->{'guarantorid'}){
147 my ($guarantor) = GetMember( $data->{'guarantorid'},'biblionumber');
148 $template->param(guarantor => 1);
149 foreach (qw(borrowernumber cardnumber firstname surname)) {
150 $template->param("guarantor$_" => $guarantor->{$_});
155 #Independant branches management
156 my $unvalidlibrarian =
157 ( ( C4::Context->preference("IndependantBranches") )
158 && ( C4::Context->userenv->{flags} != 1 )
159 && ( $data->{'branchcode'} ne C4::Context->userenv->{branch} ) );
162 $bor{'borrowernumber'} = $borrowernumber;
164 # Converts the branchcode to the branch name
166 if ( C4::Context->preference("IndependantBranches") ) {
167 my $userenv = C4::Context->userenv;
168 unless ( $userenv->{flags} == 1 ) {
169 $samebranch = ( $data->{'branchcode'} eq $userenv->{branch} );
171 $samebranch = 1 if ( $userenv->{flags} == 1 );
173 my $branchdetail = GetBranchDetail( $data->{'branchcode'});
174 $data->{'branchname'} = $branchdetail->{branchname};
177 my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
178 my $lib1 = &GetSortDetails( "Bsort1", $data->{'sort1'} );
179 my $lib2 = &GetSortDetails( "Bsort2", $data->{'sort2'} );
180 ( $template->param( lib1 => $lib1 ) ) if ($lib1);
181 ( $template->param( lib2 => $lib2 ) ) if ($lib2);
185 my ( $count, $issue ) = GetPendingIssues($borrowernumber);
186 my $roaddetails = &GetRoadTypeDetails( $data->{'streettype'} );
187 my $today = POSIX::strftime("%Y%m%d", localtime); # iso format
191 for ( my $i = 0 ; $i < $count ; $i++ ) {
192 my $datedue = $issue->[$i]{'date_due'};
193 $issue->[$i]{'date_due'} = C4::Dates->new($issue->[$i]{'date_due'},'iso')->output(C4::Context->preference('dateformat'));
194 my %row = %{ $issue->[$i] };
195 $totalprice += $issue->[$i]{'replacementprice'};
196 $row{'replacementprice'} = $issue->[$i]{'replacementprice'};
197 if ( $datedue < $today ) {
198 $row{'red'} = 1; #print "<font color=red>";
200 $row{toggle} = $toggle++ % 2;
202 #find the charge for an item
203 my ( $charge, $itemtype ) =
204 GetIssuingCharges( $issue->[$i]{'itemnumber'}, $borrowernumber );
206 my $itemtypeinfo = getitemtypeinfo($itemtype);
207 $row{'itemtype_description'} = $itemtypeinfo->{description};
208 $row{'itemtype_image'} = $itemtypeinfo->{imageurl};
210 $row{'charge'} = sprintf( "%.2f", $charge );
212 #check item is not reserved
213 my ( $restype, $reserves ) = CheckReserves( $issue->[$i]{'itemnumber'} );
214 $row{'norenew'} = ($restype) ? 1 : 0;
215 $row{'renew_failed'} = $renew_failed[$issue->[$i]{'itemnumber'}];
216 push( @issuedata, \%row );
219 ##################################################################################
221 # show all reserves of this borrower, and the position of the reservation ....
222 if ($borrowernumber) {
225 # now we show the status of the borrower's reservations
226 my @borrowerreserv = GetReservesFromBorrowernumber($borrowernumber );
228 foreach my $num_res (@borrowerreserv) {
230 my $getiteminfo = GetBiblioFromItemNumber( $num_res->{'itemnumber'} );
231 my $itemtypeinfo = getitemtypeinfo( $getiteminfo->{'itemtype'} );
232 my ( $transfertwhen, $transfertfrom, $transfertto ) =
233 GetTransfers( $num_res->{'itemnumber'} );
235 foreach (qw(waiting transfered nottransfered)) {
238 $getreserv{reservedate} = C4::Dates->new($num_res->{'reservedate'},'iso')->output(C4::Context->preference('dateformat'));
239 foreach (qw(biblionumber title author barcodereserv itemcallnumber )) {
240 $getreserv{$_} = $getiteminfo->{$_};
242 $getreserv{itemtype} = $itemtypeinfo->{'description'};
244 # check if we have a waitin status for reservations
245 if ( $num_res->{'found'} eq 'W' ) {
246 $getreserv{color} = 'reserved';
247 $getreserv{waiting} = 1;
250 # check transfers with the itemnumber foud in th reservation loop
251 if ($transfertwhen) {
252 $getreserv{color} = 'transfered';
253 $getreserv{transfered} = 1;
254 $getreserv{datesent} = C4::Dates->new($transfertwhen, 'iso')->output() or die "Cannot get new($transfertwhen, 'iso') from C4::Dates";
255 $getreserv{frombranch} = GetBranchName($transfertfrom);
258 if ( ( $getiteminfo->{'holdingbranch'} ne $num_res->{'branchcode'} )
259 and not $transfertwhen )
261 $getreserv{nottransfered} = 1;
262 $getreserv{nottransferedby} =
263 GetBranchName( $getiteminfo->{'holdingbranch'} );
266 # if we don't have a reserv on item, we put the biblio infos and the waiting position
267 if ( $getiteminfo->{'title'} eq '' ) {
268 my $getbibinfo = GetBiblioItemData( $num_res->{'biblionumber'} );
269 my $getbibtype = getitemtypeinfo( $getbibinfo->{'itemtype'} );
270 $getreserv{color} = 'inwait';
271 $getreserv{title} = $getbibinfo->{'title'};
272 $getreserv{waitingposition} = $num_res->{'priority'};
273 $getreserv{nottransfered} = 0;
274 $getreserv{itemtype} = $getbibtype->{'description'};
275 $getreserv{author} = $getbibinfo->{'author'};
276 $getreserv{itemcallnumber} = '----------';
277 $getreserv{biblionumber} = $num_res->{'biblionumber'};
280 push( @reservloop, \%getreserv );
283 # return result to the template
284 $template->param( reservloop => \@reservloop );
287 # current alert subscriptions
288 my $alerts = getalert($borrowernumber);
290 $_->{ $_->{type} } = 1;
291 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
294 my $htdocs = C4::Context->config('intrahtdocs');
295 $picture = "/borrowerimages/" . $borrowernumber . ".jpg";
296 if ( -e $htdocs . "$picture" ) {
297 $template->param( picture => $picture );
299 my $branch=C4::Context->userenv->{'branch'};
301 $template->param($data);
304 roaddetails => $roaddetails,
305 borrowernumber => $borrowernumber,
306 reregistration => $reregistration,
308 totalprice => sprintf( "%.2f", $totalprice ),
309 totaldue => sprintf( "%.2f", $total ),
310 issueloop => \@issuedata,
311 unvalidlibrarian => $unvalidlibrarian,
313 # reserveloop => \@reservedata,
316 output_html_with_http_headers $input, $cookie, $template->output;