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

(-)a/C4/Members.pm (-55 lines)
Lines 87-93 BEGIN { Link Here
87
        &GetMemberAccountRecords
87
        &GetMemberAccountRecords
88
        &GetBorNotifyAcctRecord
88
        &GetBorNotifyAcctRecord
89
89
90
        &GetborCatFromCatType
91
        GetBorrowerCategorycode
90
        GetBorrowerCategorycode
92
91
93
        &GetBorrowersToExpunge
92
        &GetBorrowersToExpunge
Lines 1508-1567 sub GetUpcomingMembershipExpires { Link Here
1508
    return $results;
1507
    return $results;
1509
}
1508
}
1510
1509
1511
=head2 GetborCatFromCatType
1512
1513
  ($codes_arrayref, $labels_hashref) = &GetborCatFromCatType();
1514
1515
Looks up the different types of borrowers in the database. Returns two
1516
elements: a reference-to-array, which lists the borrower category
1517
codes, and a reference-to-hash, which maps the borrower category codes
1518
to category descriptions.
1519
1520
=cut
1521
1522
#'
1523
sub GetborCatFromCatType {
1524
    my ( $category_type, $action, $no_branch_limit ) = @_;
1525
1526
    my $branch_limit = $no_branch_limit
1527
        ? 0
1528
        : C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
1529
1530
    # FIXME - This API  seems both limited and dangerous.
1531
    my $dbh     = C4::Context->dbh;
1532
1533
    my $request = qq{
1534
        SELECT categories.categorycode, categories.description
1535
        FROM categories
1536
    };
1537
    $request .= qq{
1538
        LEFT JOIN categories_branches ON categories.categorycode = categories_branches.categorycode
1539
    } if $branch_limit;
1540
    if($action) {
1541
        $request .= " $action ";
1542
        $request .= " AND (branchcode = ? OR branchcode IS NULL) GROUP BY description" if $branch_limit;
1543
    } else {
1544
        $request .= " WHERE branchcode = ? OR branchcode IS NULL GROUP BY description" if $branch_limit;
1545
    }
1546
    $request .= " ORDER BY categorycode";
1547
1548
    my $sth = $dbh->prepare($request);
1549
    $sth->execute(
1550
        $action ? $category_type : (),
1551
        $branch_limit ? $branch_limit : ()
1552
    );
1553
1554
    my %labels;
1555
    my @codes;
1556
1557
    while ( my $data = $sth->fetchrow_hashref ) {
1558
        push @codes, $data->{'categorycode'};
1559
        $labels{ $data->{'categorycode'} } = $data->{'description'};
1560
    }
1561
    $sth->finish;
1562
    return ( \@codes, \%labels );
1563
}
1564
1565
=head2 GetBorrowerCategorycode
1510
=head2 GetBorrowerCategorycode
1566
1511
1567
    $categorycode = &GetBorrowerCategoryCode( $borrowernumber );
1512
    $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 541-550 $amountold =~ s/^.*\$//; # remove upto the $, if any Link Here
