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

(-)a/C4/Members.pm (-55 lines)
Lines 78-84 BEGIN { Link Here
78
        &GetMemberAccountRecords
78
        &GetMemberAccountRecords
79
        &GetBorNotifyAcctRecord
79
        &GetBorNotifyAcctRecord
80
80
81
        &GetborCatFromCatType
82
        GetBorrowerCategorycode
81
        GetBorrowerCategorycode
83
82
84
        &GetBorrowersToExpunge
83
        &GetBorrowersToExpunge
Lines 1295-1354 sub GetUpcomingMembershipExpires { Link Here
1295
    return $results;
1294
    return $results;
1296
}
1295
}
1297
1296
1298
=head2 GetborCatFromCatType
1299
1300
  ($codes_arrayref, $labels_hashref) = &GetborCatFromCatType();
1301
1302
Looks up the different types of borrowers in the database. Returns two
1303
elements: a reference-to-array, which lists the borrower category
1304
codes, and a reference-to-hash, which maps the borrower category codes
1305
to category descriptions.
1306
1307
=cut
1308
1309
#'
1310
sub GetborCatFromCatType {
1311
    my ( $category_type, $action, $no_branch_limit ) = @_;
1312
1313
    my $branch_limit = $no_branch_limit
1314
        ? 0
1315
        : C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
1316
1317
    # FIXME - This API  seems both limited and dangerous.
1318
    my $dbh     = C4::Context->dbh;
1319
1320
    my $request = qq{
1321
        SELECT DISTINCT categories.categorycode, categories.description
1322
        FROM categories
1323
    };
1324
    $request .= qq{
1325
        LEFT JOIN categories_branches ON categories.categorycode = categories_branches.categorycode
1326
    } if $branch_limit;
1327
    if($action) {
1328
        $request .= " $action ";
1329
        $request .= " AND (branchcode = ? OR branchcode IS NULL)" if $branch_limit;
1330
    } else {
1331
        $request .= " WHERE branchcode = ? OR branchcode IS NULL" if $branch_limit;
1332
    }
1333
    $request .= " ORDER BY categorycode";
1334
1335
    my $sth = $dbh->prepare($request);
1336
    $sth->execute(
1337
        $action ? $category_type : (),
1338
        $branch_limit ? $branch_limit : ()
1339
    );
1340
1341
    my %labels;
1342
    my @codes;
1343
1344
    while ( my $data = $sth->fetchrow_hashref ) {
1345
        push @codes, $data->{'categorycode'};
1346
        $labels{ $data->{'categorycode'} } = $data->{'description'};
1347
    }
1348
    $sth->finish;
1349
    return ( \@codes, \%labels );
1350
}
1351
1352
=head2 GetBorrowerCategorycode
1297
=head2 GetBorrowerCategorycode
1353
1298
1354
    $categorycode = &GetBorrowerCategoryCode( $borrowernumber );
1299
    $categorycode = &GetBorrowerCategoryCode( $borrowernumber );
