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