Merge branch 'master' of git.freeside.biz:/home/git/freeside
[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 =item small_custview CUSTNUM || CUST_MAIN_OBJECT, COUNTRYDEFAULT, NOBALANCE_FLAG, URL
15
16 Sheesh. I did switch to mason, but this is still hanging around.  Figure out
17 some better way to sling mason components to self-service & RT.
18
19 =cut
20
21 sub small_custview {
22
23   my $arg = shift;
24   my $countrydefault = shift || 'US';
25   my $nobalance = shift;
26   my $url = shift;
27
28   my $cust_main = ref($arg) ? $arg
29                   : qsearchs('cust_main', { 'custnum' => $arg } )
30     or die "unknown custnum $arg";
31
32   my $html = '<DIV ID="fs_small_custview" CLASS="small_custview">';
33   
34   $html = qq!<A HREF="$url?! . $cust_main->custnum . '">'
35     if $url;
36
37   $html .= 'Customer #<B>'. $cust_main->display_custnum. '</B></A>'.
38     ' - <B><FONT COLOR="#'. $cust_main->statuscolor. '">'.
39     $cust_main->status_label. '</FONT></B>';
40
41   my @part_tag = $cust_main->part_tag;
42   if ( @part_tag ) {
43     $html .= '<TABLE>';
44     foreach my $part_tag ( @part_tag ) {
45       $html .= '<TR><TD>'.
46                '<FONT '. ( length($part_tag->tagcolor)
47                            ? 'STYLE="background-color:#'.$part_tag->tagcolor.'"'
48                            : ''
49                          ).
50                '>'.
51                  encode_entities($part_tag->tagname.': '. $part_tag->tagdesc).
52                '</FONT>'.
53                '</TD></TR>';
54     }
55     $html .= '</TABLE>';
56   }
57
58   $html .=
59     ntable('#e8e8e8'). '<TR><TD VALIGN="top">'. ntable("#cccccc",2).
60     '<TR><TD ALIGN="right" VALIGN="top">Billing<BR>Address</TD><TD BGCOLOR="#ffffff">'.
61     encode_entities($cust_main->getfield('last')). ', '.
62     encode_entities($cust_main->first). '<BR>';
63
64   $html .= encode_entities($cust_main->company). '<BR>' if $cust_main->company;
65
66   if ( $cust_main->bill_locationnum ) {
67
68     $html .= encode_entities($cust_main->address1). '<BR>';
69     $html .= encode_entities($cust_main->address2). '<BR>'
70       if $cust_main->address2;
71     $html .= encode_entities($cust_main->city). ', '. $cust_main->state. '  '.
72              $cust_main->zip. '<BR>';
73     $html .= $cust_main->country. '<BR>'
74       if $cust_main->country && $cust_main->country ne $countrydefault;
75
76   }
77
78   $html .= '</TD></TR><TR><TD></TD><TD BGCOLOR="#ffffff">';
79   if ( $cust_main->daytime && $cust_main->night ) {
80     $html .= ( FS::Msgcat::_gettext('daytime') || 'Day' ).
81              ' '. $cust_main->daytime.
82              '<BR>'. ( FS::Msgcat::_gettext('night') || 'Night' ).
83              ' '. $cust_main->night;
84   } elsif ( $cust_main->daytime || $cust_main->night ) {
85     $html .= $cust_main->daytime || $cust_main->night;
86   }
87   if ( $cust_main->fax ) {
88     $html .= '<BR>Fax '. $cust_main->fax;
89   }
90
91   $html .= '</TD></TR></TABLE></TD>';
92
93   if ( $cust_main->ship_locationnum ) {
94
95     my $ship = $cust_main->ship_location;
96
97     $html .= '<TD VALIGN="top">'. ntable("#cccccc",2).
98       '<TR><TD ALIGN="right" VALIGN="top">Service<BR>Address</TD><TD BGCOLOR="#ffffff">';
99     $html .= join('<BR>', 
100       map encode_entities($_), grep $_,
101         $cust_main->contact,
102         $cust_main->company,
103         $ship->address1,
104         $ship->address2,
105         ($ship->city . ', ' . $ship->state . '  ' . $ship->zip),
106         ($ship->country eq $countrydefault ? '' : $ship->country ),
107     );
108
109     # ship phone numbers no longer exist...
110
111     $html .= '</TD></TR></TABLE></TD>';
112
113   }
114
115   $html .= '</TR></TABLE>';
116
117   $html .= '<BR>Balance: <B>$'. $cust_main->balance. '</B><BR>'
118     unless $nobalance;
119
120   # last payment might be good here too?
121
122   $html .= '</DIV>';
123
124   $html;
125 }
126
127 #bah.  don't want to pull in all of FS::CGI, that's the whole problem in the
128 #first place
129 sub ntable {
130   my $col = shift;
131   my $cellspacing = shift || 0;
132   if ( $col ) {
133     qq!<TABLE BGCOLOR="$col" BORDER=0 CELLSPACING=$cellspacing>!;
134   } else {
135     '<TABLE BORDER CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">';
136   }
137
138 }
139
140 1;
141