X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2Fbin%2Ffreeside-overdue;h=116245f9cb2bd2523ada057109adb9426e1322a1;hb=ef92d87d1980598a4f786905ac7aff1af0ead2b8;hp=65941ce951bde15fbae9eb308c05a2475564c264;hpb=854f8d1e160d394d5019292d7e7a9019f06cc1b9;p=freeside.git diff --git a/FS/bin/freeside-overdue b/FS/bin/freeside-overdue index 65941ce95..116245f9c 100755 --- a/FS/bin/freeside-overdue +++ b/FS/bin/freeside-overdue @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/perl -w use strict; use vars qw( $days_to_pay $cust_main $cust_pkg @@ -13,12 +13,12 @@ use FS::UID qw(adminsuidsetup); &untaint_argv; my %opt; -getopts('ed:qplsc', \%opt); +getopts('ed:qpl:scbyoi', \%opt); my $user = shift or die &usage; adminsuidsetup $user; -my $now = time; +my $now = time; #eventually take a time option like freeside-bill my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($now) )[0,1,2,3,4,5]; $mon++; @@ -48,21 +48,23 @@ foreach $cust_main ( qsearch('cust_main',{} ) ) { $cust_main->balance_date(time-$opt{d} * 86400); } + if ( $opt{p} && ! grep { $_ eq 'POST' } $cust_main->invoicing_list ) { + print "\n\tAdding postal invoicing" unless $opt{q}; + my @invoicing_list = $cust_main->invoicing_list; + push @invoicing_list, 'POST'; + $cust_main->invoicing_list(\@invoicing_list); + } + if ( $opt{l} ) { print "\n\tCharging late fee of \$$opt{l}" unless $opt{q}; - + my $error = $cust_main->charge($opt{l}, 'Late fee'); + # comment or plandata with info so we don't redo the same late fee every + # day } foreach $cust_pkg ( qsearch( 'cust_pkg', { 'custnum' => $cust_main->custnum } ) ) { - if ( $opt{p} && ! grep { $_ eq 'POST' } $cust_main->invoicing_list ) { - print "\n\tAdding postal invoicing" unless $opt{q}; - my @invoicing_list = $cust_main->invoicing_list; - push @invoicing_list, 'POST'; - $cust_main->invoicing_list(\@invoicing_list); - } - if ($opt{s}) { print "\n\tSuspending pkgnum " . $cust_pkg->pkgnum unless $opt{q}; $cust_pkg->suspend; @@ -72,7 +74,31 @@ foreach $cust_main ( qsearch('cust_main',{} ) ) { print "\n\tCancelling pkgnum " . $cust_pkg->pkgnum unless $opt{q}; $cust_pkg->cancel; } + + } + + if ( $opt{b} ) { + print "\n\tBilling" unless $opt{q}; + my $error = $cust_main->bill('time'=>$now); + warn "Error billing, customer #" . $cust_main->custnum . + ":" . $error if $error; + } + + if ( $opt{y} ) { + print "\n\tApplying outstanding payments and credits" unless $opt{q}; + $cust_main->apply_payments; + $cust_main->apply_credits; + } + if ( $opt{o} ) { + print "\n\tCollecting" unless $opt{q}; + my $error = $cust_main->collect( + 'invoice_time' => $now, + 'batch_card' => $opt{i} ? 'no' : 'yes', + 'force_print' => 'yes', + ); + warn "Error collecting from customer #" . $cust_main->custnum. ":$error" + if $error; } print "\n" unless $opt{q}; @@ -83,13 +109,13 @@ foreach $cust_main ( qsearch('cust_main',{} ) ) { sub untaint_argv { foreach $_ ( $[ .. $#ARGV ) { - $ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\""; + $ARGV[$_] =~ /^([\w\-\/\.]*)$/ || die "Illegal arguement \"$ARGV[$_]\""; $ARGV[$_]=$1; } } sub usage { - die "Usage:\n\n freeside-overdue [ -e ] [ -d days ] [ -q ] [ -p ] [ -l amount ] [ -s ] [ -c ] user\n"; + die "Usage:\n\n freeside-overdue [ -e ] [ -d days ] [ -q ] [ -p ] [ -l amount ] [ -s ] [ -c ] [ -b ] [ -y ] [ -o [ -i ] ] user\n"; } @@ -99,30 +125,42 @@ freeside-overdue - Perform actions on overdue and/or expired accounts. =head1 SYNOPSIS - freeside-overdue [ -e ] [ -d days ] [ -q ] [ -p ] [ -l amount ] [ -s ] [ -c ] user + freeside-overdue [ -e ] [ -d days ] [ -q ] [ -p ] [ -l amount ] [ -s ] [ -c ] [ -b ] [ -y ] [ -o [ -i ] ] user =head1 DESCRIPTION +This script is deprecated in 1.4.0. You should use freeside-daily and invoice +events instead. + Performs actions on overdue and/or expired accounts. Selection options (at least one selection option is required): - -d: Customers with a balance due on invoices older than the supplied number - of days. Requires an integer argument. + -d: Customers with a balance due on invoices older than the supplied number + of days. Requires an integer argument. - -e: Customers with a billing expiration date in the past. + -e: Customers with a billing expiration date in the past. Action options: - -q: Be quiet (by default, selected accounts are printed). + -q: Be quiet (by default, selected accounts are printed). + + -p: Add postal invoicing to the relevant customers. + + -l: Add a charge of the given amount to the relevant customers. + + -s: Suspend accounts. - -p: Add postal invoicing to the relevant customers. + -c: Cancel accounts. - -l: Add a charge of the given amount to the relevant customers. + -b: Bill customers (create invoices) - -s: Suspend accounts. + -y: Apply unapplied payments and credits - -c: Cancel accounts. + -o: Collect from customers (charge cards, print invoices) + + -i: real-time billing (as opposed to batch billing). only relevant + for credit cards. user: From the mapsecrets file - see config.html from the base documentation @@ -146,6 +184,12 @@ Example crontab entries: Original disable-overdue version by mw/kwh: Mark W.? and Kristian Hoffmann ? +Ivan seems to be turning it into the "do-everything" CLI. + +=head1 BUGS + +Hell now that this is the do-everything CLI it should have --longoptions + =cut 1;