proper use of date_format config for international date formats, RT#7009
[freeside.git] / httemplate / view / cust_main / payment_history / credit.html
index bf76945..75038cc 100644 (file)
@@ -4,41 +4,72 @@ by <% $cust_credit->otaker %><% "$reason$desc$apply$delete$unapply" %>
 
 my( $cust_credit, %opt ) = @_;
 
+my $date_format = $opt{'date_format'} || '%m/%d/%Y';
+
+my $conf = new FS::Conf;
 my $curuser = $FS::CurrentUser::CurrentUser;
 
 my @cust_credit_bill = $cust_credit->cust_credit_bill;
 my @cust_credit_refund = $cust_credit->cust_credit_refund;
 
-my( $pre, $post, $desc, $apply, $ext ) = ( '', '', '', '', '' );
+my $desc = '';
+if ( $opt{'pkg-balances'} && $cust_credit->pkgnum ) {
+  my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cust_credit->pkgnum } );
+  $desc .= ' for '. $cust_pkg->pkg_label_long;
+}
+
+my %cust_credit_bill_width = ('width' => 392);
+my %cust_credit_bill_height = ();
+if ($conf->exists('cust_credit_bill_pkg-manual')) {
+  %cust_credit_bill_width = ('width' => 592);
+  %cust_credit_bill_height = ('height' => 436);
+}
+
+my( $pre, $post, $apply, $ext ) = ( '', '', '', '' );
 if (    scalar(@cust_credit_bill)   == 0
      && scalar(@cust_credit_refund) == 0 ) {
   #completely unapplied
   $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
   $post = '</FONT></B>';
   if ( $curuser->access_right('Apply credit') ) {
-    $apply = ' ('. include( '/elements/popup_link.html',
-                              'label'    => 'apply',
-                              'action'   => "${p}edit/cust_credit_bill.cgi?".
-                                            $cust_credit->crednum,
-                              'actionlabel' => 'Apply credit',
-                              'width'    => 392,
-                              #default# 'height' => 336,
-                          ).
-              ')';
+    if ( $cust_credit->cust_main->total_owed > 0 ) {
+      $apply = ' ('.
+               include( '/elements/popup_link.html',
+                          'label'    => 'apply',
+                          'action'   => "${p}edit/cust_credit_bill.cgi?".
+                                        $cust_credit->crednum,
+                          'actionlabel' => 'Apply credit',
+                          %cust_credit_bill_width,
+                          %cust_credit_bill_height,
+                      ).
+                ')';
+    }
+    if ( $cust_credit->cust_main->total_unapplied_refunds > 0 ) {
+      $apply.= ' ('.
+               include( '/elements/popup_link.html',
+                          'label'    => 'apply to refund',
+                          'action'   => "${p}edit/cust_credit_refund.cgi?".
+                                        $cust_credit->crednum,
+                          'actionlabel' => 'Apply credit to refund',
+                          'width'    => 392,
+                          #default# 'height' => 336,
+                      ).
+               ')';
+    }
   }
 } elsif (    scalar(@cust_credit_bill)   == 1
           && scalar(@cust_credit_refund) == 0
           && $cust_credit->credited == 0      ) {
   #applied to one invoice, the usual situation
-  $desc = ' '. $cust_credit_bill[0]->applied_to_invoice;
+  $desc .= ' '. $cust_credit_bill[0]->applied_to_invoice;
 } elsif (    scalar(@cust_credit_bill)   == 0
           && scalar(@cust_credit_refund) == 1
           && $cust_credit->credited == 0      ) {
   #applied to one refund
-  $desc = ' refunded on '.  time2str("%D", $cust_credit_refund[0]->_date);
+  $desc .= ' refunded on '.  time2str($date_format, $cust_credit_refund[0]->_date);
 } else {
   #complicated
-  $desc = '<BR>';
+  $desc .= '<BR>';
   foreach my $app ( sort { $a->_date <=> $b->_date }
                          ( @cust_credit_bill, @cust_credit_refund ) ) {
     if ( $app->isa('FS::cust_credit_bill') ) {
@@ -46,11 +77,11 @@ if (    scalar(@cust_credit_bill)   == 0
                '$'. $app->amount.
                ' '. $app->applied_to_invoice.
                '<BR>';
-               #' on '. time2str("%D", $app->_date).
+               #' on '. time2str($date_format, $app->_date).
     } elsif ( $app->isa('FS::cust_credit_refund') ) {
       $desc .= '&nbsp;&nbsp;'.
                '$'. $app->amount.
-               ' refunded on '. time2str("%D", $app->_date).
+               ' refunded on '. time2str($date_format, $app->_date).
                '<BR>';
     } else {
       die "$app is not a FS::cust_credit_bill or a FS::cust_credit_refund";
@@ -60,15 +91,30 @@ if (    scalar(@cust_credit_bill)   == 0
     $desc .= '&nbsp;&nbsp;<B><FONT COLOR="#FF0000">$'.
              $cust_credit->credited. ' unapplied</FONT></B>';
     if ( $curuser->access_right('Apply credit') ) {
-      $desc = ' ('. include( '/elements/popup_link.html',
-                              'label'       => 'apply',
-                              'action'      => "${p}edit/cust_credit_bill.cgi?".
-                                               $cust_credit->crednum,
-                              'actionlabel' => 'Apply credit',
-                              'width'       => 392,
-                              #default# 'height' => 336,
-                          ).
-              ')';
+      if ( $cust_credit->cust_main->total_owed > 0 ) {
+        $apply = ' ('.
+                 include( '/elements/popup_link.html',
+                            'label'       => 'apply',
+                            'action'      => "${p}edit/cust_credit_bill.cgi?".
+                                             $cust_credit->crednum,
+                            'actionlabel' => 'Apply credit',
+                            %cust_credit_bill_width,
+                            %cust_credit_bill_height,
+                        ).
+                 ')';
+      }
+      if ( $cust_credit->cust_main->total_unapplied_refunds > 0 ) {
+        $apply.= ' ('.
+                 include( '/elements/popup_link.html',
+                            'label'       => 'apply to refund',
+                            'action'      => "${p}edit/cust_credit_refund.cgi?".
+                                             $cust_credit->crednum,
+                            'actionlabel' => 'Apply credit to refund',
+                            'width'       => 392,
+                            #default# 'height' => 336,
+                        ).
+                 ')';
+      }
     }
     $desc .= '<BR>';
   }