<%doc> Example: include( '/elements/customer-table.html', ### # required ### #listrefs... 'header' => [ '#', 'Item' ], 'fields' => [ 'column', sub { my ($row,$param) = @_; $param->{"column$row"}; }, ], ### # optional ### 'name_singular' => 'customer', #label 'custnum_update_callback' => 'name_of_js_callback' #passed a rownum #listrefs 'types' => ['immutable', ''], # immutable or ''/text 'align' => [ 'c', 'l', 'r', '' ], 'size' => [], # sizes ignored for immutable 'color' => [], 'footer' => ['string', '_TOTAL'], # strings or the special #value _TOTAL 'footer_align' => [ 'c', 'l', 'r', '' ], 'param' => { column0 => 1 }, # preset column of row 0 to 1 ) % foreach my $header ( @{$opt{header}} ) { % } % my $row = 0; % for ( $row = 0; exists($param->{"custnum$row"}); $row++ ) { % my $col = 0; % foreach my $field ( @{$opt{fields}} ) { % my $value; % if ( ref($field) eq 'CODE' ) { % $value = &{$field}($row,$param); % } else { % $value = $param->{"$field$row"}; % } % my $name = (ref($field) eq 'CODE') ? "column${col}_$row" : "$field$row"; % my $align = $align{ $opt{align}->[$col] || 'l' }; % my $size = $sizes->[$col] || 10; % my $color = $opt{color}->[$col]; % my $font = $color ? qq() : ''; % my $onchange = ''; % if ( $opt{footer}->[$col] eq '_TOTAL' ) { % $total[$col] += $value; % $onchange = $opt{prefix}. "calc_total$col();"; % $onchange = qq(onchange="$onchange" onkeyup="$onchange"); % } % $col++; % } % } % my $col = 0; % foreach my $footer ( @{$opt{footer}} ) { % my $align = $align{ $opt{'footer_align'}->[$col] || 'c' }; % if ($footer eq '_TOTAL' ) { % my $id = $opt{'fields'}->[$col]; % $id = ref($id) ? "column${col}_TOTAL" : "${id}_TOTAL"; % } else { % } % $col++; % }
Inv # Cust # Status Customer Balance<% $header %>
" rownum = "<% $row %>" > " rownum = "<% $row %>" > " rownum="<% $row %>"> % if (! $types->[$col] || $types->[$col] eq 'text') { > % } elsif ($types->[$col] eq 'immutable') { <% $font %><% $value %><% $font ? '' : '' %> % } else { Cannot represent unknown type: <% $types->[$col] %> % }  
Total <% $row ? $row-1 : 0 %> <% PL($opt{name_singular} || 'customer', ( $row ? $row-1 : 0 ) ) %>  <% sprintf('%.2f', $total[$col] ) %><% $footer %>
<% include('/elements/xmlhttp.html', 'url' => $p. 'misc/xmlhttp-cust_main-search.cgi', 'subs' => [qw( custnum_search smart_search invnum_search )], ) %> <%init> my(%opt) = @_; my $conf = new FS::Conf; $opt{prefix} = '' unless defined $opt{prefix}; $opt{prefix} .= '_' if $opt{prefix}; my $types = $opt{'types'} ? [ @{$opt{'types'}} ] : []; my $sizes = $opt{'size'} ? [ @{$opt{'size'}} ] : []; my $param = $opt{param}; $param = $cgi->Vars if $cgi->param('error'); $opt{$_} ||= [] foreach qw(align color footer footer_align); my @total = map 0, @{$opt{footer}}; my %align = ( 'l' => 'left', 'r' => 'right', 'c' => 'center', ); my $money_char = $conf->config('money_char') || '$';