RT# 81183 Fix crash processing payment with new payment method
[freeside.git] / httemplate / misc / cust_main-merge.html
1 % if ( $error ) {
2 % $cgi->param('error', $error);
3 <% $cgi->redirect(popurl(1). "merge_cust.html?". $cgi->query_string ) %>
4 % } else {
5 <% include('/elements/header-popup.html', "Customer merged") %>
6   <SCRIPT TYPE="text/javascript">
7     window.top.location.href = '<% $p %>view/cust_main.cgi?<% $new_custnum %>';
8 %# parent.nd(1) ?
9   </SCRIPT>
10   </BODY>
11 </HTML>
12 % }
13 <%init>
14
15 die "access denied"
16   unless $FS::CurrentUser::CurrentUser->access_right('Merge customer');
17
18 my $error = '';
19
20 $cgi->param('custnum') =~ /^(\d+)$/ or die "illegal custnum";
21 my $custnum = $1;
22
23 my $new_custnum;
24 if ( $cgi->param('new_custnum') =~ /^(\d+)$/ ) {
25   $new_custnum = $1;
26
27   my $cust_main = qsearchs( {
28     'table'     => 'cust_main',
29     'hashref'   => { 'custnum' => $custnum },
30     'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
31   } );
32   die "No customer # $custnum" unless $cust_main;
33
34   if ( $cgi->param('merge') eq 'Y' ) {
35
36     #old-style merge: everything + delete old customer
37     $error = $cust_main->merge($new_custnum);
38
39   } else {
40
41     #new-style attach: move packages 3.0 style, that's it
42     $error = $cust_main->attach_pkgs($new_custnum);
43
44   }
45
46 } else {
47   $error = 'Select a customer to merge into';
48 }
49
50 </%init>