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

(-)a/Koha/List/Patron.pm (-8 / +10 lines)
Lines 173-189 sub AddPatronsToList { Link Here
173
173
174
    my @borrowernumbers;
174
    my @borrowernumbers;
175
175
176
    my %search_param;
176
    if ($cardnumbers) {
177
    if ($cardnumbers) {
177
        @borrowernumbers =
178
        $search_param{cardnumber} = { 'IN' => $cardnumbers };
178
          Koha::Database->new()->schema()->resultset('Borrower')->search(
179
    } else {
179
            { cardnumber => { 'IN' => $cardnumbers } },
180
        $search_param{borrowernumber} = { 'IN' => $borrowernumbers };
180
            { columns    => [qw/ borrowernumber /] }
181
          )->get_column('borrowernumber')->all();
182
    }
183
    else {
184
        @borrowernumbers = @$borrowernumbers;
185
    }
181
    }
186
182
183
    @borrowernumbers =
184
      Koha::Database->new()->schema()->resultset('Borrower')->search(
185
        \%search_param,
186
        { columns    => [qw/ borrowernumber /] }
187
      )->get_column('borrowernumber')->all();
188
187
    my $patron_list_id = $list->patron_list_id();
189
    my $patron_list_id = $list->patron_list_id();
188
190
189
    my $plp_rs = Koha::Database->new()->schema()->resultset('PatronListPatron');
191
    my $plp_rs = Koha::Database->new()->schema()->resultset('PatronListPatron');
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/list.tt (-17 / +30 lines)
Lines 12-21 Link Here
12
    #add_patrons_by_search {
12
    #add_patrons_by_search {
13
        display: none;
13
        display: none;
14
    }
14
    }
15
    #patron_barcodes_line {
15
    #patron_ids_line {
16
        display: none;
16
        display: none;
17
    }
17
    }
18
    #patron_barcodes_submit {
18
    #patron_ids_submit {
19
        display: none;
19
        display: none;
20
    }
20
    }
21
    #searchheader {
21
    #searchheader {
Lines 58-67 Link Here
58
        <h1>[% list.name | html %]</h1>
58
        <h1>[% list.name | html %]</h1>
59
59
60
        [% IF ( not_found.size > 0 ) %]
60
        [% IF ( not_found.size > 0 ) %]
61
        <div class="dialog alert"><p>Warning, the following cardnumbers were not found:</p></div>
61
        <div class="dialog alert"><p>Warning, the following [% id_column | html %] were not found:</p></div>
62
        <table style="margin:auto;">
62
        <table style="margin:auto;">
63
            <thead>
63
            <thead>
64
                <tr><th>Cardnumbers not found</th></tr>
64
                <tr><th>[% id_column | html FILTER ucfirst %] not found</th></tr>
65
            </thead>
65
            </thead>
66
            <tbody>
66
            <tbody>
67
            [% FOREACH nf IN not_found %]
67
            [% FOREACH nf IN not_found %]
Lines 72-81 Link Here
72
        [% END %]
72
        [% END %]
73
73
74
        [% IF ( existed.size > 0 ) %]
74
        [% IF ( existed.size > 0 ) %]
75
        <div class="dialog alert"><p>Warning, the following cardnumbers were already in this list:</p></div>
75
        <div class="dialog alert"><p>Warning, the following [% id_column | html %] were already in this list:</p></div>
76
        <table style="margin:auto;">
76
        <table style="margin:auto;">
77
            <thead>
77
            <thead>
78
                <tr><th>Cardnumbers already in list</th></tr>
78
                <tr><th>[% id_column | html FILTER ucfirst %] already in list</th></tr>
79
            </thead>
79
            </thead>
80
            <tbody>
80
            <tbody>
81
            [% FOREACH ed IN existed %]
81
            [% FOREACH ed IN existed %]
Lines 96-111 Link Here
96
                    <li id="add_patrons_by_search"><a href="#">
96
                    <li id="add_patrons_by_search"><a href="#">
97
                        <span class="label">&nbsp;</span>
97
                        <span class="label">&nbsp;</span>
98
                        <i class="fa fa-plus"></i> Search for patrons</a></li>
98
                        <i class="fa fa-plus"></i> Search for patrons</a></li>
99
                    <li id="add_patrons_by_barcode"><a href="#">
99
                    <li id="add_patrons_by_id"><a href="#">
100
                        <span class="label">&nbsp;</span>
100
                        <span class="label">&nbsp;</span>
101
                        <i class="fa fa-plus"></i> Enter multiple card numbers</a></li>
101
                        <i class="fa fa-plus"></i> Add multiple patrons</a></li>
102
                    <li id="patron_barcodes_line">
102
                    <li id="patron_ids_line">
103
                        <label for="patrons_by_barcode">Card number list (one barcode per line):</label>
103
                    <fieldset class="rows">
104
                        <textarea id="patrons_by_barcode" name="patrons_by_barcode" id="" cols="30" rows="10"></textarea>
104
                        <legend>Choose type of ID to enter</legend>
105
                        <span class="radio">
106
                            <label for "cardnumbers">
107
                                <input id="add_by_cardnumbers" type="radio" name="id_column" value="cardnumbers" checked="checked">
108
                                <span class="add_by_cardnumbers">Cardnumbers</span>
109
                            </label>
110
                            <label for "borrowernumbers">
111
                                <input id="add_by_borrwernumbers" type="radio" name="id_column" value="borrowernumbers">