541
my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
541
my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
542
542
543
if ( $borrowernumber && $borrower->{'category_type'} eq 'C') {
543
if ( $borrowernumber && $borrower->{'category_type'} eq 'C') {
544
    my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
544
    my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
545
    my $cnt = scalar(@$catcodes);
545
    $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
546
    $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
546
    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
547
    $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
548
}
547
}
549
548
550
my $lib_messages_loop = GetMessages( $borrowernumber, 'L', $branch );
549
my $lib_messages_loop = GetMessages( $borrowernumber, 'L', $branch );
(-)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 60-68 $(document).ready(function(){ Link Here
60
    <fieldset class="rows">
60
    <fieldset class="rows">
61
		<ol>
61
		<ol>
62
            <li><label for="patroncategory">Patron category: </label> <select name="Filter" id="patroncategory"><option value="" > Any category code</option>
62
            <li><label for="patroncategory">Patron category: </label> <select name="Filter" id="patroncategory"><option value="" > Any category code</option>
63
    [% FOREACH borcatloo IN borcatloop %]
63
    [% FOREACH patron_category IN patron_categories %]
64
        <option value="[% borcatloo.value %]" >[% borcatloo.description %] </option>  
64
        <option value="[% patron_category.categorycode %]" >[% patron_category.description %] </option>
65
     [% END %] 
65
    [% END %]
66
    </select>
66
    </select>
67
</li>
67
</li>
68
    <li><label for="to">Not checked out since: </label> <input size="10" id="to" name="Filter" value="" type="text" />
68
    <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 126-134 Link Here
126
      </li>
126
      </li>
127
      <li> 
127
      <li> 
128
        <label for="patroncategory">Patron category: </label><select name="Filter" id="patroncategory"><option value="" > Any Category code</option>
128
        <label for="patroncategory">Patron category: </label><select name="Filter" id="patroncategory"><option value="" > Any Category code</option>
129
    [% FOREACH borcatloo IN borcatloop %]
129
    [% FOREACH patron_category IN patron_categories %]
130
        <option value="[% borcatloo.value %]" >[% borcatloo.description %] </option>  
130
        <option value="[% patron_category.categorycode %]" >[% patron_category.description %] </option>
131
     [% END %] 
131
     [% END %]
132
    </select>
132
    </select>
133
        </li>
133
        </li>
134
				<li><label for="day">Day: </label> <input type="text" name="Filter" id="day" value="" /></li>
134
				<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 33-38 use C4::Branch; Link Here
33
use C4::Accounts;
33
use C4::Accounts;
34
use C4::Members::Attributes qw(GetBorrowerAttributes);
34
use C4::Members::Attributes qw(GetBorrowerAttributes);
35
35
36
use Koha::Patron::Categories;
37
36
my $input=new CGI;
38
my $input=new CGI;
37
39
38
40
Lines 59-68 if ( $action eq 'reverse' ) { Link Here
59
}
61
}
60
62
61
if ( $data->{'category_type'} eq 'C') {
63
if ( $data->{'category_type'} eq 'C') {
62
   my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
64
    my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
63
   my $cnt = scalar(@$catcodes);
65
    $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
64
   $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
66
    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
65
   $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
66
}
67
}
67
68
68
#get account details
69
#get account details
(-)a/members/mancredit.pl (-4 / +5 lines)
Lines 35-40 use C4::Accounts; Link Here
35
use C4::Items;
35
use C4::Items;
36
use C4::Members::Attributes qw(GetBorrowerAttributes);
36
use C4::Members::Attributes qw(GetBorrowerAttributes);
37
37
38
use Koha::Patron::Categories;
39
38
my $input=new CGI;
40
my $input=new CGI;
39
my $flagsrequired = { borrowers => 1, updatecharges => 1 };
41
my $flagsrequired = { borrowers => 1, updatecharges => 1 };
40
42
Lines 73-82 if ($add){ Link Here
73
    );
75
    );
74
					  
76
					  
75
    if ( $data->{'category_type'} eq 'C') {
77
    if ( $data->{'category_type'} eq 'C') {
76
        my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
78
        my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
77
        my $cnt = scalar(@$catcodes);
79
        $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
78
        $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
80
        $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
79
        $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
80
    }
81
    }
81
82
82
    $template->param( adultborrower => 1 ) if ( $data->{category_type} eq 'A' );
83
    $template->param( adultborrower => 1 ) if ( $data->{category_type} eq 'A' );
(-)a/members/maninvoice.pl (-4 / +5 lines)
Lines 34-39 use C4::Items; Link Here
34
use C4::Branch;
34
use C4::Branch;
35
use C4::Members::Attributes qw(GetBorrowerAttributes);
35
use C4::Members::Attributes qw(GetBorrowerAttributes);
36
36
37
use Koha::Patron::Categories;
38
37
my $input=new CGI;
39
my $input=new CGI;
38
my $flagsrequired = { borrowers => 1 };
40
my $flagsrequired = { borrowers => 1 };
39
41
Lines 99-108 if ($add){ Link Here
99
  $template->param( invoice_types_loop => \@invoice_types );
101
  $template->param( invoice_types_loop => \@invoice_types );
100
102
101
    if ( $data->{'category_type'} eq 'C') {
103
    if ( $data->{'category_type'} eq 'C') {
102
        my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
104
        my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
103
        my $cnt = scalar(@$catcodes);
105
        $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
104
        $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
106
        $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
105
        $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
106
    }
107
    }
107
108
108
    $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
109
    $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
22
21
my $input = new CGI;
23
my $input = new CGI;
Lines 150-159 if ($input->param('newflags')) { Link Here
150
    }
152
    }
