internationalization/localization, RT12515
[freeside.git] / httemplate / view / cust_main / payment_history / credit.html
1 <% $credit %>
2 <% "$reason$desc$apply$delete$unapply" %>
3 <%init>
4
5 my( $cust_credit, %opt ) = @_;
6
7 my $date_format = $opt{'date_format'} || '%m/%d/%Y';
8
9 my $conf = new FS::Conf;
10 my $money_char = $conf->config('money_char') || '$';
11 my $curuser = $FS::CurrentUser::CurrentUser;
12
13 my @cust_credit_bill = $cust_credit->cust_credit_bill;
14 my @cust_credit_refund = $cust_credit->cust_credit_refund;
15
16 my $desc = '';
17 if ( $opt{'pkg-balances'} && $cust_credit->pkgnum ) {
18   my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cust_credit->pkgnum } );
19   $desc .= ' for '. $cust_pkg->pkg_label_long;
20 }
21
22 my %cust_credit_bill_width = ('width' => 392);
23 my %cust_credit_bill_height = ();
24 if ($conf->exists('cust_credit_bill_pkg-manual')) {
25   %cust_credit_bill_width = ('width' => 592);
26   %cust_credit_bill_height = ('height' => 436);
27 }
28
29 my( $apply, $ext ) = ( '', '', '', '' );
30 my $credit = mt("Credit by [_1]", $cust_credit->otaker );
31 if (    scalar(@cust_credit_bill)   == 0
32      && scalar(@cust_credit_refund) == 0 ) {
33   #completely unapplied
34   $credit = '<B><FONT COLOR="#FF0000">'
35         . mt("Unapplied Credit by [_1]", $cust_credit->otaker )
36         . '</FONT></B>';
37   if ( $curuser->access_right('Apply credit') ) {
38     if ( $cust_credit->cust_main->total_owed > 0 ) {
39       $apply = ' ('.
40                include( '/elements/popup_link.html',
41                           'label'    => mt('apply'),
42                           'action'   => "${p}edit/cust_credit_bill.cgi?".
43                                         $cust_credit->crednum,
44                           'actionlabel' => mt('Apply credit'),
45                           %cust_credit_bill_width,
46                           %cust_credit_bill_height,
47                       ).
48                 ')';
49     }
50     if ( $cust_credit->cust_main->total_unapplied_refunds > 0 ) {
51       $apply.= ' ('.
52                include( '/elements/popup_link.html',
53                           'label'    => mt('apply to refund'),
54                           'action'   => "${p}edit/cust_credit_refund.cgi?".
55                                         $cust_credit->crednum,
56                           'actionlabel' => mt('Apply credit to refund'),
57                           'width'    => 392,
58                       ).
59                ')';
60     }
61   }
62 } elsif (    scalar(@cust_credit_bill)   == 1
63           && scalar(@cust_credit_refund) == 0
64           && $cust_credit->credited == 0      ) {
65   #applied to one invoice, the usual situation
66   $desc .= ' '. $cust_credit_bill[0]->applied_to_invoice;
67 } elsif (    scalar(@cust_credit_bill)   == 0
68           && scalar(@cust_credit_refund) == 1
69           && $cust_credit->credited == 0      ) {
70   #applied to one refund
71   $desc .= mt(" refunded on [_1]", time2str($date_format, $cust_credit_refund[0]->_date) );
72 } else {
73   #complicated
74   $desc .= '<BR>';
75   foreach my $app ( sort { $a->_date <=> $b->_date }
76                          ( @cust_credit_bill, @cust_credit_refund ) ) {
77     if ( $app->isa('FS::cust_credit_bill') ) {
78       $desc .= '&nbsp;&nbsp;' . $money_char . $app->amount . ' '
79                     . $app->applied_to_invoice . '<BR>';
80     } elsif ( $app->isa('FS::cust_credit_refund') ) {
81       $desc .= '&nbsp;&nbsp;' .
82                mt("[_1][_2] refunded on [_3]", $money_char, $app->amount,
83                     time2str($date_format, $app->_date) ) . '<BR>';
84     } else {
85       die "$app is not a FS::cust_credit_bill or a FS::cust_credit_refund";
86     }
87   }
88   if ( $cust_credit->credited > 0 ) {
89     $desc .= '&nbsp;&nbsp;<B><FONT COLOR="#FF0000">' .
90               mt("[_1][_2] unapplied", $money_char, $cust_credit->credited) .
91               '</FONT></B>';
92     if ( $curuser->access_right('Apply credit') ) {
93       if ( $cust_credit->cust_main->total_owed > 0 ) {
94         $apply = ' ('.
95                  include( '/elements/popup_link.html',
96                             'label'       => mt('apply'),
97                             'action'      => "${p}edit/cust_credit_bill.cgi?".
98                                              $cust_credit->crednum,
99                             'actionlabel' => mt('Apply credit'),
100                             %cust_credit_bill_width,
101                             %cust_credit_bill_height,
102                         ).
103                  ')';
104       }
105       if ( $cust_credit->cust_main->total_unapplied_refunds > 0 ) {
106         $apply.= ' ('.
107                  include( '/elements/popup_link.html',
108                             'label'       => mt('apply to refund'),
109                             'action'      => "${p}edit/cust_credit_refund.cgi?".
110                                              $cust_credit->crednum,
111                             'actionlabel' => mt('Apply credit to refund'),
112                             'width'       => 392,
113                         ).
114                  ')';
115       }
116     }
117     $desc .= '<BR>';
118   }
119 }
120 #
121 my $delete = '';
122 $delete = areyousure_link("${p}misc/delete-cust_credit.cgi?".$cust_credit->crednum,
123                             mt('Are you sure you want to delete this credit?'),
124                             '',
125                             mt('delete')
126                           )
127 if ( $cust_credit->closed !~ /^Y/i && $curuser->access_right('Delete credit') );
128
129 my $unapply = '';
130 $unapply = areyousure_link("${p}misc/unapply-cust_credit.cgi?".$cust_credit->crednum,
131                             mt('Are you sure you want to unapply this credit?'),
132                             '',
133                             mt('unapply')
134                           )
135 if ( $cust_credit->closed !~ /^Y/i && scalar(@cust_credit_bill)
136      && $curuser->access_right('Unapply credit') );
137
138 my $reason = $cust_credit->reason
139                ? ' ('. $cust_credit->reason. ')'
140                : '';
141
142 </%init>
143