Optimize "Customer has a referring customer" condition, RT#74452
[freeside.git] / httemplate / elements / select-cust_phone.html
1 <SELECT NAME="<% $opt{'field_name'} %>" ID="<% $opt{'field_name'} %>">
2
3      <OPTION VALUE="" selected="selected">Select a phone number
4
5 % foreach $p (@$phone_types) {
6         <OPTION VALUE="<% $phones_formatted{$p} %>"><% $p |h%> (<% $cust_phones->$p |h %>)              
7 %}
8
9 </SELECT>
10
11 <%init>
12
13 my %opt = @_;
14 my $cust_num     = $opt{'cust_num'};
15 my $phone_types  = $opt{'phone_types'};
16 my $format        = $opt{'format'};
17
18 my $cust_phones = qsearchs('cust_main', { 'custnum' => $cust_num })
19   or die 'unknown custnum' . $cust_num;
20
21 my %phones_formatted = map {
22         $_ => format_phone_number($cust_phones->$_, $format)
23 } @$phone_types;
24
25 sub format_phone_number {
26         my ($n, $f) = @_;
27         if ($f eq 'xxxxxxxxxx') { $n =~ s/-//g; }       
28         return $n;
29 }
30
31 </%init>