2 % $cgi->param('error', $error);
3 <% $cgi->redirect(popurl(3). 'misc/order_pkg.html?'. $cgi->query_string ) %>
5 % my $frag = "cust_pkg". $cust_pkg->pkgnum;
6 % my $show = $curuser->default_customer_view =~ /^(jumbo|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
13 // XXX chop off trailing #target and replace... ?
14 window.top.location = '<% popurl(3). "view/cust_main.cgi?custnum=$custnum$show;fragment=$frag#$frag" %>';
22 my $curuser = $FS::CurrentUser::CurrentUser;
25 unless $curuser->access_right('Order customer package');
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');
31 my $cust_main = qsearchs({
32 'table' => 'cust_main',
33 'hashref' => { 'custnum' => $custnum },
34 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
36 die 'unknown custnum' unless $cust_main;
38 #probably not necessary, taken care of by cust_pkg::check
39 $cgi->param('pkgpart') =~ /^(\d+)$/
40 or die 'illegal pkgpart '. $cgi->param('pkgpart');
42 $cgi->param('refnum') =~ /^(\d*)$/
43 or die 'illegal refnum '. $cgi->param('refnum');
45 $cgi->param('locationnum') =~ /^(\-?\d*)$/
46 or die 'illegal locationnum '. $cgi->param('locationnum');
48 $cgi->param('discountnum') =~ /^(\-?\d*)$/
49 or die 'illegal discountnum '. $cgi->param('discountnum');
53 my $cust_pkg = new FS::cust_pkg {
54 'custnum' => $custnum,
55 'pkgpart' => $pkgpart,
56 'start_date' => ( scalar($cgi->param('start_date'))
57 ? parse_datetime($cgi->param('start_date'))
60 'no_auto' => scalar($cgi->param('no_auto')),
62 'locationnum' => $locationnum,
63 'discountnum' => $discountnum,
64 #for the create a new discount case
65 'discountnum__type' => scalar($cgi->param('discountnum__type')),
66 'discountnum_amount' => scalar($cgi->param('discountnum_amount')),
67 'discountnum_percent' => scalar($cgi->param('discountnum_percent')),
68 'discountnum_months' => scalar($cgi->param('discountnum_months')),
69 'discountnum_setup' => scalar($cgi->param('discountnum_setup')),
70 'contract_end' => ( scalar($cgi->param('contract_end'))
71 ? parse_datetime($cgi->param('contract_end'))
74 'waive_setup' => ( $cgi->param('waive_setup') eq 'Y' ? 'Y' : '' ),
75 #'discountnum_disabled' => scalar($cgi->param('discountnum_disabled')),
78 my %opt = ( 'cust_pkg' => $cust_pkg );
80 if ( $locationnum == -1 ) {
81 my $cust_location = new FS::cust_location {
82 map { $_ => scalar($cgi->param($_)) }
83 qw( custnum address1 address2 city county state zip country geocode )
85 $opt{'cust_location'} = $cust_location;
88 my $error = $cust_main->order_pkg( %opt );