From 0b1f40cc85eee025f01dd14e155cc65837e3f9e5 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 11 Aug 1999 20:41:28 +0000 Subject: new bill script, --- FS/bin/freeside-bill | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100755 FS/bin/freeside-bill (limited to 'FS/bin/freeside-bill') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill new file mode 100755 index 000000000..8f2c32fb2 --- /dev/null +++ b/FS/bin/freeside-bill @@ -0,0 +1,122 @@ +#!/usr/bin/perl -Tw + +use strict; +use Fcntl qw(:flock); +use Date::Parse; +use Getopt::Std; +use FS::UID qw(adminsuidsetup swapuid); +use FS::Record qw(qsearch qsearchs); +use FS::cust_main; + +&untaint_argv; #what it sounds like (eww) +use vars qw($opt_a $opt_c $opt_i $opt_d); +getopts("acid:"); +my $user = shift or die &usage; + +adminsuidsetup $user; + +my %bill_only = map { $_ => 1 } ( + @ARGV ? @ARGV : ( map $_->custnum, qsearch('cust_main', {} ) ) +); + +#we're at now now (and later). +my($time)= $main::opt_d ? str2time($main::opt_d) : $^T; + +# find packages w/ bill < time && cancel != '', and create corresponding +# customer objects + +my($cust_main,%saw); +foreach $cust_main ( + map { + if ( + ( $main::opt_a || ( ( $_->getfield('bill') || 0 ) <= $time ) ) + && $bill_only{ $_->custnum } + && !$saw{ $_->custnum }++ + ) { + qsearchs('cust_main',{'custnum'=> $_->custnum } ); + } else { + (); + } + } ( qsearch('cust_pkg', { 'cancel' => '' }), + qsearch('cust_pkg', { 'cancel' => 0 }), + ) +) { + + # and bill them + + print "Billing customer #" . $cust_main->getfield('custnum') . "\n"; + next; + + my($error); + + $error=$cust_main->bill('time'=>$time); + warn "Error billing, customer #" . $cust_main->getfield('custnum') . + ":" . $error if $error; + + if ($main::opt_c) { + $error=$cust_main->collect('invoice_time'=>$time, + 'batch_card' => $main::opt_i ? 'no' : 'yes', + ); + warn "Error collecting customer #" . $cust_main->getfield('custnum') . + ":" . $error if $error; + + #sleep 1; + + } + +} + +# subroutines + +sub untaint_argv { + foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV + $ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\""; + $ARGV[$_]=$1; + } +} + +sub usage { + die "Usage:\n\n bill [ -c [ i ] ] [ -d 'date' ] [ -b ] user\n"; +} + +=head1 NAME + +freeside-bill - Command line (crontab, script) interface to customer billing. + +=head1 SYNOPSIS + + freeside-bill [ -c [ -a ] [ -i ] ] [ -d 'date' ] user [ custnum custnum ... ] + +=head1 DESCRIPTION + +Bills customers. Searches for customers who are due for billing and calls +the bill and collect methods of a cust_main object. See L. + + -c: Turn on collecting (you probably want this). + + -a: Call collect even if there isn't a new invoice (probably a bad idea for + daily use) + + -i: real-time billing (as opposed to batch billing). only relevant + for credit cards. + + -d: Pretent 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 VERSION + +$Id: freeside-bill,v 1.1 1999-08-11 20:41:27 ivan Exp $ + +=head1 BUGS + +=head1 SEE ALSO + +L, config.html from the base documentation + +=cut + -- cgit v1.2.1 From 9d1c4be2e9cc349481101bbc11a9acdc1b7c235a Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 11 Aug 1999 20:51:54 +0000 Subject: *** empty log message *** --- FS/bin/freeside-bill | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'FS/bin/freeside-bill') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index 8f2c32fb2..a251df4d5 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -45,7 +45,6 @@ foreach $cust_main ( # and bill them print "Billing customer #" . $cust_main->getfield('custnum') . "\n"; - next; my($error); @@ -110,7 +109,7 @@ customers. Otherwise, bills all customers. =head1 VERSION -$Id: freeside-bill,v 1.1 1999-08-11 20:41:27 ivan Exp $ +$Id: freeside-bill,v 1.2 1999-08-11 20:51:54 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From 7c7bc66bd24874e7ccd4fd3445f1da7f88e9679d Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 4 Oct 1999 08:23:26 +0000 Subject: silly 'use of unitialized value' errors --- FS/bin/freeside-bill | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'FS/bin/freeside-bill') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index a251df4d5..417df767b 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -28,6 +28,9 @@ my($time)= $main::opt_d ? str2time($main::opt_d) : $^T; my($cust_main,%saw); foreach $cust_main ( map { + unless ( exists $saw{ $_->custnum } && defined $saw{ $_->custnum} ) { + $saw{ $_->custnum } = 0; # to avoid 'use of uninitialized value' errors + } if ( ( $main::opt_a || ( ( $_->getfield('bill') || 0 ) <= $time ) ) && $bill_only{ $_->custnum } @@ -109,7 +112,7 @@ customers. Otherwise, bills all customers. =head1 VERSION -$Id: freeside-bill,v 1.2 1999-08-11 20:51:54 ivan Exp $ +$Id: freeside-bill,v 1.3 1999-10-04 08:23:26 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From 44261274cf5d0bf453005c50d43050143cd18774 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 3 Apr 2000 02:32:57 +0000 Subject: accept anything in ARGV for -d Date::Parse --- FS/bin/freeside-bill | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'FS/bin/freeside-bill') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index 417df767b..208f92071 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -72,7 +72,9 @@ foreach $cust_main ( sub untaint_argv { foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV - $ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\""; + #$ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\""; + # Date::Parse + $ARGV[$_] =~ /^(.*)$/ || die "Illegal arguement \"$ARGV[$_]\""; $ARGV[$_]=$1; } } @@ -112,7 +114,7 @@ customers. Otherwise, bills all customers. =head1 VERSION -$Id: freeside-bill,v 1.3 1999-10-04 08:23:26 ivan Exp $ +$Id: freeside-bill,v 1.4 2000-04-03 02:32:57 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From 27649e60bc8cf16ba2f76731a4ebab471df3801c Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 22 Jun 2000 10:52:37 +0000 Subject: tyop --- FS/bin/freeside-bill | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/bin/freeside-bill') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index 208f92071..680d29da5 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -104,7 +104,7 @@ the bill and collect methods of a cust_main object. See L. -i: real-time billing (as opposed to batch billing). only relevant for credit cards. - -d: Pretent it's 'date'. Date is in any format Date::Parse is happy with, + -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 @@ -114,7 +114,7 @@ customers. Otherwise, bills all customers. =head1 VERSION -$Id: freeside-bill,v 1.4 2000-04-03 02:32:57 ivan Exp $ +$Id: freeside-bill,v 1.5 2000-06-22 10:52:37 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From d2c5fa2eb293628ae281120322eb0e70d6a92a7d Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 24 Jun 2000 00:28:30 +0000 Subject: don't use Date::Manip; report correct program name in freeside-bill usage msg --- FS/bin/freeside-bill | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/bin/freeside-bill') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index 680d29da5..42991c4f8 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -80,7 +80,7 @@ sub untaint_argv { } sub usage { - die "Usage:\n\n bill [ -c [ i ] ] [ -d 'date' ] [ -b ] user\n"; + die "Usage:\n\n freeside-bill [ -c [ i ] ] [ -d 'date' ] [ -b ] user\n"; } =head1 NAME @@ -114,7 +114,7 @@ customers. Otherwise, bills all customers. =head1 VERSION -$Id: freeside-bill,v 1.5 2000-06-22 10:52:37 ivan Exp $ +$Id: freeside-bill,v 1.6 2000-06-24 00:28:30 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From 6ef34dda51afba96d8dc6c4dd72427c3d4003945 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 21 Aug 2001 09:34:13 +0000 Subject: no more &swapuid --- FS/bin/freeside-bill | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/bin/freeside-bill') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index 42991c4f8..3462fa149 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -4,7 +4,7 @@ use strict; use Fcntl qw(:flock); use Date::Parse; use Getopt::Std; -use FS::UID qw(adminsuidsetup swapuid); +use FS::UID qw(adminsuidsetup); use FS::Record qw(qsearch qsearchs); use FS::cust_main; @@ -114,7 +114,7 @@ customers. Otherwise, bills all customers. =head1 VERSION -$Id: freeside-bill,v 1.6 2000-06-24 00:28:30 ivan Exp $ +$Id: freeside-bill,v 1.7 2001-08-21 09:34:13 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From fbcb45dfe5a1bce7981fe4527176b9fdf2ec54b7 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 3 Sep 2001 22:07:39 +0000 Subject: fix more bugs --- FS/bin/freeside-bill | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'FS/bin/freeside-bill') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index 3462fa149..1dce9a19b 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -55,15 +55,19 @@ foreach $cust_main ( warn "Error billing, customer #" . $cust_main->getfield('custnum') . ":" . $error if $error; + if ($main::opt_p) { + $cust_main->apply_payments; + $error=$cust_main->apply_credits; + } + if ($main::opt_c) { $error=$cust_main->collect('invoice_time'=>$time, 'batch_card' => $main::opt_i ? 'no' : 'yes', ); - warn "Error collecting customer #" . $cust_main->getfield('custnum') . - ":" . $error if $error; - - #sleep 1; + warn "Error collecting from customer #" . $cust_main->gcustnum. ":$error" + if $error; + #sleep 1; } } @@ -89,7 +93,7 @@ freeside-bill - Command line (crontab, script) interface to customer billing. =head1 SYNOPSIS - freeside-bill [ -c [ -a ] [ -i ] ] [ -d 'date' ] user [ custnum custnum ... ] + freeside-bill [ -c [ -p ] [ -a ] [ -i ] ] [ -d 'date' ] user [ custnum custnum ... ] =head1 DESCRIPTION @@ -98,6 +102,9 @@ the bill and collect methods of a cust_main object. See L. -c: Turn on collecting (you probably want this). + -p: Apply unapplied payments and credits before collecting (you probably want + this too) + -a: Call collect even if there isn't a new invoice (probably a bad idea for daily use) @@ -114,7 +121,7 @@ customers. Otherwise, bills all customers. =head1 VERSION -$Id: freeside-bill,v 1.7 2001-08-21 09:34:13 ivan Exp $ +$Id: freeside-bill,v 1.8 2001-09-03 22:07:39 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From f5266a4d07d116efd732f433d0f4f3a47b143a7d Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 11 Sep 2001 00:08:18 +0000 Subject: faster (cached) fuzzy searches prelim. job queues! fixed part_svc editing --- FS/bin/freeside-bill | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'FS/bin/freeside-bill') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index 1dce9a19b..82b3321e1 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -1,3 +1,5 @@ +#!/usr/bin/perl -w +# don't take any world-facing input #!/usr/bin/perl -Tw use strict; @@ -121,7 +123,7 @@ customers. Otherwise, bills all customers. =head1 VERSION -$Id: freeside-bill,v 1.8 2001-09-03 22:07:39 ivan Exp $ +$Id: freeside-bill,v 1.9 2001-09-11 00:08:18 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From e4c4a600a9f167f84c1a0663f73797ed18934e92 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 5 Nov 2001 14:04:56 +0000 Subject: fixup getopt --- FS/bin/freeside-bill | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'FS/bin/freeside-bill') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index 82b3321e1..7898936c5 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -11,8 +11,8 @@ use FS::Record qw(qsearch qsearchs); use FS::cust_main; &untaint_argv; #what it sounds like (eww) -use vars qw($opt_a $opt_c $opt_i $opt_d); -getopts("acid:"); +use vars qw($opt_a $opt_c $opt_i $opt_d $opt_p); +getopts("acid:p"); my $user = shift or die &usage; adminsuidsetup $user; @@ -22,7 +22,7 @@ my %bill_only = map { $_ => 1 } ( ); #we're at now now (and later). -my($time)= $main::opt_d ? str2time($main::opt_d) : $^T; +my($time)= $opt_d ? str2time($opt_d) : $^T; # find packages w/ bill < time && cancel != '', and create corresponding # customer objects @@ -34,7 +34,7 @@ foreach $cust_main ( $saw{ $_->custnum } = 0; # to avoid 'use of uninitialized value' errors } if ( - ( $main::opt_a || ( ( $_->getfield('bill') || 0 ) <= $time ) ) + ( $opt_a || ( ( $_->getfield('bill') || 0 ) <= $time ) ) && $bill_only{ $_->custnum } && !$saw{ $_->custnum }++ ) { @@ -57,14 +57,14 @@ foreach $cust_main ( warn "Error billing, customer #" . $cust_main->getfield('custnum') . ":" . $error if $error; - if ($main::opt_p) { + if ($opt_p) { $cust_main->apply_payments; $error=$cust_main->apply_credits; } - if ($main::opt_c) { + if ($opt_c) { $error=$cust_main->collect('invoice_time'=>$time, - 'batch_card' => $main::opt_i ? 'no' : 'yes', + 'batch_card' => $opt_i ? 'no' : 'yes', ); warn "Error collecting from customer #" . $cust_main->gcustnum. ":$error" if $error; @@ -123,7 +123,7 @@ customers. Otherwise, bills all customers. =head1 VERSION -$Id: freeside-bill,v 1.9 2001-09-11 00:08:18 ivan Exp $ +$Id: freeside-bill,v 1.10 2001-11-05 14:04:56 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From 5e25b996982d42eb2587ec54db0d5b39508aa730 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 28 Dec 2001 14:40:35 +0000 Subject: add more options to freeside-overdue add charge method to FS::cust_main one-off packages default to disabled billing payname defaults to first and last, not "Accounts Payable" --- FS/bin/freeside-bill | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'FS/bin/freeside-bill') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index 7898936c5..49ec43c82 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -59,14 +59,14 @@ foreach $cust_main ( if ($opt_p) { $cust_main->apply_payments; - $error=$cust_main->apply_credits; + $cust_main->apply_credits; } if ($opt_c) { $error=$cust_main->collect('invoice_time'=>$time, 'batch_card' => $opt_i ? 'no' : 'yes', ); - warn "Error collecting from customer #" . $cust_main->gcustnum. ":$error" + warn "Error collecting from customer #" . $cust_main->custnum. ":$error" if $error; #sleep 1; @@ -123,7 +123,7 @@ customers. Otherwise, bills all customers. =head1 VERSION -$Id: freeside-bill,v 1.10 2001-11-05 14:04:56 ivan Exp $ +$Id: freeside-bill,v 1.11 2001-12-28 14:40:35 ivan Exp $ =head1 BUGS -- cgit v1.2.1 From 298b8d9a262265fe7106da1ff552ce6778237034 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 10 Feb 2002 01:48:00 +0000 Subject: remove -i option from freeside-bill (obsoleted by invoice events) --- FS/bin/freeside-bill | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'FS/bin/freeside-bill') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index 49ec43c82..6ef344a50 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -11,8 +11,8 @@ use FS::Record qw(qsearch qsearchs); use FS::cust_main; &untaint_argv; #what it sounds like (eww) -use vars qw($opt_a $opt_c $opt_i $opt_d $opt_p); -getopts("acid:p"); +use vars qw($opt_a $opt_c $opt_d $opt_p); +getopts("acd:p"); my $user = shift or die &usage; adminsuidsetup $user; @@ -63,9 +63,7 @@ foreach $cust_main ( } if ($opt_c) { - $error=$cust_main->collect('invoice_time'=>$time, - 'batch_card' => $opt_i ? 'no' : 'yes', - ); + $error=$cust_main->collect( 'invoice_time' => $time); warn "Error collecting from customer #" . $cust_main->custnum. ":$error" if $error; @@ -86,7 +84,7 @@ sub untaint_argv { } sub usage { - die "Usage:\n\n freeside-bill [ -c [ i ] ] [ -d 'date' ] [ -b ] user\n"; + die "Usage:\n\n freeside-bill [ -c [ -p ] ] [ -d 'date' ] user [ custnum custnum ... ]\n"; } =head1 NAME @@ -95,7 +93,7 @@ freeside-bill - Command line (crontab, script) interface to customer billing. =head1 SYNOPSIS - freeside-bill [ -c [ -p ] [ -a ] [ -i ] ] [ -d 'date' ] user [ custnum custnum ... ] + freeside-bill [ -c [ -p ] [ -a ] ] [ -d 'date' ] user [ custnum custnum ... ] =head1 DESCRIPTION @@ -110,9 +108,6 @@ the bill and collect methods of a cust_main object. See L. -a: Call collect even if there isn't a new invoice (probably a bad idea for daily use) - -i: real-time billing (as opposed to batch billing). only relevant - for credit cards. - -d: Pretend it's 'date'. Date is in any format Date::Parse is happy with, but be careful. @@ -123,7 +118,7 @@ customers. Otherwise, bills all customers. =head1 VERSION -$Id: freeside-bill,v 1.11 2001-12-28 14:40:35 ivan Exp $ +$Id: freeside-bill,v 1.12 2002-02-10 01:48:00 ivan Exp $ =head1 BUGS -- cgit v1.2.1 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-bill | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'FS/bin/freeside-bill') diff --git a/FS/bin/freeside-bill b/FS/bin/freeside-bill index 6ef344a50..49ad4a768 100755 --- a/FS/bin/freeside-bill +++ b/FS/bin/freeside-bill @@ -97,6 +97,8 @@ freeside-bill - Command line (crontab, script) interface to customer billing. =head1 DESCRIPTION +This script is deprecated in 1.4.0. You should use freeside-daily instead. + Bills customers. Searches for customers who are due for billing and calls the bill and collect methods of a cust_main object. See L. @@ -116,15 +118,11 @@ 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 VERSION - -$Id: freeside-bill,v 1.12 2002-02-10 01:48:00 ivan Exp $ - =head1 BUGS =head1 SEE ALSO -L, config.html from the base documentation +L, L, config.html from the base documentation =cut -- cgit v1.2.1