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

(-)a/C4/Reports/Guided.pm (-2 / +1 lines)
Lines 30-40 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
37
use Koha::AuthorisedValues;
35
use Koha::AuthorisedValues;
36
use Koha::Patron::Categories;
38
37
39
BEGIN {
38
BEGIN {
40
    require Exporter;
39
    require Exporter;
(-)a/admin/smart-rules.pl (-9 / +4 lines)
Lines 34-39 use Koha::Logger; Link Here
34
use Koha::RefundLostItemFeeRule;
34
use Koha::RefundLostItemFeeRule;
35
use Koha::RefundLostItemFeeRules;
35
use Koha::RefundLostItemFeeRules;
36
use Koha::Libraries;
36
use Koha::Libraries;
37
use Koha::Patron::Categories;
37
38
38
my $input = CGI->new;
39
my $input = CGI->new;
39
my $dbh = C4::Context->dbh;
40
my $dbh = C4::Context->dbh;
Lines 468-481 for my $thisbranch (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{b Link Here
468
    };
469
    };
469
}
470
}
470
471
471
my $sth=$dbh->prepare("SELECT description,categorycode FROM categories ORDER BY description");
472
my $patron_categories = Koha::Patron::Categories->search({}, { order_by => ['description'] });
472
$sth->execute;
473
my @category_loop;
474
while (my $data=$sth->fetchrow_hashref){
475
    push @category_loop,$data;
476
}
477
473
478
$sth->finish;
479
my @row_loop;
474
my @row_loop;
480
my @itemtypes = @{ GetItemTypes( style => 'array' ) };
475
my @itemtypes = @{ GetItemTypes( style => 'array' ) };
481
@itemtypes = sort { lc $a->{translated_description} cmp lc $b->{translated_description} } @itemtypes;
476
@itemtypes = sort { lc $a->{translated_description} cmp lc $b->{translated_description} } @itemtypes;
Lines 515-521 while (my $row = $sth2->fetchrow_hashref) { Link Here
515
    }
510
    }
516
    push @row_loop, $row;
511
    push @row_loop, $row;
517
}
512
}
518
$sth->finish;
519
513
520
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
514
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
521
515
Lines 624-630 if ($defaults) { Link Here
624
618
625
$template->param(default_rules => ($defaults ? 1 : 0));
619
$template->param(default_rules => ($defaults ? 1 : 0));
626
620
627
$template->param(categoryloop => \@category_loop,
621
$template->param(
622
    patron_categories => $patron_categories,
628
                        itemtypeloop => \@itemtypes,
623
                        itemtypeloop => \@itemtypes,
629
                        rules => \@sorted_row_loop,
624
                        rules => \@sorted_row_loop,
630
                        branchloop => \@branchloop,
625
                        branchloop => \@branchloop,
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-4 / +4 lines)
Lines 275-282 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
275
                    <td>
275
                    <td>
276
                        <select name="categorycode" id="categorycode">
276
                        <select name="categorycode" id="categorycode">
277
                            <option value="*">All</option>
277
                            <option value="*">All</option>
278
                        [% FOREACH categoryloo IN categoryloop %]
278
                        [% FOREACH patron_category IN patron_categories%]
279
                            <option value="[% categoryloo.categorycode %]">[% categoryloo.description %]</option>
279
                            <option value="[% patron_category.categorycode %]">[% patron_category.description %]</option>
280
                        [% END %]
280
                        [% END %]
281
                        </select>
281
                        </select>
282
                    </td>
282
                    </td>
Lines 545-552 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
545
                <tr>
545
                <tr>
546
                    <td>
546
                    <td>
547
                        <select name="categorycode">
547
                        <select name="categorycode">
548
                        [% FOREACH categoryloo IN categoryloop %]
548
                        [% FOREACH patron_category IN patron_categories%]
549
                            <option value="[% categoryloo.categorycode %]">[% categoryloo.description %]</option>
549
                            <option value="[% patron_category.categorycode %]">[% patron_category.description %]</option>
550
                        [% END %]
550
                        [% END %]
551
                        </select>
551
                        </select>
552
                    </td>
552
                    </td>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_stats.tt (-7 / +8 lines)
Lines 77-89 Link Here
77
			<td>Patron category</td>
77
			<td>Patron category</td>
78
			<td><input type="radio" name="Line" value="categorycode" /></td>
78
			<td><input type="radio" name="Line" value="categorycode" /></td>
79
			<td><input type="radio" name="Column" value="categorycode" /></td>
79
			<td><input type="radio" name="Column" value="categorycode" /></td>
80
			<td><select name="Filter"  size="1" id="catcode">
80
            <td>
81
				<option value=""></option>
81
                <select name="Filter"  size="1" id="catcode">
82
				[% FOREACH CAT_LOO IN CAT_LOOP %]
82
                    <option value=""></option>
83
				<option value="[% CAT_LOO.categorycode %]">[% CAT_LOO.description %]</option>
83
                    [% FOREACH patron_category IN patron_categories %]
84
				[% END %]
84
                        <option value="[% patron_category.categorycode %]">[% patron_category.description %]</option>
85
				</select>
85
                    [% END %]
86
			</td>
86
                </select>
87
            </td>
87
			</tr>
88
			</tr>
88
			<tr>
89
			<tr>
89
			<td>Patron status</td>
90
			<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 / +4 lines)
Lines 35-40 use C4::Log; Link Here
35
use Koha::DateUtils qw/dt_from_string output_pref/;
35
use Koha::DateUtils qw/dt_from_string output_pref/;
36
use Koha::AuthorisedValue;
36
use Koha::AuthorisedValue;
37
use Koha::AuthorisedValues;
37
use Koha::AuthorisedValues;
38
use Koha::Patron::Categories;
38
39
39
=head1 NAME
40
=head1 NAME
40
41
Lines 697-710 elsif ($phase eq 'Run this report'){ Link Here
697
                        }
698
                        }
698
                    }
699
                    }
699
                    elsif ( $authorised_value eq "categorycode" ) {
700
                    elsif ( $authorised_value eq "categorycode" ) {
700
                        my $sth = $dbh->prepare("SELECT categorycode, description FROM categories ORDER BY description");
701
                        my @patron_categories = Koha::Patron::Categories->search({}, { order_by => ['description']});
701
                        $sth->execute;
702
                        %authorised_lib = map { $_->categorycode => $_->description } @patron_categories;
702
                        while ( my ( $categorycode, $description ) = $sth->fetchrow_array ) {
703
                        push @authorised_values, $_->categorycode for @patron_categories;
703
                            push @authorised_values, $categorycode;
704
                            $authorised_lib{$categorycode} = $description;
705
                        }
706
707
                        #---- "true" authorised value
708
                    }
704
                    }
709
                    else {
705
                    else {
710
                        if ( Koha::AuthorisedValues->search({ category => $authorised_value })->count ) {
706
                        if ( Koha::AuthorisedValues->search({ category => $authorised_value })->count ) {
(-)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