improve usage_class_summary with number of calls and total minutes, #37122
[freeside.git] / conf / invoice_html
1 <STYLE TYPE="text/css">
2 .invoice {
3   font-family: sans-serif;
4   font-size: 10pt;
5   display: inline-block;
6   padding: 4pt;
7   border: 1px solid black;
8   background-color: white;
9   min-width: 625px;
10   position: relative;
11 }
12 .invoice_header {
13   font-size: 10pt;
14   border-spacing: 4pt;
15 }
16 .invoice_headerright TH { border-top: 2px solid #000000; border-bottom: 2px solid #000000 }
17 .invoice_headerright TD { font-size: 10pt; empty-cells: show }
18 .invoice_summary TH { border-bottom: 2px solid #000000 }
19 .invoice_summary TD { font-size: 10pt; empty-cells: show }
20 .invoice_longtable table { cellspacing: none }
21 .invoice_longtable TH { border-top: 2px solid #000000; border-bottom: 1px solid #000000; padding-left: none; padding-right: none; font-size: 10pt }
22 .invoice_desc TD { border-top: 2px solid #000000; font-weight: bold; font-size: 10pt }
23 .invoice_desc_more TD { font-weight: bold; font-size: 10pt }
24 .invoice_extdesc TD { font-size: 8pt }
25 .invoice_totaldesc TD { font-size: 10pt; empty-cells: show }
26 .allcaps { text-transform:uppercase; font-size: 12pt }
27 .watermark-box {
28   z-index: 10;
29   position: absolute;
30   text-align: center;
31   padding: 0;
32   filter: alpha(opacity=25);
33   opacity: 0.25;
34   width: 100%;
35   height: 100%;
36   display: table;
37   pointer-events: none;
38 }
39 .watermark-content {
40   display: table-cell;
41   vertical-align: middle;
42   font-size: 96pt;
43 }
44 </STYLE>
45
46 <div class="invoice">
47
48   <DIV CLASS="watermark-box"><DIV CLASS="watermark-content">
49       <%= $watermark %>
50   </DIV></DIV>
51
52   <table class="invoice_header" width="100%">
53     <tr>
54      <td><img src="<%= $cid ? "cid:$cid" : "cust_bill-logo.cgi?invnum=$invnum;template=$template" %>"></td>
55      <td align="left"><%= $returnaddress %></td>
56       <td align="right">
57         <table CLASS="invoice_headerright" cellspacing=0>
58           <tr>
59             <td align="center">
60               <%= emt('Invoice date') %><BR>
61               <B><%= $date %></B>
62             </td>
63             <td>
64             </td>
65             <td align="center">
66               <%= emt('Invoice #') %><BR>
67               <B><%= $invnum %></B>
68             </td>
69             <td>
70             </td>
71             <td align="center">
72               <%= emt('Customer #') %><BR>
73               <B><%= $custnum %></B>
74             </td>
75           </tr>
76           <tr>
77             <th>&nbsp;</th>
78             <th colspan=3 align="center" class="allcaps">
79               <FONT SIZE="+3"><%= substr(emt($notice_name),0,1) %></FONT><FONT SIZE="+2"><%= substr(emt($notice_name),1) %></FONT>
80             </th>
81             <th>&nbsp;</th>
82           </tr>
83         </table>
84       </td>
85     </tr>
86
87     <tr>
88       <td>
89       </td>
90       <td align="left">
91         <b><%= $payname %></b><BR>
92         <%= join('<BR>', grep length($_), $company,
93                                           $address1,
94                                           $address2,
95                                           "$city,&nbsp;$state&nbsp;&nbsp;$zip",
96                                           $country,
97                 )
98         %>
99       </td>
100       <%= $ship_enable ? ('<td align="left">'.
101                           join('<BR>',grep length($_), '<b>'.emt('Service Address').'</b>',
102                                                        $ship_company,
103                                                        $ship_address1,
104                                                        $ship_address2,
105                                                        "$ship_city,&nbsp;$ship_state&nbsp;$ship_zip",
106                                                        $ship_country,
107                                                        ' ',
108                                                        ' ',
109                               ).
110                            '</td><tr><td></td><td></td>'
111                          )
112                        : ''
113       %>
114       <td align="right">
115     <%=
116         if($barcode_cid) {
117             $OUT .= qq! <img src="cid:$barcode_cid"><br> !;
118         }
119         elsif($barcode_img) {
120             $OUT .= qq! <img src="cust_bill-barcode.cgi?invnum=$invnum;template=$template"><br> !;
121         }
122     %>
123         <%= $terms ? emt('Terms') . ": $terms" : '' %><BR>
124         <%= $po_line %>
125       </td>
126     </tr>
127
128   </table>
129   <%= $summary %>
130   <%=
131       my $notfirst = 0;
132       my $columncount = $unitprices ? 5 : 3;
133       foreach my $section ( grep { !$summary || $_->{description} ne $finance_section } @sections ) {
134         if ($section->{'pretotal'} && !$summary) {
135           $OUT .= '</table>' if $notfirst;
136           $OUT .=
137             '<table width="100%"><tr><td>'.
138             '<p align="right"><b><font size="+1">'.
139             uc(substr($section->{'pretotal'},0,1)).
140             '</font><font size="+0">'. uc(substr($section->{'pretotal'},1)).
141             '</font></b>'.
142             '<p>'.
143             '</td></tr>';
144         }
145         unless ($section->{'summarized'}) {
146           $OUT .= '</table>' if ( $notfirst || $section->{'pretotal'} && !$summary );
147           $OUT .= '<table><tr><td>';
148           $OUT .= '<p class="allcaps"><b>';
149           my $sectionhead;
150           if ( $section->{'location'} ) {
151             $sectionhead .= $section->{'location'}{'label_prefix'}. ': '
152               if length($section->{'location'}{'label_prefix'});
153             $sectionhead = $section->{'location'}{'address1'};
154             $sectionhead .= ', '.$section->{'location'}{'address2'}
155               if length($section->{'location'}{'address2'});
156             $sectionhead .= ', ' .
157                             $section->{'location'}{'city'} . ', ' .
158                             $section->{'location'}{'state'} . ' ' .
159                             $section->{'location'}{'zip'};
160             $OUT .= $sectionhead;
161           } else {
162             $sectionhead = $section->{'description'} || emt('Charges');
163             $OUT .= '<font size="+1">'. substr($sectionhead,0,1).
164               '</font><font size="+0">'. substr($sectionhead,1).
165           
166               '</font>';
167           }
168           $OUT .= '</b></p></td></tr></table>';
169
170           $OUT .=
171             '<table class="invoice_longtable" CELLSPACING=0 WIDTH="100%">'.
172             '<tr>';
173
174           if ($section->{header_generator}) {
175             my $header = &{$section->{header_generator}}();
176             $OUT .= $header;
177             $columncount = scalar(my @array = split /<\/th><th/i, $header);
178           } else {
179             my @headings = ( '', 'Description', 'Amount' );
180             my @aligns = ( 'center', 'left', 'right' );
181             if ( $unitprices ) {
182               splice @headings, 2, 0, 'Unit Price', 'Quantity';
183               splice @aligns,   2, 0, 'right', 'right';
184             }
185             if ( $section->{usage_section} ) {
186               @headings = ( '', 'Description', 'Calls', 'Duration', 'Amount' );
187               @aligns = ( '', 'left', 'right', 'right', 'right' );
188               $columncount = 5;
189             }
190
191             while ( @headings ) {
192               my $heading = shift @headings;
193               $heading = emt($heading) if $heading;
194               my $align = shift @aligns;
195               $OUT .= '
196                 <th align="' . $align . '">' . $heading . '</th>';
197             }
198           }
199
200           $OUT .= '</tr>';
201
202           my $lastref = 0;
203           foreach my $line (
204             grep { ( scalar(@sections) > 1 
205                    ? $section->{'description'} eq $_->{'section'}->{'description'}
206                    : 1
207                  ) }
208             @detail_items )
209           {
210             if ( $section->{description_generator} ) {
211               $OUT .= '<tr class="invoice_desc' .
212                       &{$section->{description_generator}}($line);
213             } elsif ( $section->{usage_section} ) {
214               my $minutes = sprintf('%d', $line->{'duration'} / 60);
215               my $seconds = $line->{'duration'} % 60;
216               $OUT .= '
217                 <tr class="invoice_desc_more">
218                   <td></td>
219                   <td align="left">' . $line->{'description'} . '</td>
220                   <td align="right">' . $line->{'quantity'} . '</td>
221                   <td align="right">' . $minutes . 'm ' . $seconds . 's' . '</td>
222                   <td align="right">' . $line->{'amount'} . '</td>
223                 </tr>';
224             } else {
225               my $class = 'invoice_desc_more';
226               if ( ($line->{'ref'} || 0) ne $lastref ) {
227                 # then it's a new package (not a continuation)
228                 $class = 'invoice_desc';
229               }
230               $OUT .= '<tr class="'.$class.'">
231                        <td align="center">';
232               $OUT .= '</td>
233                        <td align="left">'. $line->{'description'}. '</td>';
234               if ( $unitprices ) {
235                 $OUT .= 
236                   '<td align="right">'. $line->{'unit_amount'}. '</td>'.
237                   '<td align="right">'. $line->{'quantity'}. '</td>';
238               }
239               $OUT .= '<td align="right">'. $line->{'amount'}. '</td>';
240             }
241             $OUT .= '</tr>';
242             $lastref = $line->{'ref'} || 0;
243             if ( @{$line->{'ext_description'} } ) {
244               unless ( $section->{description_generator} ) {
245                 $OUT .= '<tr class="invoice_extdesc"><td></td><td';
246                 $OUT .= $unitprices ? ' colspan=3' : '';
247                 $OUT .= '><table width="100%">';
248               }
249               foreach my $ext_desc ( @{$line->{'ext_description'} } ) {
250                 $OUT .=
251                   '<tr class="invoice_extdesc">'.
252                     ( $section->{'description_generator'} ? '<td></td>' : '' ).
253                     '<td align="left" '.
254                          ( $ext_desc =~ /<\/?TD>/i ? '' : 'colspan=99' ). '>'.
255                       '&nbsp;&nbsp;'. $ext_desc.
256                     '</td>'.
257                   '</tr>'
258               }
259               unless ( $section->{description_generator} ) {
260                 $OUT .= '</table></td><td></td>';
261               }
262               $OUT .= '</tr>';
263             }
264           }
265
266
267           if ($section->{'description'} || $multisection and !$section->{no_subtotal}) {
268             my $style = 'border-top: 3px solid #000000;'.
269                         'border-bottom: 3px solid #000000;';
270             $OUT .=
271               '<tr class="invoice_totaldesc">'.
272               qq(<td style="$style">&nbsp;</td>);
273             if ($section->{total_generator}) {
274               $OUT .= &{$section->{total_generator}}($section);
275             } else {
276               $OUT .= qq(<td align="left" style="$style"). 
277                       ( $unitprices ? ' colspan=3>' : '>' ).
278                       $section->{'description'}. ' ' . emt('Total') . '</td>'.
279                       qq(<td align="right" style="$style">).
280                       $section->{'subtotal'}. '</td>';
281             }
282             $OUT .= '</tr>';
283           }
284         } # if !$section->{summarized}
285         if ($section->{'posttotal'}) {
286           $OUT .= '<tr><td align="right" colspan='. $columncount. '>';
287           $OUT .=
288             '<p><font size="+1">'. $section->{'posttotal'}.
289             '</font>'.
290             '<p>';
291           $OUT .= '</td></tr>';
292         }
293
294         $notfirst++;
295
296       }
297
298       my $style = 'border-top: 3px solid #000000;';
299       my $linenum = 0;
300
301       foreach my $line ( @total_items ) {
302
303         $style .= 'border-bottom: 3px solid #000000;'
304           if ++$linenum == scalar(@total_items) - ( $balance_due_below_line ? 1 : 0 );
305
306         $OUT .=
307           '<tr class="invoice_totaldesc">';
308         if ($section->{total_line_generator}) {
309           $OUT .= &{$section->{total_line_generator}}($line);
310         } else {
311           $OUT .= qq(<td style="$style">&nbsp;</td>).
312                   qq(<td align="left" style="$style" colspan=").
313                     ( $columncount - 2 ). '">'.
314                     $line->{'total_item'}. '</td>'.
315                   qq(<td align="right" style="$style">).
316                     $line->{'total_amount'}. '</td>';
317         }
318         $OUT .= '</tr>';
319
320         $style='';
321
322       }
323
324     %>
325   </table>
326   <br><br>
327
328 <%= length($summary)
329       ? ''
330       : ( $smallernotes
331             ? '<FONT SIZE="-1">'.$notes.'</FONT>'
332             : $notes
333         )
334 %>
335
336   <hr NOSHADE SIZE=2 COLOR="#000000">
337   <p align="center" <%= $smallerfooter ? 'STYLE="font-size:75%;"' : '' %>><%= $footer %>
338
339 </div>