a0958922e0190d70360c43b62de67999433825db
[freeside.git] / httemplate / edit / process / quick-cust_pkg.cgi
1 %if ($error) {
2 %  $cgi->param('error', $error);
3 <% $cgi->redirect(popurl(3). 'misc/order_pkg.html?'. $cgi->query_string ) %>
4 %} else {
5 %  my $frag = "cust_pkg". $cust_pkg->pkgnum;
6 %  my $show = $curuser->default_customer_view =~ /^(jumbo|packages)$/
7 %               ? ''
8 %               : ';show=packages';
9 <% header('Package ordered') %>
10   <SCRIPT TYPE="text/javascript">
11     // XXX fancy ajax rebuild table at some point, but a page reload will do for now
12
13     // XXX chop off trailing #target and replace... ?
14     window.top.location = '<% popurl(3). "view/cust_main.cgi?custnum=$custnum$show;fragment=$frag#$frag" %>';
15
16   </SCRIPT>
17
18   </BODY></HTML>
19 %}
20 <%init>
21
22 my $curuser = $FS::CurrentUser::CurrentUser;
23
24 die "access denied"
25   unless $curuser->access_right('Order customer package');
26
27 #untaint custnum (probably not necessary, searching for it is escape enough)
28 $cgi->param('custnum') =~ /^(\d+)$/
29   or die 'illegal custnum '. $cgi->param('custnum');
30 my $custnum = $1;
31 my $cust_main = qsearchs({
32   'table'     => 'cust_main',
33   'hashref'   => { 'custnum' => $custnum },
34   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
35 });
36 die 'unknown custnum' unless $cust_main;
37
38 #probably not necessary, taken care of by cust_pkg::check
39 $cgi->param('pkgpart') =~ /^(\d+)$/
40   or die 'illegal pkgpart '. $cgi->param('pkgpart');
41 my $pkgpart = $1;
42 $cgi->param('refnum') =~ /^(\d*)$/
43   or die 'illegal refnum '. $cgi->param('refnum');
44 my $refnum = $1;
45 $cgi->param('locationnum') =~ /^(\-?\d*)$/
46   or die 'illegal locationnum '. $cgi->param('locationnum');
47 my $locationnum = $1;
48 $cgi->param('discountnum') =~ /^(\-?\d*)$/
49   or die 'illegal discountnum '. $cgi->param('discountnum');
50 my $discountnum = $1;
51
52
53 my $cust_pkg = new FS::cust_pkg {
54   'custnum'              => $custnum,
55   'pkgpart'              => $pkgpart,
56   'start_date'           => ( scalar($cgi->param('start_date'))
57                                 ? str2time($cgi->param('start_date'))
58                                 : ''
59                             ),
60   'refnum'               => $refnum,
61   'locationnum'          => $locationnum,
62   'discountnum'          => $discountnum,
63   #for the create a new discount case
64   'discountnum__type'    => scalar($cgi->param('discountnum__type')),
65   'discountnum_amount'   => scalar($cgi->param('discountnum_amount')),
66   'discountnum_percent'  => scalar($cgi->param('discountnum_percent')),
67   'discountnum_months'   => scalar($cgi->param('discountnum_months')),
68   #'discountnum_disabled' => scalar($cgi->param('discountnum_disabled')),
69 };
70
71 my %opt = ( 'cust_pkg' => $cust_pkg );
72
73 if ( $locationnum == -1 ) {
74   my $cust_location = new FS::cust_location {
75     map { $_ => scalar($cgi->param($_)) }
76         qw( custnum address1 address2 city county state zip country )
77   };
78   $opt{'cust_location'} = $cust_location;
79 }
80
81 my $error = $cust_main->order_pkg( %opt );
82
83 </%init>