34c580560767977dec4cec7f146138354d68570d
[freeside.git] / httemplate / edit / process / detach-cust_pkg.html
1 % if ($error) {
2 %   $cgi->param('error', $error);
3 %   $cgi->redirect(popurl(3). 'misc/detach_pkg.html?'. $cgi->query_string );
4 % } else {
5
6     <% header(emt("Package detached")) %>
7       <SCRIPT TYPE="text/javascript">
8         topreload();
9       </SCRIPT>
10     </BODY>
11     </HTML>
12
13 % }
14 <%init>
15
16 my $curuser = $FS::CurrentUser::CurrentUser;
17
18 die "access denied"
19   unless $curuser->access_right('Change customer package');
20
21 my $cust_pkg = qsearchs({
22   'table'     => 'cust_pkg',
23   'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
24   'hashref'   => { 'pkgnum' => scalar($cgi->param('pkgnum')), },
25   'extra_sql' => ' AND '. $curuser->agentnums_sql,
26 });
27 die 'unknown pkgnum' unless $cust_pkg;
28
29 my $cust_location = new FS::cust_location {
30   map { $_ => scalar($cgi->param($_)) } FS::cust_main->location_fields
31 };
32
33 #false laziness w/process/cust_main.cgi
34 my @invoicing_list = split( /\s*\,\s*/, $cgi->param('invoicing_list') );
35 push @invoicing_list, 'POST' if $cgi->param('invoicing_list_POST');
36 push @invoicing_list, 'FAX' if $cgi->param('invoicing_list_FAX');
37 $cgi->param('invoicing_list', join(',', @invoicing_list) );
38
39 my $cust_main = new FS::cust_main {
40   ( map { ( $_, scalar($cgi->param($_)) ) } fields('cust_main') ),
41   ( map { ( "ship_$_", '' ) } FS::cust_main->location_fields ),
42   'bill_location'  => $cust_location,
43   'ship_location'  => $cust_location,
44 };
45
46 my $pkg_or_error = $cust_pkg->change( {
47   'keep_dates'            => 1,
48   'cust_main'             => $cust_main,
49   'cust_main_insert_args' => [ {}, \@invoicing_list ],
50 } );
51
52 my $error = ref($pkg_or_error) ? '' : $pkg_or_error;
53
54 </%init>