Add mobile number to ticketing view, RT#73861
[freeside.git] / FS / FS / UI / Web / small_custview.pm
1 package FS::UI::Web::small_custview;
2
3 use strict;
4 use vars qw(@EXPORT_OK @ISA);
5 use Exporter;
6 use HTML::Entities;
7 use FS::Msgcat;
8 use FS::Record qw(qsearchs);
9 use FS::cust_main;
10
11 @ISA = qw(Exporter);
12 @EXPORT_OK = qw( small_custview );
13
14 =head1 NAME
15
16 FS::UI::Web::small_custview
17
18 =head1 SYNOPSIS
19
20   use FS::UI::Web::small_custview qw( small_custview );
21   
22   #new-style
23   $html = small_custview(
24     { 'cust_main'      => $cust_main, #or 'custnum' => $custnum,
25       'countrydefault' => 'US',
26       'nobalance'      => 1,
27       'url'            => 'http://freeside.machine/freeside/view/cust_main.cgi',
28       'nopkg'          => 1,
29     }
30   );
31
32   #old-style (deprecated)
33   $html = small_custview( $cust_main, $countrydefault, $nobalance, $url );
34
35 =head1 DESCRIPTION
36
37 A subroutine for displaying customer information.
38
39 =head1 SUBROUTINES
40
41 =over 4
42
43 =item small_custview HASHREF
44
45 New-style interface.  Keys are:
46
47 =over 4
48
49 =item cust_main
50
51 Customer (as a FS::cust_main object)
52
53 =item custnum
54
55 Customer number (if cust_main is not provided).
56
57 =item countrydefault
58
59 =item nobalance
60
61 =item url
62
63 =back
64
65 =item small_custview CUSTNUM || CUST_MAIN_OBJECT, COUNTRYDEFAULT, NOBALANCE_FLAG, URL
66
67 Old-style (deprecated) interface.
68
69 =cut
70
71 sub small_custview {
72   my( $cust_main, $countrydefault, $nobalance, $url, $nopkg );
73   if ( ref($_[0]) eq 'HASH' ) {
74     my $opt = shift;
75     $cust_main =  $opt->{cust_main}
76                || qsearchs('cust_main', { 'custnum' => $opt->{custnum} } );
77     $countrydefault = $opt->{countrydefault} || 'US';
78     $nobalance = $opt->{nobalance};
79     $url = $opt->{url};
80     $nopkg = $opt->{nopkg};
81   } else {
82     my $arg = shift;
83     $countrydefault = shift || 'US';
84     $nobalance = shift;
85     $url = shift;
86     $nopkg = 0;
87
88     $cust_main = ref($arg) ? $arg
89                            : qsearchs('cust_main', { 'custnum' => $arg } )
90       or die "unknown custnum $arg";
91   }
92
93   my $html = '<DIV ID="fs_small_custview" CLASS="small_custview">';
94   
95   $html = qq!<A HREF="$url?! . $cust_main->custnum . '">'
96     if $url;
97
98   if ( $FS::CurrentUser::CurrentUser->num_agents ) {
99     $html .= encode_entities($cust_main->agent->agent). ' ';
100   }
101
102   $html .= 'Customer #<B>'. $cust_main->display_custnum.
103            '</B>: <B>'. encode_entities($cust_main->name). '</B></A>'.
104            ' - <B><FONT COLOR="#'. $cust_main->statuscolor. '">'.
105            $cust_main->status_label. '</FONT></B>';
106
107   $html .= ' (Balance: <B>$'. $cust_main->balance. '</B>)'
108     unless $nobalance;
109
110   my @part_tag = $cust_main->part_tag;
111   if ( @part_tag ) {
112     $html .= '<TABLE>';
113     foreach my $part_tag ( @part_tag ) {
114       $html .= '<TR><TD>'.
115                '<FONT '. ( length($part_tag->tagcolor)
116                            ? 'STYLE="background-color:#'.$part_tag->tagcolor.'"'
117                            : ''
118                          ).
119                '>'.
120                  encode_entities($part_tag->tagname.': '. $part_tag->tagdesc).
121                '</FONT>'.
122                '</TD></TR>';
123     }
124     $html .= '</TABLE>';
125   }
126
127   $html .=
128     ntable('#e8e8e8'). '<TR><TD VALIGN="top">'. ntable("#cccccc",2).
129     '<TR><TD ALIGN="right" VALIGN="top">Billing<BR>Address</TD><TD BGCOLOR="#ffffff">';
130
131   if ( $cust_main->bill_locationnum ) {
132
133     $html .= encode_entities($cust_main->address1). '<BR>';
134     $html .= encode_entities($cust_main->address2). '<BR>'
135       if $cust_main->address2;
136     $html .= encode_entities($cust_main->city) . ', ' if $cust_main->city;
137     $html .= encode_entities($cust_main->state). '  '.
138              encode_entities($cust_main->zip). '<BR>';
139     $html .= encode_entities($cust_main->country). '<BR>'
140       if $cust_main->country && $cust_main->country ne $countrydefault;
141
142   }
143
144   $html .= '</TD></TR><TR><TD></TD><TD BGCOLOR="#ffffff">';
145
146   my $num_numbers = 0;
147   $num_numbers++ foreach grep $cust_main->$_(), qw( daytime night mobile );
148   if ( $num_numbers > 1 ) {
149     $html .= ucfirst( FS::Msgcat::_gettext('daytime') ).
150              ' '. $cust_main->daytime. '<BR>'
151       if $cust_main->daytime;
152     $html .= ucfirst( FS::Msgcat::_gettext('night') ).
153              ' '. $cust_main->night. '<BR>'
154       if $cust_main->night;
155     $html .= ucfirst( FS::Msgcat::_gettext('mobile') ).
156              ' '. $cust_main->mobile. '<BR>'
157       if $cust_main->night;
158   } elsif ( $num_numbers ) { # == 1 ) {
159     $html .= ( $cust_main->daytime || $cust_main->night || $cust_main->mobile ).
160              '<BR>';
161   }
162   if ( $cust_main->fax ) {
163     $html .= 'Fax '. $cust_main->fax;
164   }
165
166   $html .= '</TD></TR></TABLE></TD>';
167
168   if ( $cust_main->ship_locationnum ) {
169
170     my $ship = $cust_main->ship_location;
171
172     $html .= '<TD VALIGN="top">'. ntable("#cccccc",2).
173       '<TR><TD ALIGN="right" VALIGN="top">Service<BR>Address</TD><TD BGCOLOR="#ffffff">';
174     $html .= join('<BR>', 
175       map encode_entities($_), grep $_,
176         $cust_main->ship_company,
177         $ship->address1,
178         $ship->address2,
179         (($ship->city ? $ship->city . ', ' : '') . $ship->state . '  ' . $ship->zip),
180         ($ship->country eq $countrydefault ? '' : $ship->country ),
181     );
182
183     # ship phone numbers no longer exist...
184
185     $html .= '</TD></TR></TABLE></TD>';
186
187   }
188
189   $html .= '</TR>';
190
191   #would be better to use ncancelled_active_pkgs, but that doesn't have an
192   # optimization to just count them yet, so it would be a perf problem on 
193   # tons-of-package customers
194   if ( !$nopkg && scalar($cust_main->ncancelled_pkgs) < 20 ) {
195
196     foreach my $cust_pkg ( $cust_main->ncancelled_active_pkgs ) {
197
198       $html .= '<TR><TD COLSPAN="2">'.
199                '<B><FONT COLOR="#'. $cust_pkg->statuscolor. '">'.
200                ucfirst($cust_pkg->status). '</FONT></B> - '.
201                encode_entities($cust_pkg->part_pkg->pkg_comment_only(nopkgpart=>1)).
202                '</TD></TR>';
203     }
204
205   }
206
207   $html .= '</TABLE>';
208
209   # last payment might be good here too?
210
211   $html .= '</DIV>';
212
213   $html;
214 }
215
216 #bah.  don't want to pull in all of FS::CGI, that's the whole problem in the
217 #first place
218 sub ntable {
219   my $col = shift;
220   my $cellspacing = shift || 0;
221   if ( $col ) {
222     qq!<TABLE BGCOLOR="$col" BORDER=0 CELLSPACING=$cellspacing>!;
223   } else {
224     '<TABLE BORDER CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">';
225   }
226
227 }
228
229 =back
230
231 =head1 BUGS
232
233 Sheesh. I did switch to mason, but this is still hanging around.  Figure out
234 some better way to sling mason components to self-service & RT.
235
236 (Or, is it useful to have this without depending on the regular back-office UI
237 and Mason stuff to be in place?  So we have something suitable for displaying
238 customer information in other external systems, not just RT?)
239
240 =head1 SEE ALSO
241
242 L<FS::UI::Web>
243
244 =cut
245
246 1;
247