fix A/R report
[freeside.git] / httemplate / elements / select-cust_location.html
1 <SELECT NAME     = "locationnum"
2         ID       = "locationnum"
3 %     if ( $opt{onchange} ) {
4         onchange = "<% $opt{onchange} %>"
5 %     }
6     >
7
8 % #false laziness w/select-table.html
9 % my @pre_options  = $opt{pre_options}  ? @{ $opt{pre_options} } : ();
10 % while ( @pre_options ) { 
11 %   my $pre_opt   = shift(@pre_options);
12 %   my $pre_label = shift(@pre_options);
13 %   my $selected = #$opt{'all_selected'}
14 %                  # || ( ref($locationnum) && $locationnum->{$pre_opt} )
15 %                  # ||
16 %                       ( $locationnum eq $pre_opt );
17     <OPTION VALUE="<% $pre_opt %>"
18             <% $selected ? 'SELECTED' : '' %>
19     ><% $pre_label %>
20 % } 
21
22 % if ( $cust_main ) {
23 %   my $selected = ( $locationnum == $cust_main->ship_locationnum );
24     <OPTION VALUE="<% $cust_main->ship_locationnum %>"
25             <% $selected ? 'SELECTED' : '' %>
26     ><% $opt{'empty_label'} || '(default service address)' |h %>
27 % }
28
29 % if ( $opt{'is_optional'} ) {
30   <OPTION VALUE="-2" <% $locationnum == -2 ? 'SELECTED' : ''%>><% $opt{'optional_label'} || '(not required)' |h %>
31 % }
32
33 % foreach my $loc ( @{ $opt{cust_location} } ) {
34 %   # don't show the ship_location redundantly
35 %   next if $cust_main && $cust_main->ship_locationnum == $loc->locationnum;
36     <OPTION VALUE="<% $loc->locationnum %>"
37             <% $locationnum == $loc->locationnum ? 'SELECTED' : '' %>
38     ><% $loc->line( cust_main      => $cust_main,
39                     countrydefault => $countrydefault,
40                   )
41      |h %>
42 % }
43
44 % if ( $addnew ) {
45     <OPTION VALUE="-1"
46             <% $locationnum == -1 ? 'SELECTED' : '' %>
47     >Add new location
48 % }
49
50 </SELECT>
51 <%init>
52
53 my $conf = new FS::Conf;
54 my $countrydefault = $conf->config('countrydefault') || 'US';
55
56 my %opt = @_;
57 my $cust_main     = $opt{'cust_main'};
58 my $locationnum   = $opt{'curr_value'};
59
60 $opt{'cust_location'} ||= [ $cust_main ? $cust_main->cust_location : () ];
61
62 my $addnew = exists($opt{addnew}) ? $opt{addnew}
63                                   : $cust_main ? 1 : ( $locationnum>0 ? 0 : 1 );
64
65 </%init>