see mail on koha-devel : code cleaning on Search.pm + normalizing API + use of biblio...
[koha.git] / members / moremember.pl
index 958e434..5030ff2 100755 (executable)
@@ -37,21 +37,31 @@ use C4::Output;
 use C4::Interface::CGI::Output;
 use C4::Interface::CGI::Template;
 use CGI;
-use C4::Search;
+use C4::Members;
 use Date::Manip;
 use C4::Date;
 use C4::Reserves2;
-use C4::Circulation::Renewals2;
 use C4::Circulation::Circ2;
 use C4::Koha;
+use C4::Letters;
 use HTML::Template;
 
 my $dbh = C4::Context->dbh;
 
 my $input = new CGI;
+my $print = $input->param('print');
+my $template_name;
+
+if($print eq "page"){
+       $template_name = "members/moremember-print.tmpl";
+} elsif($print eq "slip"){
+       $template_name = "members/moremember-receipt.tmpl";
+} else {
+       $template_name = "members/moremember.tmpl";
+}
 
 my ($template, $loggedinuser, $cookie)
-    = get_template_and_user({template_name => "members/moremember.tmpl",
+    = get_template_and_user({template_name => $template_name,
                             query => $input,
                             type => "intranet",
                             authnotrequired => 0,
@@ -72,6 +82,10 @@ $data->{'expiry'} = format_date($data->{'expiry'});
 $data->{'dateofbirth'} = format_date($data->{'dateofbirth'});
 $data->{'IS_ADULT'} = ($data->{'categorycode'} ne 'I');
 
+if($data->{'debarred'} || $data->{'gonenoaddress'} || $data->{'lost'} || $data->{'borrowernotes'}){
+       $template->param(flagged =>1);
+}
+
 $data->{'ethnicity'} = fixEthnicity($data->{'ethnicity'});
 
 $data->{&expand_sex_into_predicate($data->{'sex'})} = 1;
@@ -118,6 +132,15 @@ my %bor;
 $bor{'borrowernumber'}=$bornum;
 
 # Converts the branchcode to the branch name
+my $samebranch;
+if (C4::Context->preference("IndependantBranches")) {
+       my $userenv = C4::Context->userenv;
+       unless ($userenv->{flags} == 1){
+               $samebranch = ($data->{'branchcode'} eq $userenv->{branch});
+       }
+       $samebranch =1 if ($userenv->{flags} == 1);
+}
+
 $data->{'branchcode'} = &getbranchname($data->{'branchcode'});
 
 # Converts the categorycode to the description
@@ -125,13 +148,20 @@ $data->{'categorycode'} = &getborrowercategory($data->{'categorycode'});
 
 my ($numaccts,$accts,$total)=getboracctrecord('',\%bor);
 
+#
+# current issues
+#
 my ($count,$issue)=borrissues($bornum);
+
 my $today=ParseDate('today');
 my @issuedata;
+my $totalprice = 0;
 for (my $i=0;$i<$count;$i++){
        my $datedue=ParseDate($issue->[$i]{'date_due'});
        $issue->[$i]{'date_due'} = format_date($issue->[$i]{'date_due'});
        my %row = %{$issue->[$i]};
+       $totalprice += $issue->[$i]{'replacementprice'};
+       $row{'replacementprice'}=$issue->[$i]{'replacementprice'};
        if ($datedue < $today){
                $row{'red'}=1; #print "<font color=red>";
        }
@@ -143,24 +173,28 @@ for (my $i=0;$i<$count;$i++){
        # But &C4::Circulation::Renewals2::calc_charges doesn't appear to
        # return the correct item type either (or a properly-formatted
        # charge, for that matter).
-       my ($charge,$itemtype)=calc_charges(undef,$dbh,$issue->[$i]{'itemnumber'},$bornum);
-       $row{'itemtype'}=&ItemType($itemtype);
-       $row{'charge'}=$charge;
+       my ($charge,$itemtype)=calc_charges($dbh,$issue->[$i]{'itemnumber'},$bornum);
+       my $itemtypedef = getitemtypeinfo($itemtype);
+       $row{'itemtype'}=$itemtypedef->{description};
+       $row{'charge'}= sprintf("%.2f",$charge);
 
        #check item is not reserved
        my ($restype,$reserves)=CheckReserves($issue->[$i]{'itemnumber'});
        if ($restype){
-               print "<TD><a href=/cgi-bin/koha/request.pl?bib=$issue->[$i]{'biblionumber'}>On Request - no renewals</a></td></tr>";
+#              print "<TD><a href=/cgi-bin/koha/request.pl?bib=$issue->[$i]{'biblionumber'}>On Request - no renewals</a></td></tr>";
                #  } elsif ($issue->[$i]->{'renewals'} > 0) {
                #      print "<TD>Previously Renewed - no renewals</td></tr>";
+                       $row{'norenew'}=1;
        } else {
                $row{'norenew'}=0;
        }
        push (@issuedata, \%row);
 }
 
+#
+# find reserves
+#
 my ($rescount,$reserves)=FindReserves('',$bornum); #From C4::Reserves2
-
 my @reservedata;
 foreach my $reserveline (@$reserves) {
        $reserveline->{'reservedate2'} = format_date($reserveline->{'reservedate'});
@@ -173,11 +207,29 @@ foreach my $reserveline (@$reserves) {
        push (@reservedata, \%row);
 }
 
+# current alert subscriptions
+my $alerts = getalert($bornum);
+foreach (@$alerts) {
+       $_->{$_->{type}}=1;
+       $_->{relatedto} = findrelatedto($_->{type},$_->{externalid});
+}
+my $picture;
+my $htdocs = C4::Context->config('intrahtdocs');
+$picture = "/borrowerimages/".$bornum.".jpg";
+if (-e $htdocs."$picture")
+{ 
+  $template->param(picture => $picture)
+};
 $template->param($data);
 $template->param(
                 bornum          => $bornum,
+                totalprice =>$totalprice,
                 totaldue =>$total,
                 issueloop       => \@issuedata,
-                reserveloop     => \@reservedata);
+                reserveloop     => \@reservedata,
+                alertloop => $alerts);
+                independantbranches => C4::Context->preference("IndependantBranches"),
+                samebranch              => C4::Context->preference("IndependantBranches"?"":$samebranch,
+               );
 
 output_html_with_http_headers $input, $cookie, $template->output;