Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 103 lines (88 sloc) 3.273 kB
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use C4::Context;
use C4::Output;
use C4::Auth;
use C4::Koha;
use C4::Branch; # GetBranches
use C4::Members;
use C4::Accounts;
use C4::Accounts::FineThresholds;
use Text::CSV_XS;
use C4::Files;
my $input = new CGI;
my $dbh = C4::Context->dbh;
my $type=$input->param('type');
my $branch = $input->param('branch') || 'Any';
my $op = $input->param('op') || 'view';
my $commit = $input->param('commit');
my ($template, $loggedinuser, $cookie)
= get_template_and_user({template_name => "tools/fine-threshold-forgiveness.tmpl",
query => $input,
type => "intranet",
authnotrequired => 0,
flagsrequired => {parameters => 1},
debug => 1,
});
my $rule = $input->param('run_rule');
my @rules_loop = C4::Accounts::FineThresholds->getThresholdRules;
my @current_rule;
# note undef amount so that template can deal with them
foreach my $entry (@rules_loop) {
foreach (keys %$entry){
$entry->{$_.'_any'} = 1 unless defined($entry->{$_});
}
push @current_rule, $entry if($rule && $entry->{id} == $rule);
}
my @results_loop;
if ($op eq 'view') {
$template->param( view => 1,
rules => \@rules_loop,
);
} elsif ($op eq 'run' || $op eq 'dryrun') {
my $threshold_rules;
my $fine_thresholds = C4::Accounts::FineThresholds->new();
# foreach ($input->param) {
# /RUN-(\d+)/ or next;
# push @$threshold_rules, $1;
# }
# since we can't really handle cascading rule application yet, only allow a single rule to run at a time.
#Now that we have the conditions, run the query
my ($bor_cnt,$fee_cnt,$fee_amt) = $fine_thresholds->getFeesToForgive($rule);
my $forgiven;
if($fee_cnt){
$forgiven = $fine_thresholds->forgiveFines($commit);
my $csv = Text::CSV_XS->new(
{
'quote_char' => '"',
'escape_char' => '"',
'sep_char' => ',',
'binary' => 1
}
);
my $forgiven_file = "firstname, branchname, itemtype, description, surname, accounttype, amount, timestamp, action\n";;
for my $row(@$forgiven) {
my @this_row;
while( my ($k, $v) = each %$row) {
push @this_row, $v;
}
$csv->combine(@this_row);
$forgiven_file.=$csv->string."\n";
}
C4::Files::CreateFile($forgiven_file,"$bor_cnt patrons, $fee_cnt fees forgiven, $fee_amt total",'fines_forgiven');
}
$template->param(
forgive_loop => $forgiven,
bor_cnt => $bor_cnt,
fee_cnt => $fee_cnt,
fee_amt => sprintf("%.2f",$fee_amt),
dry_run => ($commit) ? 0 : 1,
run_rule => $rule,
current_rule => \@current_rule,
rule_name => $current_rule[0]->{name}
);
}
output_html_with_http_headers $input, $cookie, $template->output;
exit 0;
Jump to Line
Something went wrong with that request. Please try again.