(-)a/Koha/Patron/Categories.pm (-9 / +7 lines)
Lines 38-53 Koha::Patron::Categories - Koha Patron Category Object set class Link Here
38
=cut
38
=cut
39
39
40
sub search_limited {
40
sub search_limited {
41
    my ( $self ) = @_;
41
    my ( $self, $params, $attributes ) = @_;
42
    my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
42
    my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
43
    return $self->search({}, {order_by => ['description']}) unless $branch_limit;
43
    if ( $branch_limit ) {
44
    return $self->search({
44
        $params->{'categories_branches.branchcode'} = [ $branch_limit, undef ];
45
        'categories_branches.branchcode' => [$branch_limit, undef]},
45
        $attributes->{join} = 'categories_branches';
46
        {
46
    }
47
            join => 'categories_branches',
47
    $attributes->{order_by} = ['description'] unless $attributes->{order_by};
48
            order_by => ['description'],
48
    return $self->search($params, $attributes);
49
        }
50
    );
51
}
49
}
52
50
53
=head3 type
51
=head3 type
(-)a/circ/circulation.pl (-4 / +3 lines)
Lines 555-564 $amountold =~ s/^.*\$//; # remove upto the $, if any Link Here
555
my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
555
my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
556
556
557
if ( $borrowernumber && $borrower->{'category_type'} eq 'C') {
557
if ( $borrowernumber && $borrower->{'category_type'} eq 'C') {
558
    my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
558
    my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
559
    my $cnt = scalar(@$catcodes);
559
    $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
560
    $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
560
    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
561
    $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
562
}
561
}
563
562
564
my $librarian_messages = Koha::Patron::Messages->search(
563
my $librarian_messages = Koha::Patron::Messages->search(
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/update-child.tt (-33 / +36 lines)
Lines 49-88 window.close(); Link Here
49
49
50
[% IF ( MULTI ) %]
50
[% IF ( MULTI ) %]
51
51
52
<h3> Choose Adult category </h3>
52
    <h3> Choose Adult category </h3>
53
53
54
[% IF ( CAT_LOOP ) %]
54
    [% IF patron_categories %]
55
55
        <form method="post" action="update-child.pl">
56
<form method="post" action="update-child.pl">
56
            <fieldset>
57
<fieldset>
57
                <table id="catst">
58
<table id="catst">
58
                    <thead>
59
<thead>
59
                        <tr>
60
<tr>
60
                        <th>&nbsp;</th>
61
<th>&nbsp;</th>
61
                        <th>Code</th>
62
<th>Code</th>
62
                        <th>Description</th>
63
<th>Description</th>
63
                        </tr>
64
</tr>
64
                    </thead>
65
</thead>
65
                    <tbody>
66
<tbody>
66
                        [% FOREACH patron_category IN patron_categories %]
67
[% FOREACH CAT_LOO IN CAT_LOOP %]
67
                            <tr>
68
<tr>
68
                                <td>
69
<td>
69
                                    <input type="radio" id="catcode[% patron_category.categorycode %]" name="catcode" value="[% patron_category.categorycode %]" />
70
<input type="radio" id="catcode[% CAT_LOO.catcode %]" name="catcode" value="[% CAT_LOO.catcode %]" /></td>
70
                                </td>
71
<td>[% CAT_LOO.catcode %]</td>
71
                                <td>[% patron_category.categorycode  %]</td>
72
<td><label for="catcode[% CAT_LOO.catcode %]"><strong>[% CAT_LOO.catdesc %]</strong></label></td> 
72
                                <td><label for="catcode[% patron_category.categorycode %]"><strong>[% patron_category.description %]</strong></label></td>
73
</tr>
73
                            </tr>
74
[% END %]
74
                        [% END %]
75
</tbody>
75
                    </tbody>
76
</table>
76
                </table>
77
<input type="hidden" name="op" value="update" />
77
                <input type="hidden" name="op" value="update" />
78
<input type="hidden" name="borrowernumber" value="[% borrowernumber %]" />
78
                <input type="hidden" name="borrowernumber" value="[% borrowernumber %]" />
79
<input type="hidden" name="catcode" value="[% catcode %]" />
79
                <input type="hidden" name="catcode" value="[% catcode %]" />
80
<input type="hidden" name="cattype" value="[% cattype %]" />
80
                <input type="hidden" name="cattype" value="[% cattype %]" />
81
<input type="hidden" name="catcode_multi" value="[% CATCODE_MULTI %]" />
81
                <input type="hidden" name="catcode_multi" value="[% CATCODE_MULTI %]" />
82
<fieldset class="action"><input class="submit" type="submit" value="Submit" /> <a href="#" class="cancel close">Cancel</a></fieldset>
82
                <fieldset class="action">
83
[% END %]
83
                    <input class="submit" type="submit" value="Submit" />
84
</fieldset>
84
                    <a href="#" class="cancel close">Cancel</a>
85
</form>
85
                </fieldset>
86
            </fieldset>
87
        </form>
88
    [% END %]
86
[% END %]
89
[% END %]
87
90
88
91
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/bor_issues_top.tt (-3 / +3 lines)
Lines 154-162 function Dopop(link) { Link Here
154
			</li>
154
			</li>
155
			<li> 
155
			<li> 
156
                <label for="patroncategory">Patron category: </label><select name="Filter" id="patroncategory"><option value="" > Any category code</option>
156
                <label for="patroncategory">Patron category: </label><select name="Filter" id="patroncategory"><option value="" > Any category code</option>
157
    [% FOREACH borcatloo IN borcatloop %]
157
    [% FOREACH patron_category IN patron_categories%]
158
        <option value="[% borcatloo.value %]" >[% borcatloo.description %] </option>  
158
        <option value="[% patron_category.categorycode %]" >[% patron_category.description %] </option>
159
     [% END %] 
159
     [% END %]
160
    </select>
160
    </select>
161
			</li>
161
			</li>
162
		</ol>
162
		</ol>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_out.tt (-3 / +3 lines)
Lines 56-64 $(document).ready(function(){ Link Here
56
    <fieldset class="rows">
56
    <fieldset class="rows">
57
		<ol>
57
		<ol>
58
            <li><label for="patroncategory">Patron category: </label> <select name="Filter" id="patroncategory"><option value="" > Any category code</option>
58
            <li><label for="patroncategory">Patron category: </label> <select name="Filter" id="patroncategory"><option value="" > Any category code</option>
59
    [% FOREACH borcatloo IN borcatloop %]
59
    [% FOREACH patron_category IN patron_categories %]
60
        <option value="[% borcatloo.value %]" >[% borcatloo.description %] </option>  
60
        <option value="[% patron_category.categorycode %]" >[% patron_category.description %] </option>
61
     [% END %] 
61
    [% END %]
62
    </select>
62
    </select>
63
</li>
63
</li>
64
    <li><label for="to">Not checked out since: </label> <input size="10" id="to" name="Filter" value="" type="text" />
64
    <li><label for="to">Not checked out since: </label> <input size="10" id="to" name="Filter" value="" type="text" />
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/cat_issues_top.tt (-3 / +3 lines)
Lines 143-151 Link Here
143
      </li>
143
      </li>
144
      <li>
144
      <li>
145
        <label for="patroncategory">Patron category: </label><select name="Filter" id="patroncategory"><option value="" > Any category code</option>
145
        <label for="patroncategory">Patron category: </label><select name="Filter" id="patroncategory"><option value="" > Any category code</option>
146
    [% FOREACH borcatloo IN borcatloop %]
146
    [% FOREACH patron_category IN patron_categories %]
147
        <option value="[% borcatloo.value %]" >[% borcatloo.description %] </option>  
147
        <option value="[% patron_category.categorycode %]" >[% patron_category.description %] </option>
148
     [% END %] 
148
     [% END %]
149
    </select>
149
    </select>
150
        </li>
150
        </li>
151
				<li><label for="day">Day: </label> <input type="text" name="Filter" id="day" value="" /></li>
151
				<li><label for="day">Day: </label> <input type="text" name="Filter" id="day" value="" /></li>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_by_borrower_category.tt (-2 / +2 lines)
Lines 59-66 Link Here
59
                <label for="borrowercategory">Select a borrower category</label>
59
                <label for="borrowercategory">Select a borrower category</label>
60
                <select name="value" id="borrowercategory">
60
                <select name="value" id="borrowercategory">
61
                  <option value="">Any Category code</option>
61
                  <option value="">Any Category code</option>
62
                [%- FOREACH loopcategorie IN loopcategories %]
62
                [%- FOREACH patron_category IN patron_categories %]
63
                  <option value="[% loopcategorie.value %]" >[% loopcategorie.description %]</option>
63
                  <option value="[% patron_category.categorycode %]" >[% patron_category.description %]</option>
64
                [%- END %]
64
                [%- END %]
65
                </select>
65
                </select>
66
              </li>
66
              </li>
(-)a/members/boraccount.pl (-4 / +5 lines)
Lines 34-39 use C4::Accounts; Link Here
34
use C4::Members::Attributes qw(GetBorrowerAttributes);
34
use C4::Members::Attributes qw(GetBorrowerAttributes);
35
use Koha::Patron::Images;
35
use Koha::Patron::Images;
36
36
37
use Koha::Patron::Categories;
38
37
my $input=new CGI;
39
my $input=new CGI;
38
40
39
41
Lines 60-69 if ( $action eq 'reverse' ) { Link Here
60
}
62
}
61
63
62
if ( $data->{'category_type'} eq 'C') {
64
if ( $data->{'category_type'} eq 'C') {
63
   my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
65
    my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
64
   my $cnt = scalar(@$catcodes);
66
    $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
65
   $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
67
    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
66
   $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
67
}
68
}
68
69
69
#get account details
70
#get account details
(-)a/members/mancredit.pl (-4 / +5 lines)
Lines 36-41 use C4::Items; Link Here
36
use C4::Members::Attributes qw(GetBorrowerAttributes);
36
use C4::Members::Attributes qw(GetBorrowerAttributes);
37
use Koha::Patron::Images;
37
use Koha::Patron::Images;
38
38
39
use Koha::Patron::Categories;
40
39
my $input=new CGI;
41
my $input=new CGI;
40
my $flagsrequired = { borrowers => 1, updatecharges => 1 };
42
my $flagsrequired = { borrowers => 1, updatecharges => 1 };
41
43
Lines 74-83 if ($add){ Link Here
74
    );
76
    );
75
					  
77
					  
76
    if ( $data->{'category_type'} eq 'C') {
78
    if ( $data->{'category_type'} eq 'C') {
77
        my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
79
        my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
78
        my $cnt = scalar(@$catcodes);
80
        $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
79
        $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
81
        $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
80
        $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
81
    }
82
    }
82
83
83
    $template->param( adultborrower => 1 ) if ( $data->{category_type} eq 'A' );
84
    $template->param( adultborrower => 1 ) if ( $data->{category_type} eq 'A' );
(-)a/members/maninvoice.pl (-4 / +5 lines)
Lines 35-40 use C4::Branch; Link Here
35
use C4::Members::Attributes qw(GetBorrowerAttributes);
35
use C4::Members::Attributes qw(GetBorrowerAttributes);
36
use Koha::Patron::Images;
36
use Koha::Patron::Images;
37
37
38
use Koha::Patron::Categories;
39
38
my $input=new CGI;
40
my $input=new CGI;
39
my $flagsrequired = { borrowers => 1 };
41
my $flagsrequired = { borrowers => 1 };
40
42
Lines 100-109 if ($add){ Link Here
100
  $template->param( invoice_types_loop => \@invoice_types );
102
  $template->param( invoice_types_loop => \@invoice_types );
101
103
102
    if ( $data->{'category_type'} eq 'C') {
104
    if ( $data->{'category_type'} eq 'C') {
103
        my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
105
        my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
104
        my $cnt = scalar(@$catcodes);
106
        $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
105
        $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
107
        $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
106
        $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
107
    }
108
    }
108
109
109
    $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
110
    $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
(-)a/members/member-flags.pl (-4 / +5 lines)
Lines 16-21 use C4::Branch; Link Here
16
use C4::Members::Attributes qw(GetBorrowerAttributes);
16
use C4::Members::Attributes qw(GetBorrowerAttributes);
17
#use C4::Acquisitions;
17
#use C4::Acquisitions;
18
18
19
use Koha::Patron::Categories;
20
19
use C4::Output;
21
use C4::Output;
20
use Koha::Patron::Images;
22
use Koha::Patron::Images;
21
23
Lines 151-160 if ($input->param('newflags')) { Link Here
151
    }
153
    }
152
154
153
    if ( $bor->{'category_type'} eq 'C') {
155
    if ( $bor->{'category_type'} eq 'C') {
154
        my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
156
        my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
155
        my $cnt = scalar(@$catcodes);
157
        $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
156
        $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
158
        $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
157
        $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
158
    }
159
    }
159
	
160
	
160
$template->param( adultborrower => 1 ) if ( $bor->{'category_type'} eq 'A' );
161
$template->param( adultborrower => 1 ) if ( $bor->{'category_type'} eq 'A' );
(-)a/members/member-password.pl (-5 / +6 lines)
Lines 19-24 use C4::Members::Attributes qw(GetBorrowerAttributes); Link Here
19
use Koha::Patron::Images;
19
use Koha::Patron::Images;
20
use Koha::Token;
20
use Koha::Token;
21
21
22
use Koha::Patron::Categories;
23
22
use Digest::MD5 qw(md5_base64);
24
use Digest::MD5 qw(md5_base64);
23
25
24
my $input = new CGI;
26
my $input = new CGI;
Lines 101-111 else { Link Here
101
    $template->param( defaultnewpassword => $defaultnewpassword );
103
    $template->param( defaultnewpassword => $defaultnewpassword );
102
}
104
}
103
105
104
if ( $bor->{'category_type'} eq 'C' ) {
106
if ( $bor->{'category_type'} eq 'C') {
105
    my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
107
    my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
106
    my $cnt = scalar(@$catcodes);
108
    $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
107
    $template->param( 'CATCODE_MULTI' => 1 ) if $cnt > 1;
109
    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
108
    $template->param( 'catcode' => $catcodes->[0] ) if $cnt == 1;
109
}
110
}
110
111
111
$template->param( adultborrower => 1 ) if ( $bor->{'category_type'} eq 'A' );
112
$template->param( adultborrower => 1 ) if ( $bor->{'category_type'} eq 'A' );
(-)a/members/memberentry.pl (-19 / +23 lines)
Lines 521-547 if(!defined($data{'sex'})){ Link Here
521
my @typeloop;
521
my @typeloop;
522
my $no_categories = 1;
522
my $no_categories = 1;
523
my $no_add;
523
my $no_add;
524
foreach (qw(C A S P I X)) {
524
foreach my $category_type (qw(C A S P I X)) {
525
    my $action="WHERE category_type=?";
525
    my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => $category_type }, {order_by => ['categorycode']});
526
    my ($categories,$labels)=GetborCatFromCatType($_,$action);
526
    $no_categories = 0 if $patron_categories->count > 0;
527
    if(scalar(@$categories) > 0){ $no_categories = 0; }
527
    $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1;
528
	my @categoryloop;
528
529
	foreach my $cat (@$categories){
529
    my @categoryloop;
530
		push @categoryloop,{'categorycode' => $cat,
530
    while ( my $patron_category = $patron_categories->next ) {
531
			  'categoryname' => $labels->{$cat},
531
        push @categoryloop,
532
			  'categorycodeselected' => ((defined($borrower_data->{'categorycode'}) && 
532
          { 'categorycode' => $patron_category->categorycode,
533
                                                     $cat eq $borrower_data->{'categorycode'}) 
533
            'categoryname' => $patron_category->description,
534
                                                     || (defined($categorycode) && $cat eq $categorycode)),
534
            'categorycodeselected' =>
535
		};
535
              ( ( defined( $borrower_data->{'categorycode'} ) && $patron_category->categorycode eq $borrower_data->{'categorycode'} ) || ( defined($categorycode) && $patron_category->categorycode eq $categorycode ) ),
536
	}
536
          };
537
	my %typehash;
537
    }
538
	$typehash{'typename'}=$_;
538
    my %typehash;
539
    my $typedescription = "typename_".$typehash{'typename'};
539
    $typehash{'typename'} = $category_type;
540
	$typehash{'categoryloop'}=\@categoryloop;
540
    my $typedescription = "typename_" . $typehash{'typename'};
541
	push @typeloop,{'typename' => $_,
541
    $typehash{'categoryloop'} = \@categoryloop;
542
    push @typeloop,
543
      { 'typename'       => $category_type,
542
        $typedescription => 1,
544
        $typedescription => 1,
543
	  'categoryloop' => \@categoryloop};
545
        'categoryloop'   => \@categoryloop
546
      };
544
}
547
}
548
545
$template->param('typeloop' => \@typeloop,
549
$template->param('typeloop' => \@typeloop,
546
        no_categories => $no_categories);
550
        no_categories => $no_categories);
547
if($no_categories){ $no_add = 1; }
551
if($no_categories){ $no_add = 1; }
(-)a/members/moremember.pl (-5 / +4 lines)
Lines 62-67 if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preferen Link Here
62
use DateTime;
62
use DateTime;
63
use Koha::DateUtils;
63
use Koha::DateUtils;
64
use Koha::Database;
64
use Koha::Database;
65
use Koha::Patron::Categories;
65
66
66
use vars qw($debug);
67
use vars qw($debug);
67
68
Lines 156-166 if ( Koha::Patrons->find( $borrowernumber )->is_debarred ) { Link Here
156
$data->{ "sex_".$data->{'sex'}."_p" } = 1 if defined $data->{sex};
157
$data->{ "sex_".$data->{'sex'}."_p" } = 1 if defined $data->{sex};
157
158
158
if ( $category_type eq 'C') {
159
if ( $category_type eq 'C') {
159
   my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
160
    my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
160
   my $cnt = scalar(@$catcodes);
161
    $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
161
162
    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
162
   $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
163
   $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
164
}
163
}
165
164
166
my $patron = Koha::Patrons->find($data->{borrowernumber});
165
my $patron = Koha::Patrons->find($data->{borrowernumber});
(-)a/members/pay.pl (-9 / +5 lines)
Lines 43-48 use C4::Branch; Link Here
43
use C4::Members::Attributes qw(GetBorrowerAttributes);
43
use C4::Members::Attributes qw(GetBorrowerAttributes);
44
use Koha::Patron::Images;
44
use Koha::Patron::Images;
45
45
46
use Koha::Patron::Categories;
47
46
our $input = CGI->new;
48
our $input = CGI->new;
47
49
48
my $updatecharges_permissions = $input->param('woall') ? 'writeoff' : 'remaining_permissions';
50
my $updatecharges_permissions = $input->param('woall') ? 'writeoff' : 'remaining_permissions';
Lines 215-229 sub borrower_add_additional_fields { Link Here
215
# in a number of templates. It should not be the business of this script but in lieu of
217
# in a number of templates. It should not be the business of this script but in lieu of
216
# a revised api here it is ...
218
# a revised api here it is ...
217
    if ( $b_ref->{category_type} eq 'C' ) {
219
    if ( $b_ref->{category_type} eq 'C' ) {
218
        my ( $catcodes, $labels ) =
220
        my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
219
          GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
221
        $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
220
        if ( @{$catcodes} ) {
222
        $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
221
            if ( @{$catcodes} > 1 ) {
222
                $b_ref->{CATCODE_MULTI} = 1;
223
            } elsif ( @{$catcodes} == 1 ) {
224
                $b_ref->{catcode} = $catcodes->[0];
225
            }
226
        }
227
    } elsif ( $b_ref->{category_type} eq 'A' ) {
223
    } elsif ( $b_ref->{category_type} eq 'A' ) {
228
        $b_ref->{adultborrower} = 1;
224
        $b_ref->{adultborrower} = 1;
229
    }
225
    }
(-)a/members/paycollect.pl (-9 / +5 lines)
Lines 31-36 use C4::Koha; Link Here
31
use C4::Branch;
31
use C4::Branch;
32
use Koha::Patron::Images;
32
use Koha::Patron::Images;
33
33
34
use Koha::Patron::Categories;
35
34
my $input = CGI->new();
36
my $input = CGI->new();
35
37
36
my $updatecharges_permissions = $input->param('writeoff_individual') ? 'writeoff' : 'remaining_permissions';
38
my $updatecharges_permissions = $input->param('writeoff_individual') ? 'writeoff' : 'remaining_permissions';
Lines 165-179 sub borrower_add_additional_fields { Link Here
165
# in a number of templates. It should not be the business of this script but in lieu of
167
# in a number of templates. It should not be the business of this script but in lieu of
166
# a revised api here it is ...
168
# a revised api here it is ...
167
    if ( $b_ref->{category_type} eq 'C' ) {
169
    if ( $b_ref->{category_type} eq 'C' ) {
168
        my ( $catcodes, $labels ) =
170
        my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
169
          GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
171
        $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
170
        if ( @{$catcodes} ) {
172
        $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
171
            if ( @{$catcodes} > 1 ) {
172
                $b_ref->{CATCODE_MULTI} = 1;
173
            } elsif ( @{$catcodes} == 1 ) {
174
                $b_ref->{catcode} = $catcodes->[0];
175
            }
176
        }
177
    } elsif ( $b_ref->{category_type} eq 'A' ) {
173
    } elsif ( $b_ref->{category_type} eq 'A' ) {
178
        $b_ref->{adultborrower} = 1;
174
        $b_ref->{adultborrower} = 1;
179
    }
175
    }
(-)a/members/printfeercpt.pl (-4 / +4 lines)
Lines 33-38 use C4::Branch; Link Here
33
use C4::Accounts;
33
use C4::Accounts;
34
use Koha::DateUtils;
34
use Koha::DateUtils;
35
use Koha::Patron::Images;
35
use Koha::Patron::Images;
36
use Koha::Patron::Categories;
36
37
37
my $input=new CGI;
38
my $input=new CGI;
38
39
Lines 58-67 if ( $action eq 'print' ) { Link Here
58
}
59
}
59
60
60
if ( $data->{'category_type'} eq 'C') {
61
if ( $data->{'category_type'} eq 'C') {
61
   my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
62
    my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
62
   my $cnt = scalar(@$catcodes);
63
    $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
63
   $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
64
    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
64
   $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
65
}
65
}
66
66
67
#get account details
67
#get account details
(-)a/members/printinvoice.pl (-4 / +5 lines)
Lines 32-37 use C4::Branch; Link Here
32
use C4::Accounts;
32
use C4::Accounts;
33
use Koha::Patron::Images;
33
use Koha::Patron::Images;
34
34
35
use Koha::Patron::Categories;
36
35
my $input = new CGI;
37
my $input = new CGI;
36
38
37
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
39
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
Lines 52-61 my $accountlines_id = $input->param('accountlines_id'); Link Here
52
my $data = GetMember( 'borrowernumber' => $borrowernumber );
54
my $data = GetMember( 'borrowernumber' => $borrowernumber );
53
55
54
if ( $data->{'category_type'} eq 'C' ) {
56
if ( $data->{'category_type'} eq 'C' ) {
55
    my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
57
    my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
56
    my $cnt = scalar(@$catcodes);
58
    $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
57
    $template->param( 'CATCODE_MULTI' => 1 ) if $cnt > 1;
59
    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
58
    $template->param( 'catcode' => $catcodes->[0] ) if $cnt == 1;
59
}
60
}
60
61
61
#get account details
62
#get account details
(-)a/members/readingrec.pl (-4 / +5 lines)
Lines 34-39 use Koha::DateUtils; Link Here
34
use C4::Members::Attributes qw(GetBorrowerAttributes);
34
use C4::Members::Attributes qw(GetBorrowerAttributes);
35
use Koha::Patron::Images;
35
use Koha::Patron::Images;
36
36
37
use Koha::Patron::Categories;
38
37
my $input = CGI->new;
39
my $input = CGI->new;
38
40
39
#get borrower details
41
#get borrower details
Lines 97-106 if ( $op eq 'export_barcodes' ) { Link Here
97
}
99
}
98
100
99
if ( $data->{'category_type'} eq 'C') {
101
if ( $data->{'category_type'} eq 'C') {
100
    my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
102
    my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
101
    my $cnt = scalar(@$catcodes);
103
    $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
102
    $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
104
    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
103
    $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
104
}
105
}
105
106
106
$template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
107
$template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
(-)a/members/update-child.pl (-17 / +7 lines)
Lines 58-81 my $catcode_multi = $input->param('catcode_multi'); Link Here
58
my $op             = $input->param('op');
58
my $op             = $input->param('op');
59
59
60
if ( $op eq 'multi' ) {
60
if ( $op eq 'multi' ) {
61
    my ( $catcodes, $labels ) =
61
    # FIXME - what are the possible upgrade paths?  C -> A , C -> S ...
62
		# FIXME - what are the possible upgrade paths?  C -> A , C -> S ...
62
    #   currently just allowing C -> A
63
		#   currently just allowing C -> A because of limitation of API.
63
    my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
64
      GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
65
    my @rows;
66
    foreach my $k ( keys %$labels ) {
67
        my $row;
68
        $row->{catcode} = $k;
69
        $row->{catdesc} = $labels->{$k};
70
        my $borcat = Koha::Patron::Categories->find($row->{catcode});
71
        $row->{cattype} = $borcat->category_type;
72
        push @rows, $row;
73
    }
74
    $template->param(
64
    $template->param(
75
        MULTI          => 1,
65
        MULTI             => 1,
76
        CATCODE_MULTI          => 1,
66
        CATCODE_MULTI     => 1,
77
        borrowernumber => $borrowernumber,
67
        borrowernumber    => $borrowernumber,
78
        CAT_LOOP       => \@rows,
68
        patron_categories => $patron_categories,
79
    );
69
    );
80
    output_html_with_http_headers $input, $cookie, $template->output;
70
    output_html_with_http_headers $input, $cookie, $template->output;
81
}
71
}
(-)a/reports/bor_issues_top.pl (-13 / +6 lines)
Lines 29-35 use C4::Circulation; Link Here
29
use C4::Members;
29
use C4::Members;
30
use C4::Reports;
30
use C4::Reports;
31
use C4::Debug;
31
use C4::Debug;
32
32
use Koha::DateUtils;
33
use Koha::DateUtils;
34
use Koha::Patron::Categories;
33
35
34
=head1 NAME
36
=head1 NAME
35
37
Lines 37-44 plugin that shows a stats on borrowers Link Here
37
39
38
=head1 DESCRIPTION
40
=head1 DESCRIPTION
39
41
40
=over 2
41
42
=cut
42
=cut
43
43
44
$debug = 1;
44
$debug = 1;
Lines 129-150 foreach (sort {$itemtypes->{$a}->{translated_description} cmp $itemtypes->{$b}-> Link Here
129
              );
129
              );
130
    push @itemtypeloop, \%row;
130
    push @itemtypeloop, \%row;
131
}
131
}
132
    
