From 725f4954f7d4efaf7cd3fd5e402a5dacd5d185b9 Mon Sep 17 00:00:00 2001 From: jeff Date: Fri, 17 Jul 2009 01:44:24 +0000 Subject: [PATCH] bill usage when cancelling package --- FS/FS/Conf.pm | 7 ++++++ FS/FS/cust_main.pm | 38 +++++++++++++++++++++++++---- FS/FS/cust_pkg.pm | 17 +++++++++++++ FS/FS/part_pkg/voip_cdr.pm | 59 +++++++++++++++++++--------------------------- 4 files changed, 81 insertions(+), 40 deletions(-) diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index eb046ee42..1d937b781 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -1494,6 +1494,13 @@ worry that config_items is freeside-specific and icky. }, { + 'key' => 'bill_usage_on_cancel', + 'section' => 'billing', + 'description' => 'Enable automatic generation of an invoice for usage when a package is cancelled. Not all packages can do this. Usage data must already be available.', + 'type' => 'checkbox', + }, + + { 'key' => 'require_cardname', 'section' => 'billing', 'description' => 'Require an "Exact name on card" to be entered explicitly; don\'t default to using the first and last name.', diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 286d3332a..1f063d950 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -2201,12 +2201,16 @@ Available options are: =item ban - can be set true to ban this customer's credit card or ACH information, if present. +=item nobill - can be set true to skip billing if it might otherwise be done. + =back Always returns a list: an empty list on success or a list of errors. =cut +# nb that dates are not specified as valid options to this method + sub cancel { my( $self, %opt ) = @_; @@ -2232,6 +2236,13 @@ sub cancel { my @pkgs = $self->ncancelled_pkgs; + if ( !$opt{nobill} && $conf->exists('bill_usage_on_cancel') ) { + $opt{nobill} = 1; + my $error = $self->bill( pkg_list => [ @pkgs ], cancel => 1 ); + warn "Error billing during cancel, custnum ". $self->custnum. ": $error" + if $error; + } + warn "$me cancelling ". scalar($self->ncancelled_pkgs). "/". scalar(@pkgs). " packages for customer ". $self->custnum. "\n" if $DEBUG; @@ -2441,6 +2452,13 @@ An array ref of specific packages (objects) to attempt billing, instead trying a Used in conjunction with the I