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
48 use C4::Branch; # GetBranchName
50 my $dbh = C4::Context->dbh;
53 my $print = $input->param('print');
56 if ( $print eq "page" ) {
57 $template_name = "members/moremember-print.tmpl";
59 elsif ( $print eq "slip" ) {
60 $template_name = "members/moremember-receipt.tmpl";
63 $template_name = "members/moremember.tmpl";
66 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
68 template_name => $template_name,
72 flagsrequired => { borrowers => 1 },
76 my $borrowernumber = $input->param('borrowernumber');
78 #start the page and read in includes
79 my $data = GetMember( $borrowernumber ,'borrowernumber');
80 my $reregistration = $input->param('reregistration');
82 if ( not defined $data ) {
86 output_html_with_http_headers $input, $cookie, $template->output;
90 # re-reregistration function to automatic calcul of date expiry
92 # $data->{'dateexpiry'} = GetMembeReregistration(
93 $data->{'dateexpiry'} = ExtendMemberSubscriptionTo(
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 );
190 my $branchdetail = GetBranchDetail( $data->{'branchcode'});
191 $data->{'branchname'} = $branchdetail->{branchname};
194 my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
195 my $lib1 = &GetSortDetails( "Bsort1", $data->{'sort1'} );
196 my $lib2 = &GetSortDetails( "Bsort2", $data->{'sort2'} );
197 ( $template->param( lib1 => $lib1 ) ) if ($lib1);
198 ( $template->param( lib2 => $lib2 ) ) if ($lib2);
202 my ( $count, $issue ) = GetPendingIssues($borrowernumber);
203 my $roaddetails = &GetRoadTypeDetails( $data->{'streettype'} );
204 my $today = POSIX::strftime("%Y%m%d", localtime);
208 for ( my $i = 0 ; $i < $count ; $i++ ) {
209 my $datedue = $issue->[$i]{'date_due'};
210 $issue->[$i]{'date_due'} = format_date( $issue->[$i]{'date_due'} );
211 my %row = %{ $issue->[$i] };
212 $totalprice += $issue->[$i]{'replacementprice'};
213 $row{'replacementprice'} = $issue->[$i]{'replacementprice'};
214 if ( $datedue < $today ) {
215 $row{'red'} = 1; #print "<font color=red>";
217 $row{toggle} = $toggle++ % 2;
219 #find the charge for an item
220 my ( $charge, $itemtype ) =
221 GetIssuingCharges( $issue->[$i]{'itemnumber'}, $borrowernumber );
223 my $itemtypeinfo = getitemtypeinfo($itemtype);
224 $row{'itemtype_description'} = $itemtypeinfo->{description};
225 $row{'itemtype_image'} = $itemtypeinfo->{imageurl};
227 $row{'charge'} = sprintf( "%.2f", $charge );
229 #check item is not reserved
230 my ( $restype, $reserves ) = CheckReserves( $issue->[$i]{'itemnumber'} );
237 push( @issuedata, \%row );
240 ##################################################################################
242 # show all reserves of this borrower, and the position of the reservation ....
243 if ($borrowernumber) {
246 # now we show the status of the borrower's reservations
247 my @borrowerreserv = GetReservesFromBorrowernumber($borrowernumber );
249 foreach my $num_res (@borrowerreserv) {
259 my $getiteminfo = GetBiblioFromItemNumber( $num_res->{'itemnumber'} );
260 my $itemtypeinfo = getitemtypeinfo( $getiteminfo->{'itemtype'} );
261 my ( $transfertwhen, $transfertfrom, $transfertto ) =
262 GetTransfers( $num_res->{'itemnumber'} );
264 $getreserv{waiting} = 0;
265 $getreserv{transfered} = 0;
266 $getreserv{nottransfered} = 0;
268 $getreserv{reservedate} = format_date( $num_res->{'reservedate'} );
269 $getreserv{biblionumber} = $getiteminfo->{'biblionumber'};
270 $getreserv{title} = $getiteminfo->{'title'};
271 $getreserv{itemtype} = $itemtypeinfo->{'description'};
272 $getreserv{author} = $getiteminfo->{'author'};
273 $getreserv{barcodereserv} = $getiteminfo->{'barcode'};
274 $getreserv{itemcallnumber} = $getiteminfo->{'itemcallnumber'};
276 # check if we have a waitin status for reservations
277 if ( $num_res->{'found'} eq 'W' ) {
278 $getreserv{color} = 'reserved';
279 $getreserv{waiting} = 1;
282 # check transfers with the itemnumber foud in th reservation loop
283 if ($transfertwhen) {
284 $getreserv{color} = 'transfered';
285 $getreserv{transfered} = 1;
286 $getreserv{datesent} = format_date($transfertwhen);
287 $getreserv{frombranch} = GetBranchName($transfertfrom);
290 if ( ( $getiteminfo->{'holdingbranch'} ne $num_res->{'branchcode'} )
291 and not $transfertwhen )
293 $getreserv{nottransfered} = 1;
294 $getreserv{nottransferedby} =
295 GetBranchName( $getiteminfo->{'holdingbranch'} );
298 # if we don't have a reserv on item, we put the biblio infos and the waiting position
299 if ( $getiteminfo->{'title'} eq '' ) {
300 my $getbibinfo = GetBiblioItemData( $num_res->{'biblionumber'} );
301 my $getbibtype = getitemtypeinfo( $getbibinfo->{'itemtype'} );
302 $getreserv{color} = 'inwait';
303 $getreserv{title} = $getbibinfo->{'title'};
304 $getreserv{waitingposition} = $num_res->{'priority'};
305 $getreserv{nottransfered} = 0;
306 $getreserv{itemtype} = $getbibtype->{'description'};
307 $getreserv{author} = $getbibinfo->{'author'};
308 $getreserv{itemcallnumber} = '----------';
309 $getreserv{biblionumber} = $num_res->{'biblionumber'};
312 push( @reservloop, \%getreserv );
315 # return result to the template
316 $template->param( reservloop => \@reservloop );
320 # current alert subscriptions
321 my $alerts = getalert($borrowernumber);
323 $_->{ $_->{type} } = 1;
324 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
327 my $htdocs = C4::Context->config('intrahtdocs');
328 $picture = "/borrowerimages/" . $borrowernumber . ".jpg";
329 if ( -e $htdocs . "$picture" ) {
330 $template->param( picture => $picture );
332 my $branch=C4::Context->userenv->{'branch'};
334 $template->param($data);
337 roaddetails => $roaddetails,
338 borrowernumber => $borrowernumber,
339 reregistration => $reregistration,
341 totalprice => sprintf( "%.2f", $totalprice ),
342 totaldue => sprintf( "%.2f", $total ),
343 issueloop => \@issuedata,
344 unvalidlibrarian => $unvalidlibrarian,
346 # reserveloop => \@reservedata,
349 output_html_with_http_headers $input, $cookie, $template->output;