151
153
152
    if ( $bor->{'category_type'} eq 'C') {
154
    if ( $bor->{'category_type'} eq 'C') {
153
        my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
155
        my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
154
        my $cnt = scalar(@$catcodes);
156
        $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
155
        $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
157
        $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
156
        $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
157
    }
158
    }
158
	
159
	
159
$template->param( adultborrower => 1 ) if ( $bor->{'category_type'} eq 'A' );
160
$template->param( adultborrower => 1 ) if ( $bor->{'category_type'} eq 'A' );
(-)a/members/member-password.pl (-4 / +5 lines)
Lines 17-22 use C4::Circulation; Link Here
17
use CGI qw ( -utf8 );
17
use CGI qw ( -utf8 );
18
use C4::Members::Attributes qw(GetBorrowerAttributes);
18
use C4::Members::Attributes qw(GetBorrowerAttributes);
19
19
20
use Koha::Patron::Categories;
21
20
use Digest::MD5 qw(md5_base64);
22
use Digest::MD5 qw(md5_base64);
21
23
22
my $input = new CGI;
24
my $input = new CGI;
Lines 82-91 if ( $newpassword && !scalar(@errors) ) { Link Here
82
	$template->param( defaultnewpassword => $defaultnewpassword );
84
	$template->param( defaultnewpassword => $defaultnewpassword );
83
}
85
}
84
    if ( $bor->{'category_type'} eq 'C') {
86
    if ( $bor->{'category_type'} eq 'C') {
85
        my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
87
        my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
86
        my $cnt = scalar(@$catcodes);
88
        $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
87
        $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
89
        $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
88
        $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
89
    }
90
    }
90
	
91
	
91
$template->param( adultborrower => 1 ) if ( $bor->{'category_type'} eq 'A' );
92
$template->param( adultborrower => 1 ) if ( $bor->{'category_type'} eq 'A' );
(-)a/members/memberentry.pl (-19 / +23 lines)
Lines 508-534 if(!defined($data{'sex'})){ Link Here
508
my @typeloop;
508
my @typeloop;
509
my $no_categories = 1;
509
my $no_categories = 1;
510
my $no_add;
510
my $no_add;
511
foreach (qw(C A S P I X)) {
511
foreach my $category_type (qw(C A S P I X)) {
512
    my $action="WHERE category_type=?";
512
    my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => $category_type }, {order_by => ['categorycode']});
513
    my ($categories,$labels)=GetborCatFromCatType($_,$action);
513
    $no_categories = 0 if $patron_categories->count > 0;
514
    if(scalar(@$categories) > 0){ $no_categories = 0; }
514
    $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1;
515
	my @categoryloop;
515
516
	foreach my $cat (@$categories){
516
    my @categoryloop;
517
		push @categoryloop,{'categorycode' => $cat,
517
    while ( my $patron_category = $patron_categories->next ) {
518
			  'categoryname' => $labels->{$cat},
518
        push @categoryloop,
519
			  'categorycodeselected' => ((defined($borrower_data->{'categorycode'}) && 
519
          { 'categorycode' => $patron_category->categorycode,
520
                                                     $cat eq $borrower_data->{'categorycode'}) 
520
            'categoryname' => $patron_category->description,
521
                                                     || (defined($categorycode) && $cat eq $categorycode)),
521
            'categorycodeselected' =>
522
		};
522
              ( ( defined( $borrower_data->{'categorycode'} ) && $patron_category->categorycode eq $borrower_data->{'categorycode'} ) || ( defined($categorycode) && $patron_category->categorycode eq $categorycode ) ),
523
	}
523
          };
524
	my %typehash;
524
    }
525
	$typehash{'typename'}=$_;
525
    my %typehash;
526
    my $typedescription = "typename_".$typehash{'typename'};
526
    $typehash{'typename'} = $category_type;
527
	$typehash{'categoryloop'}=\@categoryloop;
527
    my $typedescription = "typename_" . $typehash{'typename'};
528
	push @typeloop,{'typename' => $_,
528
    $typehash{'categoryloop'} = \@categoryloop;
529
    push @typeloop,
530
      { 'typename'       => $category_type,
529
        $typedescription => 1,
531
        $typedescription => 1,
530
	  'categoryloop' => \@categoryloop};
532
        'categoryloop'   => \@categoryloop
533
      };
531
}
534
}
535
532
$template->param('typeloop' => \@typeloop,
536
$template->param('typeloop' => \@typeloop,
533
        no_categories => $no_categories);
537
        no_categories => $no_categories);
