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 From 6e606e4f3c8a27df62bb2f229a09fccca7bd4d6b Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 30 Jun 2004 10:02:45 +0000 Subject: add option to pgp/gpg encrypt scp dumps --- FS/bin/freeside-daily | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'FS/bin/freeside-daily') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 00de2987a..99d95d5d2 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -63,7 +63,6 @@ if ( driver_name eq 'Pg' ) { } } -#local hack my $conf = new FS::Conf; my $dest = $conf->config('dump-scpdest'); if ( $dest ) { @@ -75,7 +74,18 @@ if ( $dest ) { } else { die "database dumps not yet supported for ". driver_name; } - scp("/var/tmp/$database.sql", $dest); + if ( $conf->config('dump-pgpid') ) { + eval 'use GnuPG'; + my $gpg = new GnuPG; + $gpg->encrypt( plaintext => "/var/tmp/$database.sql", + output => "/var/tmp/$database.gpg", + recipient => $conf->config('dump-pgpid'), + ); + scp("/var/tmp/$database.gpg", $dest); + unlink "/var/tmp/$database.gpg" or die $!; + } else { + scp("/var/tmp/$database.sql", $dest); + } unlink "/var/tmp/$database.sql" or die $!; } -- cgit v1.2.1 From f35e156906cfabbc39f93ee4a82d4c28f79379b2 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 24 Nov 2004 01:30:19 +0000 Subject: fix perms on automated backups --- FS/bin/freeside-daily | 2 ++ 1 file changed, 2 insertions(+) (limited to 'FS/bin/freeside-daily') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 99d95d5d2..d8d36252e 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -81,9 +81,11 @@ if ( $dest ) { output => "/var/tmp/$database.gpg", recipient => $conf->config('dump-pgpid'), ); + chmod 0600, '/var/tmp/$database.gpg'; scp("/var/tmp/$database.gpg", $dest); unlink "/var/tmp/$database.gpg" or die $!; } else { + chmod 0600, '/var/tmp/$database.sql'; scp("/var/tmp/$database.sql", $dest); } unlink "/var/tmp/$database.sql" or die $!; -- cgit v1.2.1 From 5073a0d77b624018600f7fc01c7da2fee2849c18 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 22 Dec 2004 09:53:18 +0000 Subject: just "vaccum analyze" is fine --- FS/bin/freeside-daily | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'FS/bin/freeside-daily') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index d8d36252e..ae71112dd 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -57,10 +57,8 @@ 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; - } + my $sth = dbh->prepare('vacuum analyze') or die dbh->errstr; + $sth->execute or die $sth->errstr; } my $conf = new FS::Conf; -- cgit v1.2.1 From 3cf7afe4ff9bc62d1a5c0d78aae35193251dca25 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 10 Mar 2005 09:56:07 +0000 Subject: fine. --- FS/bin/freeside-daily | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'FS/bin/freeside-daily') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index ae71112dd..75bbca7d8 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -5,7 +5,7 @@ use Fcntl qw(:flock); use Date::Parse; use Getopt::Std; use FS::UID qw(adminsuidsetup driver_name dbh datasrc); -use FS::Record qw(qsearch qsearchs); +use FS::Record qw(qsearch qsearchs dbdef); use FS::Conf; use FS::cust_main; @@ -57,8 +57,10 @@ foreach $cust_main ( @cust_main ) { if ( driver_name eq 'Pg' ) { dbh->{AutoCommit} = 1; #so we can vacuum - my $sth = dbh->prepare('vacuum analyze') or die dbh->errstr; - $sth->execute or die $sth->errstr; + foreach my $table ( dbdef->tables ) { + my $sth = dbh->prepare("VACUUM ANALYZE $table") or die dbh->errstr; + $sth->execute or die $sth->errstr; + } } my $conf = new FS::Conf; -- cgit v1.2.1 From 2358bebdb617840f9a635187a71491ed4d16f614 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 9 Jun 2005 07:13:38 +0000 Subject: significant speedup from only selected customers with outstanding packages or invoice events in the initial select, and add -a flag for agentnum --- FS/bin/freeside-daily | 61 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 9 deletions(-) (limited to 'FS/bin/freeside-daily') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 75bbca7d8..db6b97128 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -11,25 +11,66 @@ use FS::cust_main; &untaint_argv; #what it sounds like (eww) use vars qw($opt_d $opt_v $opt_p $opt_s $opt_y); -getopts("p:d:vsy:"); +getopts("p:a:d:vsy:"); 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 => $_, %search } ) } @ARGV - : qsearch('cust_main', \%search ) -; +my %search = (); +$search{'payby'} = $opt_p if $opt_p; +$search{'agentnum'} = $opt_a if $opt_a; #we're at now now (and later). my($time)= $opt_d ? str2time($opt_d) : $^T; $time += $opt_y * 86400 if $opt_y; +# select * from cust_main where +my $where_pkg = <<"END"; + 0 < ( select count(*) from cust_pkg + where cust_main.custnum = cust_pkg.custnum + and ( cancel is null or cancel = 0 ) + and ( setup is null or setup = 0 + or bill is null or bill <= $time + or ( expire is not null and expire <= $^T ) + ) + ) +END + +# or +my $where_bill_event = <<"END"; + 0 < ( select count(*) from cust_bill + where cust_main.custnum = cust_bill.custnum + and 0 < charged + - ( select sum(amount) from cust_bill_pay + where cust_bill.invnum = cust_bill_pay.invnum ) + - ( select sum(amount) from cust_credit_bill + where cust_bill.invnum = cust_credit_bill.invnum ) + and 0 < ( select count(*) from part_bill_event + where payby = cust_main.payby + and ( disabled is null or disabled = '' ) + and seconds <= $time - cust_bill._date + and 0 = ( select count(*) from cust_bill_event + where cust_bill.invnum = cust_bill_event.invnum + and part_bill_event.eventpart = cust_bill_event.eventpart + and status = 'done' + ) + + ) + ) +END + +my $extra_sql = ( scalar(%search) ? ' AND ' : ' WHERE ' ). "$where_pkg OR $where_bill_event"; + +my @cust_main; +if ( @ARGV ) { + @cust_main = map { qsearchs('cust_main', { custnum => $_, %search } ) } @ARGV +} else { + @cust_main = qsearch('cust_main', \%search, '', $extra_sql ); +} +; + my($cust_main,%saw); foreach $cust_main ( @cust_main ) { @@ -112,7 +153,7 @@ freeside-daily - Run daily billing and invoice collection events. =head1 SYNOPSIS - freeside-daily [ -d 'date' ] [ -y days ] [ -p 'payby' ] [ -s ] [ -v ] user [ custnum custnum ... ] + freeside-daily [ -d 'date' ] [ -y days ] [ -p 'payby' ] [ -a agentnum ] [ -s ] [ -v ] user [ custnum custnum ... ] =head1 DESCRIPTION @@ -134,6 +175,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) + -a: Only process customers with the specified agentnum + -s: re-charge setup fees -v: enable debugging -- cgit v1.2.1 From 7183047ba319da738cb2c80beda0a07e1e49f2cc Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 9 Jun 2005 07:19:31 +0000 Subject: declare new $opt_a --- 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 db6b97128..702d749e8 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 $opt_p $opt_s $opt_y); +use vars qw($opt_d $opt_v $opt_p $opt_a $opt_s $opt_y); getopts("p:a:d:vsy:"); my $user = shift or die &usage; -- cgit v1.2.1 From ff0258d05484670831222da23427606f719cc009 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 8 Jul 2005 23:06:31 +0000 Subject: fix bug with new efficient customer-finding code. sql isn't perl, null != 0 --- FS/bin/freeside-daily | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'FS/bin/freeside-daily') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 702d749e8..589af8998 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -43,10 +43,16 @@ my $where_bill_event = <<"END"; 0 < ( select count(*) from cust_bill where cust_main.custnum = cust_bill.custnum and 0 < charged - - ( select sum(amount) from cust_bill_pay - where cust_bill.invnum = cust_bill_pay.invnum ) - - ( select sum(amount) from cust_credit_bill - where cust_bill.invnum = cust_credit_bill.invnum ) + - coalesce( + ( select sum(amount) from cust_bill_pay + where cust_bill.invnum = cust_bill_pay.invnum ) + ,0 + ) + - coalesce( + ( select sum(amount) from cust_credit_bill + where cust_bill.invnum = cust_credit_bill.invnum ) + ,0 + ) and 0 < ( select count(*) from part_bill_event where payby = cust_main.payby and ( disabled is null or disabled = '' ) @@ -61,7 +67,7 @@ my $where_bill_event = <<"END"; ) END -my $extra_sql = ( scalar(%search) ? ' AND ' : ' WHERE ' ). "$where_pkg OR $where_bill_event"; +my $extra_sql = ( scalar(%search) ? ' AND ' : ' WHERE ' ). "( $where_pkg OR $where_bill_event )"; my @cust_main; if ( @ARGV ) { -- cgit v1.2.1 From 0186436eb38e70da0a015e49dab67cec5f1a3467 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 21 Sep 2005 12:49:51 +0000 Subject: add prepaid support which sets RADIUS Expiration attribute, update customer view package UI --- FS/bin/freeside-daily | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'FS/bin/freeside-daily') diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index 589af8998..603da12b8 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -89,6 +89,19 @@ foreach $cust_main ( @cust_main ) { $cust_main->custnum. ": $error" if $error; } + # $^T not $time because -d is for pre-printing invoices + foreach my $cust_pkg ( + grep { $_->part_pkg->is_prepaid + && $_->bill && $_->bill < $^T && ! $_->susp + } + $cust_main->ncancelled_pkgs + ) { + my $error = $cust_pkg->suspend; + warn "Error suspending package ". $cust_pkg->pkgnum. + " for custnum ". $cust_main->custnum. + ": $error" + if $error; + } my $error = $cust_main->bill( 'time' => $time, 'resetup' => $opt_s, ); -- cgit v1.2.1