1 <% encode_json(\@return) %>\
4 my $curuser = $FS::CurrentUser::CurrentUser;
5 die 'access denied' unless $curuser->access_right('View invoices');
7 my $date_format = FS::Conf->new->config('date_format') || '%m/%d/%Y';
8 if ( $cgi->param('sub') eq 'custnum_search_open' ) {
9 my $custnum = $cgi->param('arg');
10 if ( $custnum =~ /^(\d+)$/ ) {
11 #warn "searching invoices for $custnum\n";
12 my $cust_main = FS::cust_main->by_key($custnum);
13 if ( $curuser->agentnums_href->{ $cust_main->agentnum } ) {
14 my @open_bills = $cust_main->open_cust_bill;
18 foreach my $cust_bill (@open_bills) {
19 my $invnum = $cust_bill->invnum;
20 my $owed = $cust_bill->owed;
21 my $date = time2str($date_format, $cust_bill->_date);
22 $invnum_len = length($invnum) if length($invnum) > $invnum_len;
23 $owed_len = length($owed) if length($owed) > $owed_len;
24 $date_len = length($date) if length($date) > $date_len;
26 push @return, { $cust_bill->hash,
30 my $format = '%' . $invnum_len . 'd - %' . $date_len . 's - '.
31 (FS::Conf->new->config('money_char') || '$') .
32 '%' . $owed_len . '.2f';
34 $_->{label} = sprintf($format, $_->{invnum}, $_->{date}, $_->{owed});