summaryrefslogtreecommitdiff
path: root/httemplate/misc/did_order_confirmed.html
blob: 3505a1e1dbb9e11f854763fb8b21df47dc4527f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<% include("/elements/header$popup.html", $header ) %>
<% include('/elements/error.html') %>
% unless ( $cgi->param('error') ) {
  <SCRIPT TYPE="text/javascript">
    <% $js %>
  </SCRIPT>
% }
  </BODY>
</HTML>
<%init>
die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Import');

my $action = $1;
my $header = '';
my $popup = '';
my $js = 'window.top.location.reload();';

$cgi->param('ordernum') =~ /^(\d+)$/ or die 'illegal ordernum';
my $ordernum = $1;
my $did_order = qsearchs( {
  'table'     => 'did_order',
  'hashref'   => { 'ordernum' => $ordernum },
} );
die "No order $ordernum" unless $did_order;

my $action = $cgi->param('action');
if ( $action eq 'confirm' ) {
    my $confirmed = '';
    $header = 'DID order confirmed';
    $confirmed = parse_datetime($cgi->param('confirmed'))
        if $cgi->param('confirmed') && $cgi->param('confirmed') !~ /^\d+$/;
    $confirmed = $1
        if $cgi->param('confirmed') && $cgi->param('confirmed') =~ /^(\d+)$/;

    die "invalid confirmation date" unless $confirmed;

    $did_order->confirmed($confirmed);
    $did_order->vendor_order_id($cgi->param('vendor_order_id'));
    $cgi->param('error',$did_order->replace);
    print $cgi->redirect(popurl(1). "did_order_confirm.html?". $cgi->query_string )
         if $cgi->param('error');
    $popup = '-popup';
}
elsif ( $action eq 'cancel' ) {
    $header = 'DID order cancelled';
    $cgi->param('error',$did_order->delete);
    $js = "window.location.href = '${p}browse/did_order.html'";
}
elsif ( $action eq 'provision' ) {
    $header = 'DID order provisioned';
    my @dids = qsearch( 'phone_avail', { ordernum => $ordernum } );
    die "no DIDs on order" unless scalar(@dids);
    my @params = $cgi->param;
    foreach my $param ( @params ) {
        next unless $param =~ /^custnum(\d+)_pkgnum_svcpart$/;
        my $custnum = $1;
        my $value = $cgi->param($param);
        next unless $value =~ /^(\d+)_(\d+)$/;
        my $pkgnum = $1;
        my $svcpart = $2;
        if ( $did_order->custnum && $did_order->custnum == $custnum ) {
        # this is our old per-order custnum case

            foreach my $did ( @dids ) {
                my $svc_phone = new FS::svc_phone({
                    pkgnum  => $pkgnum,
                    svcpart => $svcpart,
                    countrycode => 1,
                    phonenum    => $did->npa.$did->nxx.$did->station,
                });
                $cgi->param('error',$svc_phone->insert);
                last if $cgi->param('error');
            }
        }
        # XXX: now what do we do for order items? Not clear how to match a DID in an order item
    }
    $popup = '-popup';
}
elsif ( $action eq 'merge' ) {
    $header = 'DID order merged';
    $cgi->param('target_ordernum') =~ /^(\d+)$/ or die 'illegal target_ordernum';
    my $target_ordernum = $1;
    my $target_did_order = qsearchs( {
      'table'     => 'did_order',
      'hashref'   => { 'ordernum' => $target_ordernum },
    } );
    die "No order $target_ordernum" unless $target_did_order;
    $cgi->param('error',$target_did_order->merge($did_order));
    $js = "window.location.href = '${p}browse/did_order.html'";
}
else { 
    die "illegal action";
}

$header = 'Error' if $cgi->param('error');

</%init>