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

(-)a/C4/Reports/Guided.pm (-10 / +6 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;
Lines 936-950 sub build_authorised_value_list { Link Here
936
            $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
936
            $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
937
        }
937
        }
938
    } elsif ( $authorised_value eq "categorycode" ) {
938
    } elsif ( $authorised_value eq "categorycode" ) {
939
        my $sth = $dbh->prepare("SELECT categorycode, description FROM categories ORDER BY description");
939
        my @patron_categories = Koha::Patron::Categories->search({}, { order_by => ['description']});
940
        $sth->execute;
940
        %authorised_lib = map { $_->categorycode => $_->description } @patron_categories;
941
        while ( my ( $categorycode, $description ) = $sth->fetchrow_array ) {
941
        push @authorised_values, $_->categorycode for @patron_categories;
942
            push @authorised_values, $categorycode;
943
            $authorised_lib{$categorycode} = $description;
944
        }
945
946
        #---- "true" authorised value
947
    } else {
942
    } else {
943
        #---- "true" authorised value
948
        my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib");
944
        my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY lib");
949
945
950
        $authorised_values_sth->execute($authorised_value);
946
        $authorised_values_sth->execute($authorised_value);
(-)a/admin/smart-rules.pl (-9 / +4 lines)
Lines 28-33 use C4::Debug; Link Here
28
use C4::Branch; # GetBranches
28
use C4::Branch; # GetBranches
29
use Koha::DateUtils;
29
use Koha::DateUtils;
30
use Koha::Database;
30
use Koha::Database;
31
use Koha::Patron::Categories;
31
32
32
my $input = CGI->new;
33
my $input = CGI->new;
33
my $dbh = C4::Context->dbh;
34
my $dbh = C4::Context->dbh;
Lines 412-425 for my $thisbranch (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{b Link Here
412
    };
413
    };
413
}
414
}
414
415
415
my $sth=$dbh->prepare("SELECT description,categorycode FROM categories ORDER BY description");
416
my $patron_categories = Koha::Patron::Categories->search({}, { order_by => ['description'] });
416
$sth->execute;
417
my @category_loop;
418
while (my $data=$sth->fetchrow_hashref){
419
    push @category_loop,$data;
420
}
421
417
422
$sth->finish;
423
my @row_loop;
418
my @row_loop;
424
my @itemtypes = @{ GetItemTypes( style => 'array' ) };
419
my @itemtypes = @{ GetItemTypes( style => 'array' ) };
425
420
Lines 458-464 while (my $row = $sth2->fetchrow_hashref) { Link Here
458
    }
453
    }
459
    push @row_loop, $row;
454
    push @row_loop, $row;
