badly placed small_custview all of a sudden causing fatal errors?! wtf
[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 FS::Msgcat;
7 use FS::Record qw(qsearchs);
8 use FS::cust_main;
9
10 @ISA = qw(Exporter);
11 @EXPORT_OK = qw( small_custview );
12
13 =item small_custview CUSTNUM || CUST_MAIN_OBJECT, COUNTRYDEFAULT, NOBALANCE_FLAG, URL
14
15 Sheesh. I did switch to mason, but this is still hanging around.  Figure out
16 some better way to sling mason components to self-service & RT.
17
18 =cut
19
20 sub small_custview {
21
22   my $arg = shift;
23   my $countrydefault = shift || 'US';
24   my $nobalance = shift;
25   my $url = shift;
26
27   my $cust_main = ref($arg) ? $arg
28                   : qsearchs('cust_main', { 'custnum' => $arg } )
29     or die "unknown custnum $arg";
30
31   my $html;
32   
33   $html = qq!View <A HREF="$url?! . $cust_main->custnum . '">'
34     if $url;
35
36   $html .= 'Customer #<B>'. $cust_main->custnum. '</B></A>'.
37     ' - <B><FONT COLOR="#'. $cust_main->statuscolor. '">'.
38     ucfirst($cust_main->status). '</FONT></B>'.
39     ntable('#e8e8e8'). '<TR><TD VALIGN="top">'. ntable("#cccccc",2).
40     '<TR><TD ALIGN="right" VALIGN="top">Billing<BR>Address</TD><TD BGCOLOR="#ffffff">'.
41     $cust_main->getfield('last'). ', '. $cust_main->first. '<BR>';
42
43   $html .= $cust_main->company. '<BR>' if $cust_main->company;
44   $html .= $cust_main->address1. '<BR>';
45   $html .= $cust_main->address2. '<BR>' if $cust_main->address2;
46   $html .= $cust_main->city. ', '. $cust_main->state. '  '. $cust_main->zip. '<BR>';
47   $html .= $cust_main->country. '<BR>'
48     if $cust_main->country && $cust_main->country ne $countrydefault;
49
50   $html .= '</TD></TR><TR><TD></TD><TD BGCOLOR="#ffffff">';
51   if ( $cust_main->daytime && $cust_main->night ) {
52     $html .= ( FS::Msgcat::_gettext('daytime') || 'Day' ).
53              ' '. $cust_main->daytime.
54              '<BR>'. ( FS::Msgcat::_gettext('night') || 'Night' ).
55              ' '. $cust_main->night;
56   } elsif ( $cust_main->daytime || $cust_main->night ) {
57     $html .= $cust_main->daytime || $cust_main->night;
58   }
59   if ( $cust_main->fax ) {
60     $html .= '<BR>Fax '. $cust_main->fax;
61   }
62
63   $html .= '</TD></TR></TABLE></TD>';
64
65   if ( defined $cust_main->dbdef_table->column('ship_last') ) {
66
67     my $pre = $cust_main->ship_last ? 'ship_' : '';
68
69     $html .= '<TD VALIGN="top">'. ntable("#cccccc",2).
70       '<TR><TD ALIGN="right" VALIGN="top">Service<BR>Address</TD><TD BGCOLOR="#ffffff">'.
71       $cust_main->get("${pre}last"). ', '.
72       $cust_main->get("${pre}first"). '<BR>';
73     $html .= $cust_main->get("${pre}company"). '<BR>'
74       if $cust_main->get("${pre}company");
75     $html .= $cust_main->get("${pre}address1"). '<BR>';
76     $html .= $cust_main->get("${pre}address2"). '<BR>'
77       if $cust_main->get("${pre}address2");
78     $html .= $cust_main->get("${pre}city"). ', '.
79              $cust_main->get("${pre}state"). '  '.
80              $cust_main->get("${pre}zip"). '<BR>';
81     $html .= $cust_main->get("${pre}country"). '<BR>'
82       if $cust_main->get("${pre}country")
83          && $cust_main->get("${pre}country") ne $countrydefault;
84
85     $html .= '</TD></TR><TR><TD></TD><TD BGCOLOR="#ffffff">';
86
87     if ( $cust_main->get("${pre}daytime") && $cust_main->get("${pre}night") ) {
88       use FS::Msgcat;
89       $html .= ( FS::Msgcat::_gettext('daytime') || 'Day' ).
90                ' '. $cust_main->get("${pre}daytime").
91                '<BR>'. ( FS::Msgcat::_gettext('night') || 'Night' ).
92                ' '. $cust_main->get("${pre}night");
93     } elsif ( $cust_main->get("${pre}daytime")
94               || $cust_main->get("${pre}night") ) {
95       $html .= $cust_main->get("${pre}daytime")
96                || $cust_main->get("${pre}night");
97     }
98     if ( $cust_main->get("${pre}fax") ) {
99       $html .= '<BR>Fax '. $cust_main->get("${pre}fax");
100     }
101
102     $html .= '</TD></TR></TABLE></TD>';
103   }
104
105   $html .= '</TR></TABLE>';
106
107   $html .= '<BR>Balance: <B>$'. $cust_main->balance. '</B><BR>'
108     unless $nobalance;
109
110   # last payment might be good here too?
111
112   $html;
113 }
114