X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=misc%2Fcronjobs%2Ffines.pl;h=73cdf9f81bf114cb8b39d5e9dd404e65b6d81591;hb=00bd409a9a4e7576a2d5f613e7e86e26758ee287;hp=de9e8cf7fbd985872d93270a9af7bd413f08ccd0;hpb=8695b7e84f22f0047e6d2204bc6248e6089c21f7;p=koha_gimpoz diff --git a/misc/cronjobs/fines.pl b/misc/cronjobs/fines.pl index de9e8cf7fb..73cdf9f81b 100755 --- a/misc/cronjobs/fines.pl +++ b/misc/cronjobs/fines.pl @@ -21,13 +21,14 @@ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along with -# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, -# Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # FIXME: use FinesMode as described or change syspref description use strict; +#use warnings; FIXME - Bug 2505 BEGIN { # find Koha's Perl modules @@ -44,10 +45,36 @@ use C4::Overdues; use C4::Calendar qw(); # don't need any exports from Calendar use C4::Biblio; use C4::Debug; # supplying $debug and $cgi_debug +use Getopt::Long; + +my $help = 0; +my $verbose = 0; +my $output_dir; + +GetOptions( 'h|help' => \$help, + 'v|verbose' => \$verbose, + 'o|out:s' => \$output_dir, + ); +my $usage = << 'ENDUSAGE'; + +This script calculates and charges overdue fines +to patron accounts. If the Koha System Preference +'finesMode' is set to 'production', the fines are charged +to the patron accounts. If set to 'test', the fines are +calculated but not applied. + +This script has the following parameters : + -h --help: this message + -o --out: ouput directory for logs (defaults to env or /tmp if !exist) + -v --verbose + +ENDUSAGE + +die $usage if $help; use vars qw(@borrower_fields @item_fields @other_fields); use vars qw($fldir $libname $control $mode $delim $dbname $today $today_iso $today_days); -use vars qw($filename $summary); +use vars qw($filename); CHECK { @borrower_fields = qw(cardnumber categorycode surname firstname email phone address citystate); @@ -59,14 +86,6 @@ CHECK { $dbname = C4::Context->config('database'); $delim = "\t"; # ? C4::Context->preference('delimiter') || "\t"; - $today = C4::Dates->new(); - $today_iso = $today->output('iso'); - $today_days = Date_to_Days(split(/-/,$today_iso)); - $fldir = $ENV{TMPDIR} || "/tmp"; # TODO: use GetOpt - $filename = $dbname; - $filename =~ s/\W//; - $filename = $fldir . '/'. $filename . '_' . $today_iso . ".log"; - $summary = 1; # TODO: use GetOpt } INIT { @@ -77,13 +96,27 @@ INIT { "Delimiter: '$delim'\n"; } -open (FILE, ">$filename") or die "Cannot write file $filename: $!"; -print FILE join $delim, (@borrower_fields, @item_fields, @other_fields); -print FILE "\n"; - my $data = Getoverdues(); my $overdueItemsCounted = 0; my %calendars = (); +$today = C4::Dates->new(); +$today_iso = $today->output('iso'); +$today_days = Date_to_Days(split(/-/,$today_iso)); +if($output_dir){ + $fldir = $output_dir if( -d $output_dir ); +} else { + $fldir = $ENV{TMPDIR} || "/tmp"; +} +if (!-d $fldir) { + warn "Could not write to $fldir ... does not exist!"; +} +$filename = $dbname; +$filename =~ s/\W//; +$filename = $fldir . '/'. $filename . '_' . $today_iso . ".log"; +print "writing to $filename\n" if $verbose; +open (FILE, ">$filename") or die "Cannot write file $filename: $!"; +print FILE join $delim, (@borrower_fields, @item_fields, @other_fields); +print FILE "\n"; for (my $i=0; $inew($data->[$i]->{'date_due'},'iso'); @@ -125,7 +158,7 @@ for (my $i=0; $i