customer merging, RT#10247
[freeside.git] / httemplate / view / cust_main.cgi
1 <% include('/elements/header.html', {
2              'title' => $title,
3              'nobr'  => 1,
4           })
5 %>
6 <BR>
7 % my @part_tag = $cust_main->part_tag;
8 % if ( $conf->config('cust_tag-location') eq 'top' && @part_tag ) {
9 <TABLE STYLE="margin-bottom:8px" CELLSPACING=2>
10 %   foreach my $part_tag ( @part_tag ) {
11 <TR>
12   <TD>
13       <FONT SIZE="+1"
14             <% length($part_tag->tagcolor)
15                  ? 'STYLE="background-color:#'.$part_tag->tagcolor.'"'
16                  : ''
17       %>><% $part_tag->tagname.': '. $part_tag->tagdesc |h %></FONT>
18   </TD>
19 </TR>
20 %   }
21 </TABLE>
22 % }
23
24 <% include('/elements/menubar.html',
25              { 'newstyle' => 1,
26                'selected' => $viewname{$view},
27                'url_base' => $cgi->url. "?custnum=$custnum;show=",
28              },
29              %views,
30           )
31 %>
32 <DIV CLASS="fstabcontainer">
33
34 <% include('/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 </SCRIPT>
42
43 % if ( $view eq 'basics' || $view eq 'jumbo' ) {
44
45 % if ( $curuser->access_right('Edit customer') ) { 
46   <A HREF="<% $p %>edit/cust_main.cgi?<% $custnum %>">Edit this customer</A> | 
47 % } 
48
49 % if ( $curuser->access_right('Cancel customer')
50 %        && $cust_main->ncancelled_pkgs
51 %      ) {
52
53   <% include( '/elements/popup_link-cust_main.html',
54               { 'action'      => $p. 'misc/cancel_cust.html',
55                 'label'       => 'Cancel&nbsp;this&nbsp;customer',
56                 'actionlabel' => 'Confirm Cancellation',
57                 'color'       => '#ff0000',
58                 'cust_main'   => $cust_main,
59                 'width'       => 616, #make room for reasons
60                 'height'      => 366,
61               }
62             )
63   %> | 
64
65 % }
66
67 % if ( $curuser->access_right('Merge customer') ) {
68
69   <% include( '/elements/popup_link-cust_main.html',
70               { 'action'      => $p. 'misc/merge_cust.html',
71                 'label'       => 'Merge&nbsp;this&nbsp;customer',
72                 'actionlabel' => 'Merge customer',
73                 #'color'       => '#ff0000',
74                 'cust_main'   => $cust_main,
75                 'width'       => 480,
76                 'height'      => 192,
77               }
78             )
79   %> | 
80
81 % } 
82
83 % if ( $conf->exists('deletecustomers')
84 %        && $curuser->access_right('Delete customer')
85 %      ) {
86   <A HREF="<% $p %>misc/delete-customer.cgi?<% $custnum%>">Delete this customer</A> | 
87 % } 
88
89 % unless ( $conf->exists('disable_customer_referrals') ) { 
90   <A HREF="<% $p %>edit/cust_main.cgi?referral_custnum=<% $custnum %>">Refer a new customer</A> | 
91   <A HREF="<% $p %>search/cust_main.cgi?referral_custnum=<% $custnum %>">View this customer's referrals</A>
92 % } 
93
94 <BR><BR>
95
96 % if (    $curuser->access_right('Billing event reports') 
97 %      || $curuser->access_right('View customer billing events')
98 %    ) {
99
100   <A HREF="<% $p %>search/cust_event.html?custnum=<% $custnum %>">View billing events for this customer</A>
101   <BR><BR>
102
103 % }
104
105 %my $signupurl = $conf->config('signupurl');
106 %if ( $signupurl ) {
107   This customer's signup URL: <A HREF="<% $signupurl %>?ref=<% $custnum %>"><% $signupurl %>?ref=<% $custnum %></A><BR><BR>
108 % } 
109
110 %if ( $conf->exists('maestro-status_test') ) {
111   <A HREF="<% $p %>misc/maestro-customer_status-test.html?<% $custnum %>">Test maestro status</A><BR><BR>
112 % } 
113
114 <A NAME="cust_main"></A>
115 <TABLE BORDER=0>
116 <TR>
117   <TD VALIGN="top">
118     <% include('cust_main/contacts.html', $cust_main ) %>
119   </TD>
120   <TD VALIGN="top" STYLE="padding-left: 54px">
121     <% include('cust_main/misc.html', $cust_main ) %>
122 % if ( $conf->config('payby-default') ne 'HIDE' ) { 
123
124       <BR>
125       <% include('cust_main/billing.html', $cust_main ) %>
126 % } 
127
128   </TD>
129 </TR>
130 </TABLE>
131
132 % }
133
134 % if ( $view eq 'notes' || $view eq 'jumbo' ) {
135
136 %if ( $cust_main->comments =~ /[^\s\n\r]/ ) {
137 <BR>
138 Comments
139 <% ntable("#cccccc") %><TR><TD><% ntable("#cccccc",2) %>
140 <TR>
141   <TD BGCOLOR="#ffffff">
142     <PRE><% encode_entities($cust_main->comments) %></PRE>
143   </TD>
144 </TR>
145 </TABLE></TABLE>
146 <BR><BR>
147 % }
148 <A NAME="notes">
149 % my $notecount = scalar($cust_main->notes());
150 % if ( ! $conf->exists('cust_main-disable_notes') || $notecount) {
151
152 %   unless ( $view eq 'notes' && $cust_main->comments !~ /[^\s\n\r]/ ) {
153       <BR>
154       <A NAME="cust_main_note"><FONT SIZE="+2">Notes</FONT></A><BR>
155 %   }
156
157 %   if ( $curuser->access_right('Add customer note') &&
158 %        ! $conf->exists('cust_main-disable_notes')
159 %      ) {
160
161   <% include( '/elements/popup_link-cust_main.html',
162                 'label'       => 'Add customer note',
163                 'action'      => $p. 'edit/cust_main_note.cgi',
164                 'actionlabel' => 'Enter customer note',
165                 'cust_main'   => $cust_main,
166                 'width'       => 616,
167                 'height'      => 538, #575
168             )
169   %>
170
171 %   }
172
173 <BR>
174
175 <% include('cust_main/notes.html', 'custnum' => $cust_main->custnum ) %>
176
177 % }
178 <BR>
179
180 % if(! $conf->config('disable_cust_attachment') 
181 %  and $curuser->access_right('Add attachment')) {
182 <% include( '/elements/popup_link-cust_main.html',
183               'label'       => 'Attach file',
184               'action'      => $p.'edit/cust_main_attach.cgi',
185               'actionlabel' => 'Upload file',
186               'cust_main'   => $cust_main,
187               'width'       => 480,
188               'height'      => 296,
189           )
190 %>
191 % }
192 % if( $curuser->access_right('View attachments') ) {
193 <% include('cust_main/attachments.html', 'custnum' => $cust_main->custnum ) %>
194 %   if ($cgi->param('show_deleted')) {
195 <A HREF="<% $p.'view/cust_main.cgi?custnum=' . $cust_main->custnum .
196            ($view ? ";show=$view" : '') . '#notes' 
197            %>"><I>(Show active attachments)</I></A>
198 %   }
199 % elsif($curuser->access_right('View deleted attachments')) {
200 <A HREF="<% $p.'view/cust_main.cgi?custnum=' . $cust_main->custnum .
201            ($view ? ";show=$view" : '') . ';show_deleted=1#notes'
202            %>"><I>(Show deleted attachments)</I></A>
203 %   }
204 % }
205 <BR>
206
207 % }
208
209 % if ( $view eq 'jumbo' ) {
210     <BR><BR>
211     <A NAME="tickets"><FONT SIZE="+2">Tickets</FONT></A><BR>
212 % }
213
214 % if ( $view eq 'tickets' || $view eq 'jumbo' ) {
215
216 % if ( $conf->config('ticket_system') ) { 
217   <% include('cust_main/tickets.html', $cust_main ) %>
218 % } 
219   <BR><BR>
220
221 % }
222
223 % if ( $view eq 'jumbo' ) { #XXX enable me && $curuser->access_right('View customer packages') { 
224
225   <A NAME="cust_pkg"><FONT SIZE="+2">Packages</FONT></A><BR>
226 % }
227
228 % if ( $view eq 'packages' || $view eq 'jumbo' ) {
229
230 % #XXX enable me# if ( $curuser->access_right('View customer packages') { 
231 <% include('cust_main/packages.html', $cust_main ) %>
232 % #}
233
234 % }
235
236 % if ( $view eq 'jumbo' ) {
237     <BR><BR>
238     <A NAME="history"><FONT SIZE="+2">Payment History</FONT></A><BR>
239 % }
240
241 % if ( $view eq 'payment_history' || $view eq 'jumbo' ) {
242
243 % if ( $conf->config('payby-default') ne 'HIDE' ) { 
244   <% include('cust_main/payment_history.html', $cust_main ) %>
245 % } 
246
247 % }
248
249 % if ( $view eq 'change_history' ) { #  || $view eq 'jumbo'      
250 <% include('cust_main/change_history.html', $cust_main ) %>      
251 % }
252
253 % if ( $view eq 'custom' ) { 
254 <% include('cust_main/custom.html', $cust_main ) %>
255 % }
256
257 </DIV>
258 <% include('/elements/footer.html') %>
259 <%init>
260
261 my $curuser = $FS::CurrentUser::CurrentUser;
262
263 die "access denied"
264   unless $curuser->access_right('View customer');
265
266 my $conf = new FS::Conf;
267
268 my $custnum;
269 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
270   $custnum = $1;
271 } else {
272   die "No customer specified (bad URL)!" unless $cgi->keywords;
273   my($query) = $cgi->keywords; # needs parens with my, ->keywords returns array
274   $query =~ /^(\d+)$/;
275   $custnum = $1;
276 }
277
278 my $cust_main = qsearchs( {
279   'table'     => 'cust_main',
280   'hashref'   => { 'custnum' => $custnum },
281   'extra_sql' => ' AND '. $curuser->agentnums_sql,
282 });
283 die "Customer not found!" unless $cust_main;
284
285 my $title = $cust_main->name;
286 $title = '('. $cust_main->display_custnum. ") $title"
287   if $conf->exists('cust_main-title-display_custnum');
288 $title = "Customer: $title";
289
290 #false laziness w/pref/pref.html and Conf.pm (cust_main-default_view)
291 tie my %views, 'Tie::IxHash',
292        'Basics'           => 'basics',
293        'Notes'            => 'notes', #notes and files?
294 ;
295 $views{'Tickets'}         =  'tickets'
296                                if $conf->config('ticket_system');
297 $views{'Packages'}        =  'packages';
298 $views{'Payment History'} =  'payment_history'
299                                unless $conf->config('payby-default' eq 'HIDE');
300 $views{'Change History'}  =  'change_history'
301   if $curuser->access_right('View customer history');
302 $views{$conf->config('cust_main-custom_title') || 'Custom'} =  'custom'
303   if $conf->config('cust_main-custom_link');
304 $views{'Jumbo'}           =  'jumbo';
305
306 my %viewname = reverse %views;
307
308 my $view =  $cgi->param('show') || $curuser->default_customer_view;
309
310 </%init>