Skip to content
Browse files

Merge branch 'Bug3484' into ptfs-master

Conflicts:

	admin/systempreferences.pl
	circ/circulation.pl
	koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl
  • Loading branch information...
2 parents eb49ce3 + e889551 commit bd0704195017ecc47636e048264800306a03a789 J. David Bavousett committed Apr 28, 2010
View
33 C4/Overdues.pm
@@ -39,6 +39,7 @@ BEGIN {
&CalcFine
&Getoverdues
&checkoverdues
+ &GetFinesSummary
&CheckAccountLineLevelInfo
&CheckAccountLineItemInfo
&CheckExistantNotifyid
@@ -177,6 +178,38 @@ sub checkoverdues {
return ( scalar(@$results), $results); # returning the count and the results is silly
}
+=head2 GetOverdueSummary
+
+=over 4
+
+my $fines_by_type = GetFinesSummary( $borrowernumber );
+
+=back
+
+Given a borrowernumber, this will return a hashref with the keys being the types
+of fines and the values being the totals for each kind of fine.
+
+=cut
+
+sub GetFinesSummary {
+ my ( $borrowernumber ) = @_;
+
+ my $dbh = C4::Context->dbh;
+
+ my $sth = $dbh->prepare( "
+ SELECT
+ accounttype, SUM(amountoutstanding) AS total
+ FROM accountlines
+ WHERE borrowernumber = ?
+ GROUP BY accounttype
+ HAVING total > 0 OR total < 0
+ " );
+
+ $sth->execute( $borrowernumber );
+
+ return { map { $_->{'accounttype'} => $_->{'total'} } @{ $sth->fetchall_arrayref( {} ) } }
+}
+
=head2 CalcFine
($amount, $chargename, $daycount, $daycounttotal) =
View
1 admin/systempreferences.pl
@@ -177,6 +177,7 @@ =head1 systempreferences.pl
$tabsysprefs{HoldButtonPrintConfirm} = "Circulation";
$tabsysprefs{HoldButtonIgnore} = "Circulation";
$tabsysprefs{AllowDueDateInPast} = "Circulation";
+$tabsysprefs{CircFinesBreakdown} = "Circulation";
# Staff Client
$tabsysprefs{TemplateEncoding} = "StaffClient";
View
45 circ/circulation.pl
@@ -27,6 +27,8 @@
use C4::Print;
use C4::Auth qw/:DEFAULT get_session check_override_perms/;
use C4::Dates qw/format_date/;
+use C4::Overdues qw( GetFinesSummary );
+use List::Util qw( sum );
use C4::Branch; # GetBranches
use C4::Koha; # GetPrinter
use C4::Circulation;
@@ -43,6 +45,43 @@
Date_to_Days
);
+sub FormatFinesSummary {
+ my ( $borrower ) = @_;
+
+ my %type_map = (
+ L => 'lost_fines',
+ F => 'overdue_fines',
+ FU => 'overdue_fines',
+ Res => 'reserve_fees'
+ );
+
+ my $dbh = C4::Context->dbh;
+
+ my $summary = GetFinesSummary( $borrower->{'borrowernumber'} );
+
+ my %params;
+
+ foreach my $type ( keys %type_map ) {
+ next if ( !$summary->{$type} );
+
+ $params{$type_map{$type} . "_total"} = ( $params{ $type_map{$type} . "_total" } || 0 ) + $summary->{$type};
+
+ delete $summary->{$type};
+ }
+
+ foreach my $type ( keys %$summary ) {
+ next if ( $summary->{$type} > 0 );
+
+ $params{"credits_total"} = ( $params{"credits_total"} || 0 ) - $summary->{$type};
+
+ delete $summary->{$type};
+ }
+
+ # Since the types we care about have already been removed, all that is left is 'Other'
+ $params{'other_fees_total'} = sum( values %$summary );
+
+ return +{ map { $params{$_} ? ( $_ => sprintf( '%0.2f', $params{$_} ) ) : undef } keys %params };
+}
#
# PARAMETERS READING
@@ -634,6 +673,8 @@
if ( override_can( $circ_session, 'override_max_fines' ) ) {
$template->param( charges_override => 1 );
}
+
+ $template->param( FormatFinesSummary( $borrower ) ) if ( C4::Context->preference( 'CircFinesBreakdown' ) );
}
if ( $flag eq 'CREDITS' ) {
$template->param(
@@ -650,12 +691,16 @@
chargesmsg => $flags->{'CHARGES'}->{'message'},
chargesamount => $flags->{'CHARGES'}->{'amount'},
);
+
+ $template->param( FormatFinesSummary( $borrower ) ) if ( C4::Context->preference( 'CircFinesBreakdown' ) );
}
elsif ( $flag eq 'CREDITS' ) {
$template->param(
credits => 'true',
creditsmsg => $flags->{'CREDITS'}->{'message'}
);
+
+ $template->param( FormatFinesSummary( $borrower ) ) if ( C4::Context->preference( 'CircFinesBreakdown' ) );
}
elsif ( $flag eq 'ODUES' ) {
$template->param(
View
16 koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tmpl
@@ -622,9 +622,19 @@ No patron matched <span class="ex"><!-- TMPL_VAR name="message" --></span>
<!-- TMPL_ELSE -->
<li>
<!-- /TMPL_IF -->
- <span class="circ-hlt">Fines:</span> Patron has <a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=<!-- TMPL_VAR name="borrowernumber" -->">Outstanding fines<!-- TMPL_IF NAME="chargesamount" --> of <!-- TMPL_VAR NAME="chargesamount" --><!-- /TMPL_IF --></a>.
+ <p>
+ <span class="circ-hlt">Fines:</span> Patron has <a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=<!-- TMPL_VAR name="borrowernumber" -->">Outstanding fines<!-- TMPL_IF NAME="chargesamount" --> of $<!-- TMPL_VAR NAME="chargesamount" --><!-- /TMPL_IF --></a>:
+ </p>
+ <ul>
+ <!-- TMPL_IF NAME="lost_fines_total" --><li><span class="circ-hlt">Replacement fees:</span> $<!-- TMPL_VAR NAME="lost_fines_total" --></li><!-- /TMPL_IF -->
+ <!-- TMPL_IF NAME="overdue_fines_total" --><li><span class="circ-hlt">Overdue fines:</span> $<!-- TMPL_VAR NAME="overdue_fines_total" --></li><!-- /TMPL_IF -->
+ <!-- TMPL_IF NAME="reserve_fees_total" --><li><span class="circ-hlt">Hold fees:</span> $<!-- TMPL_VAR NAME="reserve_fees_total" --></li><!-- /TMPL_IF -->
+ <!-- TMPL_IF NAME="other_fees_total" --><li><span class="circ-hlt">Other fees:</span> $<!-- TMPL_VAR NAME="other_fees_total" --></li><!-- /TMPL_IF -->
+ <!-- TMPL_IF NAME="credits_total" --><li><span class="circ-hlt">Credits:</span> -$<!-- TMPL_VAR NAME="credits_total" --></li><!-- /TMPL_IF -->
+ </ul>
+ <p>
<!-- TMPL_IF NAME="charges_is_blocker" -->
- Checkouts are blocked because fine balance is over the limit.
+ Checkouts are blocked because fine balance is over the limit.
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="CAN_user_updatecharges_accept_payment" -->
Make <a href="/cgi-bin/koha/members/pay.pl?borrowernumber=<!-- TMPL_VAR name="borrowernumber" -->">Payment</a>
@@ -637,7 +647,7 @@ No patron matched <span class="ex"><!-- TMPL_VAR name="message" --></span>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="credits" -->
- <li><span class="circ-hlt">Credits:</span> Patron has a credit</li>
+ <li><span class="circ-hlt">Credits:</span> Patron has a credit</li>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="override_user" -->

0 comments on commit bd07041

Please sign in to comment.
Something went wrong with that request. Please try again.