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

(-)a/C4/Reports/Guided.pm (-2 / +2 lines)
Lines 30-39 use C4::Output; Link Here
30
use XML::Simple;
30
use XML::Simple;
31
use XML::Dumper;
31
use XML::Dumper;
32
use C4::Debug;
32
use C4::Debug;
33
# use Smart::Comments;
34
# use Data::Dumper;
35
use C4::Log;
33
use C4::Log;
36
34
35
use Koha::Patron::Categories;
36
37
BEGIN {
37
BEGIN {
38
    # set the version for version checking
38
    # set the version for version checking
39
    $VERSION = 3.07.00.049;
39
    $VERSION = 3.07.00.049;
(-)a/admin/smart-rules.pl (-9 / +4 lines)
Lines 31-36 use Koha::Database; Link Here
31
use Koha::IssuingRule;
31
use Koha::IssuingRule;
32
use Koha::IssuingRules;
32
use Koha::IssuingRules;
33
use Koha::Libraries;
33
use Koha::Libraries;
34
use Koha::Patron::Categories;
34
35
35
my $input = CGI->new;
36
my $input = CGI->new;
36
my $dbh = C4::Context->dbh;
37
my $dbh = C4::Context->dbh;
Lines 430-443 for my $thisbranch (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{b Link Here
430
    };
431
    };
431
}
432
}
432
433
433
my $sth=$dbh->prepare("SELECT description,categorycode FROM categories ORDER BY description");
434
my $patron_categories = Koha::Patron::Categories->search({}, { order_by => ['description'] });
434
$sth->execute;
435
my @category_loop;
436
while (my $data=$sth->fetchrow_hashref){
437
    push @category_loop,$data;
438
}
439
435
440
$sth->finish;
441
my @row_loop;
436
my @row_loop;
442
my @itemtypes = @{ GetItemTypes( style => 'array' ) };
437
my @itemtypes = @{ GetItemTypes( style => 'array' ) };
443
@itemtypes = sort { lc $a->{translated_description} cmp lc $b->{translated_description} } @itemtypes;
438
@itemtypes = sort { lc $a->{translated_description} cmp lc $b->{translated_description} } @itemtypes;
Lines 477-483 while (my $row = $sth2->fetchrow_hashref) { Link Here
477
    }
472
    }
478
    push @row_loop, $row;
473
    push @row_loop, $row;
