summaryrefslogtreecommitdiff
path: root/httemplate/browse/did_order.html
blob: 3da8cb1bafc73041202c5a4a0219fb1df216d3e8 (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<% include( 'elements/browse.html',
                 'title'       => 'Bulk DID Orders',
                 'html_init'   =>  $html_init,
                 'name'        => 'bulk DID orders',
                 'disableable' => 0,
                 'query'       => $query,
                 'count_query' => 'SELECT COUNT(*) FROM did_order', # XXX: this is wrong!?
                 'header'      => [ '#', 'Vendor',' Vendor Order #', 
                                    'Submitted', 'Confirmed', 'Customer',
                                    'Received', 'Provision', 'Cancel',
                                  ],
                 'fields'      => [ sub {
                                        my $did_order = shift;
                                        $did_order->ordernum;
                                    }, 
                                    'vendorname', 
                                    'vendor_order_id', 
                                    sub { &$display_date(shift->submitted); },
                                    sub { # Confirmed
                                        my $did_order = shift;
                                        my $ordernum = $did_order->ordernum;
                                        return &$display_date($did_order->confirmed) 
                                            if $did_order->confirmed;
                                        include( '/elements/popup_link.html',
                                          { 'action'      => "${p}misc/did_order_confirm.html?ordernum=$ordernum",
                                            'label'       => 'Confirm',
                                            'actionlabel' => 'Confirm Bulk DID Order',
                                            'width'       => 480,
                                            'height'      => 300,
                                          }
                                        )
                                    }, 
                                    sub { # Customer
                                        my $did_order = shift;
                                        my $cust_main = $did_order->cust_main;
                                        return "Stock" unless $cust_main;
                                        "<A HREF='${p}view/cust_main.cgi?".$cust_main->custnum."'>".$cust_main->name."</A>";
                                    },
                                    sub { # Received
                                        my $did_order = shift;
                                        my $ordernum = $did_order->ordernum;
                                        return "<A HREF='${p}misc/phone_avail-import.html?ordernum=$ordernum'>Upload Received</A>"
                                            unless $did_order->received;
                                        "<A HREF='${p}search/phone_avail.html?ordernum=$ordernum'>"
                                                . &$display_date($did_order->received) . "</A>";
                                    },
                                    sub { # Provision
                                        my $did_order = shift;
                                        my $ordernum = $did_order->ordernum;
                                        my @provisioned = $did_order->provisioned;
                                        return '' 
                                            unless $did_order->received 
                                                        && $did_order->custnum
                                                        && !scalar(@provisioned);
                                        include( '/elements/popup_link.html',
                                          { 'action'      => "${p}misc/did_order_provision.html?ordernum=".$did_order->ordernum,
                                            'label'       => 'Provision All DIDs',
                                            'actionlabel' => 'Bulk DID order - DID provisioning',
                                            'width'       => 520,
                                            'height'      => 300,
                                          }
                                        )
                                    },
                                    sub { # Cancel
                                        my $did_order = shift;
                                        return '' unless !$did_order->received;
                                        qq!<A HREF="javascript:areyousure('${p}misc/did_order_confirmed.html?action=cancel;ordernum=!
                                        . $did_order->ordernum . qq!', 'Cancel this order (#!
                                        . $did_order->ordernum . qq!)?')">Cancel</A>!
                                    },
                                  ],
                 'links'       => [
                                    [ $p.'edit/did_order.html?', 'ordernum' ],
				                  ],
                 'html_foot' => '
                            <script type="text/javascript">
                                function areyousure(href,msg) {
                                    if (confirm(msg))
                                        window.location.href = href;
                                }
                            </script>
                                ',
             )
%>
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Import');

my $conf = new FS::Conf;
my $date_format = $conf->config('date_format') || '%m/%d/%Y';

my $display_date = sub {
    my $date = shift;
    return '' unless $date;
    time2str($date_format, $date);
};

my $html_init = qq!<A HREF="${p}edit/did_order.html">Add a bulk DID order</A>
                    <BR><BR>!;

my $query = { 
    'table'      => 'did_order',
    'hashref'    => {},
    'addl_from' => 'left join did_vendor using (vendornum) ',
    'order_by' => 'ORDER BY ordernum',
            };
$query->{'hashref'}->{'custnum'} = $1 if $cgi->param('custnum') =~ /^(\d+)$/;
if ( $cgi->param('custrcvdunprov') ) {
    $query->{'hashref'}->{'received'} = { 'op' => '>', 'value' => '0', };
    $query->{'hashref'}->{'custnum'} = { 'op' => '>', 'value' => '0', };
    $query->{'addl_from'} .= ' left join phone_avail using (ordernum) ';
    $query->{'extra_sql'} .= ' and svcnum is null ';
    $html_init .= qq!<A HREF="${p}browse/did_order.html">Browse all DID orders</A>!;
}
else {
    $html_init .= qq!<A HREF="${p}browse/did_order.html?custrcvdunprov=1">
                    Browse all non-stock orders with received unprovisioned DIDs
                    </A>!;
}

$html_init .= "<BR><BR>";

</%init>