534
if($no_categories){ $no_add = 1; }
538
if($no_categories){ $no_add = 1; }
(-)a/members/moremember.pl (-5 / +4 lines)
Lines 61-66 if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preferen Link Here
61
use DateTime;
61
use DateTime;
62
use Koha::DateUtils;
62
use Koha::DateUtils;
63
use Koha::Database;
63
use Koha::Database;
64
use Koha::Patron::Categories;
64
65
65
use vars qw($debug);
66
use vars qw($debug);
66
67
Lines 156-166 $data->{ "sex_".$data->{'sex'}."_p" } = 1 if defined $data->{sex}; Link Here
156
157
157
my $catcode;
158
my $catcode;
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 ( $count, $guarantees ) = GetGuarantees( $data->{'borrowernumber'} );
165
my ( $count, $guarantees ) = GetGuarantees( $data->{'borrowernumber'} );
(-)a/members/pay.pl (-9 / +5 lines)
Lines 42-47 use C4::Overdues; Link Here
42
use C4::Branch;
42
use C4::Branch;
43
use C4::Members::Attributes qw(GetBorrowerAttributes);
43
use C4::Members::Attributes qw(GetBorrowerAttributes);
44
44
45
use Koha::Patron::Categories;
46
45
our $input = CGI->new;
47
our $input = CGI->new;
46
48
47
my $updatecharges_permissions = $input->param('woall') ? 'writeoff' : 'remaining_permissions';
49
my $updatecharges_permissions = $input->param('woall') ? 'writeoff' : 'remaining_permissions';
Lines 212-226 sub borrower_add_additional_fields { Link Here
212
# in a number of templates. It should not be the business of this script but in lieu of
214
# in a number of templates. It should not be the business of this script but in lieu of
213
# a revised api here it is ...
215
# a revised api here it is ...
214
    if ( $b_ref->{category_type} eq 'C' ) {
216
    if ( $b_ref->{category_type} eq 'C' ) {
215
        my ( $catcodes, $labels ) =
217
        my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
216
          GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
218
        $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
217
        if ( @{$catcodes} ) {
219
        $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
218
            if ( @{$catcodes} > 1 ) {
219
                $b_ref->{CATCODE_MULTI} = 1;
220
            } elsif ( @{$catcodes} == 1 ) {
221
                $b_ref->{catcode} = $catcodes->[0];
222
            }
223
        }
224
    } elsif ( $b_ref->{category_type} eq 'A' ) {
220
    } elsif ( $b_ref->{category_type} eq 'A' ) {
225
        $b_ref->{adultborrower} = 1;
221
        $b_ref->{adultborrower} = 1;
226
    }
222
    }
(-)a/members/paycollect.pl (-9 / +5 lines)
Lines 30-35 use C4::Accounts; Link Here
30
use C4::Koha;
30
use C4::Koha;
31
use C4::Branch;
31
use C4::Branch;
32
32
33
use Koha::Patron::Categories;
34
33
my $input = CGI->new();
35
my $input = CGI->new();
34
36
35
my $updatecharges_permissions = $input->param('writeoff_individual') ? 'writeoff' : 'remaining_permissions';
37
my $updatecharges_permissions = $input->param('writeoff_individual') ? 'writeoff' : 'remaining_permissions';
Lines 163-177 sub borrower_add_additional_fields { Link Here
163
# in a number of templates. It should not be the business of this script but in lieu of
165
# in a number of templates. It should not be the business of this script but in lieu of
164
# a revised api here it is ...
166
# a revised api here it is ...
165
    if ( $b_ref->{category_type} eq 'C' ) {
167
    if ( $b_ref->{category_type} eq 'C' ) {
166
        my ( $catcodes, $labels ) =
168
        my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
167
          GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
169
        $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
168
        if ( @{$catcodes} ) {
170
        $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
169
            if ( @{$catcodes} > 1 ) {
170
                $b_ref->{CATCODE_MULTI} = 1;
171
            } elsif ( @{$catcodes} == 1 ) {
172
                $b_ref->{catcode} = $catcodes->[0];
173
            }
174
        }
175
    } elsif ( $b_ref->{category_type} eq 'A' ) {
171
    } elsif ( $b_ref->{category_type} eq 'A' ) {
176
        $b_ref->{adultborrower} = 1;
172
        $b_ref->{adultborrower} = 1;
177
    }
173
    }
(-)a/members/printfeercpt.pl (-4 / +4 lines)
Lines 32-37 use C4::Members; Link Here
32
use C4::Branch;
32
use C4::Branch;
33
use C4::Accounts;
33
use C4::Accounts;
34
use Koha::DateUtils;
34
use Koha::DateUtils;
35
use Koha::Patron::Categories;
35
36
36
my $input=new CGI;
37
my $input=new CGI;
37
38
Lines 57-66 if ( $action eq 'print' ) { Link Here
57
}
58
}
58
59
59
if ( $data->{'category_type'} eq 'C') {
60
if ( $data->{'category_type'} eq 'C') {
60
   my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
61
    my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
61
   my $cnt = scalar(@$catcodes);
62
    $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
62
   $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
63
    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
63
   $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
64
}
64
}
65
65
66
#get account details
66
#get account details
(-)a/members/printinvoice.pl (-4 / +5 lines)
Lines 31-36 use C4::Members; Link Here
31
use C4::Branch;
31
use C4::Branch;
32
use C4::Accounts;
32
use C4::Accounts;
33
33
34
use Koha::Patron::Categories;
35
34
my $input = new CGI;
36
my $input = new CGI;
35
37
36
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
38
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
Lines 51-60 my $accountlines_id = $input->param('accountlines_id'); Link Here
51
my $data = GetMember( 'borrowernumber' => $borrowernumber );
53
my $data = GetMember( 'borrowernumber' => $borrowernumber );
52
54
53
if ( $data->{'category_type'} eq 'C' ) {
55
if ( $data->{'category_type'} eq 'C' ) {
54
    my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
56
    my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
55
    my $cnt = scalar(@$catcodes);
57
    $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
56
    $template->param( 'CATCODE_MULTI' => 1 ) if $cnt > 1;
58
    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
57
    $template->param( 'catcode' => $catcodes->[0] ) if $cnt == 1;
58
}
59
}
59
60
60
#get account details
61
#get account details
(-)a/members/readingrec.pl (-4 / +5 lines)
Lines 33-38 use List::MoreUtils qw/any uniq/; Link Here
33
use Koha::DateUtils;
33
use Koha::DateUtils;
34
use C4::Members::Attributes qw(GetBorrowerAttributes);
34
use C4::Members::Attributes qw(GetBorrowerAttributes);
35
35
36
use Koha::Patron::Categories;
37
36
my $input = CGI->new;
38
my $input = CGI->new;
37
39
38
#get borrower details
40
#get borrower details
Lines 93-102 if ( $op eq 'export_barcodes' ) { Link Here
93
}
95
}
94
96
95
if ( $data->{'category_type'} eq 'C') {
97
if ( $data->{'category_type'} eq 'C') {
96
    my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
98
    my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
97
    my $cnt = scalar(@$catcodes);
99
    $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
98
    $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
100
    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
99
    $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
100
}
101
}
101
102
102
$template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
103
$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 (-14 / +4 lines)
Lines 129-153 if ($do_it) { Link Here
129
                            );