112
                                <span class="add_by_borrowernumbers">Borrowernumbers</span>
113
                            </label>
114
                        </span>
115
                    </fieldset>
116
                        <label for="patrons_by_id">List (one barcode per line):</label>
117
                        <textarea id="patrons_by_id" name="patrons_by_id" id="" cols="30" rows="10"></textarea>
105
                    </li>
118
                    </li>
106
                </ol>
119
                </ol>
107
            </fieldset>
120
            </fieldset>
108
            <fieldset id="patron_barcodes_submit" class="action">
121
            <fieldset id="patron_ids_submit" class="action">
109
                <input type="submit" value="Submit" />
122
                <input type="submit" value="Submit" />
110
            </fieldset>
123
            </fieldset>
111
124
Lines 249-262 Link Here
249
                }
262
                }
250
            });
263
            });
251
264
252
            $("#add_patrons_by_barcode a").on("click", function(){
265
            $("#add_patrons_by_id a").on("click", function(){
253
                $("#add_patrons_by_barcode, #patron_search_line").hide();
266
                $("#add_patrons_by_id, #patron_search_line").hide();
254
                $("#add_patrons_by_search, #patron_barcodes_line, #patron_barcodes_submit").show();
267
                $("#add_patrons_by_search, #patron_ids_line, #patron_ids_submit").show();
255
            });
268
            });
256
269
257
            $("#add_patrons_by_search a").on("click", function(){
270
            $("#add_patrons_by_search a").on("click", function(){
258
                $("#add_patrons_by_barcode, #patron_search_line").show();
271
                $("#add_patrons_by_id, #patron_search_line").show();
259
                $("#add_patrons_by_search, #patron_barcodes_line, #patron_barcodes_submit").hide();
272
                $("#add_patrons_by_search, #patron_ids_line, #patron_ids_submit").hide();
260
            });
273
            });
261
274
262
            $('.merge-patrons').on('click', function() {
275
            $('.merge-patrons').on('click', function() {
(-)a/patron_lists/list.pl (-10 / +15 lines)
Lines 46-67 my ($list) = Link Here
46
46
47
my @existing = $list->patron_list_patrons;
47
my @existing = $list->patron_list_patrons;
48
48
49
my $cardnumbers = $cgi->param('patrons_by_barcode');
49
my $patrons_by_id = $cgi->param('patrons_by_id');
50
my @patrons_by_barcode;
50
my $id_column = $cgi->param('id_column');
51
51
52
if ( $cardnumbers ){
52
if ( $patrons_by_id ){
53
    push my @patrons_by_barcode, uniq( split(/\s\n/, $cardnumbers) );
53
    push my @patrons_list, uniq( split(/\s\n/, $patrons_by_id) );
54
    my @results = AddPatronsToList( { list => $list, cardnumbers => \@patrons_by_barcode } );
54
    my %add_params;
55
    my %found = map { $_->borrowernumber->cardnumber => 1 } @results;
55
    $add_params{list} = $list;
56
    my %exist = map { $_->borrowernumber->cardnumber => 1 } @existing;
56
    $add_params{ $id_column } = \@patrons_list;
57
    my @results = AddPatronsToList(\%add_params);
58
    my $id = $id_column eq 'borrowernumbers' ? 'borrowernumber' : 'cardnumber';
59
    my %found = map { $_->borrowernumber->$id => 1 } @results;
60
    my %exist = map { $_->borrowernumber->$id => 1 } @existing;
57
    my (@not_found, @existed);
61
    my (@not_found, @existed);
58
    foreach my $barcode ( @patrons_by_barcode ){
62
    foreach my $patron ( @patrons_list ){
59
        push (@not_found, $barcode) unless defined $found{$barcode};
63
        push (@not_found, $patron) unless defined $found{$patron};
60
        push (@existed, $barcode) if defined $exist{$barcode};
64
        push (@existed, $patron) if defined $exist{$patron};
61
    }
65
    }
62
    $template->param(
66
    $template->param(
63
        not_found => \@not_found,
67
        not_found => \@not_found,
64
        existed   => \@existed,
68
        existed   => \@existed,
69
        id_column => $id_column,
65
    );
70
    );
66
}
71
}
67
72
(-)a/t/db_dependent/PatronLists.t (-2 / +8 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 9;
20
use Test::More tests => 11;
21
use t::lib::TestBuilder;
21
use t::lib::TestBuilder;
22
use t::lib::Mocks;
22
use t::lib::Mocks;
23
23
Lines 80-85 is( Link Here
80
    'AddPatronsToList works for borrowernumbers'
80
    'AddPatronsToList works for borrowernumbers'
81
);
81
);
82
82
83
my $deleted_patron = $builder->build_object({ class => 'Koha::Patrons' });
84
$deleted_patron->delete;
85
my @result = AddPatronsToList({list => $list2,borrowernumbers => [ $deleted_patron->borrowernumber ]});
86
is( scalar @result, 0,'Invalid borrowernumber not added');
87
@result = AddPatronsToList({list => $list2,cardnumbers => [ $deleted_patron->cardnumber ]});
88
is( scalar @result, 0,'Invalid cardnumber not added');
89
83
my @ids =
90
my @ids =
84
  $list1->patron_list_patrons()->get_column('patron_list_patron_id')->all();
91
  $list1->patron_list_patrons()->get_column('patron_list_patron_id')->all();
85
DelPatronsFromList(
92
DelPatronsFromList(
86
- 

Return to bug 16446