132
133
my ($codes,$labels) = GetborCatFromCatType(undef,undef);
133
my $patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['categorycode']});
134
my @borcatloop;
134
135
foreach (sort keys %$labels) {
136
	my %row =(value => $_,
137
              description => $labels->{$_},
138
             );
139
    push @borcatloop, \%row;
140
}
141
    
142
$template->param(
135
$template->param(
143
	    mimeloop => \@mime,
136
	    mimeloop => \@mime,
144
	  CGIseplist => $delims,
137
	  CGIseplist => $delims,
145
	  branchloop => \@branchloop,
138
	  branchloop => \@branchloop,
146
	itemtypeloop => \@itemtypeloop,
139
	itemtypeloop => \@itemtypeloop,
147
	  borcatloop => \@borcatloop,
140
patron_categories => $patron_categories,
148
);
141
);
149
output_html_with_http_headers $input, $cookie, $template->output;
142
output_html_with_http_headers $input, $cookie, $template->output;
150
143
(-)a/reports/borrowers_out.pl (-10 / +5 lines)
Lines 28-34 use C4::Output; Link Here
28
use C4::Circulation;
28
use C4::Circulation;
29
use C4::Reports;
29
use C4::Reports;
30
use C4::Members;
30
use C4::Members;
31
31
use Koha::DateUtils;
32
use Koha::DateUtils;
33
use Koha::Patron::Categories;
32
34
33
=head1 NAME
35
=head1 NAME
34
36
Lines 116-134 if ($do_it) { Link Here
116
    
118
    
117
    my $CGIextChoice = ( 'CSV' ); # FIXME translation
119
    my $CGIextChoice = ( 'CSV' ); # FIXME translation
118
	my $CGIsepChoice = GetDelimiterChoices;
120
	my $CGIsepChoice = GetDelimiterChoices;
119
    
121
120
    my ($codes,$labels) = GetborCatFromCatType(undef,undef);
122
    my $patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['categorycode']});
