customer view UI
[freeside.git] / httemplate / view / cust_main.cgi
1 <& /elements/header.html, {
2              'title' => $title,
3              'title_noescape' => $title_noescape,
4              'head'  => $head,
5              'nobr'  => 1,
6           }
7 &>
8 <BR>
9 % my @part_tag = $cust_main->part_tag;
10 % if ( $conf->config('cust_tag-location') eq 'top' && @part_tag ) {
11 <TABLE STYLE="margin-bottom:8px" CELLSPACING=2>
12 %   foreach my $part_tag ( @part_tag ) {
13 <TR>
14   <TD>
15       <FONT SIZE="+1"
16             <% length($part_tag->tagcolor)
17                  ? 'STYLE="background-color:#'.$part_tag->tagcolor.'"'
18                  : ''
19       %>><% $part_tag->tagname.': '. $part_tag->tagdesc |h %></FONT>
20   </TD>
21 </TR>
22 %   }
23 </TABLE>
24 % }
25
26 <& /elements/menubar.html,
27              { 'newstyle' => 1,
28                'selected' => $viewname{$view},
29                'url_base' => $cgi->url. "?custnum=$custnum;show=",
30              },
31              %views,
32 &>
33 <DIV CLASS="fstabcontainer">
34
35 <& /elements/init_overlib.html &>
36
37 <SCRIPT TYPE="text/javascript">
38 function areyousure(href, message) {
39   if (confirm(message) == true)
40     window.location.href = href;
41 }
42 </SCRIPT>
43
44
45 % ###
46 % # Basics
47 % ###
48
49 % if ( $view eq 'basics' || $view eq 'jumbo' ) {
50
51 % if ( $curuser->access_right('Edit customer') ) { 
52   <A HREF="<% $p %>edit/cust_main.cgi?<% $custnum %>"><% mt('Edit this customer') |h %></A> | 
53 % } 
54
55 % if ( $curuser->access_right('Suspend customer')
56 %        && scalar($cust_main->unsuspended_pkgs)
57 %      ) {
58   <& /elements/popup_link-cust_main.html,
59               { 'action'      => $p. 'misc/suspend_cust.html',
60                 'label'       => emt('Suspend this customer'),
61                 'actionlabel' => emt('Confirm Suspension'),
62                 'color'       => '#ff9900',
63                 'cust_main'   => $cust_main,
64                 'width'       => 768, #make room for reasons
65                 'height'      => 450, 
66               }
67   &> | 
68 % }
69
70 % if ( $curuser->access_right('Unsuspend customer')
71 %        && scalar($cust_main->suspended_pkgs)
72 %      ) {
73   <& /elements/popup_link-cust_main.html,
74               { 'action'      => $p. 'misc/unsuspend_cust.html',
75                 'label'       => emt('Unsuspend this customer'),
76                 'actionlabel' => emt('Confirm Unsuspension'),
77                 #'color'       => '#ff9900',
78                 'cust_main'   => $cust_main,
79                 #'width'       => 616, #make room for reasons
80                 #'height'      => 366,
81               }
82   &> | 
83 % }
84
85 % if ( $curuser->access_right('Cancel customer')
86 %        && scalar($cust_main->ncancelled_pkgs)
87 %      ) {
88   <& /elements/popup_link-cust_main.html,
89               { 'action'      => $p. 'misc/cancel_cust.html',
90                 'label'       => emt('Cancel this customer'),
91                 'actionlabel' => emt('Confirm Cancellation'),
92                 'color'       => '#ff0000',
93                 'cust_main'   => $cust_main,
94                 'width'       => 616, #make room for reasons
95                 'height'      => 410,
96               }
97   &> | 
98 % }
99
100 % if (     $curuser->access_right('Merge customer')
101 %      and (    scalar($cust_main->ncancelled_pkgs)
102 %            # || we start supporting payment info merge again in some way
103 %          )
104 %    )
105 % {
106   <& /elements/popup_link-cust_main.html,
107               { 'action'      => $p. 'misc/merge_cust.html',
108                 'label'       => emt('Merge this customer'),
109                 'actionlabel' => emt('Merge customer'),
110                 'cust_main'   => $cust_main,
111                 'width'       => 569,
112                 'height'      => 210,
113               }
114   &> | 
115 % } 
116
117 % unless ( $conf->exists('disable_customer_referrals') ) { 
118   <A HREF="<% $p %>edit/cust_main.cgi?referral_custnum=<% $custnum %>"><% mt('Refer a new customer') |h %></A> | 
119   <A HREF="<% $p %>search/cust_main.cgi?referral_custnum=<% $custnum %>"><% mt('View this customer\'s referrals') |h %></A>
120 % } 
121
122 <BR><BR>
123
124 % my $br = 0;
125 % if (    $curuser->access_right('Billing event reports') 
126 %      || $curuser->access_right('View customer billing events')
127 %    ) {
128 % $br=1;
129   <A HREF="<% $p %>search/cust_event.html?custnum=<% $custnum %>"><% mt('View billing events for this customer') |h %></A>
130 % }
131
132 % my $email_link = ($cust_main->invoicing_list_emailonly) && 
133 %   include('/elements/email-link.html',
134 %            'table'               => 'cust_main', 
135 %            'search_hash'         => { 'custnum' => $custnum },
136 %            'agent_virt_agentnum' => $cust_main->agentnum,
137 %            'label'               => 'Email a notice to this customer',
138 % );
139 % if ( $email_link and $br ) {
140  | 
141 % }
142 <% $email_link || '' %>
143
144 % if ( $curuser->access_right('Order customer package') && $conf->exists('cust_main-enable_order_package') ) {
145   | <& /elements/order_pkg_link.html, 'cust_main'=>$cust_main &>
146 % }
147
148 % if ( $conf->config('cust_main-external_links') ) {
149     <% $br++ ? ' | ' : '' %>
150 %   my @links = split(/\n/, $conf->config('cust_main-external_links'));
151 %   foreach my $link (@links) {
152 %     $link =~ /^\s*(\S+)\s+(.*?)(\s*\(([^\)]*)\))?$/ or next;
153 %     my($url, $label, $alt) = ($1, $2, $4);
154       <A HREF="<% $url.$custnum %>" ALT="<% $alt |h %>"><% $label |h %></A>
155 %   }
156 % }
157
158 % if ( $br ) {
159   <BR><BR>
160 % }
161
162 %my $signupurl = $conf->config('signupurl');
163 %if ( $signupurl ) {
164   <% mt('This customer\'s signup URL:') |h %>
165   <A HREF="<% $signupurl %>?ref=<% $custnum %>"><% $signupurl %>?ref=<% $custnum %></A>
166   <BR><BR>
167 % } 
168
169 <A NAME="cust_main"></A>
170 <TABLE BORDER=0>
171 <TR>
172   <TD VALIGN="top">
173     <& cust_main/contacts.html, $cust_main &>
174     <BR>
175     <& cust_main/misc.html, $cust_main &>
176   </TD>
177   <TD VALIGN="top" STYLE="padding-left: 54px">
178     <& cust_main/billing.html, $cust_main &>
179     <BR>
180     <& cust_main/cust_payby.html, $cust_main &>
181   </TD>
182 </TR>
183 <TR>
184   <TD COLSPAN = 2>
185     <& cust_main/contacts_new.html, $cust_main &>
186   </TD>
187 </TR>
188 </TABLE>
189
190 % }
191
192
193 % ###
194 % # Notes
195 % ###
196
197 % if ( $view eq 'notes' || $view eq 'jumbo' ) {
198
199 <& cust_main/notes.html, 'cust_main' => $cust_main &>
200
201 % }
202
203 % if ( $view eq 'jumbo' ) {
204     <BR>
205 % }
206
207 <BR>
208
209
210 % ###
211 % # Tickets
212 % ###
213
214 % if ( $view eq 'tickets' || $view eq 'jumbo' ) {
215
216 % if ( $conf->config('ticket_system') ) { 
217   <& cust_main/tickets.html, $cust_main &>
218 % } 
219   <BR><BR>
220
221 % }
222
223 % ###
224 % # Appointments
225 % ###
226
227 % if ( $view eq 'appointments' || $view eq 'jumbo' ) {
228
229 % if ( $conf->config('ticket_system')
230 %        && $curuser->access_right('View appointments') ) { 
231   <& cust_main/appointments.html, $cust_main &>
232 % } 
233   <BR><BR>
234
235 % }
236
237
238 % ###
239 % # Quotations
240 % ###
241
242 % if ( $view eq 'jumbo' && $curuser->access_right('Generate quotation') ) { 
243   <A NAME="quotations"><FONT SIZE="+2"><% mt('Quotations') |h %></FONT></A><BR>
244 % }
245
246 % if ( $view eq 'quotations' || $view eq 'jumbo' ) {
247
248 %   if ( $curuser->access_right('Generate quotation') ) { 
249       <& cust_main/quotations.html, $cust_main &>
250 %   }
251
252 % }
253
254
255 % ###
256 % # Packages
257 % ###
258
259 % if ( $view eq 'jumbo' ) { #XXX enable me && $curuser->access_right('View customer packages') { 
260
261   <A NAME="cust_pkg"><FONT SIZE="+2"><% mt('Packages') |h %></FONT></A><BR>
262 % }
263
264 % if ( $view eq 'packages' || $view eq 'jumbo' ) {
265
266 % #XXX enable me# if ( $curuser->access_right('View customer packages') { 
267 <& cust_main/packages.html, $cust_main &>
268 % #}
269
270 % }
271
272
273 % ###
274 % # Payment History
275 % ###
276
277 % if ( $view eq 'jumbo' ) {
278     <BR><BR>
279     <A NAME="history"><FONT SIZE="+2"><% mt('Payment History') |h %></FONT></A>
280     <BR>
281 % }
282
283 % if ( $view eq 'payment_history' || $view eq 'jumbo' ) {
284
285 <& cust_main/payment_history.html, $cust_main &>
286
287 % }
288
289
290 % ###
291 % # Change History
292 % ###
293
294 % if ( $view eq 'change_history' ) { #  || $view eq 'jumbo'      
295 <& cust_main/change_history.html, $cust_main &>          
296 % }
297
298 % if ( $view eq 'custom' ) { 
299 %   if ( $conf->config('cust_main-custom_link') ) {
300 <& cust_main/custom.html, $cust_main &>
301 %   } elsif ( $conf->config('cust_main-custom_content') ) {
302       <& cust_main/custom_content.html, $cust_main &>
303 %   #} else {
304 %   #  warn "custom view without cust_main-custom_link or -custom_content?";
305 %   }
306 % }
307
308 </DIV>
309 <& /elements/footer.html &>
310 <%init>
311
312 my $curuser = $FS::CurrentUser::CurrentUser;
313
314 die "access denied"
315   unless $curuser->access_right('View customer');
316
317 my $conf = new FS::Conf;
318
319 my $custnum;
320 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
321   $custnum = $1;
322 } else {
323   die "No customer specified (bad URL)!" unless $cgi->keywords;
324   my($query) = $cgi->keywords; # needs parens with my, ->keywords returns array
325   $query =~ /^(\d+)$/;
326   $custnum = $1;
327   $cgi->param('custnum', $1);
328 }
329
330 my $cust_main = qsearchs( {
331   'table'     => 'cust_main',
332   'hashref'   => { 'custnum' => $custnum },
333   'extra_sql' => ' AND '. $curuser->agentnums_sql,
334 });
335 die "Customer not found!" unless $cust_main;
336
337 my $title = encode_entities($cust_main->name);
338 $title = '#'. $cust_main->display_custnum. " $title";
339 #  if $conf->exists('cust_main-title-display_custnum');
340 $title = mt("Customer")." ".$title;
341
342 my @agentnums = $curuser->agentnums;
343 if (scalar(@agentnums) > 1 ) {
344   $title = encode_entities($cust_main->agent->agent). " $title";
345 }
346
347 my $status = $cust_main->status_label;
348 $status .= ' (Cancelled)' if $cust_main->is_status_delay_cancel;
349 my $title_noescape = $title. ' (<B><FONT COLOR="#'. $cust_main->statuscolor. '">'. $status.  '</FONT></B>)';
350 $title .= " ($status)";
351
352 #false laziness w/pref/pref.html and Conf.pm (cust_main-default_view)
353 tie my %views, 'Tie::IxHash',
354        emt('Basics')           => 'basics',
355        emt('Notes')            => 'notes', #notes and files?
356 ;
357 if ( $conf->config('ticket_system') ) {
358   $views{emt('Tickets')}       =  'tickets';
359   $views{emt('Appointments')}  =  'appointments'
360     if $curuser->access_right('View appointments');
361 }
362 $views{emt('Quotations')}      =  'quotations';
363 $views{emt('Packages')}        =  'packages';
364 $views{emt('Payment History')} =  'payment_history';
365 $views{emt('Change History')}  =  'change_history'
366   if $curuser->access_right('View customer history');
367 $views{$conf->config('cust_main-custom_title') || emt('Custom')} =  'custom'
368   if $conf->config('cust_main-custom_link')
369   || $conf->config('cust_main-custom_content');
370 $views{emt('Jumbo')}           =  'jumbo';
371
372 my %viewname = reverse %views;
373
374 my $view =  $cgi->param('show') || $curuser->default_customer_view;
375
376 my $ie_compat = $conf->config('ie-compatibility_mode');
377 my $head = '';
378 if ( $ie_compat ) {
379   $head = qq(<meta http-equiv="X-UA-Compatible" content="IE=$ie_compat" />);
380 }
381
382 </%init>