finish UI improvements wrt refunds: now you have to post a check or cash refund expli...
[freeside.git] / httemplate / view / cust_main / payment_history / payment.html
index b9a0694..346c0d0 100644 (file)
@@ -40,25 +40,30 @@ if (    scalar(@cust_bill_pay)   == 0
   $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
   $post = '</FONT></B>';
   if ( $curuser->access_right('Apply payment') ) {
-    $apply = ' ('. include( '/elements/popup_link.html',
-                              'label'       => 'apply',
-                              'action'      => "${p}edit/cust_bill_pay.cgi?".
-                                               $cust_pay->paynum,
-                              'actionlabel' => 'Apply payment',
-                              'width'       => 392,
-                              #default# 'height' => 336,
-                          ).
-              ')';
-    #XXX if there are any open refunds
-    $apply.= ' ('. include( '/elements/popup_link.html',
-                              'label'       => 'apply to refund',
-                              'action'      => "${p}edit/cust_pay_refund.cgi?".
-                                               $cust_pay->paynum,
-                              'actionlabel' => 'Apply payment to refund',
-                              'width'       => 392,
-                              #default# 'height' => 336,
-                          ).
-              ')';
+    if ( $cust_pay->cust_main->total_owed > 0 ) {
+      $apply = ' ('.
+               include( '/elements/popup_link.html',
+                          'label'       => 'apply',
+                          'action'      => "${p}edit/cust_bill_pay.cgi?".
+                                           $cust_pay->paynum,
+                          'actionlabel' => 'Apply payment',
+                          'width'       => 392,
+                          #default# 'height' => 336,
+                      ).
+                ')';
+    }
+    if ( $cust_pay->cust_main->total_unapplied_refunds > 0 ) {
+      $apply.= ' ('.
+               include( '/elements/popup_link.html',
+                          'label'       => 'apply to refund',
+                          'action'      => "${p}edit/cust_pay_refund.cgi?".
+                                           $cust_pay->paynum,
+                          'actionlabel' => 'Apply payment to refund',
+                          'width'       => 392,
+                          #default# 'height' => 336,
+                      ).
+               ')';
+    }
   }
 } elsif (    scalar(@cust_bill_pay)   == 1
           && scalar(@cust_pay_refund) == 0
@@ -95,25 +100,30 @@ if (    scalar(@cust_bill_pay)   == 0
              '<B><FONT COLOR="#FF0000">$'.
              $cust_pay->unapplied. ' unapplied</FONT></B>';
     if ( $curuser->access_right('Apply payment') ) {
-      $apply = ' ('. include( '/elements/popup_link.html',
-                                'label'      => 'apply',
-                                'action'     => "${p}edit/cust_bill_pay.cgi?".
-                                                $cust_pay->paynum,
-                                'actionlabel' => 'Apply payment',
-                                'width'      => 392,
-                                #default# 'height' => 336,
-                           ).
-               ')';
-      #XXX if there are any open refunds
-      $apply.= ' ('. include( '/elements/popup_link.html',
-                                'label'      => 'apply to refund',
-                                'action'     => "${p}edit/cust_pay_refund.cgi?".
-                                                $cust_pay->paynum,
-                                'actionlabel' => 'Apply payment to refund',
-                                'width'      => 392,
-                                #default# 'height' => 336,
-                           ).
-               ')';
+      if ( $cust_pay->cust_main->total_owed > 0 ) {
+        $apply = ' ('.
+                 include( '/elements/popup_link.html',
+                            'label'      => 'apply',
+                            'action'     => "${p}edit/cust_bill_pay.cgi?".
+                                            $cust_pay->paynum,
+                            'actionlabel' => 'Apply payment',
+                            'width'      => 392,
+                            #default# 'height' => 336,
+                        ).
+                 ')';
+      }
+      if ( $cust_pay->cust_main->total_unapplied_refunds > 0 ) {
+        $apply.= ' ('.
+                 include( '/elements/popup_link.html',
+                            'label'      => 'apply to refund',
+                            'action'     => "${p}edit/cust_pay_refund.cgi?".
+                                            $cust_pay->paynum,
+                            'actionlabel' => 'Apply payment to refund',
+                            'width'      => 392,
+                            #default# 'height' => 336,
+                        ).
+                 ')';
+      }
     }
     $desc .= '<BR>';
   }