This commit was generated by cvs2svn to compensate for changes in r11022,
[freeside.git] / httemplate / browse / did_order.html
1 <% include( 'elements/browse.html',
2                  'title'       => 'Bulk DID Orders',
3                  'html_init'   =>  $html_init,
4                  'name'        => 'bulk DID orders',
5                  'disableable' => 0,
6                  'query'       => $query,
7                  'count_query' => 'SELECT COUNT(*) FROM did_order', # XXX: this is wrong!?
8                  'header'      => [ '#', 'Vendor',' Vendor Order #', 
9                                     'Submitted', 'Confirmed', 'Customer',
10                                     'Received', 'Provision', 'Cancel',
11                                   ],
12                  'fields'      => [ sub {
13                                         my $did_order = shift;
14                                         $did_order->ordernum;
15                                     }, 
16                                     'vendorname', 
17                                     'vendor_order_id', 
18                                     sub { &$display_date(shift->submitted); },
19                                     sub { # Confirmed
20                                         my $did_order = shift;
21                                         my $ordernum = $did_order->ordernum;
22                                         return &$display_date($did_order->confirmed) 
23                                             if $did_order->confirmed;
24                                         include( '/elements/popup_link.html',
25                                           { 'action'      => "${p}misc/did_order_confirm.html?ordernum=$ordernum",
26                                             'label'       => 'Confirm',
27                                             'actionlabel' => 'Confirm Bulk DID Order',
28                                             'width'       => 480,
29                                             'height'      => 300,
30                                           }
31                                         )
32                                     }, 
33                                     sub { # Customer
34                                         my $did_order = shift;
35                                         my $cust_main = $did_order->cust_main;
36                                         return "Stock" unless $cust_main;
37                                         "<A HREF='${p}view/cust_main.cgi?".$cust_main->custnum."'>".$cust_main->name."</A>";
38                                     },
39                                     sub { # Received
40                                         my $did_order = shift;
41                                         my $ordernum = $did_order->ordernum;
42                                         return "<A HREF='${p}misc/phone_avail-import.html?ordernum=$ordernum'>Upload Received</A>"
43                                             unless $did_order->received;
44                                         "<A HREF='${p}search/phone_avail.html?ordernum=$ordernum'>"
45                                                 . &$display_date($did_order->received) . "</A>";
46                                     },
47                                     sub { # Provision
48                                         my $did_order = shift;
49                                         my $ordernum = $did_order->ordernum;
50                                         my @provisioned = $did_order->provisioned;
51                                         return '' 
52                                             unless $did_order->received 
53                                                         && $did_order->custnum
54                                                         && !scalar(@provisioned);
55                                         include( '/elements/popup_link.html',
56                                           { 'action'      => "${p}misc/did_order_provision.html?ordernum=".$did_order->ordernum,
57                                             'label'       => 'Provision All DIDs',
58                                             'actionlabel' => 'Bulk DID order - DID provisioning',
59                                             'width'       => 520,
60                                             'height'      => 300,
61                                           }
62                                         )
63                                     },
64                                     sub { # Cancel
65                                         my $did_order = shift;
66                                         return '' unless !$did_order->received;
67                                         qq!<A HREF="javascript:areyousure('${p}misc/did_order_confirmed.html?action=cancel;ordernum=!
68                                         . $did_order->ordernum . qq!', 'Cancel this order (#!
69                                         . $did_order->ordernum . qq!)?')">Cancel</A>!
70                                     },
71                                   ],
72                  'links'       => [
73                                     [ $p.'edit/did_order.html?', 'ordernum' ],
74                                                   ],
75                  'html_foot' => '
76                             <script type="text/javascript">
77                                 function areyousure(href,msg) {
78                                     if (confirm(msg))
79                                         window.location.href = href;
80                                 }
81                             </script>
82                                 ',
83              )
84 %>
85 <%init>
86
87 die "access denied"
88   unless $FS::CurrentUser::CurrentUser->access_right('Import');
89
90 my $conf = new FS::Conf;
91 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
92
93 my $display_date = sub {
94     my $date = shift;
95     return '' unless $date;
96     time2str($date_format, $date);
97 };
98
99 my $html_init = qq!<A HREF="${p}edit/did_order.html">Add a bulk DID order</A>
100                     <BR><BR>!;
101
102 my $query = { 
103     'table'      => 'did_order',
104     'hashref'    => {},
105     'addl_from' => 'left join did_vendor using (vendornum) ',
106     'order_by' => 'ORDER BY ordernum',
107             };
108 $query->{'hashref'}->{'custnum'} = $1 if $cgi->param('custnum') =~ /^(\d+)$/;
109 if ( $cgi->param('custrcvdunprov') ) {
110     $query->{'hashref'}->{'received'} = { 'op' => '>', 'value' => '0', };
111     $query->{'hashref'}->{'custnum'} = { 'op' => '>', 'value' => '0', };
112     $query->{'addl_from'} .= ' left join phone_avail using (ordernum) ';
113     $query->{'extra_sql'} .= ' and svcnum is null ';
114     $html_init .= qq!<A HREF="${p}browse/did_order.html">Browse all DID orders</A>!;
115 }
116 else {
117     $html_init .= qq!<A HREF="${p}browse/did_order.html?custrcvdunprov=1">
118                     Browse all non-stock orders with received unprovisioned DIDs
119                     </A>!;
120 }
121
122 $html_init .= "<BR><BR>";
123
124 </%init>