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 % my $redir_url = popurl(3)
10 % ."view/cust_main.cgi?custnum=$custnum$show;fragment=$frag#$frag";
12 % # for going right to a provision service after ordering a package
14 % my $part_svc = qsearchs('part_svc', { 'svcpart' => $svcpart } );
16 % $redir_url = popurl(3)."edit/".$part_svc->svcdb.".cgi?"
17 % ."pkgnum=".$cust_pkg->pkgnum.";svcpart=$svcpart";
20 <% header('Package ordered') %>
21 <SCRIPT TYPE="text/javascript">
22 // XXX fancy ajax rebuild table at some point, but a page reload will do for now
24 // XXX chop off trailing #target and replace... ?
25 window.top.location = '<% $redir_url %>';
33 my $curuser = $FS::CurrentUser::CurrentUser;
36 unless $curuser->access_right('Order customer package');
38 #untaint custnum (probably not necessary, searching for it is escape enough)
39 $cgi->param('custnum') =~ /^(\d+)$/
40 or die 'illegal custnum '. $cgi->param('custnum');
42 my $cust_main = qsearchs({
43 'table' => 'cust_main',
44 'hashref' => { 'custnum' => $custnum },
45 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
47 die 'unknown custnum' unless $cust_main;
49 #probably not necessary, taken care of by cust_pkg::check
50 $cgi->param('pkgpart') =~ /^(\d+)$/
51 or die 'illegal pkgpart '. $cgi->param('pkgpart');
53 $cgi->param('refnum') =~ /^(\d*)$/
54 or die 'illegal refnum '. $cgi->param('refnum');
56 $cgi->param('locationnum') =~ /^(\-?\d*)$/
57 or die 'illegal locationnum '. $cgi->param('locationnum');
59 $cgi->param('discountnum') =~ /^(\-?\d*)$/
60 or die 'illegal discountnum '. $cgi->param('discountnum');
63 # for going right to a provision service after ordering a package
65 if ( $cgi->param('svcpart') ) {
66 $cgi->param('svcpart') =~ /^(\-?\d*)$/
67 or die 'illegal svcpart '. $cgi->param('svcpart');
71 my $cust_pkg = new FS::cust_pkg {
72 'custnum' => $custnum,
73 'pkgpart' => $pkgpart,
74 'start_date' => ( scalar($cgi->param('start_date'))
75 ? parse_datetime($cgi->param('start_date'))
78 'no_auto' => scalar($cgi->param('no_auto')),
80 'locationnum' => $locationnum,
81 'discountnum' => $discountnum,
82 #for the create a new discount case
83 'discountnum__type' => scalar($cgi->param('discountnum__type')),
84 'discountnum_amount' => scalar($cgi->param('discountnum_amount')),
85 'discountnum_percent' => scalar($cgi->param('discountnum_percent')),
86 'discountnum_months' => scalar($cgi->param('discountnum_months')),
87 'contract_end' => ( scalar($cgi->param('contract_end'))
88 ? parse_datetime($cgi->param('contract_end'))
91 #'discountnum_disabled' => scalar($cgi->param('discountnum_disabled')),
94 my %opt = ( 'cust_pkg' => $cust_pkg );
96 if ( $locationnum == -1 ) {
97 my $cust_location = new FS::cust_location {
98 map { $_ => scalar($cgi->param($_)) }
99 qw( custnum address1 address2 city county state zip country geocode )
101 $opt{'cust_location'} = $cust_location;
104 my $error = $cust_main->order_pkg( \%opt );