121
    my @borcatloop;
122
    foreach my $thisborcat (sort keys %$labels) {
123
            my %row =(value => $thisborcat,
124
                                    description => $labels->{$thisborcat},
125
                            );
126
            push @borcatloop, \%row;
127
    }
128
    $template->param(
123
    $template->param(
129
                    CGIextChoice => $CGIextChoice,
124
                    CGIextChoice => $CGIextChoice,
130
                    CGIsepChoice => $CGIsepChoice,
125
                    CGIsepChoice => $CGIsepChoice,
131
                    borcatloop =>\@borcatloop,
126
                    patron_categories => $patron_categories,
132
                    );
127
                    );
133
output_html_with_http_headers $input, $cookie, $template->output;
128
output_html_with_http_headers $input, $cookie, $template->output;
134
}
129
}
(-)a/reports/cat_issues_top.pl (-13 / +3 lines)
Lines 154-171 if ($do_it) { Link Here
154
154
155
    @shelvinglocloop = sort {$a->{value} cmp $b->{value}} @shelvinglocloop;
155
    @shelvinglocloop = sort {$a->{value} cmp $b->{value}} @shelvinglocloop;
156
156
157
    #borcat
157
    my $patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['categorycode']});
158
    my ($codes,$labels) = GetborCatFromCatType(undef,undef);
