Text body
+=item to_contact_classnum
+
+The customer contact class (or classes, as a comma-separated list) to send
+the message to. If unspecified, will be sent to any contacts that are marked
+as invoice destinations (the equivalent of specifying 'invoice').
+
=back
Returns an error message, or false for success.
my $subject = delete $param->{subject};
my $html_body = delete $param->{html_body};
my $text_body = delete $param->{text_body};
+ my $to_contact_classnum = delete $param->{to_contact_classnum};
my $error = '';
my $job = delete $param->{'job'}
%message = $msg_template->prepare(
'cust_main' => $cust_main,
'object' => $obj,
+ 'to_contact_classnum' => $to_contact_classnum,
);
- }
- else {
- my @to = $cust_main->invoicing_list_emailonly;
+
+ } else {
+ # 3.x: false laziness with msg_template.pm; on 4.x, all email notices
+ # are generated from templates and this case goes away
+ my @classes;
+ if ( $to_contact_classnum ) {
+ @classes = ref($to_contact_classnum) ? @$to_contact_classnum : split(',', $to_contact_classnum);
+ }
+ if (!@classes) {
+ @classes = ( 'invoice' );
+ }
+ my @to = $cust_main->contact_list_email(@classes);
next if !@to;
%message = (
my $maxbalance;
if ($setting eq 'Zero') {
$maxbalance = 0;
+
+ # kind of a pain to load/check all cust_bill instead of just open ones,
+ # but if for some reason payment gets applied to later bills before
+ # earlier ones, we still want to consider the later ones as allowable balance
} elsif ($setting eq 'Latest invoice charges') {
my @cust_bill = $cust_main->cust_bill();
my $cust_bill = $cust_bill[-1]; #always want the most recent one
- return unless $cust_bill;
- $maxbalance = $cust_bill->charged || 0;
+ if ($cust_bill) {
+ $maxbalance = $cust_bill->charged || 0;
+ } else {
+ $maxbalance = 0;
+ }
+ } elsif ($setting eq 'Charges not past due') {
+ my $now = time;
+ $maxbalance = 0;
+ foreach my $cust_bill ($cust_main->cust_bill()) {
+ next unless $now <= ($cust_bill->due_date || $cust_bill->_date);
+ $maxbalance += $cust_bill->charged || 0;
+ }
} elsif (length($setting)) {
warn "Unrecognized unsuspend_balance setting $setting";
return;
}
my $balance = $cust_main->balance || 0;
if ($balance <= $maxbalance) {
- # or should this be
- # my @errors = grep { ($_->get('setup')) && $_->unsuspend } $cust_main->unflagged_suspended_pkgs;
my @errors = $cust_main->unsuspend;
# side-fx with nested transactions? upstack rolls back?
warn "WARNING:Errors unsuspending customer ". $cust_main->custnum. ": ".