129
                            );
130
            push @itemtypeloop, \%row;
130
            push @itemtypeloop, \%row;
131
    }
131
    }
132
    
132
133
    #borcat
133
    my $patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['categorycode']});
134
    my ($codes,$labels) = GetborCatFromCatType(undef,undef);
134
135
    my @borcatloop;
136
    foreach my $thisborcat (sort {$labels->{$a} cmp $labels->{$b}} keys %$labels) {
137
            my %row =(value => $thisborcat,
138
                      description => $labels->{$thisborcat},
139
                            );
140
            push @borcatloop, \%row;
141
    }
142
    
143
    #Day
144
    #Month
145
    $template->param(
135
    $template->param(
146
                    CGIextChoice => $CGIextChoice,
136
                    CGIextChoice => $CGIextChoice,
147
                    CGIsepChoice => $CGIsepChoice,
137
                    CGIsepChoice => $CGIsepChoice,
148
                    branchloop => GetBranchesLoop(C4::Context->userenv->{'branch'}),
138
                    branchloop => GetBranchesLoop(C4::Context->userenv->{'branch'}),
149
                    itemtypeloop =>\@itemtypeloop,
139
                    itemtypeloop =>\@itemtypeloop,
150
                    borcatloop =>\@borcatloop,
140
                    patron_categories => $patron_categories,
151
                    );
141
                    );
