stray closing /TABLE in the no-ticket case
[freeside.git] / httemplate / search / 477.html
1 <& /elements/header.html, $title &>
2 <STYLE TYPE="text/css">
3 table.fcc477part {
4   border-collapse: collapse;
5   border: 1px #777 solid;
6   margin-bottom: 20px;
7 }
8 table.fcc477part td {
9   padding: 0px 4px;
10   border-left: 1px #777 solid;
11   border-right: 1px #777 solid;
12 }
13 table.fcc477part tbody td {
14   text-align: right;
15 }
16 table.fcc477part thead tr.head {
17   text-align: center;
18   vertical-align: top;
19   font-weight: bold;
20   border-top: 1px #777 solid;
21   border-bottom: 1px #777 solid;
22 }
23 table.fcc477part thead tr.subhead {
24   text-align: center;
25   font-weight: bold;
26   font-size: small;
27   border-top: 1px #777 solid;
28   border-bottom: 1px #777 solid;
29 }
30 .parttitle {
31   font-weight: bold;
32   font-size: large;
33   float: left;
34 }
35 .errortitle {
36   font-weight: bold;
37   color: #ff0000;
38 }
39 tr.error td {
40   background-color: #ffdddd;
41 }
42 tr.error td.error {
43   text-align: left;
44   border: none;
45 }
46 tr.error ul {
47   margin: 0px;
48   list-style-image: url("<% $fsurl %>images/cross.png");
49 }
50 a.download {
51   float: right;
52 }
53 </STYLE>
54 % foreach my $partname (@partnames) {
55 %   my $this_part = $parts{$partname};
56 %   $cgi->param('parts', $partname);
57 %   $cgi->param('type', 'csv');
58 <table class="fcc477part">
59   <caption>
60     <span class="parttitle"><% $part_titles->{$partname} %></span>
61 %   if ( $this_part->{num_errors} > 0 ) {
62 %     # disable downloading while it contains errors
63     <span class="errortitle">
64       <% emt('This section contains [quant,_1,error].', $this_part->{num_errors}) %>
65     </span>
66 %   } else {
67     <a class="download" href="<% $cgi->self_url %>">Download</a>
68 %   }
69   </caption>
70 %   my $header = ".header_$partname";
71 %   my $data = $this_part->{data};
72 %   my $error = $this_part->{error};
73   <thead>
74     <& $header &>
75   </thead>
76 %   my $rownum = 0;
77 %   foreach my $row (@$data) {
78 %     my %eh; # error hash
79 %     if ( $error->[$rownum] ) {
80 %       %eh = %{ $error->[$rownum] };
81 %     }
82   <tr<% keys(%eh) ? ' class="error"' : ''%>>
83 %     my $first = 1;
84 %     foreach my $item (@$row) {
85     <td>
86 %     if ($first and $part_link{$partname}) {
87       <a href="<% $part_link{$partname} . "477rownum=$rownum" %>"><% $item || '(empty)' %></a>
88 %       $first = 0;
89 %     } else {
90       <% $item %>
91 %     }
92     </td>
93 %   } #foreach $item
94 %   # display errors
95 %   if ( keys %eh ) {
96     <td class="error"><ul>
97 %     foreach my $key (sort keys %eh) {
98       <li><% $eh{$key} %></li>
99 %     }
100     </ul></td>
101 %   } # if there are errors
102   </tr>
103 %   $rownum++;
104 %   } #foreach $row
105 </table>
106 % } # foreach $partname
107 <& /elements/footer.html &>
108 <%init>
109 die "access denied"
110   unless $FS::CurrentUser::CurrentUser->access_right('List packages');
111
112 my %parts;
113 my %part_link;
114 # load from cache if possible
115 my $session;
116 if ( $cgi->param('session') =~ /^(\d+)$/ ) {
117   $session = $1;
118   %parts = %{ $m->cache->get($session) };
119 } else {
120   $session = sprintf('%010d%06d', time, int(rand(1000000)));
121   $cgi->param('session', $session);
122 }
123
124 my $agentnum;
125 if ($cgi->param('agentnum') =~ /^(\d+)$/ ) {
126   $agentnum = $1;
127 }
128 my $date = parse_datetime($cgi->param('date')) || time;
129 my @partnames = grep /^\w+$/, $cgi->param('parts');
130 my $ignore_quantity = ($cgi->param('ignore_quantity') ? 1 : 0);
131
132 foreach my $partname (@partnames) {
133   $parts{$partname} ||= FS::Report::FCC_477->report( $partname,
134     date            => $date,
135     agentnum        => $agentnum,
136     ignore_quantity => $ignore_quantity,
137   ); # includes error, detail, and data parts
138   my $detail_table = FS::Report::FCC_477->part_table($partname);
139   if ($detail_table eq 'cust_pkg') {
140     my $link = popurl(1).'477_cust_pkg.html?477part='.$partname.";date=$date;";
141     if ($agentnum) {
142       $link .= "agentnum=$agentnum;";
143     }
144     $part_link{$partname} = $link;
145   } # don't include detail links to deploy_blocks, that's pointless
146 }
147 $m->cache->set($session, \%parts, '1h');
148
149 my $title = 'FCC Form 477 Data - ' . time2str('%b %o, %Y', $date);
150
151 if ( $cgi->param('type') eq 'csv' ) {
152   my $partname = $partnames[0]; # ignore any beyond the first
153   my $data = $parts{$partname}->{data};
154   my $csv = Text::CSV_XS->new({ eol => "\r\n" }); # i think
155
156   my $filename = time2str('%Y-%m-%d', $date) . '-'. $partname . '.csv';
157   http_header('Content-Type' => 'text/csv');
158   http_header('Content-Disposition' => qq(attachment;filename="$filename"));
159
160   $m->clear_buffer;
161
162   foreach my $row (@$data) {
163     $csv->combine(@$row);
164     $m->print($csv->string);
165   }
166   $m->abort;
167 }
168
169 my $part_titles = FS::Report::FCC_477->parts;
170
171 </%init>
172 <%def .header_fbd>
173   <TR CLASS="head">
174     <TD ROWSPAN=2>Census Block</TD>
175     <TD ROWSPAN=2>DBA Name</TD>
176     <TD ROWSPAN=2>Technology</TD>
177     <TD ROWSPAN=2>Consumer?</TD>
178     <TD COLSPAN=2>Advertised Speed (Mbps)</TD>
179     <TD ROWSPAN=2>Business?</TD>
180     <TD COLSPAN=2>Contractual Speed (Mbps)</TD>
181   </TR>
182   <TR CLASS="subhead">
183     <TD>Down</TD>
184     <TD>Up</TD>
185     <TD>Down</TD>
186     <TD>Up</TD>
187   </TR>
188 </%def>
189 <%def .header_fbs>
190   <TR CLASS="head">
191     <TD ROWSPAN=2>Census Tract</TD>
192     <TD ROWSPAN=2>Technology</TD>
193     <TD COLSPAN=2>Speed (Mbps)</TD>
194     <TD COLSPAN=2>Subscriptions</TD>
195   </TR>
196   <TR CLASS="subhead">
197     <TD>Down</TD>
198     <TD>Up</TD>
199     <TD>Total</TD>
200     <TD>Consumer</TD>
201   </TR>
202 </%def>
203 <%def .header_fvs>
204   <TR CLASS="head">
205     <TD ROWSPAN=2>Census Tract</TD>
206     <TD ROWSPAN=2>VoIP?</TD>
207     <TD COLSPAN=2>Lines/Subscriptions</TD>
208   </TR>
209   <TR CLASS="subhead">
210     <TD>Total</TD>
211     <TD>Consumer</TD>
212   </TR>
213 </%def>
214 <%def .header_lts>
215   <TR CLASS="head">
216     <TD ROWSPAN=3>State</TD>
217     <TD COLSPAN=2>Wholesale</TD>
218     <TD COLSPAN=12>End User Lines</TD>
219   </TR>
220   <TR CLASS="subhead">
221     <TD ROWSPAN=2>VGEs</TD>
222     <TD ROWSPAN=2>UNE-Ls</TD>
223
224     <TD ROWSPAN=2>Total</TD>
225     <TD ROWSPAN=2>With Broadband</TD>
226     <TD COLSPAN=2>Consumer</TD>
227     <TD COLSPAN=2>Business</TD>
228
229     <TD COLSPAN=3>Local Loop</TD>
230
231     <TD COLSPAN=3>Special Media</TD>
232   </TR>
233
234   <TR CLASS="subhead">
235     <TD> </TD>
236     <TD>+LD</TD>
237     <TD> </TD>
238     <TD>+LD</TD>
239
240     <TD>Owned</TD>
241     <TD>UNE-L</TD>
242     <TD>Resale</TD>
243
244     <TD>Fiber</TD>
245     <TD>Coaxial</TD>
246     <TD>Wireless</TD>
247   </TR>
248 </%def>
249 <%def .header_voip>
250   <TR CLASS="head">
251     <TD ROWSPAN=3>State</TD>
252     <TD COLSPAN=2>VoIP OTT</TD>
253     <TD COLSPAN=8>VoIP Non-OTT</TD>
254   </TR>
255   <TR CLASS="subhead">
256     <TD ROWSPAN=2>Total</TD>
257     <TD ROWSPAN=2>Consumer</TD>
258
259     <TD ROWSPAN=2>Total</TD>
260     <TD ROWSPAN=2>Consumer</TD>
261     <TD ROWSPAN=2>Bundled</TD>
262     <TD COLSPAN=5>Media Type</TD>
263   </TR>
264   <TR CLASS="subhead">
265     <TD>Copper</TD>
266     <TD>Fiber</TD>
267     <TD>Coaxial</TD>
268     <TD>Wireless</TD>
269     <TD>Other</TD>
270   </TR>
271 </%def>
272 <%def .header_mbs>
273 %# unimplemented
274   <TR CLASS="head">
275     <TD ROWSPAN=2>State</TD>
276     <TD COLSPAN=2>Speed (Mbps)</TD>
277     <TD COLSPAN=2>Subscriptions</TD>
278   </TR>
279   <TR CLASS="subhead">
280     <TD>Down</TD>
281     <TD>Up</TD>
282     <TD>Total</TD>
283     <TD>Consumer</TD>
284   </TR>
285 </%def>
286 <%def .header_mvs>
287 %# unimplemented
288   <TR CLASS="head">
289     <TD ROWSPAN=2>State</TD>
290     <TD COLSPAN=2>Subscriptions</TD>
291   </TR>
292   <TR CLASS="subhead">
293     <TD>Total</TD>
294     <TD>Direct</TD>
295   </TR>
296 </%def>
297