html invoices!
[freeside.git] / httemplate / view / cust_bill.cgi
index 3c23d60..5dd8a8d 100755 (executable)
@@ -4,9 +4,11 @@
 #untaint invnum
 my($query) = $cgi->keywords;
 $query =~ /^((.+)-)?(\d+)$/;
-my $templatename = $1;
+my $templatename = $2;
 my $invnum = $3;
 
+my $conf = new FS::Conf;
+
 my $cust_bill = qsearchs('cust_bill',{'invnum'=>$invnum});
 die "Invoice #$invnum not found!" unless $cust_bill;
 my $custnum = $cust_bill->getfield('custnum');
@@ -27,48 +29,60 @@ if ( grep { $_ ne 'POST' } $cust_bill->cust_main->invoicing_list ) {
         qq!Re-email this invoice</A>!;
 }
 
+print qq! | <A HREF="${p}misc/fax-invoice.cgi?$invnum">Refax this invoice</A>!
+  if ($conf->exists('hylafax'));
+
 print '<BR><BR>';
 
-my $conf = new FS::Conf;
 if ( $conf->exists('invoice_latex') ) {
+  my $link = "${p}view/cust_bill-pdf.cgi?";
+  $link .= "$templatename-" if $templatename;
+  $link .= "$invnum.pdf";
   print menubar(
-    'View typeset invoice' => "${p}view/cust_bill-pdf.cgi?$invnum.pdf",
+    'View typeset invoice' => $link,
   ), '<BR><BR>';
 }
 
 #false laziness with search/cust_bill_event.cgi
 
-print table(). '<TR><TH>Event</TH><TH>Date</TH><TH>Status</TH></TR>';
-foreach my $cust_bill_event (
-  sort { $a->_date <=> $b->_date } $cust_bill->cust_bill_event
-) {
-  my $status = $cust_bill_event->status;
-  $status .= ': '. $cust_bill_event->statustext if $cust_bill_event->statustext;
-  my $part_bill_event = $cust_bill_event->part_bill_event;
-  print '<TR><TD>'. $part_bill_event->event;
-
-  if (
-    $part_bill_event->plan eq 'send_alternate'
-    && $part_bill_event->plandata =~ /^templatename (.*)$/m
+unless ( $templatename ) {
+  print table(). '<TR><TH>Event</TH><TH>Date</TH><TH>Status</TH></TR>';
+  foreach my $cust_bill_event (
+    sort { $a->_date <=> $b->_date } $cust_bill->cust_bill_event
   ) {
-    my $templatename = $1;
-    print qq! ( <A HREF="${p}view/cust_bill.cgi?$templatename-$invnum">!.
-          'view text</A> | '.
-          qq!<A HREF="${p}view/cust_bill-pdf.cgi?$templatename-$invnum.pdf">!.
-          'view typeset</A> )';
+    my $status = $cust_bill_event->status;
+    $status .= ': '. encode_entities($cust_bill_event->statustext)
+      if $cust_bill_event->statustext;
+    my $part_bill_event = $cust_bill_event->part_bill_event;
+    print '<TR><TD>'. $part_bill_event->event;
+  
+    if (
+      $part_bill_event->plan eq 'send_alternate'
+      && $part_bill_event->plandata =~ /^templatename (.*)$/m
+    ) {
+      my $templatename = $1;
+      print qq! ( <A HREF="${p}view/cust_bill.cgi?$templatename-$invnum">!.
+            'view</A> | '.
+            qq!<A HREF="${p}view/cust_bill-pdf.cgi?$templatename-$invnum.pdf">!.
+            'view typeset</A> )';
+    }
+  
+    print '</TD><TD>'.
+          time2str("%a %b %e %T %Y", $cust_bill_event->_date). '</TD><TD>'.
+          $status. '</TD></TR>';
   }
-
-  print '</TD><TD>'.
-        time2str("%a %b %e %T %Y", $cust_bill_event->_date). '</TD><TD>'.
-        $status. '</TD></TR>';
+  print '</TABLE><BR>';
 }
-print '</TABLE><BR><PRE>';
 
-print $cust_bill->print_text('', $templatename);
+if ( $conf->exists('invoice_html') ) {
+  print $cust_bill->print_html('', $templatename);
+} else {
+  print '<PRE>', $cust_bill->print_text('', $templatename), '</PRE>';
+}
 
        #formatting
        print <<END;
-    </PRE></FONT>
+    </FONT>
   </BODY>
 </HTML>
 END