1 <% include("/elements/header$popup.html", $header ) %>
2 <% include('/elements/error.html') %>
3 % unless ( $cgi->param('error') ) {
4 <SCRIPT TYPE="text/javascript">
12 unless $FS::CurrentUser::CurrentUser->access_right('Import');
17 my $js = 'window.top.location.reload();';
19 $cgi->param('ordernum') =~ /^(\d+)$/ or die 'illegal ordernum';
21 my $did_order = qsearchs( {
22 'table' => 'did_order',
23 'hashref' => { 'ordernum' => $ordernum },
25 die "No order $ordernum" unless $did_order;
27 my $action = $cgi->param('action');
28 if ( $action eq 'confirm' ) {
30 $header = 'DID order confirmed';
31 $confirmed = parse_datetime($cgi->param('confirmed'))
32 if $cgi->param('confirmed') && $cgi->param('confirmed') !~ /^\d+$/;
34 if $cgi->param('confirmed') && $cgi->param('confirmed') =~ /^(\d+)$/;
36 die "invalid confirmation date" unless $confirmed;
38 $did_order->confirmed($confirmed);
39 $did_order->vendor_order_id($cgi->param('vendor_order_id'));
40 $cgi->param('error',$did_order->replace);
41 print $cgi->redirect(popurl(1). "did_order_confirm.html?". $cgi->query_string )
42 if $cgi->param('error');
45 elsif ( $action eq 'cancel' ) {
46 $header = 'DID order cancelled';
47 $cgi->param('error',$did_order->delete);
48 $js = "window.location.href = '${p}browse/did_order.html'";
50 elsif ( $action eq 'provision' ) {
51 $header = 'DID order provisioned';
52 my @dids = qsearch( 'phone_avail', { ordernum => $ordernum } );
53 die "no DIDs on order" unless scalar(@dids);
54 my @params = $cgi->param;
55 foreach my $param ( @params ) {
56 next unless $param =~ /^custnum(\d+)_pkgnum_svcpart$/;
58 my $value = $cgi->param($param);
59 next unless $value =~ /^(\d+)_(\d+)$/;
62 if ( $did_order->custnum && $did_order->custnum == $custnum ) {
63 # this is our old per-order custnum case
65 foreach my $did ( @dids ) {
66 my $svc_phone = new FS::svc_phone({
70 phonenum => $did->npa.$did->nxx.$did->station,
72 $cgi->param('error',$svc_phone->insert);
73 last if $cgi->param('error');
76 # XXX: now what do we do for order items? Not clear how to match a DID in an order item
80 elsif ( $action eq 'merge' ) {
81 $header = 'DID order merged';
82 $cgi->param('target_ordernum') =~ /^(\d+)$/ or die 'illegal target_ordernum';
83 my $target_ordernum = $1;
84 my $target_did_order = qsearchs( {
85 'table' => 'did_order',
86 'hashref' => { 'ordernum' => $target_ordernum },
88 die "No order $target_ordernum" unless $target_did_order;
89 $cgi->param('error',$target_did_order->merge($did_order));
90 $js = "window.location.href = '${p}browse/did_order.html'";
96 $header = 'Error' if $cgi->param('error');