This commit was generated by cvs2svn to compensate for changes in r11022,
[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;
33   
34   $html = qq!View <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     ucfirst($cust_main->status). '</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     $cust_main->getfield('last'). ', '. $cust_main->first. '<BR>';
62
63   $html .= $cust_main->company. '<BR>' if $cust_main->company;
64   $html .= $cust_main->address1. '<BR>';
65   $html .= $cust_main->address2. '<BR>' if $cust_main->address2;
66   $html .= $cust_main->city. ', '. $cust_main->state. '  '. $cust_main->zip. '<BR>';
67   $html .= $cust_main->country. '<BR>'
68     if $cust_main->country && $cust_main->country ne $countrydefault;
69
70   $html .= '</TD></TR><TR><TD></TD><TD BGCOLOR="#ffffff">';
71   if ( $cust_main->daytime && $cust_main->night ) {
72     $html .= ( FS::Msgcat::_gettext('daytime') || 'Day' ).
73              ' '. $cust_main->daytime.
74              '<BR>'. ( FS::Msgcat::_gettext('night') || 'Night' ).
75              ' '. $cust_main->night;
76   } elsif ( $cust_main->daytime || $cust_main->night ) {
77     $html .= $cust_main->daytime || $cust_main->night;
78   }
79   if ( $cust_main->fax ) {
80     $html .= '<BR>Fax '. $cust_main->fax;
81   }
82
83   $html .= '</TD></TR></TABLE></TD>';
84
85   if ( defined $cust_main->dbdef_table->column('ship_last') ) {
86
87     my $pre = $cust_main->ship_last ? 'ship_' : '';
88
89     $html .= '<TD VALIGN="top">'. ntable("#cccccc",2).
90       '<TR><TD ALIGN="right" VALIGN="top">Service<BR>Address</TD><TD BGCOLOR="#ffffff">'.
91       $cust_main->get("${pre}last"). ', '.
92       $cust_main->get("${pre}first"). '<BR>';
93     $html .= $cust_main->get("${pre}company"). '<BR>'
94       if $cust_main->get("${pre}company");
95     $html .= $cust_main->get("${pre}address1"). '<BR>';
96     $html .= $cust_main->get("${pre}address2"). '<BR>'
97       if $cust_main->get("${pre}address2");
98     $html .= $cust_main->get("${pre}city"). ', '.
99              $cust_main->get("${pre}state"). '  '.
100              $cust_main->get("${pre}zip"). '<BR>';
101     $html .= $cust_main->get("${pre}country"). '<BR>'
102       if $cust_main->get("${pre}country")
103          && $cust_main->get("${pre}country") ne $countrydefault;
104
105     $html .= '</TD></TR><TR><TD></TD><TD BGCOLOR="#ffffff">';
106
107     if ( $cust_main->get("${pre}daytime") && $cust_main->get("${pre}night") ) {
108       use FS::Msgcat;
109       $html .= ( FS::Msgcat::_gettext('daytime') || 'Day' ).
110                ' '. $cust_main->get("${pre}daytime").
111                '<BR>'. ( FS::Msgcat::_gettext('night') || 'Night' ).
112                ' '. $cust_main->get("${pre}night");
113     } elsif ( $cust_main->get("${pre}daytime")
114               || $cust_main->get("${pre}night") ) {
115       $html .= $cust_main->get("${pre}daytime")
116                || $cust_main->get("${pre}night");
117     }
118     if ( $cust_main->get("${pre}fax") ) {
119       $html .= '<BR>Fax '. $cust_main->get("${pre}fax");
120     }
121
122     $html .= '</TD></TR></TABLE></TD>';
123   }
124
125   $html .= '</TR></TABLE>';
126
127   $html .= '<BR>Balance: <B>$'. $cust_main->balance. '</B><BR>'
128     unless $nobalance;
129
130   # last payment might be good here too?
131
132   $html;
133 }
134
135 #bah.  don't want to pull in all of FS::CGI, that's the whole problem in the
136 #first place
137 sub ntable {
138   my $col = shift;
139   my $cellspacing = shift || 0;
140   if ( $col ) {
141     qq!<TABLE BGCOLOR="$col" BORDER=0 CELLSPACING=$cellspacing>!;
142   } else {
143     '<TABLE BORDER CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">';
144   }
145
146 }
147
148 1;
149