View | Details | Raw Unified | Return to bug 31051
Collapse All | Expand All

(-)a/Koha/Patron.pm (-14 / +12 lines)
Lines 2294-2315 sub get_savings { Link Here
2294
2294
2295
    my $savings = 0;
2295
    my $savings = 0;
2296
2296
2297
    # get old issues
2297
    # get old checkouts
2298
    my $old_issues_rs = $self->_result->old_issues;
2298
    my @old_checkouts = $self->old_checkouts->as_list;
2299
    my @old_itemnumbers = $old_issues_rs->get_column('itemnumber')->all;
2299
    foreach my $old_checkout ( @old_checkouts ) {
2300
2300
        if ( $old_checkout->item ) {
2301
    foreach my $itemnumber ( @old_itemnumbers ) {
2301
            $savings += $old_checkout->item->replacementprice;
2302
        my $item = Koha::Items->find( $itemnumber );
2302
        }
2303
        $savings += $item->replacementprice;
2304
    }
2303
    }
2305
2304
2306
    # get current issues
2305
    # get current checkouts
2307
    my $issues_rs = $self->_result->issues;
2306
    my @checkouts = $self->checkouts->as_list;
2308
    my @itemnumbers = $issues_rs->get_column('itemnumber')->all;
2307
    foreach my $checkout ( @checkouts ) {
2309
2308
        if ( $checkout->item ) {
2310
    foreach my $itemnumber ( @itemnumbers ) {
2309
            $savings += $checkout->item->replacementprice;
2311
        my $item = Koha::Items->find( $itemnumber );
2310
        }
2312
        $savings += $item->replacementprice;
2313
    }
2311
    }
2314
2312
2315
    return $savings;
2313
    return $savings;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref (+1 lines)
Lines 537-542 OPAC: Link Here
537
                  checkouthistory: "on patron's checkout history page (the system preference <em>opacreadinghistory</em> must be enabled)"
537
                  checkouthistory: "on patron's checkout history page (the system preference <em>opacreadinghistory</em> must be enabled)"
538
                  summary: "in user summary box on OPAC homepage (the system preference <em>OPACUserSummary</em> must be enabled)"
538
                  summary: "in user summary box on OPAC homepage (the system preference <em>OPACUserSummary</em> must be enabled)"
539
                  user: "on patron's 'your summary' page"
539
                  user: "on patron's 'your summary' page"
540
            - ". Note that displayed savings may be inaccurate if checkout history is anonymized."
540
    OpenURL:
541
    OpenURL:
541
        -
542
        -
542
            - 'Complete URL of OpenURL resolver (starting with <code>http://</code> or <code>https://</code>):'
543
            - 'Complete URL of OpenURL resolver (starting with <code>http://</code> or <code>https://</code>):'
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt (-1 / +1 lines)
Lines 56-62 Link Here
56
                        <div id="opac-user-readingrec">
56
                        <div id="opac-user-readingrec">
57
57
58
                        [% IF savings %]
58
                        [% IF savings %]
59
                            <div class="alert alert-info">
59
                            <div class="alert alert-info" id="savings">
60
                                Congratulations, you have saved a total of [% savings | $Price with_symbol => 1 %] by using the library.
60
                                Congratulations, you have saved a total of [% savings | $Price with_symbol => 1 %] by using the library.
61
                            </div>
61
                            </div>
62
                        [% END %]
62
                        [% END %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt (-1 / +1 lines)
Lines 163-169 Link Here
163
                    [% END # / IF patron_flagged %]
163
                    [% END # / IF patron_flagged %]
164
164
165
                    [% IF savings %]
165
                    [% IF savings %]
166
                        <div class="alert alert-info">
166
                        <div class="alert alert-info" id="savings">
167
                            Congratulations, you have saved a total of [% savings | $Price with_symbol => 1 %] by using the library.
167
                            Congratulations, you have saved a total of [% savings | $Price with_symbol => 1 %] by using the library.
168
                        </div>
168
                        </div>
169
                    [% END %]
169
                    [% END %]
(-)a/t/db_dependent/Koha/Patron.t (-2 / +30 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 19;
22
use Test::More tests => 20;
23
use Test::Exception;
23
use Test::Exception;
24
use Test::Warn;
24
use Test::Warn;
25
25
Lines 29-34 use Koha::DateUtils qw(dt_from_string); Link Here
29
use Koha::ArticleRequests;
29
use Koha::ArticleRequests;
30
use Koha::Patrons;
30
use Koha::Patrons;
31
use Koha::Patron::Relationships;
31
use Koha::Patron::Relationships;
32
use C4::Circulation qw( AddIssue AddReturn );
32
33
33
use t::lib::TestBuilder;
34
use t::lib::TestBuilder;
34
use t::lib::Mocks;
35
use t::lib::Mocks;
Lines 1349-1351 subtest 'notify_library_of_registration()' => sub { Link Here
1349
1350
1350
    $schema->storage->txn_rollback;
1351
    $schema->storage->txn_rollback;
1351
};
1352
};
1352
- 
1353
1354
subtest 'get_savings tests' => sub {
1355
    plan tests => 2;
1356
1357
    $schema->storage->txn_begin;
1358
1359
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
1360
    my $patron = $builder->build_object({ class => 'Koha::Patrons' }, { value => { branchcode => $library->branchcode } });
1361
1362
    t::lib::Mocks::mock_userenv({ patron => $patron, branchcode => $library->branchcode });
1363
1364
    my $biblio1 = $builder->build_object({ class => 'Koha::Biblios' });
1365
    my $item1 = $builder->build_object({ class => 'Koha::Items' }, { value => { biblionumber => $biblio1->biblionumber, replacementprice => '5.00', holdingbranch => $library->branchcode, homebranch => $library->branchcode } });
1366
    my $item2 = $builder->build_object({ class => 'Koha::Items' }, { value => { biblionumber => $biblio1->biblionumber, replacementprice => '5.00', holdingbranch => $library->branchcode, homebranch => $library->branchcode } });
1367
1368
    AddIssue( $patron->unblessed, $item1->barcode );
1369
    AddIssue( $patron->unblessed, $item2->barcode );
1370
1371
    my $savings = $patron->get_savings;
1372
    is( $savings, $item1->replacementprice + $item2->replacementprice, "Savings correctly calculated from current issues" );
1373
1374
    AddReturn( $item2->barcode, $item2->homebranch );
1375
1376
    $savings = $patron->get_savings;
1377
    is( $savings, $item1->replacementprice + $item2->replacementprice, "Savings correctly calculated from current and old issues" );
1378
1379
    $schema->storage->txn_rollback;
1380
};

Return to bug 31051