479
}
474
}
480
$sth->finish;
481
475
482
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
476
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
483
477
Lines 585-591 if ($defaults) { Link Here
585
579
586
$template->param(default_rules => ($defaults ? 1 : 0));
580
$template->param(default_rules => ($defaults ? 1 : 0));
587
581
588
$template->param(categoryloop => \@category_loop,
582
$template->param(
583
    patron_categories => $patron_categories,
589
                        itemtypeloop => \@itemtypes,
584
                        itemtypeloop => \@itemtypes,
590
                        rules => \@sorted_row_loop,
585
                        rules => \@sorted_row_loop,
591
                        branchloop => \@branchloop,
586
                        branchloop => \@branchloop,
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-4 / +4 lines)
Lines 261-268 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
261
                    <td>
261
                    <td>
262
                        <select name="categorycode" id="categorycode">
262
                        <select name="categorycode" id="categorycode">
263
                            <option value="*">All</option>
263
                            <option value="*">All</option>
264
                        [% FOREACH categoryloo IN categoryloop %]
264
                        [% FOREACH patron_category IN patron_categories%]
265
                            <option value="[% categoryloo.categorycode %]">[% categoryloo.description %]</option>
265
                            <option value="[% patron_category.categorycode %]">[% patron_category.description %]</option>
266
                        [% END %]
266
                        [% END %]
267
                        </select>
267
                        </select>
268
                    </td>
268
                    </td>
Lines 497-504 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
497
                <tr>
497
                <tr>
498
                    <td>
498
                    <td>
499
                        <select name="categorycode">
499
                        <select name="categorycode">
500
                        [% FOREACH categoryloo IN categoryloop %]
500
                        [% FOREACH patron_category IN patron_categories%]
501
                            <option value="[% categoryloo.categorycode %]">[% categoryloo.description %]</option>
501
                            <option value="[% patron_category.categorycode %]">[% patron_category.description %]</option>
502
                        [% END %]
502
                        [% END %]
503
                        </select>
503
                        </select>
504
                    </td>
504
                    </td>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_stats.tt (-7 / +8 lines)
Lines 78-90 Link Here
78
			<td>Patron category</td>
78
			<td>Patron category</td>
79
			<td><input type="radio" name="Line" value="categorycode" /></td>
79
			<td><input type="radio" name="Line" value="categorycode" /></td>
80
			<td><input type="radio" name="Column" value="categorycode" /></td>
80
			<td><input type="radio" name="Column" value="categorycode" /></td>
81
			<td><select name="Filter"  size="1" id="catcode">
81
            <td>
82
				<option value=""></option>
82
                <select name="Filter"  size="1" id="catcode">
83
				[% FOREACH CAT_LOO IN CAT_LOOP %]
83
                    <option value=""></option>
84
				<option value="[% CAT_LOO.categorycode %]">[% CAT_LOO.description %]</option>
84
                    [% FOREACH patron_category IN patron_categories %]
85
				[% END %]
85
                        <option value="[% patron_category.categorycode %]">[% patron_category.description %]</option>
86
				</select>
86
                    [% END %]
87
			</td>
87
                </select>
88
            </td>
88
			</tr>
89
			</tr>
89
			<tr>
90
			<tr>
90
			<td>Patron status</td>
91
			<td>Patron status</td>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_avg_stats.tt (-2 / +2 lines)
Lines 155-162 Link Here
155
                <td>
155
                <td>
156
                    <select name="Filter" size="1" id="borcat">
156
                    <select name="Filter" size="1" id="borcat">
157
                        <option value=""></option>
157
                        <option value=""></option>
158
                        [% FOREACH value IN BorCat.values %]
158
                        [% FOREACH patron_category IN patron_categories %]
159
                        <option value="[%- value -%]">[%- BorCat.labels.$value -%]</option>
159
                            <option value="[%- patron_category.categorycode -%]">[%- patron_category.description-%]</option>
160
                        [% END %]
160
                        [% END %]
161
                    </select>
161
                    </select>
162
                </td>
162
                </td>
(-)a/reports/borrowers_stats.pl (-21 / +9 lines)
Lines 31-36 use C4::Output; Link Here
31
use C4::Reports;
31
use C4::Reports;
32
use C4::Circulation;
32
use C4::Circulation;
33
use C4::Members::AttributeTypes;
33
use C4::Members::AttributeTypes;
34
35
use Koha::Patron::Categories;
36
34
use Date::Calc qw(
37
use Date::Calc qw(
35
  Today
38
  Today
36
  Add_Delta_YM
39
  Add_Delta_YM
Lines 116-122 if ($do_it) { Link Here
116
} else {
119
} else {
117
	my $dbh = C4::Context->dbh;
120
	my $dbh = C4::Context->dbh;
118
	my $req;
121
	my $req;
119
	$template->param(  CAT_LOOP => &catcode_aref);
122
    my $patron_categories = Koha::Patron::Categories->search({}, {order_by => ['description']});
123
    $template->param( patron_categories => $patron_categories );
120
	my @branchloop;
124
	my @branchloop;
121
	foreach (sort {$branches->{$a}->{branchname} cmp $branches->{$b}->{branchname}} keys %$branches) {
125
	foreach (sort {$branches->{$a}->{branchname} cmp $branches->{$b}->{branchname}} keys %$branches) {
122
		my $line = {branchcode => $_, branchname => $branches->{$_}->{branchname} || 'UNKNOWN'};
126
		my $line = {branchcode => $_, branchname => $branches->{$_}->{branchname} || 'UNKNOWN'};
Lines 148-167 if ($do_it) { Link Here
148
}
152
}
149
output_html_with_http_headers $input, $cookie, $template->output;
153
output_html_with_http_headers $input, $cookie, $template->output;
150
154
151
sub catcode_aref {
152
	my $req = C4::Context->dbh->prepare("SELECT categorycode, description FROM categories ORDER BY description");
153
	$req->execute;
154
	return $req->fetchall_arrayref({});
155
}
156
sub catcodes_hash {
157
	my %cathash;
158
	my $catcodes = &catcode_aref;
159
	foreach (@$catcodes) {
160
		$cathash{$_->{categorycode}} = ($_->{description} || 'NO_DESCRIPTION') . " ($_->{categorycode})";
161
	}
162
	return %cathash;
163
}
164
165
sub calculate {
155
sub calculate {
166
	my ($line, $column, $digits, $status, $activity, $filters, $attr_filters) = @_;
156
	my ($line, $column, $digits, $status, $activity, $filters, $attr_filters) = @_;
167
157
Lines 269-277 sub calculate { Link Here
269
    } else {
259
    } else {
270
        $linefield = $line;
260
        $linefield = $line;
271
    }
261
    }
272
262
    my $patron_categories = Koha::Patron::Categories->search({}, {order_by => ['categorycode']});
273
	my %cathash = ($line eq 'categorycode' or $column eq 'categorycode') ? &catcodes_hash : ();
263
    push @loopfilter, {debug=>1, crit=>"\%cathash", filter=>join(", ", map { $_->categorycode . ' (' . ( $_->description || 'NO_DESCRIPTION' ) . ')'} $patron_categories->as_list )};
274
	push @loopfilter, {debug=>1, crit=>"\%cathash", filter=>join(", ", map {$cathash{$_}} sort keys %cathash)};
275
264
276
    my $strsth;
265
    my $strsth;
277
    my @strparams; # bind parameters for the query
266
    my @strparams; # bind parameters for the query
Lines 299-306 sub calculate { Link Here
299
 		my %cell;
288
 		my %cell;
300
		if ($celvalue) {
289
		if ($celvalue) {
301
			$cell{rowtitle} = $celvalue;
290
			$cell{rowtitle} = $celvalue;
302
			# $cell{rowtitle_display} = ($linefield eq 'branchcode') ? $branches->{$celvalue}->{branchname} : $celvalue;
291
            $cell{rowtitle_display} = ($patron_categories->find($celvalue)->description || "$celvalue\*") if ($line eq 'categorycode');
303
			$cell{rowtitle_display} = ($cathash{$celvalue} || "$celvalue\*") if ($line eq 'categorycode');
304
		}
292
		}
305
 		$cell{totalrow} = 0;
293
 		$cell{totalrow} = 0;
306
		push @loopline, \%cell;
294
		push @loopline, \%cell;
Lines 348-354 sub calculate { Link Here
348
             if (defined $celvalue) {
336
             if (defined $celvalue) {
349
			$cell{coltitle} = $celvalue;
337
			$cell{coltitle} = $celvalue;
350
			# $cell{coltitle_display} = ($colfield eq 'branchcode') ? $branches->{$celvalue}->{branchname} : $celvalue;
338
			# $cell{coltitle_display} = ($colfield eq 'branchcode') ? $branches->{$celvalue}->{branchname} : $celvalue;
351
			$cell{coltitle_display} = $cathash{$celvalue} if ($column eq 'categorycode');
339
            $cell{coltitle_display} = $patron_categories->find($celvalue)->description if ($column eq 'categorycode');
352
		}
340
		}
353
		push @loopcol, \%cell;
341
		push @loopcol, \%cell;
354
 	}
342
 	}
(-)a/reports/guided_reports.pl (-8 / +5 lines)
Lines 33-38 use C4::Koha qw/IsAuthorisedValueCategory GetFrameworksLoop/; Link Here
33
use C4::Context;
33
use C4::Context;
34
use C4::Log;
34
use C4::Log;
35
use Koha::DateUtils qw/dt_from_string output_pref/;
35
use Koha::DateUtils qw/dt_from_string output_pref/;
36
use Koha::Patron::Categories;
36
37
37
=head1 NAME
38
=head1 NAME
38
39
Lines 695-710 elsif ($phase eq 'Run this report'){ Link Here
695
                        }
696
                        }
696
                    }
697
                    }
697
                    elsif ( $authorised_value eq "categorycode" ) {
698
                    elsif ( $authorised_value eq "categorycode" ) {
698
                        my $sth = $dbh->prepare("SELECT categorycode, description FROM categories ORDER BY description");
699
                        my @patron_categories = Koha::Patron::Categories->search({}, { order_by => ['description']});
699
                        $sth->execute;
700
                        %authorised_lib = map { $_->categorycode => $_->description } @patron_categories;
700
                        while ( my ( $categorycode, $description ) = $sth->fetchrow_array ) {
701
                        push @authorised_values, $_->categorycode for @patron_categories;
701
                            push @authorised_values, $categorycode;
702
                            $authorised_lib{$categorycode} = $description;
703
                        }
704
705
                        #---- "true" authorised value
706
                    }
702
                    }
707
                    else {
703
                    else {
704
                        #---- "true" authorised value
708
                        if ( IsAuthorisedValueCategory($authorised_value) ) {
705
                        if ( IsAuthorisedValueCategory($authorised_value) ) {
709
                            my $query = '
706
                            my $query = '
710
                            SELECT authorised_value,lib
707
                            SELECT authorised_value,lib
(-)a/reports/issues_avg_stats.pl (-19 / +5 lines)
Lines 29-34 use C4::Koha; Link Here
29
use C4::Circulation;
29
use C4::Circulation;
30
use C4::Reports;
30
use C4::Reports;
31
use Koha::DateUtils;
31
use Koha::DateUtils;
32
use Koha::Patron::Categories;
32
use Date::Calc qw(Delta_Days);
33
use Date::Calc qw(Delta_Days);
33
34
34
=head1 NAME
35
=head1 NAME
Lines 37-44 plugin that shows a stats on borrowers Link Here
37
38
38
=head1 DESCRIPTION
39
=head1 DESCRIPTION
39
40
40
=over 2
41
42
=cut
41
=cut
43
42
44
my $input = new CGI;
43
my $input = new CGI;
Lines 119-143 if ($do_it) { Link Here
119
    }
118
    }
120
# Displaying choices
119
# Displaying choices
121
} else {
120
} else {
122
    my $dbh = C4::Context->dbh;
121
    my $patron_categories = Koha::Patron::Categories->search({}, {order_by => ['description']});
123
    my @values;
124
    my $req;
125
    $req = $dbh->prepare("select distinctrow categorycode,description from categories order by description");
126
    $req->execute;
127
    my %labelsc;
128
    my @selectc;
129
    while (my ($value, $desc) =$req->fetchrow) {
130
        push @selectc, $value;
131
        $labelsc{$value} = $desc;
132
    }
133
    my $BorCat = {
134
        values   => \@selectc,
135
        labels   => \%labelsc,
136
    };
137
122
138
    my $itemtypes = GetItemTypes( style => 'array' );
123
    my $itemtypes = GetItemTypes( style => 'array' );
139
124
140
    $req = $dbh->prepare("select distinctrow sort1 from borrowers where sort1 is not null order by sort1");
125
    my $dbh = C4::Context->dbh;
126
    my $req = $dbh->prepare("select distinctrow sort1 from borrowers where sort1 is not null order by sort1");
141
    $req->execute;
127
    $req->execute;
142
    my @selects1;
128
    my @selects1;
143
    my $hassort1;
129
    my $hassort1;
Lines 166-172 if ($do_it) { Link Here
166
    my $CGIsepChoice=GetDelimiterChoices;
152
    my $CGIsepChoice=GetDelimiterChoices;
167
    
153
    
168
    $template->param(
154
    $template->param(
169
                    BorCat       => $BorCat,
155
                    patron_categories => $patron_categories,
170
                    itemtypes    => $itemtypes,
156
                    itemtypes    => $itemtypes,
171
                    branchloop   => GetBranchesLoop(),
157
                    branchloop   => GetBranchesLoop(),
172
                    hassort1     => $hassort1,
158
                    hassort1     => $hassort1,
(-)a/tools/overduerules.pl (-17 / +15 lines)
Lines 30-43 use C4::Members; Link Here
30
use C4::Overdues;
30
use C4::Overdues;
31
use Koha::Libraries;
31
use Koha::Libraries;
32
32
33
use Koha::Patron::Categories;
34
33
our $input = new CGI;
35
our $input = new CGI;
34
my $dbh = C4::Context->dbh;
36
my $dbh = C4::Context->dbh;
35
37
36
my @categories = @{$dbh->selectall_arrayref(
38
my @patron_categories = Koha::Patron::Categories->search( { overduenoticerequired => { '>' => 0 } } );
37
    'SELECT description, categorycode FROM categories WHERE overduenoticerequired > 0',
39
my @category_codes  = map { $_->categorycode } @patron_categories;
38
    { Slice => {} }
39
)};
40
my @category_codes  = map { $_->{categorycode} } @categories;
41
our @rule_params     = qw(delay letter debarred);
40
our @rule_params     = qw(delay letter debarred);
42
41
43
# blank_row($category_code) - return true if the entire row is blank.
42
# blank_row($category_code) - return true if the entire row is blank.
Lines 224-230 my @line_loop; Link Here
224
223
225
my $message_transport_types = C4::Letters::GetMessageTransportTypes();
224
my $message_transport_types = C4::Letters::GetMessageTransportTypes();
226
my ( @first, @second, @third );
225
my ( @first, @second, @third );
227
for my $data (@categories) {
226
for my $patron_category (@patron_categories) {
228
    if (%temphash and not $input_saved){
227
    if (%temphash and not $input_saved){
229
        # if we managed to save the form submission, don't
228
        # if we managed to save the form submission, don't
230
        # reuse %temphash, but take the values from the
229
        # reuse %temphash, but take the values from the
Lines 232-244 for my $data (@categories) { Link Here
232
        # bugs where the form submission was not correctly saved
231
        # bugs where the form submission was not correctly saved
233
        for my $i ( 1..3 ){
232
        for my $i ( 1..3 ){
234
            my %row = (
233
            my %row = (
235
                overduename => $data->{'categorycode'},
234
                overduename => $patron_category->categorycode,
236
                line        => $data->{'description'}
235
                line        => $patron_category->description,
237
            );
236
            );
238
            $row{delay}=$temphash{$data->{'categorycode'}}->{"delay$i"};
237
            $row{delay}=$temphash{$patron_category->categorycode}->{"delay$i"};
239
            $row{debarred}=$temphash{$data->{'categorycode'}}->{"debarred$i"};
238
            $row{debarred}=$temphash{$patron_category->categorycode}->{"debarred$i"};
240
            $row{selected_lettercode} = $temphash{ $data->{categorycode} }->{"letter$i"};
239
            $row{selected_lettercode} = $temphash{ $patron_category->categorycode }->{"letter$i"};
241
            my @selected_mtts = @{ GetOverdueMessageTransportTypes( $branch, $data->{'categorycode'}, $i) };
240
            my @selected_mtts = @{ GetOverdueMessageTransportTypes( $branch, $patron_category->categorycode, $i) };
242
            my @mtts;
241
            my @mtts;
243
            for my $mtt ( @$message_transport_types ) {
242
            for my $mtt ( @$message_transport_types ) {
244
                push @mtts, {
243
                push @mtts, {
Lines 258-276 for my $data (@categories) { Link Here
258
    } else {
257
    } else {
259
    #getting values from table
258
    #getting values from table
260
        my $sth2=$dbh->prepare("SELECT * from overduerules WHERE branchcode=? AND categorycode=?");
259
        my $sth2=$dbh->prepare("SELECT * from overduerules WHERE branchcode=? AND categorycode=?");
261
        $sth2->execute($branch,$data->{'categorycode'});
260
        $sth2->execute($branch,$patron_category->categorycode);
262
        my $dat=$sth2->fetchrow_hashref;
261
        my $dat=$sth2->fetchrow_hashref;
263
        for my $i ( 1..3 ){
262
        for my $i ( 1..3 ){
264
            my %row = (
263
            my %row = (
265
                overduename => $data->{'categorycode'},
264
                overduename => $patron_category->categorycode,
266
                line        => $data->{'description'}
265
                line        => $patron_category->description,
267
            );
266
            );
268
267
269
            $row{selected_lettercode} = $dat->{"letter$i"};
268
            $row{selected_lettercode} = $dat->{"letter$i"};
270
269
271
            if ($dat->{"delay$i"}){$row{delay}=$dat->{"delay$i"};}
270
            if ($dat->{"delay$i"}){$row{delay}=$dat->{"delay$i"};}
272
            if ($dat->{"debarred$i"}){$row{debarred}=$dat->{"debarred$i"};}
271
            if ($dat->{"debarred$i"}){$row{debarred}=$dat->{"debarred$i"};}
273
            my @selected_mtts = @{ GetOverdueMessageTransportTypes( $branch, $data->{'categorycode'}, $i) };
272
            my @selected_mtts = @{ GetOverdueMessageTransportTypes( $branch, $patron_category->categorycode, $i) };
274
            my @mtts;
273
            my @mtts;
275
            for my $mtt ( @$message_transport_types ) {
274
            for my $mtt ( @$message_transport_types ) {
276
                push @mtts, {
275
                push @mtts, {
277
- 

Return to bug 15407