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;
28 my($pkgnum,$svcpart,$phonenum) = (shift,shift,shift);
29 my $svc_phone = new FS::svc_phone({
33 phonenum => $phonenum,
35 $cgi->param('error',$svc_phone->insert);
38 my $action = $cgi->param('action');
39 if ( $action eq 'confirm' ) {
41 $header = 'DID order confirmed';
42 $confirmed = parse_datetime($cgi->param('confirmed'))
43 if $cgi->param('confirmed') && $cgi->param('confirmed') !~ /^\d+$/;
45 if $cgi->param('confirmed') && $cgi->param('confirmed') =~ /^(\d+)$/;
47 die "invalid confirmation date" unless $confirmed;
49 $did_order->confirmed($confirmed);
50 $did_order->vendor_order_id($cgi->param('vendor_order_id'));
51 $cgi->param('error',$did_order->replace);
52 print $cgi->redirect(popurl(1). "did_order_confirm.html?". $cgi->query_string )
53 if $cgi->param('error');
56 elsif ( $action eq 'cancel' ) {
57 $header = 'DID order cancelled';
58 $cgi->param('error',$did_order->delete);
59 $js = "window.location.href = '${p}browse/did_order.html'";
61 elsif ( $action eq 'provision' ) {
62 # XXX: most of this should move into did_order.pm and become transaction-enabled
64 $header = 'DID order provisioned';
65 my @dids = qsearch( 'phone_avail', { ordernum => $ordernum } );
66 die "no DIDs on order" unless scalar(@dids);
67 my @params = $cgi->param;
68 foreach my $param ( @params ) {
69 next unless $param =~ /^custnum(\d+)_pkgnum_svcpart$/;
71 my $value = $cgi->param($param);
72 next unless $value =~ /^(\d+)_(\d+)$/;
75 if ( $did_order->custnum && $did_order->custnum == $custnum ) {
76 # per-order custnum case
78 foreach my $did ( @dids ) {
79 didprov($pkgnum,$svcpart,$did->npa.$did->nxx.$did->station);
80 last if $cgi->param('error');
83 elsif(!$did_order->custnum) { # multi-customer/stock case
85 # get each order item for this customer for this order
86 my @did_order_item = qsearch('did_order_item', {
87 'ordernum' => $ordernum,
88 'custnum' => $custnum,
90 foreach my $did_order_item ( @did_order_item ) {
91 # get imported unprovisioned DIDs for this order matching this order item
92 my $didsearch = { 'ordernum' => $ordernum,
95 $didsearch->{'npa'} = $did_order_item->npa
96 if $did_order_item->npa;
97 $didsearch->{'state'} = $did_order_item->state
98 if $did_order_item->state;
99 $didsearch->{'name'} = $did_order_item->rate_center->description
100 if $did_order_item->rate_center;
101 $didsearch->{'msanum'} = $did_order_item->msanum
102 if $did_order_item->msanum;
103 $didsearch->{'latanum'} = $did_order_item->latanum
104 if $did_order_item->latanum;
105 @dids = qsearch('phone_avail', $didsearch);
106 my $limit = $did_order_item->quantity;
107 foreach my $did ( @dids ) {
108 didprov($pkgnum,$svcpart,$did->npa.$did->nxx.$did->station);
110 last if $cgi->param('error') || $limit == 0;
112 last if $cgi->param('error');
118 elsif ( $action eq 'merge' ) {
119 $header = 'DID order merged';
120 $cgi->param('target_ordernum') =~ /^(\d+)$/ or die 'illegal target_ordernum';
121 my $target_ordernum = $1;
122 my $target_did_order = qsearchs( {
123 'table' => 'did_order',
124 'hashref' => { 'ordernum' => $target_ordernum },
126 die "No order $target_ordernum" unless $target_did_order;
127 $cgi->param('error',$target_did_order->merge($did_order));
128 $js = "window.location.href = '${p}browse/did_order.html'";
131 die "illegal action";
134 $header = 'Error' if $cgi->param('error');