+=item invoicing_list [ ITEM, ITEM, ... ]
+
+If arguements are given, sets these email addresses as invoice recipients
+(see L<FS::cust_main_invoice>). Errors are not fatal and are not reported
+(except as warnings), so use check_invoicing_list first.
+
+Returns a list of email addresses (with svcnum entries expanded).
+
+=cut
+
+sub invoicing_list {
+ my($self, @addresses) = @_;
+ if ( @addresses ) {
+ my @cust_main_invoice =
+ qsearch('cust_main_invoice', { 'custnum' => $self->custnum } );
+ foreach my $cust_main_invoice ( @cust_main_invoice ) {
+ unless ( grep { $cust_main_invoice->address eq $_ } @addresses ) {
+ $cust_main_invoice->delete;
+ }
+ }
+ @cust_main_invoice =
+ qsearch('cust_main_invoice', { 'custnum' => $self->custnum } );
+ foreach my $address ( @addresses ) {
+ unless ( grep { $address eq $_->address } @cust_main_invoice ) {
+ my $cust_main_invoice = create FS::cust_main_invoice (
+ 'custnum' => $self->custnum,
+ 'dest' => $address,
+ );
+ my $error = $cust_main_invoice->insert;
+ warn $error if $error;
+ }
+ }
+ }
+ map { $_->address }
+ qsearch('cust_main_invoice', { 'custnum' => $self->custnum } );
+}
+
+=item check_invoicing_list ITEM, ITEM
+
+Checks these arguements as valid input for the invoicing_list method. If there
+is an error, returns the error, otherwise returns false.
+
+=cut
+
+sub check_invoicing_list {
+ my($self, @addresses) = @_;
+ foreach my $address ( @addresses ) {
+ my $cust_main_invoice = create FS::cust_main_invoice (
+ 'custnum' => $self->custnum,
+ 'dest' => $address,
+ );
+ my $error = $cust_main_invoice->check;
+ return $error if $error;
+ }
+ '';
+}
+