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
39 use C4::Interface::CGI::Output;
40 use C4::Interface::CGI::Template;
50 use C4::Branch; # GetBranchName
52 my $dbh = C4::Context->dbh;
55 my $print = $input->param('print');
58 if ( $print eq "page" ) {
59 $template_name = "members/moremember-print.tmpl";
61 elsif ( $print eq "slip" ) {
62 $template_name = "members/moremember-receipt.tmpl";
65 $template_name = "members/moremember.tmpl";
68 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
70 template_name => $template_name,
74 flagsrequired => { borrowers => 1 },
78 my $borrowernumber = $input->param('borrowernumber');
80 #start the page and read in includes
81 my $data = borrdata( '', $borrowernumber );
82 my $reregistration = $input->param('reregistration');
84 if ( not defined $data ) {
88 output_html_with_http_headers $input, $cookie, $template->output;
92 # re-reregistration function to automatic calcul of date expiry
94 $data->{'dateexpiry'} = GetMembeReregistration(
95 $data->{'categorycode'},
96 $borrowernumber, $data->{'dateenrolled'}
98 ) if ( $reregistration eq 'y' );
99 my ( undef, undef, undef, $category_type ) =
100 getborrowercategory( $data->{'categorycode'} );
102 # in template <TMPL_IF name="I"> => instutitional (A for Adult& C for children)
103 $template->param( $data->{'categorycode'} => 1 );
105 $data->{'dateenrolled'} = format_date( $data->{'dateenrolled'} );
106 $data->{'dateexpiry'} = format_date( $data->{'dateexpiry'} );
107 $data->{'dateofbirth'} = format_date( $data->{'dateofbirth'} );
108 $data->{'IS_ADULT'} = ( $data->{'categorycode'} ne 'I' );
110 if ( $data->{'debarred'}
111 || $data->{'gonenoaddress'}
113 || $data->{'borrowernotes'} )
115 $template->param( flagged => 1 );
118 $data->{'ethnicity'} = fixEthnicity( $data->{'ethnicity'} );
120 $data->{ &expand_sex_into_predicate( $data->{'sex'} ) } = 1;
122 if ( $category_type eq 'C' and $data->{'guarantorid'} ne '0' ) {
123 my $data2 = borrdata( '', $data->{'guarantorid'} );
124 $data->{'address'} = $data2->{'address'};
125 $data->{'city'} = $data2->{'city'};
126 $data->{'B_address'} = $data2->{'B_address'};
127 $data->{'B_city'} = $data2->{'B_city'};
128 $data->{'phone'} = $data2->{'phone'};
129 $data->{'mobile'} = $data2->{'mobile'};
130 $data->{'zipcode'} = $data2->{'zipcode'};
133 if ( $data->{'ethnicity'} || $data->{'ethnotes'} ) {
134 $template->param( printethnicityline => 1 );
136 if ( $category_type eq 'A' ) {
137 $template->param( isguarantee => 1 );
140 # It looks like the $i is only being returned to handle walking through
141 # the array, which is probably better done as a foreach loop.
143 my ( $count, $guarantees ) = findguarantees( $data->{'borrowernumber'} );
145 for ( my $i = 0 ; $i < $count ; $i++ ) {
149 borrowernumber => $guarantees->[$i]->{'borrowernumber'},
150 cardnumber => $guarantees->[$i]->{'cardnumber'},
151 name => $guarantees->[$i]->{'firstname'} . " "
152 . $guarantees->[$i]->{'surname'}
156 $template->param( guaranteeloop => \@guaranteedata );
157 ( $template->param( adultborrower => 1 ) ) if ( $category_type eq 'A' );
161 my ($guarantorid) = findguarantor( $data->{'borrowernumber'} );
162 ( $template->param( guarantor => 1 ) )
163 if ( ( $data->{'guarantorid'} > '0' ) );
164 if ( $guarantorid->{'borrowernumber'} ) {
166 guarantorborrowernumber => $guarantorid->{'borrowernumber'},
167 guarantorcardnumber => $guarantorid->{'cardnumber'},
168 guarantorfirstname => $guarantorid->{'firstname'},
169 guarantorsurname => $guarantorid->{'surname'}
174 #Independant branches management
175 my $unvalidlibrarian =
176 ( ( C4::Context->preference("IndependantBranches") )
177 && ( C4::Context->userenv->{flags} != 1 )
178 && ( $data->{'branchcode'} ne C4::Context->userenv->{branch} ) );
181 $bor{'borrowernumber'} = $borrowernumber;
183 # Converts the branchcode to the branch name
185 if ( C4::Context->preference("IndependantBranches") ) {
186 my $userenv = C4::Context->userenv;
187 unless ( $userenv->{flags} == 1 ) {
188 $samebranch = ( $data->{'branchcode'} eq $userenv->{branch} );
190 $samebranch = 1 if ( $userenv->{flags} == 1 );
193 $data->{'branchname'} =
194 ( ( GetBranchDetail( $data->{'branchcode'} ) )->{'branchname'} );
196 # Converts the categorycode to the description
197 ( $data->{'categorycode'}, undef, undef ) =
198 &getborrowercategory( $data->{'categorycode'} );
200 my ( $numaccts, $accts, $total ) = getboracctrecord( '', \%bor );
201 my $lib1 = &GetSortDetails( "Bsort1", $data->{'sort1'} );
202 my $lib2 = &GetSortDetails( "Bsort2", $data->{'sort2'} );
203 ( $template->param( lib1 => $lib1 ) ) if ($lib1);
204 ( $template->param( lib2 => $lib2 ) ) if ($lib2);
208 my ( $count, $issue ) = borrissues($borrowernumber);
209 my $roaddetails = &GetRoadTypeDetails( $data->{'streettype'} );
210 my $today = ParseDate('today');
214 for ( my $i = 0 ; $i < $count ; $i++ ) {
215 my $datedue = ParseDate( $issue->[$i]{'date_due'} );
216 $issue->[$i]{'date_due'} = format_date( $issue->[$i]{'date_due'} );
217 my %row = %{ $issue->[$i] };
218 $totalprice += $issue->[$i]{'replacementprice'};
219 $row{'replacementprice'} = $issue->[$i]{'replacementprice'};
220 if ( $datedue < $today ) {
221 $row{'red'} = 1; #print "<font color=red>";
223 $row{toggle} = $toggle++ % 2;
225 #find the charge for an item
226 my ( $charge, $itemtype ) =
227 GetIssuingCharges( $issue->[$i]{'itemnumber'}, $borrowernumber );
229 my $itemtypeinfo = getitemtypeinfo($itemtype);
230 $row{'itemtype_description'} = $itemtypeinfo->{description};
231 $row{'itemtype_image'} = $itemtypeinfo->{imageurl};
233 $row{'charge'} = sprintf( "%.2f", $charge );
235 #check item is not reserved
236 my ( $restype, $reserves ) = CheckReserves( $issue->[$i]{'itemnumber'} );
239 # print "<TD><a href=/cgi-bin/koha/reserve/request.pl?biblionumber=$issue->[$i]{'biblionumber'}>On Request - no renewals</a></td></tr>";
240 # } elsif ($issue->[$i]->{'renewals'} > 0) {
241 # print "<TD>Previously Renewed - no renewals</td></tr>";
247 push( @issuedata, \%row );
253 # my ($rescount,$reserves)=FindReserves('',$borrowernumber); #From C4::Reserves2
256 # foreach my $reserveline (@$reserves) {
257 # $reserveline->{'reservedate2'} = format_date($reserveline->{'reservedate'});
259 # my %row = %$reserveline;
260 # $row{toggle} = $toggle++%2;
261 # if ($reserveline->{'constrainttype'} eq 'o'){
262 # $restitle=GetReserveTitle($reserveline->{'biblionumber'},$reserveline->{'borrowernumber'},$reserveline->{'reservedate'},$reserveline->{'rtimestamp'});
263 # %row = (%row , %$restitle) if $restitle;
265 # push (@reservedata, \%row);
268 ##################################################################################
270 # show all reserves of this borrower, and the position of the reservation ....
271 if ($borrowernumber) {
274 # now we show the status of the borrower's reservations
275 my @borrowerreserv = GetReservations( 0, $borrowernumber );
277 foreach my $num_res (@borrowerreserv) {
280 my $getiteminfo = GetBiblioFromItemNumber( $num_res->{'itemnumber'} );
281 my $itemtypeinfo = getitemtypeinfo( $getiteminfo->{'itemtype'} );
282 my ( $transfertwhen, $transfertfrom, $transfertto ) =
283 GetTransfers( $num_res->{'itemnumber'} );
285 $getreserv{waiting} = 0;
286 $getreserv{transfered} = 0;
287 $getreserv{nottransfered} = 0;
289 $getreserv{reservedate} = format_date( $num_res->{'reservedate'} );
290 $getreserv{biblionumber} = $getiteminfo->{'biblionumber'};
291 $getreserv{title} = $getiteminfo->{'title'};
292 $getreserv{itemtype} = $itemtypeinfo->{'description'};
293 $getreserv{author} = $getiteminfo->{'author'};
294 $getreserv{barcodereserv} = $getiteminfo->{'barcode'};
295 $getreserv{itemcallnumber} = $getiteminfo->{'itemcallnumber'};
297 # check if we have a waitin status for reservations
298 if ( $num_res->{'found'} eq 'W' ) {
299 $getreserv{color} = 'reserved';
300 $getreserv{waiting} = 1;
303 # check transfers with the itemnumber foud in th reservation loop
304 if ($transfertwhen) {
305 $getreserv{color} = 'transfered';
306 $getreserv{transfered} = 1;
307 $getreserv{datesent} = format_date($transfertwhen);
308 $getreserv{frombranch} = GetBranchName($transfertfrom);
311 if ( ( $getiteminfo->{'holdingbranch'} ne $num_res->{'branchcode'} )
312 and not $transfertwhen )
314 $getreserv{nottransfered} = 1;
315 $getreserv{nottransferedby} =
316 GetBranchName( $getiteminfo->{'holdingbranch'} );
319 # if we don't have a reserv on item, we put the biblio infos and the waiting position
320 if ( $getiteminfo->{'title'} eq '' ) {
321 my $getbibinfo = GetBiblioItemData( $num_res->{'biblionumber'} );
322 my $getbibtype = getitemtypeinfo( $getbibinfo->{'itemtype'} );
323 $getreserv{color} = 'inwait';
324 $getreserv{title} = $getbibinfo->{'title'};
325 $getreserv{waitingposition} = $num_res->{'priority'};
326 $getreserv{nottransfered} = 0;
327 $getreserv{itemtype} = $getbibtype->{'description'};
328 $getreserv{author} = $getbibinfo->{'author'};
329 $getreserv{itemcallnumber} = '----------';
330 $getreserv{biblionumber} = $num_res->{'biblionumber'};
333 push( @reservloop, \%getreserv );
336 # return result to the template
337 $template->param( reservloop => \@reservloop );
341 # current alert subscriptions
342 my $alerts = getalert($borrowernumber);
344 $_->{ $_->{type} } = 1;
345 $_->{relatedto} = findrelatedto( $_->{type}, $_->{externalid} );
348 my $htdocs = C4::Context->config('intrahtdocs');
349 $picture = "/borrowerimages/" . $borrowernumber . ".jpg";
350 if ( -e $htdocs . "$picture" ) {
351 $template->param( picture => $picture );
355 $template->param($data);
358 roaddetails => $roaddetails,
359 borrowernumber => $borrowernumber,
360 reregistration => $reregistration,
361 totalprice => sprintf( "%.2f", $totalprice ),
362 totaldue => sprintf( "%.2f", $total ),
363 issueloop => \@issuedata,
364 unvalidlibrarian => $unvalidlibrarian,
366 # reserveloop => \@reservedata,
369 output_html_with_http_headers $input, $cookie, $template->output;