Disable-overdue

Kristian Hoffmann khoff at pc-intouch.com
Tue Mar 14 12:24:19 PST 2000


Here's the script Mark and I (Mark mainly) wrote to disable overdue
accounts.  You can specify whether or not you want to disable accounts or
just print a list that would be (-s).  You can also specify how many days
overdue you want the suspended accounts to be (-d days).  It requires a
change to cust_main.pm.  You just replace....

sub balance {
...
}

with...

sub balance_date {
  my $self = shift;
  my $time = shift;
  sprintf( "%.2f", $self->total_owed_date($time)
                 - $self->total_credited );
}

sub balance {
  my $self = shift;
  balance_date($self, time);
}


-Kristian
<khoff at pc-intouch.com>

-------------- next part --------------
#!/usr/bin/perl

use strict;
use vars qw( $days_to_pay $cust_main $cust_pkg 
             $cust_svc $svc_acct );
use Getopt::Std;
use FS::cust_main;
use FS::cust_pkg;
use FS::cust_svc;
use FS::svc_acct;
use FS::Record qw(qsearch qsearchs);
use FS::UID qw(adminsuidsetup swapuid);

&untaint_argv;
my %opt;
getopts('sd:', \%opt);
my $user = shift or die &usage;

adminsuidsetup $user;

foreach $cust_main ( qsearch('cust_main',{} ) ) {
  if($cust_main->balance_date(time - $opt{d} * 86400) > 0 &&
     qsearchs( 'cust_pkg', { 'custnum' => $cust_main->custnum,
                             'susp' => "" } )
    ) { 
    print $cust_main->custnum, "\t",
          $cust_main->last, "\t", $cust_main->first, "\t",
          $cust_main->balance_date(time-$opt{d} * 86400);
    foreach $cust_pkg ( qsearch( 'cust_pkg', 
                                 { 'custnum' => $cust_main->custnum } ) ) {
      if ($opt{s}) {
		 print "\n\tSuspending pkgnum " . $cust_pkg->pkgnum;
		}
      $cust_pkg->suspend;
    }
  print "\n";
  }
}

sub untaint_argv {
  foreach $_ ( $[ .. $#ARGV ) { 
    $ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
    $ARGV[$_]=$1;
  }
}

sub usage {
  die "Usage:\n\n  disable-overdue -s -d days user\n";
}


=head1 NAME

disable-overdue - Designed to disable accounts n days overdue.

=head1 SYNOPSIS

  disable-overdue -s -d days user

=head1 DESCRIPTION

Disables overdue accounts.  Sets svc_acct.active = 0 for all services listed
	under cust_svc for the overdue cust_pkgs. 

  -s:	Suspend overdue accounts instead of just listing them.

  -d:	Number of days allowed to be overdue before being disabled.
	Requires an integer argument.

  user: From the mapsecrets file - see config.html from the base documentation
	but be careful.

=head1 VERSION

$Id: disable-overdue,v 1.0.2 2000/03/14 12:15:10 mw/kwh $

=cut



More information about the freeside-users mailing list