RT#37908: Convert existing email-sending code to use common interface [removals and...
[freeside.git] / httemplate / view / cust_main / payment_history / credit.html
index 88bbe9b..db2e5e5 100644 (file)
@@ -1,11 +1,9 @@
-<% $pre %>Credit<% $post %>
-by <% $cust_credit->otaker %><% "$reason$desc$apply$delete$unapply" %>
+<% $credit. ' '. $reason. $desc. $change_pkg. $apply . $unapply. $void %>
 <%init>
 
 my( $cust_credit, %opt ) = @_;
 
-my $conf = new FS::Conf;
-my $curuser = $FS::CurrentUser::CurrentUser;
+my $date_format = $opt{'date_format'} || '%m/%d/%Y';
 
 my @cust_credit_bill = $cust_credit->cust_credit_bill;
 my @cust_credit_refund = $cust_credit->cust_credit_refund;
@@ -18,39 +16,40 @@ if ( $opt{'pkg-balances'} && $cust_credit->pkgnum ) {
 
 my %cust_credit_bill_width = ('width' => 392);
 my %cust_credit_bill_height = ();
-if ($conf->exists('cust_credit_bill_pkg-manual')) {
+if ( $opt{'cust_credit_bill_pkg-manual'} ) {
   %cust_credit_bill_width = ('width' => 592);
   %cust_credit_bill_height = ('height' => 436);
 }
 
-my( $pre, $post, $apply, $ext ) = ( '', '', '', '' );
+my( $apply, $ext ) = ( '', '', '', '' );
+my $credit = emt("Credit by [_1]", $cust_credit->otaker );
 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') ) {
-    if ( $cust_credit->cust_main->total_owed > 0 ) {
+  $credit = '<B><FONT COLOR="#FF0000">'
+        . emt("Unapplied Credit by [_1]", $cust_credit->otaker )
+        . '</FONT></B>';
+  if ( $opt{'Apply credit'} ) {
+    if ( $opt{total_owed} > 0 ) {
       $apply = ' ('.
                include( '/elements/popup_link.html',
-                          'label'    => 'apply',
+                          'label'    => emt('apply'),
                           'action'   => "${p}edit/cust_credit_bill.cgi?".
                                         $cust_credit->crednum,
-                          'actionlabel' => 'Apply credit',
+                          'actionlabel' => emt('Apply credit'),
                           %cust_credit_bill_width,
                           %cust_credit_bill_height,
                       ).
                 ')';
     }
-    if ( $cust_credit->cust_main->total_unapplied_refunds > 0 ) {
+    if ( $opt{total_unapplied_refunds} > 0 ) {
       $apply.= ' ('.
                include( '/elements/popup_link.html',
-                          'label'    => 'apply to refund',
+                          'label'    => emt('apply to refund'),
                           'action'   => "${p}edit/cust_credit_refund.cgi?".
                                         $cust_credit->crednum,
-                          'actionlabel' => 'Apply credit to refund',
+                          'actionlabel' => emt('Apply credit to refund'),
                           'width'    => 392,
-                          #default# 'height' => 336,
                       ).
                ')';
     }
@@ -64,52 +63,48 @@ if (    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 .= emt(" refunded on [_1]", time2str($date_format, $cust_credit_refund[0]->_date) );
 } else {
   #complicated
   $desc .= '<BR>';
   foreach my $app ( sort { $a->_date <=> $b->_date }
                          ( @cust_credit_bill, @cust_credit_refund ) ) {
     if ( $app->isa('FS::cust_credit_bill') ) {
-      $desc .= '&nbsp;&nbsp;'.
-               '$'. $app->amount.
-               ' '. $app->applied_to_invoice.
-               '<BR>';
-               #' on '. time2str("%D", $app->_date).
+      $desc .= '&nbsp;&nbsp;' . $opt{money_char} . $app->amount . ' '
+                    . $app->applied_to_invoice . '<BR>';
     } elsif ( $app->isa('FS::cust_credit_refund') ) {
-      $desc .= '&nbsp;&nbsp;'.
-               '$'. $app->amount.
-               ' refunded on '. time2str("%D", $app->_date).
-               '<BR>';
+      $desc .= '&nbsp;&nbsp;' .
+               emt("[_1][_2] refunded on [_3]", $opt{money_char}, $app->amount,
+                    time2str($date_format, $app->_date) ) . '<BR>';
     } else {
       die "$app is not a FS::cust_credit_bill or a FS::cust_credit_refund";
     }
   }
   if ( $cust_credit->credited > 0 ) {
-    $desc .= '&nbsp;&nbsp;<B><FONT COLOR="#FF0000">$'.
-             $cust_credit->credited. ' unapplied</FONT></B>';
-    if ( $curuser->access_right('Apply credit') ) {
-      if ( $cust_credit->cust_main->total_owed > 0 ) {
+    $desc .= '&nbsp;&nbsp;<B><FONT COLOR="#FF0000">'.
+              emt("[_1][_2] unapplied",$opt{money_char},$cust_credit->credited).
+              '</FONT></B>';
+    if ( $opt{'Apply credit'} ) {
+      if ( $opt{total_owed} > 0 ) {
         $apply = ' ('.
                  include( '/elements/popup_link.html',
-                            'label'       => 'apply',
+                            'label'       => emt('apply'),
                             'action'      => "${p}edit/cust_credit_bill.cgi?".
                                              $cust_credit->crednum,
-                            'actionlabel' => 'Apply credit',
+                            'actionlabel' => emt('Apply credit'),
                             %cust_credit_bill_width,
                             %cust_credit_bill_height,
                         ).
                  ')';
       }
-      if ( $cust_credit->cust_main->total_unapplied_refunds > 0 ) {
+      if ( $opt{total_unapplied_refunds} > 0 ) {
         $apply.= ' ('.
                  include( '/elements/popup_link.html',
-                            'label'       => 'apply to refund',
+                            'label'       => emt('apply to refund'),
                             'action'      => "${p}edit/cust_credit_refund.cgi?".
                                              $cust_credit->crednum,
-                            'actionlabel' => 'Apply credit to refund',
+                            'actionlabel' => emt('Apply credit to refund'),
                             'width'       => 392,
-                            #default# 'height' => 336,
                         ).
                  ')';
       }
@@ -117,38 +112,44 @@ if (    scalar(@cust_credit_bill)   == 0
     $desc .= '<BR>';
   }
 }
-#
-my $delete = '';
-if ( $cust_credit->closed !~ /^Y/i
 
-     #s'pose deleting a credit isn't bad like deleting a payment
-     # and this needs to be generally available until we have credit voiding..
-     #&& $conf->exists('deletecredits')
-
-     && $curuser->access_right('Delete credit')
-   )
-{
-  $delete = qq! (<A HREF="javascript:areyousure('!.
-            qq!${p}misc/delete-cust_credit.cgi?!. $cust_credit->crednum.
-            qq!', 'Are you sure you want to delete this credit?')">!.
-            qq!delete</A>)!;
+my $change_pkg = '';
+if ( $apply && $opt{'pkg-balances'} && $cust_credit->pkgnum ) {
+  $change_pkg =
+  ' ('. include('/elements/popup_link.html',
+                  'label'       => emt('change package'),
+                  'action'      => "${p}edit/cust_credit-pkgnum.html?crednum=".
+                                    $cust_credit->crednum,
+                  'actionlabel' => emt('Change credit package'),
+                  'width'       => 763,
+               ).
+   ')';
 }
 
+my $void = '';
+$void = ' ('.
+               include( '/elements/popup_link.html',
+                    'label'    => emt('void'),
+                    'action'   => "${p}misc/void-cust_credit.html?".
+                                  $cust_credit->crednum,
+                    'actionlabel' => emt('Void credit'),
+                ).
+          ')'
+  if $cust_credit->closed !~ /^Y/i
+  && $opt{'Void credit'};
+
 my $unapply = '';
-if (    $cust_credit->closed !~ /^Y/i
-     && scalar(@cust_credit_bill)
-     && $curuser->access_right('Unapply credit')
-   )
-{
-  $unapply = qq! (<A HREF="javascript:areyousure('!.
-             qq!${p}misc/unapply-cust_credit.cgi?!. $cust_credit->crednum.
-             qq!', 'Are you sure you want to unapply this credit?')">!.
-             qq!unapply</A>)!;
-}
+$unapply = areyousure_link("${p}misc/unapply-cust_credit.cgi?".$cust_credit->crednum,
+                            emt('Are you sure you want to unapply this credit?'),
+                            '',
+                            emt('unapply')
+                          )
+  if $cust_credit->closed !~ /^Y/i
+  && scalar(@cust_credit_bill)
+  && $opt{'Unapply credit'};
 
-my $reason = $cust_credit->reason
-               ? ' ('. $cust_credit->reason. ')'
-               : '';
+my $reason = $cust_credit->reason;
+$reason = $reason ? " ($reason)" : '';
 
 </%init>