internationalization/localization, RT12515
[freeside.git] / httemplate / view / cust_main / payment_history / payment.html
1 <% $payment %>
2 <% "$info$desc$view$apply$refund$void$delete$unapply" %>
3 <%init>
4
5 my( $cust_pay, %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 $payby = $cust_pay->payby;
13
14 my $payinfo;
15 if ( $payby eq 'CARD' ) {
16   $payinfo = $cust_pay->paymask;
17 } elsif ( $payby eq 'CHEK' ) {
18   my( $account, $aba ) = split('@', $cust_pay->paymask );
19   $payinfo = mt("ABA [_1], Acct #[_2]",$aba,$account);
20 } else {
21   $payinfo = $cust_pay->payinfo;
22 }
23 my @cust_bill_pay = $cust_pay->cust_bill_pay;
24 my @cust_pay_refund = $cust_pay->cust_pay_refund;
25
26 my $target = "$payby$payinfo";
27 $payby = translate_payby($payby,$payinfo);
28 my $info = $payby ? "($payby$payinfo)" : '';
29
30 my $desc = '';
31 if ( $opt{'pkg-balances'} && $cust_pay->pkgnum ) {
32   my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cust_pay->pkgnum } );
33   $desc .= ' for '. $cust_pkg->pkg_label_long;
34 }
35
36 my %cust_bill_pay_width = ('width' => 392);
37 my %cust_bill_pay_height = ();
38 if ($conf->exists('cust_bill_pay_pkg-manual')) {
39   %cust_bill_pay_width = ('width' => 592);
40   %cust_bill_pay_height = ('height' => 436);
41 }
42
43 my( $apply, $ext ) = ( '', '', '', '' );
44
45 my $otaker = $cust_pay->otaker;
46 $otaker = '<i>auto billing</i>'          if $otaker eq 'fs_daily';
47 $otaker = '<i>customer self-service</i>' if $otaker eq 'fs_selfservice';
48
49 my $payment = mt("Payment by [_1]",$otaker);
50
51 if (    scalar(@cust_bill_pay)   == 0
52      && scalar(@cust_pay_refund) == 0 ) {
53   #completely unapplied
54   $payment = '<B><FONT COLOR="#FF0000">' 
55                 . mt("Unapplied Payment by [_1]",$otaker)
56                 . '</FONT></B>';
57   if ( $curuser->access_right('Apply payment') ) {
58     if ( $cust_pay->cust_main->total_owed > 0 ) {
59       $apply = ' ('.
60                include( '/elements/popup_link.html',
61                           'label'       => mt('apply'),
62                           'action'      => "${p}edit/cust_bill_pay.cgi?".
63                                            $cust_pay->paynum,
64                           'actionlabel' => mt('Apply payment'),
65                           %cust_bill_pay_width,
66                           %cust_bill_pay_height,
67                       ).
68                 ')';
69     }
70     if ( $cust_pay->cust_main->total_unapplied_refunds > 0 ) {
71       $apply.= ' ('.
72                include( '/elements/popup_link.html',
73                           'label'       => mt('apply to refund'),
74                           'action'      => "${p}edit/cust_pay_refund.cgi?".
75                                            $cust_pay->paynum,
76                           'actionlabel' => mt('Apply payment to refund'),
77                           'width'       => 392,
78                       ).
79                ')';
80     }
81   }
82 } elsif (    scalar(@cust_bill_pay)   == 1
83           && scalar(@cust_pay_refund) == 0
84           && $cust_pay->unapplied == 0     ) {
85   #applied to one invoice, the usual situation
86   $desc .= ' '. $cust_bill_pay[0]->applied_to_invoice;
87 } elsif (    scalar(@cust_bill_pay)   == 0
88           && scalar(@cust_pay_refund) == 1
89           && $cust_pay->unapplied == 0     ) {
90   #applied to one refund
91   $desc .= mt(" refunded on [_1]", time2str($date_format, $cust_pay_refund[0]->_date) );
92 } else {
93   #complicated
94   $desc .= '<BR>';
95   foreach my $app ( sort { $a->_date <=> $b->_date }
96                          ( @cust_bill_pay, @cust_pay_refund ) ) {
97     if ( $app->isa('FS::cust_bill_pay') ) {
98       $desc .= '&nbsp;&nbsp;'.
99                '$'. $app->amount.
100                ' '. $app->applied_to_invoice.
101                '<BR>';
102                #' on '. time2str($date_format, $cust_bill_pay->_date).
103     } elsif ( $app->isa('FS::cust_pay_refund') ) {
104       $desc .= '&nbsp;&nbsp;'.
105                '$'. $app->amount.
106                mt(" refunded on [_1]", time2str($date_format, $app->_date) ) .
107                '<BR>';
108     } else {
109       die "$app is not a FS::cust_bill_pay or FS::cust_pay_refund";
110     }
111   }
112   if ( $cust_pay->unapplied > 0 ) {
113     $desc .= '&nbsp;&nbsp;'.
114              '<B><FONT COLOR="#FF0000">$'.
115              $cust_pay->unapplied. ' unapplied</FONT></B>';
116     if ( $curuser->access_right('Apply payment') ) {
117       if ( $cust_pay->cust_main->total_owed > 0 ) {
118         $apply = ' ('.
119                  include( '/elements/popup_link.html',
120                             'label'      => mt('apply'),
121                             'action'     => "${p}edit/cust_bill_pay.cgi?".
122                                             $cust_pay->paynum,
123                             'actionlabel' => mt('Apply payment'),
124                             %cust_bill_pay_width,
125                             %cust_bill_pay_height,
126                         ).
127                  ')';
128       }
129       if ( $cust_pay->cust_main->total_unapplied_refunds > 0 ) {
130         $apply.= ' ('.
131                  include( '/elements/popup_link.html',
132                             'label'      => mt('apply to refund'),
133                             'action'     => "${p}edit/cust_pay_refund.cgi?".
134                                             $cust_pay->paynum,
135                             'actionlabel' => mt('Apply payment to refund'),
136                             'width'      => 392,
137                         ).
138                  ')';
139       }
140     }
141     $desc .= '<BR>';
142   }
143 }
144
145 my $view =
146   ' ('. include('/elements/popup_link.html',
147                   'label'     => mt('view receipt'),
148                   'action'    => "${p}view/cust_pay.html?link=popup;paynum=".
149                                   $cust_pay->paynum,
150                   'actionlabel' => mt('Payment Receipt'),
151                ).
152    ')';
153
154 my $refund = '';
155 my $refund_days = $opt{'card_refund-days'} || 120;
156 my @rights = ('Refund payment');
157 push @rights, 'Refund credit card payment' if $payby eq 'CARD';
158 push @rights, 'Refund Echeck payment' if $payby eq 'CHEK';
159 if (    $cust_pay->closed !~ /^Y/i
160      && $cust_pay->payby =~ /^(CARD|CHEK)$/
161      && time-$cust_pay->_date < $refund_days*86400
162      && $cust_pay->unrefunded > 0
163      && $curuser->access_right(\@rights)
164 ) {
165   $refund = qq! (<A HREF="${p}edit/cust_refund.cgi?payby=$1;!.
166             qq!paynum=!. $cust_pay->paynum. '"'.
167             qq! TITLE="Send a refund for this payment to the payment gateway"!.
168             qq!>refund</A>)!;
169 }
170
171 my $void = '';
172 if (    $cust_pay->closed !~ /^Y/i
173      && (    ( $cust_pay->payby eq 'CARD'
174                && $curuser->access_right('Credit card void')
175              )
176           || ( $cust_pay->payby eq 'CHEK'
177                && $curuser->access_right('Echeck void')
178              )
179           || ( $cust_pay->payby !~ /^(CARD|CHEK)$/
180                && $curuser->access_right('Regular void')
181              )
182         )
183    )
184 {
185   $void = qq! (<A HREF="javascript:areyousure('!.
186           qq!${p}misc/void-cust_pay.cgi?!. $cust_pay->paynum.
187           qq!', 'Are you sure you want to void this payment?')"!.
188           qq! TITLE="Void this payment from the database!.
189             ( $cust_pay->payby =~ /^(CARD|CHEK)$/
190               ? ' (do not send anything to the payment gateway)'
191               : '' 
192             ). '"'.
193           qq!>void</A>)!;
194 }
195
196 my $delete = '';
197 if ( $cust_pay->closed !~ /^Y/i
198      && $opt{'deletepayments'}
199      && $curuser->access_right('Delete payment')
200    )
201 {
202   $delete = qq! (<A HREF="javascript:areyousure('!.
203             qq!${p}misc/delete-cust_pay.cgi?!. $cust_pay->paynum.
204             qq!', 'Are you sure you want to delete this payment?')"!.
205             qq! TITLE="Delete this payment from the database completely - not recommended"!.
206             qq!>delete</A>)!;
207 }
208
209 my $unapply = '';
210 if (    $cust_pay->closed !~ /^Y/i
211      && scalar(@cust_bill_pay)           
212      && $curuser->access_right('Unapply payment')
213    )
214 {
215   $unapply = qq! (<A HREF="javascript:areyousure('!.
216              qq!${p}misc/unapply-cust_pay.cgi?!. $cust_pay->paynum.
217              qq!', 'Are you sure you want to unapply this payment?')"!.
218              qq! TITLE="Keep this payment, but dissociate it from the invoices it is currently applied against"!.
219              qq!>unapply</A>)!;
220 }
221
222 </%init>