Adding replacement price to issues loop and a totalprice variable which totals the...
[koha.git] / members / moremember.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
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
11 #
12 # needs html removed and to use the C4::Output more, but its tricky
13 #
14
15
16 # Copyright 2000-2002 Katipo Communications
17 #
18 # This file is part of Koha.
19 #
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
23 # version.
24 #
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.
28 #
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
32
33 use strict;
34 use C4::Auth;
35 use C4::Context;
36 use C4::Output;
37 use C4::Interface::CGI::Output;
38 use C4::Interface::CGI::Template;
39 use CGI;
40 use C4::Search;
41 use Date::Manip;
42 use C4::Date;
43 use C4::Reserves2;
44 use C4::Circulation::Circ2;
45 use C4::Koha;
46 use HTML::Template;
47
48 my $dbh = C4::Context->dbh;
49
50 my $input = new CGI;
51
52 my ($template, $loggedinuser, $cookie)
53     = get_template_and_user({template_name => "members/moremember.tmpl",
54                              query => $input,
55                              type => "intranet",
56                              authnotrequired => 0,
57                              flagsrequired => {borrowers => 1},
58                              debug => 1,
59                              });
60
61 my $bornum=$input->param('bornum');
62
63 #start the page and read in includes
64
65 my $data=borrdata('',$bornum);
66
67 $template->param($data->{'categorycode'} => 1); # in template <TMPL_IF name="I"> => instutitional (A for Adult & C for children)
68
69 $data->{'dateenrolled'} = format_date($data->{'dateenrolled'});
70 $data->{'expiry'} = format_date($data->{'expiry'});
71 $data->{'dateofbirth'} = format_date($data->{'dateofbirth'});
72 $data->{'IS_ADULT'} = ($data->{'categorycode'} ne 'I');
73
74 $data->{'ethnicity'} = fixEthnicity($data->{'ethnicity'});
75
76 $data->{&expand_sex_into_predicate($data->{'sex'})} = 1;
77
78 if ($data->{'categorycode'} eq 'C'){
79         my $data2=borrdata('',$data->{'guarantor'});
80         $data->{'streetaddress'}=$data2->{'streetaddress'};
81         $data->{'city'}=$data2->{'city'};
82         $data->{'physstreet'}=$data2->{'physstreet'};
83         $data->{'streetcity'}=$data2->{'streetcity'};
84         $data->{'phone'}=$data2->{'phone'};
85         $data->{'phoneday'}=$data2->{'phoneday'};
86         $data->{'zipcode'} = $data2->{'zipcode'};
87 }
88
89
90 if ($data->{'ethnicity'} || $data->{'ethnotes'}) {
91         $template->param(printethnicityline => 1);
92 }
93
94 if ($data->{'categorycode'} ne 'C'){
95         $template->param(isguarantee => 1);
96         # FIXME
97         # It looks like the $i is only being returned to handle walking through
98         # the array, which is probably better done as a foreach loop.
99         #
100         my ($count,$guarantees)=findguarantees($data->{'borrowernumber'});
101         my @guaranteedata;
102         for (my $i=0;$i<$count;$i++){
103                 push (@guaranteedata, {borrowernumber => $guarantees->[$i]->{'borrowernumber'},
104                                         cardnumber => $guarantees->[$i]->{'cardnumber'},
105                                         name => $guarantees->[$i]->{'firstname'} . " " . $guarantees->[$i]->{'surname'}});
106         }
107         $template->param(guaranteeloop => \@guaranteedata);
108
109 } else {
110         my ($guarantor)=findguarantor($data->{'borrowernumber'});
111         unless ($guarantor->{'borrowernumber'} == 0){
112                 $template->param(guarantorborrowernumber => $guarantor->{'borrowernumber'}, guarantorcardnumber => $guarantor->{'cardnumber'});
113         }
114 }
115
116 my %bor;
117 $bor{'borrowernumber'}=$bornum;
118
119 # Converts the branchcode to the branch name
120 $data->{'branchcode'} = &getbranchname($data->{'branchcode'});
121
122 # Converts the categorycode to the description
123 $data->{'categorycode'} = &getborrowercategory($data->{'categorycode'});
124
125 my ($numaccts,$accts,$total)=getboracctrecord('',\%bor);
126
127 my ($count,$issue)=borrissues($bornum);
128 my $today=ParseDate('today');
129 my @issuedata;
130 my $totalprice = 0;
131 for (my $i=0;$i<$count;$i++){
132         my $datedue=ParseDate($issue->[$i]{'date_due'});
133         $issue->[$i]{'date_due'} = format_date($issue->[$i]{'date_due'});
134         my %row = %{$issue->[$i]};
135         $totalprice += $issue->[$i]{'replacementprice'};
136         $row{'replacementprice'}=$issue->[$i]{'replacementprice'};
137         if ($datedue < $today){
138                 $row{'red'}=1; #print "<font color=red>";
139         }
140         #find the charge for an item
141         # FIXME - This is expecting
142         # &C4::Circulation::Renewals2::calc_charges, but it's getting
143         # &C4::Circulation::Circ2::calc_charges, which only returns one
144         # element, so itemtype isn't being set.
145         # But &C4::Circulation::Renewals2::calc_charges doesn't appear to
146         # return the correct item type either (or a properly-formatted
147         # charge, for that matter).
148         my ($charge,$itemtype)=calc_charges(undef,$dbh,$issue->[$i]{'itemnumber'},$bornum);
149         $row{'itemtype'}=&ItemType($itemtype);
150         $row{'charge'}=$charge;
151
152         #check item is not reserved
153         my ($restype,$reserves)=CheckReserves($issue->[$i]{'itemnumber'});
154         if ($restype){
155 #               print "<TD><a href=/cgi-bin/koha/request.pl?bib=$issue->[$i]{'biblionumber'}>On Request - no renewals</a></td></tr>";
156                 #  } elsif ($issue->[$i]->{'renewals'} > 0) {
157                 #      print "<TD>Previously Renewed - no renewals</td></tr>";
158                         $row{'norenew'}=1;
159         } else {
160                 $row{'norenew'}=0;
161         }
162         push (@issuedata, \%row);
163 }
164
165 my ($rescount,$reserves)=FindReserves('',$bornum); #From C4::Reserves2
166
167 my @reservedata;
168 foreach my $reserveline (@$reserves) {
169         $reserveline->{'reservedate2'} = format_date($reserveline->{'reservedate'});
170         my $restitle;
171         my %row = %$reserveline;
172         if ($reserveline->{'constrainttype'} eq 'o'){
173                 $restitle=getreservetitle($reserveline->{'biblionumber'},$reserveline->{'borrowernumber'},$reserveline->{'reservedate'},$reserveline->{'rtimestamp'});
174                 %row =  (%row , %$restitle) if $restitle;
175         }
176         push (@reservedata, \%row);
177 }
178
179 $template->param($data);
180 $template->param(
181                  bornum          => $bornum,
182                  totalprice =>$totalprice,
183                  totaldue =>$total,
184                  issueloop       => \@issuedata,
185                  reserveloop     => \@reservedata);
186
187 output_html_with_http_headers $input, $cookie, $template->output;