@@ -, +, @@ --- Koha/Patron.pm | 34 +++++++++++++++++++ .../bootstrap/en/modules/opac-main.tt | 8 +++++ .../en/modules/opac-readingrecord.tt | 7 ++++ .../bootstrap/en/modules/opac-user.tt | 6 ++++ opac/opac-main.pl | 8 ++++- opac/opac-readingrecord.pl | 6 ++++ opac/opac-user.pl | 5 +++ 7 files changed, 73 insertions(+), 1 deletion(-) --- a/Koha/Patron.pm +++ a/Koha/Patron.pm @@ -2196,6 +2196,40 @@ sub virtualshelves { return Koha::Virtualshelves->_new_from_dbic( scalar $self->_result->virtualshelves ); } +=head3 get_savings + + my $savings = $patron->get_savings; + +Use the replacement price of patron's old and current issues to calculate how much they have 'saved' by using the library. + +=cut + +sub get_savings { + my ( $self ) = @_; + + my $savings = 0; + + # get old issues + my $old_issues_rs = $self->_result->old_issues; + my @old_itemnumbers = $old_issues_rs->get_column('itemnumber')->all; + + foreach my $itemnumber ( @old_itemnumbers ) { + my $item = Koha::Items->find( $itemnumber ); + $savings += $item->replacementprice; + } + + # get current issues + my $issues_rs = $self->_result->issues; + my @itemnumbers = $issues_rs->get_column('itemnumber')->all; + + foreach my $itemnumber ( @itemnumbers ) { + my $item = Koha::Items->find( $itemnumber ); + $savings += $item->replacementprice; + } + + return $savings; +} + =head2 Internal methods =head3 _type --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt +++ a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt @@ -282,6 +282,14 @@ [% END %] [% END %] + [% IF savings %] +
  • + + [% savings | $Price with_symbol => 1 %] + total savings + +
  • + [% END %] [% END %] --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt +++ a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt @@ -4,6 +4,7 @@ [% USE TablesSettings %] [% USE AdditionalContents %] [% USE Asset %] +[% USE Price %] [% SET OpacNav = AdditionalContents.get( location => "OpacNav", lang => lang, library => logged_in_user.branchcode || default_branch, blocktitle => 0 ) %] [% SET OpacNavBottom = AdditionalContents.get( location => "OpacNavBottom", lang => lang, library => logged_in_user.branchcode || default_branch, blocktitle => 0 ) %] [% INCLUDE 'doc-head-open.inc' %] @@ -54,6 +55,12 @@ [% ELSE %]
    + [% IF savings %] +
    + Congratulations, you have saved a total of [% savings | $Price with_symbol => 1 %] by using the [% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog. +
    + [% END %] +
    [% UNLESS ( limit ) %][% END %] --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt +++ a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt @@ -162,6 +162,12 @@
    [% END # / IF patron_flagged %] + [% IF savings %] +
    + Congratulations, you have saved a total of [% savings | $Price with_symbol => 1 %] by using the [% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog. +
    + [% END %] + [% IF ( OpacMySummaryNote ) %] [% PROCESS koha_news_block news => OpacMySummaryNote %] --- a/opac/opac-main.pl +++ a/opac/opac-main.pl @@ -94,7 +94,12 @@ if ( $patron ) { }); my $patron_note = $patron->opacnote; my $total = $patron->account->balance; - if ( $checkouts > 0 || $overdues_count > 0 || $holds_pending > 0 || $holds_waiting > 0 || $total > 0 || $patron_note || $patron_messages->count ) { + my $saving_display = C4::Context->preference('OPACShowSavings'); + my $savings = 0; + if ( $saving_display =~ /summary/ ) { + $savings = $patron->get_savings; + } + if ( $checkouts > 0 || $overdues_count > 0 || $holds_pending > 0 || $holds_waiting > 0 || $total > 0 || $patron_note || $patron_messages->count || $savings > 0 ) { $template->param( dashboard_info => 1, checkouts => $checkouts, @@ -104,6 +109,7 @@ if ( $patron ) { total_owing => $total, patron_messages => $patron_messages, opacnote => $patron_note, + savings => $savings, ); } } --- a/opac/opac-readingrecord.pl +++ a/opac/opac-readingrecord.pl @@ -141,6 +141,12 @@ for(qw(AmazonCoverImages GoogleJackets)) { # BakerTaylorEnabled handled above $template->param(JacketImages=>1); } +my $saving_display = C4::Context->preference('OPACShowSavings'); +if ( $saving_display =~ /checkouthistory/ ) { + my $patron = Koha::Patrons->find( $borrowernumber ); + $template->param( savings => $patron->get_savings ); +} + $template->param( READING_RECORD => $issues, limit => $limit, --- a/opac/opac-user.pl +++ a/opac/opac-user.pl @@ -164,6 +164,11 @@ if ( $borr->{'dateexpiry'} && C4::Context->preference('NotifyBorrowerDeparture') } } +my $saving_display = C4::Context->preference('OPACShowSavings'); +if ( $saving_display =~ /user/ ) { + $template->param( savings => $patron->get_savings ); +} + # pass on any renew errors to the template for displaying my $renew_error = $query->param('renew_error'); --