158
159
    my @borcatloop;
160
    foreach my $thisborcat (sort {$labels->{$a} cmp $labels->{$b}} keys %$labels) {
161
            my %row =(value => $thisborcat,
162
                      description => $labels->{$thisborcat},
163
                            );
164
            push @borcatloop, \%row;
165
    }
166
    
167
    #Day
168
    #Month
169
    $template->param(
159
    $template->param(
170
                    CGIextChoice => $CGIextChoice,
160
                    CGIextChoice => $CGIextChoice,
171
                    CGIsepChoice => $CGIsepChoice,
161
                    CGIsepChoice => $CGIsepChoice,
Lines 173-179 if ($do_it) { Link Here
173
                    itemtypeloop =>\@itemtypeloop,
163
                    itemtypeloop =>\@itemtypeloop,
174
                    ccodeloop =>\@ccodeloop,
164
                    ccodeloop =>\@ccodeloop,
175
                    shelvinglocloop =>\@shelvinglocloop,
165
                    shelvinglocloop =>\@shelvinglocloop,
176
                    borcatloop =>\@borcatloop,
166
                    patron_categories => $patron_categories,
177
                    );
167
                    );
178
output_html_with_http_headers $input, $cookie, $template->output;
168
output_html_with_http_headers $input, $cookie, $template->output;
179
}
169
}
(-)a/reports/issues_by_borrower_category.plugin (-10 / +5 lines)
Lines 29-34 use C4::Members; Link Here
29
29
30
use C4::Branch; # GetBranches
30
use C4::Branch; # GetBranches
31
31
32
use Koha::Patron::Categories;
33
32
=head1 NAME
34
=head1 NAME
33
35
34
plugin that shows a table with issues for categories and borrower
36
plugin that shows a table with issues for categories and borrower
Lines 65-80 sub set_parameters { Link Here
65
    my ($template) = @_;
67
    my ($template) = @_;
66
68
67
    $template->param( branchloop => GetBranchesLoop() );
69
    $template->param( branchloop => GetBranchesLoop() );
68
  
70
69
    my ($codes,$labels)=GetborCatFromCatType(undef,undef);
71
    my $patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['categorycode']});
