From 2ba88139a89dfc5a80cb0f40d0ad3d66ff36ee29 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Tue, 28 Jun 2022 16:58:03 +1200 Subject: [PATCH] Bug 31051: Show patron savings on the OPAC This new feature shows a patron how much they have saved by using the library rather than purchasing items. Savings are calculated based on item replacement prices. The system preference allows you to choose where to display the savings - the user page, the summary box on the OPAC homepage, or the checkout history page. To test: 1. Update database and restart services 2. Confirm the new OPACShowSavings system preference is found in the OPAC tab of Administration -> global system preferences. There should be no options selected. 3. Find a patron with a checkout history, or check out a few items to a patron. 4. Test with different values of OPACShowSavings and confirm that savings are shown in the expected places. Sponsored-by: Horowhenua Libraries Trust --- Koha/Patron.pm | 34 ++++++++++++++++++++++ .../opac-tmpl/bootstrap/en/modules/opac-main.tt | 8 +++++ .../bootstrap/en/modules/opac-readingrecord.tt | 7 +++++ .../opac-tmpl/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(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index c4788eaa68..bfa354f3e2 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -2184,6 +2184,40 @@ sub decoded_secret { return $self->secret; } +=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 diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt index 76fa790f8f..9113ffce10 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt @@ -278,6 +278,14 @@ [% END %] [% END %] + [% IF savings %] +
  • + + [% savings | $Price with_symbol => 1 %] + total savings + +
  • + [% END %] [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt index c637e4ad97..b16f73621f 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt @@ -3,6 +3,7 @@ [% USE KohaDates %] [% USE TablesSettings %] [% USE AdditionalContents %] +[% 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' %] @@ -53,6 +54,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 %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt index b0578c55d1..5d8e8ef008 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt +++ b/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 %] diff --git a/opac/opac-main.pl b/opac/opac-main.pl index 779c06d587..78f7975a10 100755 --- a/opac/opac-main.pl +++ b/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, ); } } diff --git a/opac/opac-readingrecord.pl b/opac/opac-readingrecord.pl index 927c37b275..55981483e9 100755 --- a/opac/opac-readingrecord.pl +++ b/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, diff --git a/opac/opac-user.pl b/opac/opac-user.pl index 86960e0c84..730b49e82c 100755 --- a/opac/opac-user.pl +++ b/opac/opac-user.pl @@ -167,6 +167,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'); -- 2.11.0