152
output_html_with_http_headers $input, $cookie, $template->output;
142
output_html_with_http_headers $input, $cookie, $template->output;
153
}
143
}
(-)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 (-2 / +9 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 9;
22
use Test::More tests => 11;
23
23
24
use C4::Context;
24
use C4::Context;
25
use Koha::Database;
25
use Koha::Database;
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
})->store;
46
})->store;
45
47
Lines 55-60 C4::Context->_new_userenv('my_new_userenv'); Link Here
55
C4::Context->set_userenv( 0, 0, 'usercnum', 'firstname', 'surname', $another_branch->{branchcode}, 'My wonderful library', '', '', '' );
57
C4::Context->set_userenv( 0, 0, 'usercnum', 'firstname', 'surname', $another_branch->{branchcode}, 'My wonderful library', '', '', '' );
56
my $new_category_3 = Koha::Patron::Category->new(
58
my $new_category_3 = Koha::Patron::Category->new(
57
    {   categorycode => 'mycatcodeZ',
59
    {   categorycode => 'mycatcodeZ',
60
        category_type => 'A',
58
        description  => 'mycatdescZ',
61
        description  => 'mycatdescZ',
59
    }
62
    }
60
)->store;
63
)->store;
Lines 66-71 is( scalar( grep { $_ eq $new_category_1->categorycode } @limited_category_codes Link Here
66
is( scalar( grep { $_ eq $new_category_2->categorycode } @limited_category_codes ), 1, 'The second category is not limited' );
69
is( scalar( grep { $_ eq $new_category_2->categorycode } @limited_category_codes ), 1, 'The second category is not limited' );
67
is( scalar( grep { $_ eq $new_category_3->categorycode } @limited_category_codes ), 1, 'The third category is limited to my branch ' );
70
is( scalar( grep { $_ eq $new_category_3->categorycode } @limited_category_codes ), 1, 'The third category is limited to my branch ' );
68
71
72
my @limited_categories_for_A = Koha::Patron::Categories->search_limited({ category_type => 'A' });
73
my @limited_category_codes_for_A = map { $_->categorycode } @limited_categories_for_A;
74
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' );
75
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' );
76
69
$retrieved_category_1->delete;
77
$retrieved_category_1->delete;
70
is( Koha::Patron::Categories->search->count, $nb_of_categories + 2, 'Delete should have deleted the patron category' );
78
is( Koha::Patron::Categories->search->count, $nb_of_categories + 2, 'Delete should have deleted the patron category' );
71
79
72
- 

Return to bug 15407