70
    my @borcatloop;
72
    $template->param( patron_categories => $patron_categories );
71
    foreach my $thisborcat (sort keys %$labels) {
72
        push @borcatloop, {
73
                          value       => $thisborcat,
74
                          description => $labels->{$thisborcat},
75
                          };
76
    }
77
    $template->param(loopcategories => \@borcatloop);
78
    return $template;
73
    return $template;
79
}
74
}
80
75
(-)a/t/db_dependent/Koha/Patron/Categories.t (-1 / +8 lines)
Lines 35-45 my $branch = $builder->build({ source => 'Branch', }); Link Here
35
my $nb_of_categories = Koha::Patron::Categories->search->count;
35
my $nb_of_categories = Koha::Patron::Categories->search->count;
36
my $new_category_1 = Koha::Patron::Category->new({
36
my $new_category_1 = Koha::Patron::Category->new({
37
    categorycode => 'mycatcodeX',
37
    categorycode => 'mycatcodeX',
38
    category_type => 'A',
38
    description  => 'mycatdescX',
39
    description  => 'mycatdescX',
39
})->store;
40
})->store;
40
$new_category_1->add_branch_limitation( $branch->{branchcode} );
41
$new_category_1->add_branch_limitation( $branch->{branchcode} );
41
my $new_category_2 = Koha::Patron::Category->new({
42
my $new_category_2 = Koha::Patron::Category->new({
42
    categorycode => 'mycatcodeY',
43
    categorycode => 'mycatcodeY',
44
    category_type => 'S',
43
    description  => 'mycatdescY',
45
    description  => 'mycatdescY',
44
    checkprevcheckout => undef,
46
    checkprevcheckout => undef,
45
})->store;
47
})->store;
Lines 60-65 C4::Context->_new_userenv('my_new_userenv'); Link Here
60
C4::Context->set_userenv( 0, 0, 'usercnum', 'firstname', 'surname', $another_branch->{branchcode}, 'My wonderful library', '', '', '' );
62
C4::Context->set_userenv( 0, 0, 'usercnum', 'firstname', 'surname', $another_branch->{branchcode}, 'My wonderful library', '', '', '' );
61
my $new_category_3 = Koha::Patron::Category->new(
63
my $new_category_3 = Koha::Patron::Category->new(
62
    {   categorycode => 'mycatcodeZ',
64
    {   categorycode => 'mycatcodeZ',
65
        category_type => 'A',
63
        description  => 'mycatdescZ',
66
        description  => 'mycatdescZ',
64
    }
67
    }
65
)->store;
68
)->store;
Lines 71-76 is( scalar( grep { $_ eq $new_category_1->categorycode } @limited_category_codes Link Here
71
is( scalar( grep { $_ eq $new_category_2->categorycode } @limited_category_codes ), 1, 'The second category is not limited' );
74
is( scalar( grep { $_ eq $new_category_2->categorycode } @limited_category_codes ), 1, 'The second category is not limited' );
72
is( scalar( grep { $_ eq $new_category_3->categorycode } @limited_category_codes ), 1, 'The third category is limited to my branch ' );
75
is( scalar( grep { $_ eq $new_category_3->categorycode } @limited_category_codes ), 1, 'The third category is limited to my branch ' );
73
76
77
my @limited_categories_for_A = Koha::Patron::Categories->search_limited({ category_type => 'A' });
78
my @limited_category_codes_for_A = map { $_->categorycode } @limited_categories_for_A;
79
is( scalar( grep { $_ eq $new_category_2->categorycode } @limited_category_codes_for_A ), 0, 'The second category is not limited but has a category_type S' );
80
is( scalar( grep { $_ eq $new_category_3->categorycode } @limited_category_codes_for_A ), 1, 'The third category is limited to my branch and has a category_type A' );
81
74
$retrieved_category_1->delete;
82
$retrieved_category_1->delete;
75
is( Koha::Patron::Categories->search->count, $nb_of_categories + 2, 'Delete should have deleted the patron category' );
83
is( Koha::Patron::Categories->search->count, $nb_of_categories + 2, 'Delete should have deleted the patron category' );
76
84
77
- 

Return to bug 15407