5 # script to do a borrower enquiry/bring up borrower details etc
6 # Displays all the details about a borrower
7 # written 20/12/99 by chris@katipo.co.nz
8 # last modified 21/1/2000 by chris@katipo.co.nz
9 # modified 31/1/2001 by chris@katipo.co.nz
10 # to not allow items on request to be renewed
12 # needs html removed and to use the C4::Output more, but its tricky
16 # Copyright 2000-2002 Katipo Communications
18 # This file is part of Koha.
20 # Koha is free software; you can redistribute it and/or modify it under the
21 # terms of the GNU General Public License as published by the Free Software
22 # Foundation; either version 2 of the License, or (at your option) any later
25 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
26 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
27 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
29 # You should have received a copy of the GNU General Public License along with
30 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
31 # Suite 330, Boston, MA 02111-1307 USA
37 use C4::Interface::CGI::Output;
38 use C4::Interface::CGI::Template;
44 use C4::Circulation::Circ2;
49 my $dbh = C4::Context->dbh;
52 my $print = $input->param('print');
56 $template_name = "members/moremember-print.tmpl";
57 } elsif($print eq "slip"){
58 $template_name = "members/moremember-receipt.tmpl";
60 $template_name = "members/moremember.tmpl";
63 my ($template, $loggedinuser, $cookie)
64 = get_template_and_user({template_name => $template_name,
68 flagsrequired => {borrowers => 1},
72 my $bornum=$input->param('bornum');
73 #start the page and read in includes
74 my $data=borrdata('',$bornum);
76 my (undef,undef,undef,$category_type)=getborrowercategory($data->{'categorycode'});
77 $template->param($data->{'categorycode'} => 1); # in template <TMPL_IF name="I"> => instutitional (A for Adult & C for children)
78 $data->{'dateenrolled'} = format_date($data->{'dateenrolled'});
79 $data->{'dateexpiry'} = format_date($data->{'dateexpiry'});
80 $data->{'dateofbirth'} = format_date($data->{'dateofbirth'});
81 $data->{'IS_ADULT'} = ($data->{'categorycode'} ne 'I');
83 if($data->{'debarred'} || $data->{'gonenoaddress'} || $data->{'lost'} || $data->{'borrowernotes'}){
84 $template->param(flagged =>1);
87 $data->{'ethnicity'} = fixEthnicity($data->{'ethnicity'});
89 $data->{&expand_sex_into_predicate($data->{'sex'})} = 1;
91 if ($category_type eq 'C' and $data->{'guarantorid'} ne '0' ){
92 my $data2=borrdata('',$data->{'guarantorid'});
93 $data->{'address'}=$data2->{'address'};
94 $data->{'city'}=$data2->{'city'};
95 $data->{'B_address'}=$data2->{'B_address'};
96 $data->{'B_city'}=$data2->{'B_city'};
97 $data->{'phone'}=$data2->{'phone'};
98 $data->{'mobile'}=$data2->{'mobile'};
99 $data->{'zipcode'} = $data2->{'zipcode'};
102 if ($data->{'ethnicity'} || $data->{'ethnotes'}) {
103 $template->param(printethnicityline => 1);
105 if ($category_type ne 'C'){
106 $template->param(isguarantee => 1);
108 # It looks like the $i is only being returned to handle walking through
109 # the array, which is probably better done as a foreach loop.
111 my ($count,$guarantees)=findguarantees($data->{'borrowernumber'});
113 for (my $i=0;$i<$count;$i++){
114 push (@guaranteedata, {borrowernumber => $guarantees->[$i]->{'borrowernumber'},
115 cardnumber => $guarantees->[$i]->{'cardnumber'},
116 name => $guarantees->[$i]->{'firstname'} . " " . $guarantees->[$i]->{'surname'}});
118 $template->param(guaranteeloop => \@guaranteedata);
119 ($template->param(adultborrower=>1)) if ($category_type eq 'A');
121 my ($guarantorid)=findguarantor($data->{guarantorid});
122 if ($guarantorid->{'borrowernumber'}){
123 $template->param(guarantorborrowernumber => $guarantorid->{'borrowernumber'}, guarantorcardnumber => $guarantorid->{'cardnumber'});
127 #Independant branches management
128 my $unvalidlibrarian = ((C4::Context->preference("IndependantBranches")) && (C4::Context->userenv->{flags}!=1) && ($data->{'branchcode'} ne C4::Context->userenv->{branch}));
131 $bor{'borrowernumber'}=$bornum;
133 # Converts the branchcode to the branch name
135 if (C4::Context->preference("IndependantBranches")) {
136 my $userenv = C4::Context->userenv;
137 unless ($userenv->{flags} == 1){
138 $samebranch = ($data->{'branchcode'} eq $userenv->{branch});
140 $samebranch =1 if ($userenv->{flags} == 1);
143 $data->{'branchname'} = ((getbranchdetail($data->{'branchcode'}))->{'branchname'});
145 # Converts the categorycode to the description
146 ($data->{'categorycode'},undef,undef) = &getborrowercategory($data->{'categorycode'});
148 my ($numaccts,$accts,$total)=getboracctrecord('',\%bor);
153 my ($count,$issue)=borrissues($bornum);
155 my $today=ParseDate('today');
159 for (my $i=0;$i<$count;$i++){
160 my $datedue=ParseDate($issue->[$i]{'date_due'});
161 $issue->[$i]{'date_due'} = format_date($issue->[$i]{'date_due'});
162 my %row = %{$issue->[$i]};
163 $totalprice += $issue->[$i]{'replacementprice'};
164 $row{'replacementprice'}=$issue->[$i]{'replacementprice'};
165 if ($datedue < $today){
166 $row{'red'}=1; #print "<font color=red>";
168 $row{toggle} = $toggle++%2;
169 #find the charge for an item
170 # FIXME - This is expecting
171 # &C4::Circulation::Renewals2::calc_charges, but it's getting
172 # &C4::Circulation::Circ2::calc_charges, which only returns one
173 # element, so itemtype isn't being set.
174 # But &C4::Circulation::Renewals2::calc_charges doesn't appear to
175 # return the correct item type either (or a properly-formatted
176 # charge, for that matter).
177 my ($charge,$itemtype)=calc_charges($dbh,$issue->[$i]{'itemnumber'},$bornum);
179 my $itemtypeinfo = getitemtypeinfo($itemtype);
180 $row{'itemtype_description'} = $itemtypeinfo->{description};
181 $row{'itemtype_image'} = $itemtypeinfo->{imageurl};
183 $row{'charge'}= sprintf("%.2f",$charge);
185 #check item is not reserved
186 my ($restype,$reserves)=CheckReserves($issue->[$i]{'itemnumber'});
188 # print "<TD><a href=/cgi-bin/koha/request.pl?bib=$issue->[$i]{'biblionumber'}>On Request - no renewals</a></td></tr>";
189 # } elsif ($issue->[$i]->{'renewals'} > 0) {
190 # print "<TD>Previously Renewed - no renewals</td></tr>";
195 push (@issuedata, \%row);
201 my ($rescount,$reserves)=FindReserves('',$bornum); #From C4::Reserves2
204 foreach my $reserveline (@$reserves) {
205 $reserveline->{'reservedate2'} = format_date($reserveline->{'reservedate'});
207 my %row = %$reserveline;
208 $row{toggle} = $toggle++%2;
209 if ($reserveline->{'constrainttype'} eq 'o'){
210 $restitle=getreservetitle($reserveline->{'biblionumber'},$reserveline->{'borrowernumber'},$reserveline->{'reservedate'},$reserveline->{'rtimestamp'});
211 %row = (%row , %$restitle) if $restitle;
213 push (@reservedata, \%row);
216 # current alert subscriptions
217 my $alerts = getalert($bornum);
220 $_->{relatedto} = findrelatedto($_->{type},$_->{externalid});
223 my $htdocs = C4::Context->config('intrahtdocs');
224 $picture = "/borrowerimages/".$bornum.".jpg";
225 if (-e $htdocs."$picture")
227 $template->param(picture => $picture)
229 $template->param($data);
232 totalprice =>sprintf("%.2f",$totalprice),
233 totaldue => sprintf("%.2f",$total),
234 issueloop => \@issuedata,
235 unvalidlibrarian => $unvalidlibrarian,
236 reserveloop => \@reservedata,
237 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
238 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
239 IntranetNav => C4::Context->preference("IntranetNav"),
240 patronimages => C4::Context->preference("patronimages"),
243 output_html_with_http_headers $input, $cookie, $template->output;