add cust_credit_bill relating multiple invoices to credits
[freeside.git] / httemplate / view / cust_main.cgi
index 8b6fb0c..492183d 100755 (executable)
@@ -1,5 +1,5 @@
 <%
-#<!-- $Id: cust_main.cgi,v 1.3 2001-08-11 05:52:56 ivan Exp $ -->
+#<!-- $Id: cust_main.cgi,v 1.6 2001-09-01 21:52:20 jeff Exp $ -->
 
 use strict;
 use vars qw ( $cgi $query $custnum $cust_main $hashref $agent $referral 
@@ -43,8 +43,18 @@ print qq!<A HREF="!, popurl(2),
 print qq! | <A HREF="!, popurl(2), 
       qq!misc/delete-customer.cgi?$custnum"> Delete this customer</A>!
   if $conf->exists('deletecustomers');
-print '<BR><BR>';
 
+unless ( $conf->exists('disable_customer_referrals') ) {
+  print qq! | <A HREF="!, popurl(2),
+        qq!edit/cust_main.cgi?referral_custnum=$custnum">!,
+        qq!Refer a new customer</A>!;
+
+  print qq! | <A HREF="!, popurl(2),
+        qq!search/cust_main.cgi?referral_custnum=$custnum">!,
+        qq!View this customer's referrals<A>!;
+}
+
+print '<BR><BR>';
 print '<A NAME="cust_main"></A>';
 
 print &itable(), '<TR>';
@@ -158,6 +168,22 @@ print '<TD VALIGN="top">';
   print '<TR><TD ALIGN="right">Order taker</TD><TD BGCOLOR="#ffffff">',
     $cust_main->otaker, '</TD></TR>';
 
+  print '<TR><TD ALIGN="right">Referring Customer</TD><TD BGCOLOR="#ffffff">';
+  my $referring_cust_main = '';
+  if ( $cust_main->referral_custnum
+       && ( $referring_cust_main =
+            qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
+          )
+     ) {
+    print '<A HREF="'. popurl(1). 'cust_main.cgi?'.
+          $cust_main->referral_custnum. '">'.
+          $cust_main->referral_custnum. ': '.
+          ( $referring_cust_main->company
+            || $referring_cust_main->last. ', '. $referring_cust_main->first ).
+          '</A>';
+  }
+  print '</TD></TR>';
+
   print '</TABLE></TD></TR></TABLE>';
 
 print '<BR>';
@@ -210,7 +236,9 @@ print '<BR>';
 
 print '</TD></TR></TABLE>';
 
-if ( defined $cust_main->dbdef_table->column('comments') ) {
+if ( defined $cust_main->dbdef_table->column('comments')
+     && $cust_main->comments )
+{
   print "<BR>Comments", &ntable("#cccccc"), "<TR><TD>",
         &ntable("#cccccc",2),
         '<TR><TD BGCOLOR="#ffffff"><PRE>', $cust_main->comments,
@@ -329,9 +357,15 @@ foreach $bill (@bills) {
 @credits = qsearch('cust_credit',{'custnum'=>$custnum});
 foreach $credit (@credits) {
   my($cref)=$credit->hashref;
+  my($credited)=$credit->credited;
   push @history,
-    $cref->{_date} . "\tCredit #" . $cref->{crednum} . ", (Balance \$" .
-    $cref->{credited} . ") by " . $cref->{otaker} . " - " .
+    $cref->{_date} . "\t" .
+    ($credited ?
+       (qq!<A HREF="! . popurl(2). qq!edit/cust_credit_bill.cgi?!. $cref->{crednum} . qq!">!) :
+       "") .
+    "Credit #" .
+    $cref->{crednum} . ", (Balance \$" .
+    $credited . ")" . ($credited ? "</A>" : "") .
     $cref->{reason} . "\t\t\t" . $cref->{amount} . "\t";
 
   my(@refunds)=qsearch('cust_refund',{'crednum'=> $cref->{crednum} } );