2 % $cgi->param('error', $error);
3 <% $cgi->redirect(popurl(3). 'misc/order_pkg.html?'. $cgi->query_string ) %>
5 % my $show = $curuser->default_customer_view =~ /^(jumbo|packages)$/
9 % my $redir_url = popurl(3);
10 % if ( $svcpart ) { # for going straight to service provisining after ordering
11 % $redir_url .= 'edit/'.$part_svc->svcdb.'.cgi?'.
12 % 'pkgnum='.$cust_pkg->pkgnum. ";svcpart=$svcpart";
13 % $redir_url .= ";qualnum=$qualnum" if $qualnum;
14 % } elsif ( $quotationnum ) {
15 % $redir_url .= "view/quotation.html?quotationnum=$quotationnum";
17 % my $custnum = $cust_main->custnum;
18 % my $frag = "cust_pkg". $cust_pkg->pkgnum;
20 % "view/cust_main.cgi?custnum=$custnum$show;fragment=$frag#$frag";
23 <% header('Package ordered') %>
24 <SCRIPT TYPE="text/javascript">
25 // XXX fancy ajax rebuild table at some point, but a page reload will do for now
27 // XXX chop off trailing #target and replace... ?
28 window.top.location = '<% $redir_url %>';
36 my $curuser = $FS::CurrentUser::CurrentUser;
39 unless $curuser->access_right('Order customer package');
42 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
44 $cust_main = qsearchs({
45 'table' => 'cust_main',
46 'hashref' => { 'custnum' => $custnum },
47 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
52 if ( $cgi->param('prospectnum') =~ /^(\d+)$/ ) {
54 $prospect_main = qsearchs({
55 'table' => 'prospect_main',
56 'hashref' => { 'prospectnum' => $prospectnum },
57 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
61 die 'no custnum or prospectnum' unless $cust_main || $prospect_main;
63 #probably not necessary, taken care of by cust_pkg::check
64 $cgi->param('pkgpart') =~ /^(\d+)$/
65 or die 'illegal pkgpart '. $cgi->param('pkgpart');
67 $cgi->param('quantity') =~ /^(\d*)$/
68 or die 'illegal quantity '. $cgi->param('quantity');
69 my $quantity = $1 || 1;
70 $cgi->param('refnum') =~ /^(\d*)$/
71 or die 'illegal refnum '. $cgi->param('refnum');
73 $cgi->param('salesnum') =~ /^(\d*)$/
74 or die 'illegal salesnum '. $cgi->param('salesnum');
76 $cgi->param('contactnum') =~ /^(\-?\d*)$/
77 or die 'illegal contactnum '. $cgi->param('contactnum');
79 $cgi->param('locationnum') =~ /^(\-?\d*)$/
80 or die 'illegal locationnum '. $cgi->param('locationnum');
82 $cgi->param('discountnum') =~ /^(\-?\d*)$/
83 or die 'illegal discountnum '. $cgi->param('discountnum');
86 # for going right to a provision service after ordering a package
87 my( $svcpart, $part_svc ) = ( '', '' );
88 if ( $cgi->param('svcpart') ) {
89 $cgi->param('svcpart') =~ /^(\-?\d*)$/
90 or die 'illegal svcpart '. $cgi->param('svcpart');
92 $part_svc = qsearchs('part_svc', { 'svcpart' => $svcpart } )
93 or die "unknown svcpart $svcpart";
97 if ( $cgi->param('qualnum') =~ /^(\d+)$/ ) {
100 my $quotationnum = '';
101 if ( $cgi->param('quotationnum') =~ /^(\d+)$/ ) {
104 # verify this quotation is visible to this user
107 my $quotation_pkg = '';
111 'pkgpart' => $pkgpart,
112 'quantity' => $quantity,
113 'salesnum' => $salesnum,
115 'contactnum' => $contactnum,
116 'locationnum' => $locationnum,
117 'discountnum' => $discountnum,
118 #for the create a new discount case
119 'discountnum__type' => scalar($cgi->param('discountnum__type')),
120 'discountnum_amount' => scalar($cgi->param('discountnum_amount')),
121 'discountnum_percent' => scalar($cgi->param('discountnum_percent')),
122 'discountnum_months' => scalar($cgi->param('discountnum_months')),
123 'discountnum_setup' => scalar($cgi->param('discountnum_setup')),
124 'contract_end' => ( scalar($cgi->param('contract_end'))
125 ? parse_datetime($cgi->param('contract_end'))
128 'waive_setup' => ( $cgi->param('waive_setup') eq 'Y' ? 'Y' : '' ),
130 $hash{'custnum'} = $cust_main->custnum if $cust_main;
132 if ( $cgi->param('start') eq 'on_hold' ) {
133 $hash{'susp'} = 'now';
134 } elsif ( $cgi->param('start') eq 'on_date' ) {
135 $hash{'start_date'} = scalar($cgi->param('start_date'))
136 ? parse_datetime($cgi->param('start_date'))
140 if ( $quotationnum ) {
142 $quotation_pkg = new FS::quotation_pkg \%hash;
143 $quotation_pkg->quotationnum($quotationnum);
144 $quotation_pkg->prospectnum($prospect_main->prospectnum) if $prospect_main;
148 if ( $locationnum == -1 ) {
149 my $cust_location = FS::cust_location->new({
150 'custnum' => $cust_main ? $cust_main->custnum : '',
151 'prospectnum' => $prospect_main ? $prospect_main->prospectnum : '',
152 map { $_ => scalar($cgi->param($_)) }
153 FS::cust_main->location_fields
155 $opt{'cust_location'} = $cust_location;
157 $opt{'locationnum'} = $locationnum;
160 $error = $quotation_pkg->insert(%opt) || $quotation_pkg->estimate;
164 $cust_pkg = new FS::cust_pkg \%hash;
166 $cust_pkg->no_auto( scalar($cgi->param('no_auto')) );
168 my %opt = ( 'cust_pkg' => $cust_pkg );
170 if ( $contactnum == -1 ) {
171 my $contact = FS::contact->new({
172 'custnum' => scalar($cgi->param('custnum')),
173 map { $_ => scalar($cgi->param("contactnum_$_")) } qw( first last )
175 $opt{'contact'} = $contact;
178 if ( $locationnum == -1 ) {
179 my $cust_location = FS::cust_location->new({
180 map { $_ => scalar($cgi->param($_)) }
181 ('custnum', FS::cust_main->location_fields)
183 $opt{'cust_location'} = $cust_location;
185 $opt{'locationnum'} = $locationnum;
188 $error = $cust_main->order_pkg( \%opt );