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