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