+ # we use it about a thousand times, let's cache it
+ if ( !exists($self->{Hash}->{cust_bill}) ) {
+ my @cust_bill;
+ if ( $self->invnum && $self->invnum =~ /^\d+$/ ) {
+ # one specific invoice
+ @cust_bill = FS::cust_bill->by_key($self->invnum)
+ or die "unknown invnum '".$self->invnum."'";
+ $self->set('custnum' => $cust_bill[0]->custnum);
+ } elsif ( $self->statementnum eq 'ALL' ) {
+ # all open invoices
+ @cust_bill = $self->cust_main->open_cust_bill;
+ } else {
+ @cust_bill = qsearch('cust_bill',
+ { statementnum => $self->statementnum }
+ );
+ }
+ $self->{Hash}->{cust_bill} = \@cust_bill;
+ }
+
+ @{ $self->{Hash}->{cust_bill} }