1 <% $pre %>Payment<% $post %> by <% $otaker %>
2 <% "$info$desc$view$apply$refund$void$delete$unapply" %>
5 my( $cust_pay, %opt ) = @_;
7 my $conf = new FS::Conf;
8 my $curuser = $FS::CurrentUser::CurrentUser;
10 my $payby = $cust_pay->payby;
13 if ( $payby eq 'CARD' ) {
14 $payinfo = $cust_pay->paymask;
15 } elsif ( $payby eq 'CHEK' ) {
16 my( $account, $aba ) = split('@', $cust_pay->paymask );
17 $payinfo = "ABA $aba, Acct #$account";
19 $payinfo = $cust_pay->payinfo;
21 my @cust_bill_pay = $cust_pay->cust_bill_pay;
22 my @cust_pay_refund = $cust_pay->cust_pay_refund;
24 my $target = "$payby$payinfo";
25 $payby =~ s/^BILL$/Check #/ if $payinfo;
26 $payby =~ s/^CHEK$/Electronic check /;
27 $payby =~ s/^PREP$/Prepaid card /;
28 $payby =~ s/^CARD$/Credit card #/;
29 $payby =~ s/^COMP$/Complimentary by /;
30 $payby =~ s/^CASH$/Cash/;
31 $payby =~ s/^WEST$/Western Union/;
32 $payby =~ s/^MCRD$/Manual credit card/;
34 my $info = $payby ? "($payby$payinfo)" : '';
36 my( $pre, $post, $desc, $apply, $ext ) = ( '', '', '', '', '' );
37 if ( scalar(@cust_bill_pay) == 0
38 && scalar(@cust_pay_refund) == 0 ) {
40 $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
41 $post = '</FONT></B>';
42 if ( $curuser->access_right('Apply payment') ) {
43 if ( $cust_pay->cust_main->total_owed > 0 ) {
45 include( '/elements/popup_link.html',
47 'action' => "${p}edit/cust_bill_pay.cgi?".
49 'actionlabel' => 'Apply payment',
51 #default# 'height' => 336,
55 if ( $cust_pay->cust_main->total_unapplied_refunds > 0 ) {
57 include( '/elements/popup_link.html',
58 'label' => 'apply to refund',
59 'action' => "${p}edit/cust_pay_refund.cgi?".
61 'actionlabel' => 'Apply payment to refund',
63 #default# 'height' => 336,
68 } elsif ( scalar(@cust_bill_pay) == 1
69 && scalar(@cust_pay_refund) == 0
70 && $cust_pay->unapplied == 0 ) {
71 #applied to one invoice, the usual situation
72 $desc = ' '. $cust_bill_pay[0]->applied_to_invoice;
73 } elsif ( scalar(@cust_bill_pay) == 0
74 && scalar(@cust_pay_refund) == 1
75 && $cust_pay->unapplied == 0 ) {
76 #applied to one refund
77 $desc = ' refunded on '. time2str("%D", $cust_pay_refund[0]->_date);
81 foreach my $app ( sort { $a->_date <=> $b->_date }
82 ( @cust_bill_pay, @cust_pay_refund ) ) {
83 if ( $app->isa('FS::cust_bill_pay') ) {
84 $desc .= ' '.
86 ' '. $app->applied_to_invoice.
88 #' on '. time2str("%D", $cust_bill_pay->_date).
89 } elsif ( $app->isa('FS::cust_pay_refund') ) {
90 $desc .= ' '.
92 ' refunded on '. time2str("%D", $app->_date).
95 die "$app is not a FS::cust_bill_pay or FS::cust_pay_refund";
98 if ( $cust_pay->unapplied > 0 ) {
99 $desc .= ' '.
100 '<B><FONT COLOR="#FF0000">$'.
101 $cust_pay->unapplied. ' unapplied</FONT></B>';
102 if ( $curuser->access_right('Apply payment') ) {
103 if ( $cust_pay->cust_main->total_owed > 0 ) {
105 include( '/elements/popup_link.html',
107 'action' => "${p}edit/cust_bill_pay.cgi?".
109 'actionlabel' => 'Apply payment',
111 #default# 'height' => 336,
115 if ( $cust_pay->cust_main->total_unapplied_refunds > 0 ) {
117 include( '/elements/popup_link.html',
118 'label' => 'apply to refund',
119 'action' => "${p}edit/cust_pay_refund.cgi?".
121 'actionlabel' => 'Apply payment to refund',
123 #default# 'height' => 336,
133 ' ('. include('/elements/popup_link.html',
134 'label' => 'view receipt',
135 'action' => "${p}view/cust_pay.html?link=popup;paynum=".
137 'actionlabel' => 'Payment Receipt',
142 my $refund_days = $conf->config('card_refund-days') || 120;
143 if ( $cust_pay->closed !~ /^Y/i
144 && $cust_pay->payby =~ /^(CARD|CHEK)$/
145 && time-$cust_pay->_date < $refund_days*86400
146 && $cust_pay->unrefunded > 0
147 && $curuser->access_right('Refund payment')
149 $refund = qq! (<A HREF="${p}edit/cust_refund.cgi?payby=$1;!.
150 qq!paynum=!. $cust_pay->paynum. '"'.
151 qq! TITLE="Send a refund for this payment to the payment gateway"!.
156 if ( $cust_pay->closed !~ /^Y/i
157 && ( ( $cust_pay->payby eq 'CARD'
158 && $curuser->access_right('Credit card void')
160 || ( $cust_pay->payby eq 'CHEK'
161 && $curuser->access_right('Echeck void')
163 || ( $cust_pay->payby !~ /^(CARD|CHEK)$/
164 && $curuser->access_right('Regular void')
169 $void = qq! (<A HREF="javascript:areyousure('!.
170 qq!${p}misc/void-cust_pay.cgi?!. $cust_pay->paynum.
171 qq!', 'Are you sure you want to void this payment?')"!.
172 qq! TITLE="Void this payment from the database!.
173 ( $cust_pay->payby =~ /^(CARD|CHEK)$/
174 ? ' (do not send anything to the payment gateway)'
181 if ( $cust_pay->closed !~ /^Y/i
182 && $conf->exists('deletepayments')
183 && $curuser->access_right('Delete payment')
186 $delete = qq! (<A HREF="javascript:areyousure('!.
187 qq!${p}misc/delete-cust_pay.cgi?!. $cust_pay->paynum.
188 qq!', 'Are you sure you want to delete this payment?')"!.
189 qq! TITLE="Delete this payment from the database completely - not recommended"!.
194 if ( $cust_pay->closed !~ /^Y/i
195 && scalar(@cust_bill_pay)
196 && $curuser->access_right('Unapply payment')
199 $unapply = qq! (<A HREF="javascript:areyousure('!.
200 qq!${p}misc/unapply-cust_pay.cgi?!. $cust_pay->paynum.
201 qq!', 'Are you sure you want to unapply this payment?')"!.
202 qq! TITLE="Keep this payment, but dissociate it from the invoices it is currently applied against"!.
206 my $otaker = $cust_pay->otaker;
207 $otaker = '<i>auto billing</i>' if $otaker eq 'fs_daily';
208 $otaker = '<i>customer self-service</i>' if $otaker eq 'fs_selfservice';