460
}
455
}
461
$sth->finish;
462
456
463
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
457
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
464
458
Lines 558-564 if ($defaults) { Link Here
558
552
559
$template->param(default_rules => ($defaults ? 1 : 0));
553
$template->param(default_rules => ($defaults ? 1 : 0));
560
554
561
$template->param(categoryloop => \@category_loop,
555
$template->param(
556
    patron_categories => $patron_categories,
562
                        itemtypeloop => \@itemtypes,
557
                        itemtypeloop => \@itemtypes,
563
                        rules => \@sorted_row_loop,
558
                        rules => \@sorted_row_loop,
564
                        branchloop => \@branchloop,
559
                        branchloop => \@branchloop,
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-4 / +4 lines)
Lines 242-249 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
242
                    <td>
242
                    <td>
243
                        <select name="categorycode" id="categorycode">
243
                        <select name="categorycode" id="categorycode">
244
                            <option value="*">All</option>
244
                            <option value="*">All</option>
245
                        [% FOREACH categoryloo IN categoryloop %]
245
                        [% FOREACH patron_category IN patron_categories%]
246
                            <option value="[% categoryloo.categorycode %]">[% categoryloo.description %]</option>
246
                            <option value="[% patron_category.categorycode %]">[% patron_category.description %]</option>
247
                        [% END %]
247
                        [% END %]
248
                        </select>
248
                        </select>
249
                    </td>
249
                    </td>
Lines 476-483 for="tobranch"><strong>Clone these rules to:</strong></label> <input type="hidde Link Here
476
                <tr>
476
                <tr>
477
                    <td>
477
                    <td>
478
                        <select name="categorycode">
478
                        <select name="categorycode">
479
                        [% FOREACH categoryloo IN categoryloop %]
479
                        [% FOREACH patron_category IN patron_categories%]
480
                            <option value="[% categoryloo.categorycode %]">[% categoryloo.description %]</option>
480
                            <option value="[% patron_category.categorycode %]">[% patron_category.description %]</option>
481
                        [% END %]
481
                        [% END %]
482
                        </select>
482
                        </select>
483
                    </td>
483
                    </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 29-42 use C4::Letters; Link Here
29
use C4::Members;
29
use C4::Members;
30
use C4::Overdues;
30
use C4::Overdues;
31
31
32
use Koha::Patron::Categories;
33
32
our $input = new CGI;
34
our $input = new CGI;
33
my $dbh = C4::Context->dbh;
35
my $dbh = C4::Context->dbh;
34
36
35
my @categories = @{$dbh->selectall_arrayref(
37
my @patron_categories = Koha::Patron::Categories->search( { overduenoticerequired => { '>' => 0 } } );
36
    'SELECT description, categorycode FROM categories WHERE overduenoticerequired > 0',
38
my @category_codes  = map { $_->categorycode } @patron_categories;
37
    { Slice => {} }
38
)};
39
my @category_codes  = map { $_->{categorycode} } @categories;
40
our @rule_params     = qw(delay letter debarred);
39
our @rule_params     = qw(delay letter debarred);
41
40
42
# blank_row($category_code) - return true if the entire row is blank.
41
# blank_row($category_code) - return true if the entire row is blank.
Lines 212-218 my @line_loop; Link Here
212
211
213
my $message_transport_types = C4::Letters::GetMessageTransportTypes();
212
my $message_transport_types = C4::Letters::GetMessageTransportTypes();
214
my ( @first, @second, @third );
213
my ( @first, @second, @third );
215
for my $data (@categories) {
214
for my $patron_category (@patron_categories) {
216
    if (%temphash and not $input_saved){
215
    if (%temphash and not $input_saved){
217
        # if we managed to save the form submission, don't
216
        # if we managed to save the form submission, don't
218
        # reuse %temphash, but take the values from the
217
        # reuse %temphash, but take the values from the
Lines 220-232 for my $data (@categories) { Link Here
220
        # bugs where the form submission was not correctly saved
219
        # bugs where the form submission was not correctly saved
221
        for my $i ( 1..3 ){
220
        for my $i ( 1..3 ){
222
            my %row = (
221
            my %row = (
223
                overduename => $data->{'categorycode'},
222
                overduename => $patron_category->categorycode,
224
                line        => $data->{'description'}
223
                line        => $patron_category->description,
225
            );
224
            );
226
            $row{delay}=$temphash{$data->{'categorycode'}}->{"delay$i"};
225
            $row{delay}=$temphash{$patron_category->categorycode}->{"delay$i"};
227
            $row{debarred}=$temphash{$data->{'categorycode'}}->{"debarred$i"};
226
            $row{debarred}=$temphash{$patron_category->categorycode}->{"debarred$i"};
228
            $row{selected_lettercode} = $temphash{ $data->{categorycode} }->{"letter$i"};
227
            $row{selected_lettercode} = $temphash{ $patron_category->categorycode }->{"letter$i"};
229
            my @selected_mtts = @{ GetOverdueMessageTransportTypes( $branch, $data->{'categorycode'}, $i) };
228
            my @selected_mtts = @{ GetOverdueMessageTransportTypes( $branch, $patron_category->categorycode, $i) };
230
            my @mtts;
229
            my @mtts;
231
            for my $mtt ( @$message_transport_types ) {
230
            for my $mtt ( @$message_transport_types ) {
232
                push @mtts, {
231
                push @mtts, {
Lines 246-264 for my $data (@categories) { Link Here
246
    } else {
245
    } else {
247
    #getting values from table
246
    #getting values from table
248
        my $sth2=$dbh->prepare("SELECT * from overduerules WHERE branchcode=? AND categorycode=?");
247
        my $sth2=$dbh->prepare("SELECT * from overduerules WHERE branchcode=? AND categorycode=?");
249
        $sth2->execute($branch,$data->{'categorycode'});
248
        $sth2->execute($branch,$patron_category->categorycode);
250
        my $dat=$sth2->fetchrow_hashref;
249
        my $dat=$sth2->fetchrow_hashref;
251
        for my $i ( 1..3 ){
250
        for my $i ( 1..3 ){
252
            my %row = (
251
            my %row = (
253
                overduename => $data->{'categorycode'},
252
                overduename => $patron_category->categorycode,
254
                line        => $data->{'description'}
253
                line        => $patron_category->description,
255
            );
254
            );
256
255
257
            $row{selected_lettercode} = $dat->{"letter$i"};
256
            $row{selected_lettercode} = $dat->{"letter$i"};
258
257
259
            if ($dat->{"delay$i"}){$row{delay}=$dat->{"delay$i"};}
258
            if ($dat->{"delay$i"}){$row{delay}=$dat->{"delay$i"};}
260
            if ($dat->{"debarred$i"}){$row{debarred}=$dat->{"debarred$i"};}
259
            if ($dat->{"debarred$i"}){$row{debarred}=$dat->{"debarred$i"};}
261
            my @selected_mtts = @{ GetOverdueMessageTransportTypes( $branch, $data->{'categorycode'}, $i) };
260
            my @selected_mtts = @{ GetOverdueMessageTransportTypes( $branch, $patron_category->categorycode, $i) };
262
            my @mtts;
261
            my @mtts;
263
            for my $mtt ( @$message_transport_types ) {
262
            for my $mtt ( @$message_transport_types ) {
264
                push @mtts, {
263
                push @mtts, {
265
- 

Return to bug 15407