From 7e3eb82f87c371785544b706b7347c7edde2b593 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 10 Feb 2002 19:58:43 +0000 Subject: update billing documentation for the new world of invoice events added freeside-daily replacing freeside-bill for the new world of invoice events --- FS/bin/freeside-daily | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100755 FS/bin/freeside-daily (limited to 'FS/bin/freeside-daily') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily new file mode 100755 index 000000000..8d839cb21 --- /dev/null +++ b/FS/bin/freeside-daily @@ -0,0 +1,90 @@ +#!/usr/bin/perl -w + +use strict; +use Fcntl qw(:flock); +use Date::Parse; +use Getopt::Std; +use FS::UID qw(adminsuidsetup); +use FS::Record qw(qsearch qsearchs); +use FS::cust_main; + +&untaint_argv; #what it sounds like (eww) +use vars qw($opt_d); +getopts("d:"); +my $user = shift or die &usage; + +adminsuidsetup $user; + +my @cust_main = @ARGV + ? map { qsearchs('cust_main', { custnum => $_ } ) } @ARGV + : qsearch('cust_main', {} ) +; + +#we're at now now (and later). +my($time)= $opt_d ? str2time($opt_d) : $^T; + +my($cust_main,%saw); +foreach $cust_main ( @cust_main ) { + + my $error; + + $error = $cust_main->bill( 'time' => $time ); + warn "Error billing, custnum ". $cust_main->custnum. ": $error" if $error; + + $cust_main->apply_payments; + $cust_main->apply_credits; + + $error=$cust_main->collect( 'invoice_time' => $time ); + warn "Error collecting, custnum". $cust_main->custnum. ": $error" if $error; + +} + +# subroutines + +sub untaint_argv { + foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV + #$ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\""; + # Date::Parse + $ARGV[$_] =~ /^(.*)$/ || die "Illegal arguement \"$ARGV[$_]\""; + $ARGV[$_]=$1; + } +} + +sub usage { + die "Usage:\n\n freeside-daily [ -d 'date' ] user [ custnum custnum ... ]\n"; +} + +=head1 NAME + +freeside-daily - Run daily billing and invoice collection events. + +=head1 SYNOPSIS + + freeside-daily [ -d 'date' ] user [ custnum custnum ... ] + +=head1 DESCRIPTION + +Bills customers and runs invoice collection events. Should be run from +crontab daily. + +This script replaces freeside-bill from 1.3.1. + +Bills customers. Searches for customers who are due for billing and calls +the bill and collect methods of a cust_main object. See L. + + -d: Pretend it's 'date'. Date is in any format Date::Parse is happy with, + but be careful. + +user: From the mapsecrets file - see config.html from the base documentation + +custnum: if one or more customer numbers are specified, only bills those +customers. Otherwise, bills all customers. + +=head1 BUGS + +=head1 SEE ALSO + +L, config.html from the base documentation + +=cut + -- cgit v1.2.1 From 49bc2dac92d2bb60e000088449b27aa380cc3490 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 27 Feb 2002 21:57:24 +0000 Subject: better debugging --- FS/bin/freeside-daily | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'FS/bin/freeside-daily') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 8d839cb21..e6f02df33 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -9,12 +9,14 @@ use FS::Record qw(qsearch qsearchs); use FS::cust_main; &untaint_argv; #what it sounds like (eww) -use vars qw($opt_d); -getopts("d:"); +use vars qw($opt_d $opt_v); +getopts("d:v"); my $user = shift or die &usage; adminsuidsetup $user; +$FS::cust_main::Debug = 1 if $opt_v; + my @cust_main = @ARGV ? map { qsearchs('cust_main', { custnum => $_ } ) } @ARGV : qsearch('cust_main', {} ) -- cgit v1.2.1 From 6414c4c23d3fac2012d1524f17c0aae5e5012935 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 27 Jul 2002 02:47:12 +0000 Subject: vacuum pg databases daily --- FS/bin/freeside-daily | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'FS/bin/freeside-daily') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index e6f02df33..142b0c73a 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -4,7 +4,7 @@ use strict; use Fcntl qw(:flock); use Date::Parse; use Getopt::Std; -use FS::UID qw(adminsuidsetup); +use FS::UID qw(adminsuidsetup driver_name dbh); use FS::Record qw(qsearch qsearchs); use FS::cust_main; @@ -41,6 +41,13 @@ foreach $cust_main ( @cust_main ) { } +if ( driver_name eq 'Pg' ) { + foreach my $statement ( 'vacuum', 'vacuum analyze' ) { + my $sth = dbh->prepare($statement) or die dbh->errstr; + $sth->execute or die $sth->errstr; + } +} + # subroutines sub untaint_argv { -- cgit v1.2.1 From 0f5ad6c181cccbbdec6c48ea74e41d92ef5e3a26 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 19 Sep 2002 08:43:03 +0000 Subject: package expiration --- FS/bin/freeside-daily | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'FS/bin/freeside-daily') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 142b0c73a..22bf2c963 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -28,15 +28,23 @@ my($time)= $opt_d ? str2time($opt_d) : $^T; my($cust_main,%saw); foreach $cust_main ( @cust_main ) { - my $error; + # $^T not $time because -d is for pre-printing invoices + foreach my $cust_pkg ( + grep { $_->expire && $_->expire >= $^T } $cust_main->ncancelled_pkgs + ) { + my $error = $cust_pkg->cancel; + warn "Error cancelling expired pkg ". $cust_pkg->pkgnum. " for custnum ". + $cust_main->custnum. ": $error" + if $error; + } - $error = $cust_main->bill( 'time' => $time ); + my $error = $cust_main->bill( 'time' => $time ); warn "Error billing, custnum ". $cust_main->custnum. ": $error" if $error; $cust_main->apply_payments; $cust_main->apply_credits; - $error=$cust_main->collect( 'invoice_time' => $time ); + $error = $cust_main->collect( 'invoice_time' => $time ); warn "Error collecting, custnum". $cust_main->custnum. ": $error" if $error; } -- cgit v1.2.1 From 54a27b35957baddb725e2b7544d9f134989bfd99 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 4 Oct 2002 12:39:29 +0000 Subject: turn on AutoCommit when vacuuming --- FS/bin/freeside-daily | 1 + 1 file changed, 1 insertion(+) (limited to 'FS/bin/freeside-daily') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 22bf2c963..52028b773 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -50,6 +50,7 @@ foreach $cust_main ( @cust_main ) { } if ( driver_name eq 'Pg' ) { + dbh->{AutoCommit} = 1; #so we can vacuum foreach my $statement ( 'vacuum', 'vacuum analyze' ) { my $sth = dbh->prepare($statement) or die dbh->errstr; $sth->execute or die $sth->errstr; -- cgit v1.2.1 From 656b802d26a8eb0dfd6fd71dbcdebfab156041e9 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 7 Oct 2002 08:47:10 +0000 Subject: cancel when it is *after* expiration date, not when it is *before* --- FS/bin/freeside-daily | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin/freeside-daily') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 52028b773..17ee798ff 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -30,7 +30,7 @@ foreach $cust_main ( @cust_main ) { # $^T not $time because -d is for pre-printing invoices foreach my $cust_pkg ( - grep { $_->expire && $_->expire >= $^T } $cust_main->ncancelled_pkgs + grep { $_->expire && $_->expire <= $^T } $cust_main->ncancelled_pkgs ) { my $error = $cust_pkg->cancel; warn "Error cancelling expired pkg ". $cust_pkg->pkgnum. " for custnum ". -- cgit v1.2.1 From 1583472a6afefb1ad33e05656fd206674f37d9df Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 23 Oct 2002 17:07:59 +0000 Subject: database dump & scp support --- FS/bin/freeside-daily | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'FS/bin/freeside-daily') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 17ee798ff..1db786120 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -4,8 +4,9 @@ use strict; use Fcntl qw(:flock); use Date::Parse; use Getopt::Std; -use FS::UID qw(adminsuidsetup driver_name dbh); +use FS::UID qw(adminsuidsetup driver_name dbh datasrc); use FS::Record qw(qsearch qsearchs); +use FS::Conf; use FS::cust_main; &untaint_argv; #what it sounds like (eww) @@ -57,6 +58,22 @@ if ( driver_name eq 'Pg' ) { } } +#local hack +my $conf = new FS::Conf; +my $dest = $conf->config('dump-scpdest'); +if ( $dest ) { + datasrc =~ /dbname=([\w\.]+)$/ or die "unparsable datasrc ". datasrc; + my $database = $1; + eval "use Net::SCP qw(scp);"; + if ( driver_name eq 'Pg' ) { + system("pg_dump $database >/var/tmp/$database.sql") + } else { + die "database dumps not yet supported for ". driver_name; + } + scp("/var/tmp/$database.sql", $dest); + unlink "/var/tmp/$database.sql" or die $!; +} + # subroutines sub untaint_argv { -- cgit v1.2.1 From 1a7b34a94745208217187050c1daec5bb31b7eb7 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 22 Dec 2002 08:53:25 +0000 Subject: -p option for freeside-daily to only run for a particular payby $disable_agentcheck option for cust_pkg for import optimization --- FS/bin/freeside-daily | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'FS/bin/freeside-daily') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 1db786120..c82dc07a0 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -11,16 +11,19 @@ use FS::cust_main; &untaint_argv; #what it sounds like (eww) use vars qw($opt_d $opt_v); -getopts("d:v"); +getopts("p:d:v"); my $user = shift or die &usage; adminsuidsetup $user; $FS::cust_main::Debug = 1 if $opt_v; +my %search; +$search{'payby'} = $opt_p if $opt_p; + my @cust_main = @ARGV - ? map { qsearchs('cust_main', { custnum => $_ } ) } @ARGV - : qsearch('cust_main', {} ) + ? map { qsearchs('cust_main', { custnum => $_, %search } ) } @ARGV + : qsearch('cust_main', \%search ) ; #we're at now now (and later). @@ -95,7 +98,7 @@ freeside-daily - Run daily billing and invoice collection events. =head1 SYNOPSIS - freeside-daily [ -d 'date' ] user [ custnum custnum ... ] + freeside-daily [ -d 'date' ] [ -p 'payby' ] [ -v ] user [ custnum custnum ... ] =head1 DESCRIPTION @@ -110,6 +113,10 @@ the bill and collect methods of a cust_main object. See L. -d: Pretend it's 'date'. Date is in any format Date::Parse is happy with, but be careful. + -p: Only process customers with the specified payby (CARD, CHEK, BILL, COMP, LECB) + + -v: enable debugging + user: From the mapsecrets file - see config.html from the base documentation custnum: if one or more customer numbers are specified, only bills those -- cgit v1.2.1 From 7926d92e41b592b08f15d250ac5e78f75a2a29c7 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 25 Dec 2002 06:59:09 +0000 Subject: declare $opt_p usage --- FS/bin/freeside-daily | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin/freeside-daily') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index c82dc07a0..579d071ac 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -10,7 +10,7 @@ use FS::Conf; use FS::cust_main; &untaint_argv; #what it sounds like (eww) -use vars qw($opt_d $opt_v); +use vars qw($opt_d $opt_v $opt_p); getopts("p:d:v"); my $user = shift or die &usage; -- cgit v1.2.1 From 030bef17868168b05a67d9f5866b55da1bb9439c Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 21 Apr 2003 20:53:57 +0000 Subject: on-demand vs. automatic cards & checks: added DCRD and DCHK payment types --- FS/bin/freeside-daily | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin/freeside-daily') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 579d071ac..63e621b57 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -113,7 +113,7 @@ the bill and collect methods of a cust_main object. See L. -d: Pretend it's 'date'. Date is in any format Date::Parse is happy with, but be careful. - -p: Only process customers with the specified payby (CARD, CHEK, BILL, COMP, LECB) + -p: Only process customers with the specified payby (I, I, I, I, I, I, I) -v: enable debugging -- cgit v1.2.1 From 74e6f7cb1f048778a417e0124143f6c447c9f87c Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 26 Sep 2003 13:04:26 +0000 Subject: re-setup option to re-charge setup fee --- FS/bin/freeside-daily | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'FS/bin/freeside-daily') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 63e621b57..80b8edf82 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -10,8 +10,8 @@ use FS::Conf; use FS::cust_main; &untaint_argv; #what it sounds like (eww) -use vars qw($opt_d $opt_v $opt_p); -getopts("p:d:v"); +use vars qw($opt_d $opt_v $opt_p $opt_s); +getopts("p:d:vs"); my $user = shift or die &usage; adminsuidsetup $user; @@ -42,7 +42,8 @@ foreach $cust_main ( @cust_main ) { if $error; } - my $error = $cust_main->bill( 'time' => $time ); + my $error = $cust_main->bill( 'time' => $time, + 'resetup' => $opt_s, ); warn "Error billing, custnum ". $cust_main->custnum. ": $error" if $error; $cust_main->apply_payments; @@ -98,7 +99,7 @@ freeside-daily - Run daily billing and invoice collection events. =head1 SYNOPSIS - freeside-daily [ -d 'date' ] [ -p 'payby' ] [ -v ] user [ custnum custnum ... ] + freeside-daily [ -d 'date' ] [ -p 'payby' ] [ -s ] [ -v ] user [ custnum custnum ... ] =head1 DESCRIPTION @@ -115,6 +116,8 @@ the bill and collect methods of a cust_main object. See L. -p: Only process customers with the specified payby (I, I, I, I, I, I, I) + -s: re-charge setup fees + -v: enable debugging user: From the mapsecrets file - see config.html from the base documentation -- cgit v1.2.1 From 9d7f2b5a7bd69a3f968277df8e5fb8491a66a1e5 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 2 Oct 2003 10:18:24 +0000 Subject: added -y switch to freeside-daily to specify an offset in days --- FS/bin/freeside-daily | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'FS/bin/freeside-daily') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 80b8edf82..5fb966665 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -10,8 +10,8 @@ use FS::Conf; use FS::cust_main; &untaint_argv; #what it sounds like (eww) -use vars qw($opt_d $opt_v $opt_p $opt_s); -getopts("p:d:vs"); +use vars qw($opt_d $opt_v $opt_p $opt_s $opt_y); +getopts("p:d:vsy:"); my $user = shift or die &usage; adminsuidsetup $user; @@ -28,6 +28,7 @@ my @cust_main = @ARGV #we're at now now (and later). my($time)= $opt_d ? str2time($opt_d) : $^T; +$time += $opt_y * 86400 if $opt_y; my($cust_main,%saw); foreach $cust_main ( @cust_main ) { @@ -99,7 +100,7 @@ freeside-daily - Run daily billing and invoice collection events. =head1 SYNOPSIS - freeside-daily [ -d 'date' ] [ -p 'payby' ] [ -s ] [ -v ] user [ custnum custnum ... ] + freeside-daily [ -d 'date' ] [ -y days ] [ -p 'payby' ] [ -s ] [ -v ] user [ custnum custnum ... ] =head1 DESCRIPTION @@ -114,6 +115,11 @@ the bill and collect methods of a cust_main object. See L. -d: Pretend it's 'date'. Date is in any format Date::Parse is happy with, but be careful. + -y: In addition to -d, which specifies an absolute date, the -y switch + specifies an offset, in days. For example, "-y 15" would increment the + "pretend date" 15 days from whatever was specified by the -d switch + (or now, if no -d switch was given). + -p: Only process customers with the specified payby (I, I, I, I, I, I, I) -s: re-charge setup fees -- cgit v1.2.1 From 1b15d4bbb47875129b8da15331b118a6ad6727f3 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 5 Mar 2004 05:59:16 +0000 Subject: fix -v --- FS/bin/freeside-daily | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS/bin/freeside-daily') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 5fb966665..00de2987a 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -16,7 +16,7 @@ my $user = shift or die &usage; adminsuidsetup $user; -$FS::cust_main::Debug = 1 if $opt_v; +$FS::cust_main::DEBUG = 1 if $opt_v; my %search; $search{'payby'} = $opt_p if $opt_p; -- cgit v1.2.1