From 408b934cdd98f7dc5fa09fce4a6256d6381e9e0a 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 Signed-off-by: Marie-Luce Signed-off-by: Axelle Signed-off-by: Owen Leonard Signed-off-by: Katrin Fischer Signed-off-by: Fridolin Somers --- 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(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 96a72a393a..a82fe54ea1 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -2281,6 +2281,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 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 040ceb0d96..4ffbc8e024 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt @@ -300,6 +300,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 ea005d458c..a33b824d52 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt +++ b/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 %] 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 9ab67912e9..c9e916e8ef 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 ba45ddd237..0380d88a9b 100755 --- a/opac/opac-user.pl +++ b/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'); -- 2.39.0