3505a1e1dbb9e11f854763fb8b21df47dc4527f0
[freeside.git] / httemplate / misc / did_order_confirmed.html
1 <% include("/elements/header$popup.html", $header ) %>
2 <% include('/elements/error.html') %>
3 % unless ( $cgi->param('error') ) {
4   <SCRIPT TYPE="text/javascript">
5     <% $js %>
6   </SCRIPT>
7 % }
8   </BODY>
9 </HTML>
10 <%init>
11 die "access denied"
12   unless $FS::CurrentUser::CurrentUser->access_right('Import');
13
14 my $action = $1;
15 my $header = '';
16 my $popup = '';
17 my $js = 'window.top.location.reload();';
18
19 $cgi->param('ordernum') =~ /^(\d+)$/ or die 'illegal ordernum';
20 my $ordernum = $1;
21 my $did_order = qsearchs( {
22   'table'     => 'did_order',
23   'hashref'   => { 'ordernum' => $ordernum },
24 } );
25 die "No order $ordernum" unless $did_order;
26
27 my $action = $cgi->param('action');
28 if ( $action eq 'confirm' ) {
29     my $confirmed = '';
30     $header = 'DID order confirmed';
31     $confirmed = parse_datetime($cgi->param('confirmed'))
32         if $cgi->param('confirmed') && $cgi->param('confirmed') !~ /^\d+$/;
33     $confirmed = $1
34         if $cgi->param('confirmed') && $cgi->param('confirmed') =~ /^(\d+)$/;
35
36     die "invalid confirmation date" unless $confirmed;
37
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');
43     $popup = '-popup';
44 }
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'";
49 }
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$/;
57         my $custnum = $1;
58         my $value = $cgi->param($param);
59         next unless $value =~ /^(\d+)_(\d+)$/;
60         my $pkgnum = $1;
61         my $svcpart = $2;
62         if ( $did_order->custnum && $did_order->custnum == $custnum ) {
63         # this is our old per-order custnum case
64
65             foreach my $did ( @dids ) {
66                 my $svc_phone = new FS::svc_phone({
67                     pkgnum  => $pkgnum,
68                     svcpart => $svcpart,
69                     countrycode => 1,
70                     phonenum    => $did->npa.$did->nxx.$did->station,
71                 });
72                 $cgi->param('error',$svc_phone->insert);
73                 last if $cgi->param('error');
74             }
75         }
76         # XXX: now what do we do for order items? Not clear how to match a DID in an order item
77     }
78     $popup = '-popup';
79 }
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 },
87     } );
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'";
91 }
92 else { 
93     die "illegal action";
94 }
95
96 $header = 'Error' if $cgi->param('error');
97
98 </%init>