use XML::Simple;
use XML::Dumper;
use C4::Debug;
-# use Smart::Comments;
-# use Data::Dumper;
use C4::Log;
use Koha::AuthorisedValues;
+use Koha::Patron::Categories;
BEGIN {
require Exporter;
use Koha::RefundLostItemFeeRule;
use Koha::RefundLostItemFeeRules;
use Koha::Libraries;
+use Koha::Patron::Categories;
my $input = CGI->new;
my $dbh = C4::Context->dbh;
};
}
-my $sth=$dbh->prepare("SELECT description,categorycode FROM categories ORDER BY description");
-$sth->execute;
-my @category_loop;
-while (my $data=$sth->fetchrow_hashref){
- push @category_loop,$data;
-}
+my $patron_categories = Koha::Patron::Categories->search({}, { order_by => ['description'] });
-$sth->finish;
my @row_loop;
my @itemtypes = @{ GetItemTypes( style => 'array' ) };
@itemtypes = sort { lc $a->{translated_description} cmp lc $b->{translated_description} } @itemtypes;
}
push @row_loop, $row;
}
-$sth->finish;
my @sorted_row_loop = sort by_category_and_itemtype @row_loop;
$template->param(default_rules => ($defaults ? 1 : 0));
-$template->param(categoryloop => \@category_loop,
+$template->param(
+ patron_categories => $patron_categories,
itemtypeloop => \@itemtypes,
rules => \@sorted_row_loop,
branchloop => \@branchloop,
<td>
<select name="categorycode" id="categorycode">
<option value="*">All</option>
- [% FOREACH categoryloo IN categoryloop %]
- <option value="[% categoryloo.categorycode %]">[% categoryloo.description %]</option>
+ [% FOREACH patron_category IN patron_categories%]
+ <option value="[% patron_category.categorycode %]">[% patron_category.description %]</option>
[% END %]
</select>
</td>
<tr>
<td>
<select name="categorycode">
- [% FOREACH categoryloo IN categoryloop %]
- <option value="[% categoryloo.categorycode %]">[% categoryloo.description %]</option>
+ [% FOREACH patron_category IN patron_categories%]
+ <option value="[% patron_category.categorycode %]">[% patron_category.description %]</option>
[% END %]
</select>
</td>
<td>Patron category</td>
<td><input type="radio" name="Line" value="categorycode" /></td>
<td><input type="radio" name="Column" value="categorycode" /></td>
- <td><select name="Filter" size="1" id="catcode">
- <option value=""></option>
- [% FOREACH CAT_LOO IN CAT_LOOP %]
- <option value="[% CAT_LOO.categorycode %]">[% CAT_LOO.description %]</option>
- [% END %]
- </select>
- </td>
+ <td>
+ <select name="Filter" size="1" id="catcode">
+ <option value=""></option>
+ [% FOREACH patron_category IN patron_categories %]
+ <option value="[% patron_category.categorycode %]">[% patron_category.description %]</option>
+ [% END %]
+ </select>
+ </td>
</tr>
<tr>
<td>Patron status</td>
<td>
<select name="Filter" size="1" id="borcat">
<option value=""></option>
- [% FOREACH value IN BorCat.values %]
- <option value="[%- value -%]">[%- BorCat.labels.$value -%]</option>
+ [% FOREACH patron_category IN patron_categories %]
+ <option value="[%- patron_category.categorycode -%]">[%- patron_category.description-%]</option>
[% END %]
</select>
</td>
use C4::Reports;
use C4::Circulation;
use C4::Members::AttributeTypes;
+
+use Koha::Patron::Categories;
+
use Date::Calc qw(
Today
Add_Delta_YM
} else {
my $dbh = C4::Context->dbh;
my $req;
- $template->param( CAT_LOOP => &catcode_aref);
+ my $patron_categories = Koha::Patron::Categories->search({}, {order_by => ['description']});
+ $template->param( patron_categories => $patron_categories );
my @branchloop;
foreach (sort {$branches->{$a}->{branchname} cmp $branches->{$b}->{branchname}} keys %$branches) {
my $line = {branchcode => $_, branchname => $branches->{$_}->{branchname} || 'UNKNOWN'};
}
output_html_with_http_headers $input, $cookie, $template->output;
-sub catcode_aref {
- my $req = C4::Context->dbh->prepare("SELECT categorycode, description FROM categories ORDER BY description");
- $req->execute;
- return $req->fetchall_arrayref({});
-}
-sub catcodes_hash {
- my %cathash;
- my $catcodes = &catcode_aref;
- foreach (@$catcodes) {
- $cathash{$_->{categorycode}} = ($_->{description} || 'NO_DESCRIPTION') . " ($_->{categorycode})";
- }
- return %cathash;
-}
-
sub calculate {
my ($line, $column, $digits, $status, $activity, $filters, $attr_filters) = @_;
} else {
$linefield = $line;
}
-
- my %cathash = ($line eq 'categorycode' or $column eq 'categorycode') ? &catcodes_hash : ();
- push @loopfilter, {debug=>1, crit=>"\%cathash", filter=>join(", ", map {$cathash{$_}} sort keys %cathash)};
+ my $patron_categories = Koha::Patron::Categories->search({}, {order_by => ['categorycode']});
+ push @loopfilter, {debug=>1, crit=>"\%cathash", filter=>join(", ", map { $_->categorycode . ' (' . ( $_->description || 'NO_DESCRIPTION' ) . ')'} $patron_categories->as_list )};
my $strsth;
my @strparams; # bind parameters for the query
my %cell;
if ($celvalue) {
$cell{rowtitle} = $celvalue;
- # $cell{rowtitle_display} = ($linefield eq 'branchcode') ? $branches->{$celvalue}->{branchname} : $celvalue;
- $cell{rowtitle_display} = ($cathash{$celvalue} || "$celvalue\*") if ($line eq 'categorycode');
+ $cell{rowtitle_display} = ($patron_categories->find($celvalue)->description || "$celvalue\*") if ($line eq 'categorycode');
}
$cell{totalrow} = 0;
push @loopline, \%cell;
if (defined $celvalue) {
$cell{coltitle} = $celvalue;
# $cell{coltitle_display} = ($colfield eq 'branchcode') ? $branches->{$celvalue}->{branchname} : $celvalue;
- $cell{coltitle_display} = $cathash{$celvalue} if ($column eq 'categorycode');
+ $cell{coltitle_display} = $patron_categories->find($celvalue)->description if ($column eq 'categorycode');
}
push @loopcol, \%cell;
}
use Koha::DateUtils qw/dt_from_string output_pref/;
use Koha::AuthorisedValue;
use Koha::AuthorisedValues;
+use Koha::Patron::Categories;
=head1 NAME
}
}
elsif ( $authorised_value eq "categorycode" ) {
- my $sth = $dbh->prepare("SELECT categorycode, description FROM categories ORDER BY description");
- $sth->execute;
- while ( my ( $categorycode, $description ) = $sth->fetchrow_array ) {
- push @authorised_values, $categorycode;
- $authorised_lib{$categorycode} = $description;
- }
-
- #---- "true" authorised value
+ my @patron_categories = Koha::Patron::Categories->search({}, { order_by => ['description']});
+ %authorised_lib = map { $_->categorycode => $_->description } @patron_categories;
+ push @authorised_values, $_->categorycode for @patron_categories;
}
else {
if ( Koha::AuthorisedValues->search({ category => $authorised_value })->count ) {
use C4::Circulation;
use C4::Reports;
use Koha::DateUtils;
+use Koha::Patron::Categories;
use Date::Calc qw(Delta_Days);
=head1 NAME
=head1 DESCRIPTION
-=over 2
-
=cut
my $input = new CGI;
}
# Displaying choices
} else {
- my $dbh = C4::Context->dbh;
- my @values;
- my $req;
- $req = $dbh->prepare("select distinctrow categorycode,description from categories order by description");
- $req->execute;
- my %labelsc;
- my @selectc;
- while (my ($value, $desc) =$req->fetchrow) {
- push @selectc, $value;
- $labelsc{$value} = $desc;
- }
- my $BorCat = {
- values => \@selectc,
- labels => \%labelsc,
- };
+ my $patron_categories = Koha::Patron::Categories->search({}, {order_by => ['description']});
my $itemtypes = GetItemTypes( style => 'array' );
- $req = $dbh->prepare("select distinctrow sort1 from borrowers where sort1 is not null order by sort1");
+ my $dbh = C4::Context->dbh;
+ my $req = $dbh->prepare("select distinctrow sort1 from borrowers where sort1 is not null order by sort1");
$req->execute;
my @selects1;
my $hassort1;
my $CGIsepChoice=GetDelimiterChoices;
$template->param(
- BorCat => $BorCat,
+ patron_categories => $patron_categories,
itemtypes => $itemtypes,
branchloop => GetBranchesLoop(),
hassort1 => $hassort1,
use C4::Overdues;
use Koha::Libraries;
+use Koha::Patron::Categories;
+
our $input = new CGI;
my $dbh = C4::Context->dbh;
-my @categories = @{$dbh->selectall_arrayref(
- 'SELECT description, categorycode FROM categories WHERE overduenoticerequired > 0',
- { Slice => {} }
-)};
-my @category_codes = map { $_->{categorycode} } @categories;
+my @patron_categories = Koha::Patron::Categories->search( { overduenoticerequired => { '>' => 0 } } );
+my @category_codes = map { $_->categorycode } @patron_categories;
our @rule_params = qw(delay letter debarred);
# blank_row($category_code) - return true if the entire row is blank.
my $message_transport_types = C4::Letters::GetMessageTransportTypes();
my ( @first, @second, @third );
-for my $data (@categories) {
+for my $patron_category (@patron_categories) {
if (%temphash and not $input_saved){
# if we managed to save the form submission, don't
# reuse %temphash, but take the values from the
# bugs where the form submission was not correctly saved
for my $i ( 1..3 ){
my %row = (
- overduename => $data->{'categorycode'},
- line => $data->{'description'}
+ overduename => $patron_category->categorycode,
+ line => $patron_category->description,
);
- $row{delay}=$temphash{$data->{'categorycode'}}->{"delay$i"};
- $row{debarred}=$temphash{$data->{'categorycode'}}->{"debarred$i"};
- $row{selected_lettercode} = $temphash{ $data->{categorycode} }->{"letter$i"};
- my @selected_mtts = @{ GetOverdueMessageTransportTypes( $branch, $data->{'categorycode'}, $i) };
+ $row{delay}=$temphash{$patron_category->categorycode}->{"delay$i"};
+ $row{debarred}=$temphash{$patron_category->categorycode}->{"debarred$i"};
+ $row{selected_lettercode} = $temphash{ $patron_category->categorycode }->{"letter$i"};
+ my @selected_mtts = @{ GetOverdueMessageTransportTypes( $branch, $patron_category->categorycode, $i) };
my @mtts;
for my $mtt ( @$message_transport_types ) {
push @mtts, {
} else {
#getting values from table
my $sth2=$dbh->prepare("SELECT * from overduerules WHERE branchcode=? AND categorycode=?");
- $sth2->execute($branch,$data->{'categorycode'});
+ $sth2->execute($branch,$patron_category->categorycode);
my $dat=$sth2->fetchrow_hashref;
for my $i ( 1..3 ){
my %row = (
- overduename => $data->{'categorycode'},
- line => $data->{'description'}
+ overduename => $patron_category->categorycode,
+ line => $patron_category->description,
);
$row{selected_lettercode} = $dat->{"letter$i"};
if ($dat->{"delay$i"}){$row{delay}=$dat->{"delay$i"};}
if ($dat->{"debarred$i"}){$row{debarred}=$dat->{"debarred$i"};}
- my @selected_mtts = @{ GetOverdueMessageTransportTypes( $branch, $data->{'categorycode'}, $i) };
+ my @selected_mtts = @{ GetOverdueMessageTransportTypes( $branch, $patron_category->categorycode, $i) };
my @mtts;
for my $mtt ( @$message_transport_types ) {
push @mtts, {