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
24 script to do a borrower enquiry/bring up borrower details etc
25 Displays all the details about a borrower
26 written 20/12/99 by chris@katipo.co.nz
27 last modified 21/1/2000 by chris@katipo.co.nz
28 modified 31/1/2001 by chris@katipo.co.nz
29 to not allow items on request to be renewed
31 needs html removed and to use the C4::Output more, but its tricky
49 use C4::Branch; # GetBranchName
51 my $dbh = C4::Context->dbh;
54 my $print = $input->param('print');
57 if ( $print eq "page" ) {
58 $template_name = "members/moremember-print.tmpl";
60 elsif ( $print eq "slip" ) {
61 $template_name = "members/moremember-receipt.tmpl";
64 $template_name = "members/moremember.tmpl";
67 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
69 template_name => $template_name,
73 flagsrequired => { borrowers => 1 },
77 my $borrowernumber = $input->param('borrowernumber');
79 #start the page and read in includes
80 my $data = GetMember( $borrowernumber ,'borrowernumber');
81 my $reregistration = $input->param('reregistration');
83 if ( not defined $data ) {
87 output_html_with_http_headers $input, $cookie, $template->output;
91 # re-reregistration function to automatic calcul of date expiry
93 $data->{'dateexpiry'} = GetMembeReregistration(
94 $data->{'categorycode'},
95 $borrowernumber, $data->{'dateenrolled'}
97 ) if ( $reregistration eq 'y' );
98 my $borrowercategory = GetBorrowercategory( $data->{'categorycode'} );
99 my $category_type = $borrowercategory->{'category_type'};
101 # in template <TMPL_IF name="I"> => instutitional (A for Adult& C for children)
102 $template->param( $data->{'categorycode'} => 1 );
104 $data->{'dateenrolled'} = format_date( $data->{'dateenrolled'} );
105 $data->{'dateexpiry'} = format_date( $data->{'dateexpiry'} );
106 $data->{'dateofbirth'} = format_date( $data->{'dateofbirth'} );
107 $data->{'IS_ADULT'} = ( $data->{'categorycode'} ne 'I' );
109 if ( $data->{'debarred'}
110 || $data->{'gonenoaddress'}
112 || $data->{'borrowernotes'} )
114 $template->param( flagged => 1 );
117 $data->{'ethnicity'} = fixEthnicity( $data->{'ethnicity'} );
119 $data->{ "sex_".$data->{'sex'}."_p" } = 1;
121 if ( $category_type eq 'C' and $data->{'guarantorid'} ne '0' ) {
122 my $data2 = GetMember( $data->{'guarantorid'} ,'borrowernumber');
123 $data->{'address'} = $data2->{'address'};
124 $data->{'city'} = $data2->{'city'};
125 $data->{'B_address'} = $data2->{'B_address'};
126 $data->{'B_city'} = $data2->{'B_city'};
127 $data->{'phone'} = $data2->{'phone'};
128 $data->{'mobile'} = $data2->{'mobile'};
129 $data->{'zipcode'} = $data2->{'zipcode'};
132 if ( $data->{'ethnicity'} || $data->{'ethnotes'} ) {
133 $template->param( printethnicityline => 1 );
135 if ( $category_type eq 'A' ) {
136 $template->param( isguarantee => 1 );
139 # It looks like the $i is only being returned to handle walking through
140 # the array, which is probably better done as a foreach loop.
142 my ( $count, $guarantees ) = GetGuarantees( $data->{'borrowernumber'} );
144 for ( my $i = 0 ; $i < $count ; $i++ ) {
148 borrowernumber => $guarantees->[$i]->{'borrowernumber'},
149 cardnumber => $guarantees->[$i]->{'cardnumber'},
150 name => $guarantees->[$i]->{'firstname'} . " "
151 . $guarantees->[$i]->{'surname'}
155 $template->param( guaranteeloop => \@guaranteedata );
156 ( $template->param( adultborrower => 1 ) ) if ( $category_type eq 'A' );
160 if ($data->{'guarantorid'}){
161 my ($guarantor) = GetMember( $data->{'guarantorid'},'biblionumber');
164 guarantorborrowernumber => $guarantor->{'borrowernumber'},
165 guarantorcardnumber => $guarantor->{'cardnumber'},
166 guarantorfirstname => $guarantor->{'firstname'},
167 guarantorsurname => $guarantor->{'surname'}
172 #Independant branches management
173 my $unvalidlibrarian =
174 ( ( C4::Context->preference("IndependantBranches") )
175 && ( C4::Context->userenv->{flags} != 1 )
176 && ( $data->{'branchcode'} ne C4::Context->userenv->{branch} ) );
179 $bor{'borrowernumber'} = $borrowernumber;
181 # Converts the branchcode to the branch name
183 if ( C4::Context->preference("IndependantBranches") ) {
184 my $userenv = C4::Context->userenv;
185 unless ( $userenv->{flags} == 1 ) {
186 $samebranch = ( $data->{'branchcode'} eq $userenv->{branch} );
188 $samebranch = 1 if ( $userenv->{flags} == 1 );
191 $data->{'branchname'} =
192 ( ( GetBranchDetail( $data->{'branchcode'} ) )->{'branchname'} );
195 my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
196 my $lib1 = &GetSortDetails( "Bsort1", $data->{'sort1'} );
197 my $lib2 = &GetSortDetails( "Bsort2", $data->{'sort2'} );
198 ( $template->param( lib1 => $lib1 ) ) if ($lib1);
199 ( $template->param( lib2 => $lib2 ) ) if ($lib2);
203 my ( $count, $issue ) = GetPendingIssues($borrowernumber);
204 my $roaddetails = &GetRoadTypeDetails( $data->{'streettype'} );
205 my $today = ParseDate('today');
209 for ( my $i = 0 ; $i < $count ; $i++ ) {
210 my $datedue = ParseDate( $issue->[$i]{'date_due'} );
211 $issue->[$i]{'date_due'} = format_date( $issue->[$i]{'date_due'} );
212 my %row = %{ $issue->[$i] };
213 $totalprice += $issue->[$i]{'replacementprice'};
214 $row{'replacementprice'} = $issue->[$i]{'replacementprice'};
215 if ( $datedue < $today ) {
216 $row{'red'} = 1; #print "<font color=red>";
218 $row{toggle} = $toggle++ % 2;
220 #find the charge for an item
221 my ( $charge, $itemtype ) =
222 GetIssuingCharges( $issue->[$i]{'itemnumber'}, $borrowernumber );
224 my $itemtypeinfo = getitemtypeinfo($itemtype);
225 $row{'itemtype_description'} = $itemtypeinfo->{description};
226 $row{'itemtype_image'} = $itemtypeinfo->{imageurl};
228 $row{'charge'} = sprintf( "%.2f", $charge );
230 #check item is not reserved
231 my ( $restype, $reserves ) = CheckReserves( $issue->[$i]{'itemnumber'} );
234 # print "<TD><a href=/cgi-bin/koha/reserve/request.pl?biblionumber=$issue->[$i]{'biblionumber'}>On Request - no renewals</a></td></tr>";
235 # } elsif ($issue->[$i]->{'renewals'} > 0) {
236 # print "<TD>Previously Renewed - no renewals</td></tr>";
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 $getreserv{waiting} = 0;
262 $getreserv{transfered} = 0;
263 $getreserv{nottransfered} = 0;
265 $getreserv{reservedate} = format_date( $num_res->{'reservedate'} );
266 $getreserv{biblionumber} = $getiteminfo->{'biblionumber'};
267 $getreserv{title} = $getiteminfo->{'title'};
268 $getreserv{itemtype} = $itemtypeinfo->{'description'};
269 $getreserv{author} = $getiteminfo->{'author'};
270 $getreserv{barcodereserv} = $getiteminfo->{'barcode'};
271 $getreserv{itemcallnumber} = $getiteminfo->{'itemcallnumber'};
273 # check if we have a waitin status for reservations
274 if ( $num_res->{'found'} eq 'W' ) {
275 $getreserv{color} = 'reserved';
276 $getreserv{waiting} = 1;
279 # check transfers with the itemnumber foud in th reservation loop
280 if ($transfertwhen) {
281 $getreserv{color} = 'transfered';
282 $getreserv{transfered} = 1;
283 $getreserv{datesent} = format_date($transfertwhen);
284 $getreserv{frombranch} = GetBranchName($transfertfrom);
287 if ( ( $getiteminfo->{'holdingbranch'} ne $num_res->{'branchcode'} )
288 and not $transfertwhen )
290 $getreserv{nottransfered} = 1;
291 $getreserv{nottransferedby} =
292 GetBranchName( $getiteminfo->{'holdingbranch'} );
295 # if we don't have a reserv on item, we put the biblio infos and the waiting position
296 if ( $getiteminfo->{'title'} eq '' ) {
297 my $getbibinfo = GetBiblioItemData( $num_res->{'biblionumber'} );
298 my $getbibtype = getitemtypeinfo( $getbibinfo->{'itemtype'} );
299 $getreserv{color} = 'inwait';
300 $getreserv{title} = $getbibinfo->{'title'};
301 $getreserv{waitingposition} = $num_res->{'priority'};
302 $getreserv{nottransfered} = 0;
303 $getreserv{itemtype} = $getbibtype->{'description'};
304 $getreserv{author} = $getbibinfo->{'author'};
305 $getreserv{itemcallnumber} = '----------';
306 $getreserv{biblionumber} = $num_res->{'biblionumber'};
309 push( @reservloop, \%getreserv );
312 # return result to the template
313 $template->param( reservloop => \@reservloop );
317 # current alert subscriptions
318 my $alerts = getalert($borrowernumber);
320 $_->{ $_->{type} } = 1;
321 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
324 my $htdocs = C4::Context->config('intrahtdocs');
325 $picture = "/borrowerimages/" . $borrowernumber . ".jpg";
326 if ( -e $htdocs . "$picture" ) {
327 $template->param( picture => $picture );
331 $template->param($data);
334 roaddetails => $roaddetails,
335 borrowernumber => $borrowernumber,
336 reregistration => $reregistration,
337 totalprice => sprintf( "%.2f", $totalprice ),
338 totaldue => sprintf( "%.2f", $total ),
339 issueloop => \@issuedata,
340 unvalidlibrarian => $unvalidlibrarian,
342 # reserveloop => \@reservedata,
345 output_html_with_http_headers $input, $cookie, $template->output;