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

(-)a/Koha/Patron.pm (-1 / +44 lines)
Lines 21-27 package Koha::Patron; Link Here
21
use Modern::Perl;
21
use Modern::Perl;
22
22
23
use List::MoreUtils    qw( any none uniq notall zip6);
23
use List::MoreUtils    qw( any none uniq notall zip6);
24
use JSON               qw( to_json );
24
use JSON               qw( from_json to_json );
25
use Scalar::Util       qw(looks_like_number);
25
use Scalar::Util       qw(looks_like_number);
26
use Unicode::Normalize qw( NFKD );
26
use Unicode::Normalize qw( NFKD );
27
use Try::Tiny;
27
use Try::Tiny;
Lines 33-38 use C4::Letters qw( GetPreparedLetter EnqueueLetter SendQueuedMessages ); Link Here
33
use C4::Log     qw( logaction );
33
use C4::Log     qw( logaction );
34
use C4::Scrubber;
34
use C4::Scrubber;
35
use Koha::Account;
35
use Koha::Account;
36
use Koha::ActionLogs;
36
use Koha::ArticleRequests;
37
use Koha::ArticleRequests;
37
use Koha::AuthUtils;
38
use Koha::AuthUtils;
38
use Koha::Caches;
39
use Koha::Caches;
Lines 639-644 sub relationships_debt { Link Here
639
    return $non_issues_charges;
640
    return $non_issues_charges;
640
}
641
}
641
642
643
=head3 historic_cardnumbers
644
645
Returns a list of historic cardnumbers and their change date, or undef
646
647
=cut
648
649
sub historic_cardnumbers {
650
    my ($self) = @_;
651
652
    my $logentries = Koha::ActionLogs->search(
653
        {
654
            module => 'MEMBERS',
655
            action => 'MODIFY_CARDNUMBER',
656
            object => $self->borrowernumber,
657
        },
658
        { order_by => { -desc => 'timestamp' } }
659
    )->unblessed or return;
660
661
    my @cardnumbers;
662
    for my $logentry ( @{$logentries} ) {
663
        my $info      = from_json( $logentry->{info} );
664
        my $timestamp = $logentry->{timestamp};
665
666
        next
667
            unless $info->{before}
668
            and $info->{after}
669
            and $timestamp;
670
671
        my $object = {
672
            previous_cardnumber => $info->{before},
673
            new_cardnumber      => $info->{after},
674
            timestamp           => $timestamp,
675
        };
676
677
        push @cardnumbers, $object;
678
    }
679
680
    return \@cardnumbers;
681
}
682
642
=head3 housebound_profile
683
=head3 housebound_profile
643
684
644
Returns the HouseboundProfile associated with this patron.
685
Returns the HouseboundProfile associated with this patron.
Lines 3020-3025 sub to_api { Link Here
3020
        ? Mojo::JSON->true
3061
        ? Mojo::JSON->true
3021
        : Mojo::JSON->false;
3062
        : Mojo::JSON->false;
3022
3063
3064
    $json_patron->{historic_cardnumbers} = $self->historic_cardnumbers;
3065
3023
    return $json_patron;
3066
    return $json_patron;
3024
}
3067
}
3025
3068
(-)a/api/v1/swagger/definitions/historic_cardnumbers.yaml (+18 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  previous_cardnumber:
5
    description: The previous cardnumber of this patron
6
    type: string
7
  new_cardnumber:
8
    description: The new cardnumber of this patron
9
    type: string
10
  timestamp:
11
    description: The date and time of the cardnumber change
12
    type:
13
      - string
14
additionalProperties: false
15
required:
16
  - previous_cardnumber
17
  - new_cardnumber
18
  - timestamp
(-)a/api/v1/swagger/definitions/patron.yaml (+7 lines)
Lines 408-413 properties: Link Here
408
      - "null"
408
      - "null"
409
    description: patron's primary contact method
409
    description: patron's primary contact method
410
    maxLength: 45
410
    maxLength: 45
411
  historic_cardnumbers:
412
    type:
413
      - array
414
      - "null"
415
    description: patron's historic cardnumbers
416
    items:
417
      $ref: "historic_cardnumbers.yaml"
411
  _strings:
418
  _strings:
412
    type:
419
    type:
413
      - object
420
      - object
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt (+19 lines)
Lines 627-632 Link Here
627
                [%# /div#patron-consents %]
627
                [%# /div#patron-consents %]
628
            [% END %]
628
            [% END %]
629
629
630
            [% IF historic_cardnumbers.size %]
631
                <div id="historic-cardnumbers" class="patroninfo-section">
632
                    <div class="patroninfo-heading">
633
                        <h3>Historic cardnumbers</h3>
634
                    </div>
635
                    <div class="rows">
636
                        <ol>
637
                            [% FOREACH historic_cardnumber IN historic_cardnumbers %]
638
                                <li>
639
                                    <span class="label">[% historic_cardnumber.timestamp | $KohaDates with_hours => 1 %]:</span>
640
                                    [% historic_cardnumber.previous_cardnumber | html %] &rarr; [% historic_cardnumber.new_cardnumber | html %]
641
                                </li>
642
                            [% END %]
643
                        </ol>
644
                    </div>
645
                </div>
646
                [%# /div#historic-cardnumbers %]
647
            [% END %]
648
630
            <div id="patron-alternate-address" class="patroninfo-section">
649
            <div id="patron-alternate-address" class="patroninfo-section">
631
                [% IF ( patron.B_phone || patron.B_email || patron.contactnote || patron.B_address || patron.B_address2 || patron.B_city || patron.B_zipcode || patron.B_country ) %]
650
                [% IF ( patron.B_phone || patron.B_email || patron.contactnote || patron.B_address || patron.B_address2 || patron.B_city || patron.B_zipcode || patron.B_country ) %]
632
                    <div class="patroninfo-heading">
651
                    <div class="patroninfo-heading">
(-)a/members/moremember.pl (+6 lines)
Lines 317-322 if ( C4::Context->preference('UseRecalls') ) { Link Here
317
    );
317
    );
318
}
318
}
319
319
320
if ( C4::Context->preference('CardnumberLog') ) {
321
    $template->param(
322
        historic_cardnumbers => $patron->historic_cardnumbers,
323
    );
324
}
325
320
# Fetch available consent types and patron's consents
326
# Fetch available consent types and patron's consents
321
my $consent_types = Koha::Patron::Consents->available_types;
327
my $consent_types = Koha::Patron::Consents->available_types;
322
if ( keys %$consent_types ) {
328
if ( keys %$consent_types ) {
(-)a/t/db_dependent/Koha/Patrons.t (-2 / +16 lines)
Lines 2029-2035 $retrieved_patron_1->delete; Link Here
2029
is( Koha::Patrons->search->count, $nb_of_patrons - 1, 'Delete should have deleted the patron' );
2029
is( Koha::Patrons->search->count, $nb_of_patrons - 1, 'Delete should have deleted the patron' );
2030
2030
2031
subtest 'BorrowersLog and CardnumberLog tests' => sub {
2031
subtest 'BorrowersLog and CardnumberLog tests' => sub {
2032
    plan tests => 13;
2032
    plan tests => 16;
2033
2033
2034
    t::lib::Mocks::mock_preference( 'BorrowersLog',  1 );
2034
    t::lib::Mocks::mock_preference( 'BorrowersLog',  1 );
2035
    t::lib::Mocks::mock_preference( 'CardnumberLog', 0 );
2035
    t::lib::Mocks::mock_preference( 'CardnumberLog', 0 );
Lines 2081-2086 subtest 'BorrowersLog and CardnumberLog tests' => sub { Link Here
2081
        'With CardnumberLog, one detailed MODIFY_CARDNUMBER action should be logged for the modification.'
2081
        'With CardnumberLog, one detailed MODIFY_CARDNUMBER action should be logged for the modification.'
2082
    );
2082
    );
2083
2083
2084
    ## test for historic_cardnumber accessor
2085
    my @historic_cardnumbers = @{ $patron->historic_cardnumbers };
2086
    is(
2087
        $historic_cardnumbers[0]->{previous_cardnumber}, 'TESTCARDNUMBER',
2088
        'previous_cardnumber in historic_cardnumbers[0] should be TESTCARDNUMBER'
2089
    );
2090
    is(
2091
        $historic_cardnumbers[0]->{new_cardnumber}, 'TESTCARDNUMBER_1',
2092
        'new_cardnumber in historic_cardnumbers[0] should be TESTCARDNUMBER_1'
2093
    );
2094
    is(
2095
        exists( $historic_cardnumbers[0]->{timestamp} ), 1,
2096
        'timestamp in historic_cardnumbers[0] should be set'
2097
    );
2098
2084
    t::lib::Mocks::mock_preference( 'BorrowersLog', 0 );
2099
    t::lib::Mocks::mock_preference( 'BorrowersLog', 0 );
2085
    $patron->set( { cardnumber => 'TESTCARDNUMBER' } )->store;
2100
    $patron->set( { cardnumber => 'TESTCARDNUMBER' } )->store;
2086
    @logs = $schema->resultset('ActionLog')
2101
    @logs = $schema->resultset('ActionLog')
2087
- 

Return to bug 27364