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');
55 if ($print eq "page") { $template_name = "members/moremember-print.tmpl"; }
56 elsif ($print eq "slip") { $template_name = "members/moremember-receipt.tmpl"; }
57 else { $template_name = "members/moremember.tmpl"; }
59 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
61 template_name => $template_name,
65 flagsrequired => { borrowers => 1 },
69 my $borrowernumber = $input->param('borrowernumber');
71 #start the page and read in includes
72 my $data = GetMember( $borrowernumber ,'borrowernumber');
73 my $reregistration = $input->param('reregistration');
75 if ( not defined $data ) {
76 $template->param (unknowuser => 1);
80 # re-reregistration function to automatic calcul of date expiry
82 # $data->{'dateexpiry'} = GetMembeReregistration(
83 $data->{'dateexpiry'} = ExtendMemberSubscriptionTo(
84 $data->{'categorycode'},
85 $borrowernumber, $data->{'dateenrolled'}
87 ) if ( $reregistration eq 'y' );
88 my $borrowercategory = GetBorrowercategory( $data->{'categorycode'} );
89 my $category_type = $borrowercategory->{'category_type'};
91 # in template <TMPL_IF name="I"> => instutitional (A for Adult& C for children)
92 $template->param( $data->{'categorycode'} => 1 );
94 foreach (qw(dateenrolled dateexpiry dateofbirth)) {
95 $data->{$_} = C4::Dates->new($data->{$_}, 'iso')->output()
96 or die ("failed C4::Dates->new(" . $data->{$_} . ", 'iso')->output()");
98 $data->{'IS_ADULT'} = ( $data->{'categorycode'} ne 'I' );
100 for (qw(debarred gonenoaddress lost borrowernotes)) {
101 $data->{$_} and $template->param(flagged => 1) and last;
104 $data->{'ethnicity'} = fixEthnicity( $data->{'ethnicity'} );
106 $data->{ "sex_".$data->{'sex'}."_p" } = 1;
108 if ( $category_type eq 'C' and $data->{'guarantorid'} ne '0' ) {
109 my $data2 = GetMember( $data->{'guarantorid'} ,'borrowernumber');
110 foreach (qw(address city B_address B_city phone mobilezipcode)) {
111 $data->{$_} = $data2->{$_};
115 if ( $data->{'ethnicity'} || $data->{'ethnotes'} ) {
116 $template->param( printethnicityline => 1 );
118 if ( $category_type eq 'A' ) {
119 $template->param( isguarantee => 1 );
122 # It looks like the $i is only being returned to handle walking through
123 # the array, which is probably better done as a foreach loop.
125 my ( $count, $guarantees ) = GetGuarantees( $data->{'borrowernumber'} );
127 for ( my $i = 0 ; $i < $count ; $i++ ) {
130 borrowernumber => $guarantees->[$i]->{'borrowernumber'},
131 cardnumber => $guarantees->[$i]->{'cardnumber'},
132 name => $guarantees->[$i]->{'firstname'} . " "
133 . $guarantees->[$i]->{'surname'}
137 $template->param( guaranteeloop => \@guaranteedata );
138 ( $template->param( adultborrower => 1 ) ) if ( $category_type eq 'A' );
141 if ($data->{'guarantorid'}){
142 my ($guarantor) = GetMember( $data->{'guarantorid'},'biblionumber');
143 $template->param(guarantor => 1);
144 foreach (qw(borrowernumber cardnumber firstname surname)) {
145 $template->param("guarantor$_" => $guarantor->{$_});
150 #Independant branches management
151 my $unvalidlibrarian =
152 ( ( C4::Context->preference("IndependantBranches") )
153 && ( C4::Context->userenv->{flags} != 1 )
154 && ( $data->{'branchcode'} ne C4::Context->userenv->{branch} ) );
157 $bor{'borrowernumber'} = $borrowernumber;
159 # Converts the branchcode to the branch name
161 if ( C4::Context->preference("IndependantBranches") ) {
162 my $userenv = C4::Context->userenv;
163 unless ( $userenv->{flags} == 1 ) {
164 $samebranch = ( $data->{'branchcode'} eq $userenv->{branch} );
166 $samebranch = 1 if ( $userenv->{flags} == 1 );
168 my $branchdetail = GetBranchDetail( $data->{'branchcode'});
169 $data->{'branchname'} = $branchdetail->{branchname};
172 my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
173 my $lib1 = &GetSortDetails( "Bsort1", $data->{'sort1'} );
174 my $lib2 = &GetSortDetails( "Bsort2", $data->{'sort2'} );
175 ( $template->param( lib1 => $lib1 ) ) if ($lib1);
176 ( $template->param( lib2 => $lib2 ) ) if ($lib2);
180 my ( $count, $issue ) = GetPendingIssues($borrowernumber);
181 my $roaddetails = &GetRoadTypeDetails( $data->{'streettype'} );
182 my $today = POSIX::strftime("%Y%m%d", localtime); # iso format
186 for ( my $i = 0 ; $i < $count ; $i++ ) {
187 my $datedue = $issue->[$i]{'date_due'};
188 $issue->[$i]{'date_due'} = C4::Dates->new($issue->[$i]{'date_due'})->output('iso');
189 my %row = %{ $issue->[$i] };
190 $totalprice += $issue->[$i]{'replacementprice'};
191 $row{'replacementprice'} = $issue->[$i]{'replacementprice'};
192 if ( $datedue < $today ) {
193 $row{'red'} = 1; #print "<font color=red>";
195 $row{toggle} = $toggle++ % 2;
197 #find the charge for an item
198 my ( $charge, $itemtype ) =
199 GetIssuingCharges( $issue->[$i]{'itemnumber'}, $borrowernumber );
201 my $itemtypeinfo = getitemtypeinfo($itemtype);
202 $row{'itemtype_description'} = $itemtypeinfo->{description};
203 $row{'itemtype_image'} = $itemtypeinfo->{imageurl};
205 $row{'charge'} = sprintf( "%.2f", $charge );
207 #check item is not reserved
208 my ( $restype, $reserves ) = CheckReserves( $issue->[$i]{'itemnumber'} );
209 $row{'norenew'} = ($restype) ? 1 : 0;
210 push( @issuedata, \%row );
213 ##################################################################################
215 # show all reserves of this borrower, and the position of the reservation ....
216 if ($borrowernumber) {
219 # now we show the status of the borrower's reservations
220 my @borrowerreserv = GetReservesFromBorrowernumber($borrowernumber );
222 foreach my $num_res (@borrowerreserv) {
226 ($@) and next; # is this eval just a dumb way of checking to see if the arrays have any elements?
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)) {
239 $getreserv{reservedate} = C4::Dates->new($num_res->{'reservedate'})->output() or die "Cannot get new($num_res->{'reservedate'}) from C4::Dates";
240 foreach (qw(biblionumber title author barcodereserv itemcallnumber )) {
241 $getreserv{$_} = $getiteminfo->{$_};
243 $getreserv{itemtype} = $itemtypeinfo->{'description'};
245 # check if we have a waitin status for reservations
246 if ( $num_res->{'found'} eq 'W' ) {
247 $getreserv{color} = 'reserved';
248 $getreserv{waiting} = 1;
251 # check transfers with the itemnumber foud in th reservation loop
252 if ($transfertwhen) {
253 $getreserv{color} = 'transfered';
254 $getreserv{transfered} = 1;
255 $getreserv{datesent} = C4::Dates->new($transfertwhen, 'iso')->output() or die "Cannot get new($transfertwhen, 'iso') from C4::Dates";
256 $getreserv{frombranch} = GetBranchName($transfertfrom);
259 if ( ( $getiteminfo->{'holdingbranch'} ne $num_res->{'branchcode'} )
260 and not $transfertwhen )
262 $getreserv{nottransfered} = 1;
263 $getreserv{nottransferedby} =
264 GetBranchName( $getiteminfo->{'holdingbranch'} );
267 # if we don't have a reserv on item, we put the biblio infos and the waiting position
268 if ( $getiteminfo->{'title'} eq '' ) {
269 my $getbibinfo = GetBiblioItemData( $num_res->{'biblionumber'} );
270 my $getbibtype = getitemtypeinfo( $getbibinfo->{'itemtype'} );
271 $getreserv{color} = 'inwait';
272 $getreserv{title} = $getbibinfo->{'title'};
273 $getreserv{waitingposition} = $num_res->{'priority'};
274 $getreserv{nottransfered} = 0;
275 $getreserv{itemtype} = $getbibtype->{'description'};
276 $getreserv{author} = $getbibinfo->{'author'};
277 $getreserv{itemcallnumber} = '----------';
278 $getreserv{biblionumber} = $num_res->{'biblionumber'};
281 push( @reservloop, \%getreserv );
284 # return result to the template
285 $template->param( reservloop => \@reservloop );
288 # current alert subscriptions
289 my $alerts = getalert($borrowernumber);
291 $_->{ $_->{type} } = 1;
292 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
295 my $htdocs = C4::Context->config('intrahtdocs');
296 $picture = "/borrowerimages/" . $borrowernumber . ".jpg";
297 if ( -e $htdocs . "$picture" ) {
298 $template->param( picture => $picture );
300 my $branch=C4::Context->userenv->{'branch'};
302 $template->param($data);
305 roaddetails => $roaddetails,
306 borrowernumber => $borrowernumber,
307 reregistration => $reregistration,
309 totalprice => sprintf( "%.2f", $totalprice ),
310 totaldue => sprintf( "%.2f", $total ),
311 issueloop => \@issuedata,
312 unvalidlibrarian => $unvalidlibrarian,
314 # reserveloop => \@reservedata,
317 output_html_with_http_headers $input, $cookie, $template->output;