+ my $lastref = 0;
+ foreach my $line (
+ grep { ( scalar(@sections) > 1
+ ? $section->{'description'} eq $_->{'section'}->{'description'}
+ : 1
+ ) }
+ @detail_items )
+ {
+ if ( $section->{description_generator} ) {
+ $OUT .= '<tr class="invoice_desc' .
+ &{$section->{description_generator}}($line);
+ } else {
+ my $class = 'invoice_desc_more';
+ if ( $line->{'ref'} and $line->{'ref'} ne $lastref ) {
+ # then it's a new package (not a continuation)
+ $class = 'invoice_desc';
+ }
+ $OUT .= '<tr class="'.$class.'">
+ <td align="center">';
+ #if ( $line->{'ref'} ne $lastref ) {
+ # $OUT .= $line->{'ref'};
+ #}
+ $OUT .= '</td>
+ <td align="left">'. $line->{'description'}. '</td>';
+ if ( $unitprices ) {
+ $OUT .=
+ '<td align="right">'. $line->{'unit_amount'}. '</td>'.
+ '<td align="right">'. $line->{'quantity'}. '</td>';
+ }
+ $OUT .= '<td align="right">'. $line->{'amount'}. '</td>';
+ }
+ $OUT .= '</tr>';
+ $lastref = $line->{'ref'};
+ if ( @{$line->{'ext_description'} } ) {
+ unless ( $section->{description_generator} ) {
+ $OUT .= '<tr class="invoice_extdesc"><td></td><td';
+ $OUT .= $unitprices ? ' colspan=3' : '';
+ $OUT .= '><table width="100%">';
+ }
+ foreach my $ext_desc ( @{$line->{'ext_description'} } ) {
+ $OUT .=
+ '<tr class="invoice_extdesc">'.
+ ( $section->{'description_generator'} ? '<td></td>' : '' ).
+ '<td align="left" '.
+ ( $ext_desc =~ /<\/?TD>/i ? '' : 'colspan=99' ). '>'.
+ ' '. $ext_desc.
+ '</td>'.
+ '</tr>'
+ }
+ unless ( $section->{description_generator} ) {
+ $OUT .= '</table></td><td></td>';
+ }
+ $OUT .= '</tr>';
+ }
+ }