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 $apply = ' ('. include( '/elements/popup_link.html',
45 'action' => "${p}edit/cust_bill_pay.cgi?".
47 'actionlabel' => 'Apply payment',
49 #default# 'height' => 336,
53 } elsif ( scalar(@cust_bill_pay) == 1
54 && scalar(@cust_pay_refund) == 0
55 && $cust_pay->unapplied == 0 ) {
56 #applied to one invoice, the usual situation
57 $desc = ' '. $cust_bill_pay[0]->applied_to_invoice;
58 } elsif ( scalar(@cust_bill_pay) == 0
59 && scalar(@cust_pay_refund) == 1
60 && $cust_pay->unapplied == 0 ) {
61 #applied to one refund
62 $desc = ' refunded on '. time2str("%D", $cust_pay_refund[0]->_date);
66 foreach my $app ( sort { $a->_date <=> $b->_date }
67 ( @cust_bill_pay, @cust_pay_refund ) ) {
68 if ( $app->isa('FS::cust_bill_pay') ) {
69 $desc .= ' '.
71 ' '. $app->applied_to_invoice.
73 #' on '. time2str("%D", $cust_bill_pay->_date).
74 } elsif ( $app->isa('FS::cust_pay_refund') ) {
75 $desc .= ' '.
77 ' refunded on '. time2str("%D", $app->_date).
80 die "$app is not a FS::cust_bill_pay or FS::cust_pay_refund";
83 if ( $cust_pay->unapplied > 0 ) {
84 $desc .= ' '.
85 '<B><FONT COLOR="#FF0000">$'.
86 $cust_pay->unapplied. ' unapplied</FONT></B>';
87 if ( $curuser->access_right('Apply payment') ) {
88 $desc = ' ('. include( '/elements/popup_link.html',
90 'action' => "${p}edit/cust_bill_pay.cgi?".
92 'actionlabel' => 'Apply payment',
94 #default# 'height' => 336,
103 ' ('. include('/elements/popup_link.html',
104 'label' => 'view receipt',
105 'action' => "${p}view/cust_pay.html?link=popup;paynum=".
107 'actionlabel' => 'Payment Receipt',
112 my $refund_days = $conf->config('card_refund-days') || 120;
113 if ( $cust_pay->closed !~ /^Y/i
114 && $cust_pay->payby =~ /^(CARD|CHEK)$/
115 && time-$cust_pay->_date < $refund_days*86400
116 && $cust_pay->unrefunded > 0
117 && $curuser->access_right('Refund payment')
119 $refund = qq! (<A HREF="${p}edit/cust_refund.cgi?payby=$1;!.
120 qq!paynum=!. $cust_pay->paynum. '"'.
121 qq! TITLE="Send a refund for this payment to the payment gateway"!.
126 if ( $cust_pay->closed !~ /^Y/i
127 && ( ( $cust_pay->payby eq 'CARD'
128 && $curuser->access_right('Credit card void')
130 || ( $cust_pay->payby eq 'CHEK'
131 && $curuser->access_right('Echeck void')
133 || ( $cust_pay->payby !~ /^(CARD|CHEK)$/
134 && $curuser->access_right('Regular void')
139 $void = qq! (<A HREF="javascript:areyousure('!.
140 qq!${p}misc/void-cust_pay.cgi?!. $cust_pay->paynum.
141 qq!', 'Are you sure you want to void this payment?')"!.
142 qq! TITLE="Void this payment from the database!.
143 ( $cust_pay->payby =~ /^(CARD|CHEK)$/
144 ? ' (do not send anything to the payment gateway)'
151 if ( $cust_pay->closed !~ /^Y/i
152 && $conf->exists('deletepayments')
153 && $curuser->access_right('Delete payment')
156 $delete = qq! (<A HREF="javascript:areyousure('!.
157 qq!${p}misc/delete-cust_pay.cgi?!. $cust_pay->paynum.
158 qq!', 'Are you sure you want to delete this payment?')"!.
159 qq! TITLE="Delete this payment from the database completely - not recommended"!.
164 if ( $cust_pay->closed !~ /^Y/i
165 && scalar(@cust_bill_pay)
166 && $curuser->access_right('Unapply payment')
169 $unapply = qq! (<A HREF="javascript:areyousure('!.
170 qq!${p}misc/unapply-cust_pay.cgi?!. $cust_pay->paynum.
171 qq!', 'Are you sure you want to unapply this payment?')"!.
172 qq! TITLE="Keep this payment, but dissociate it from the invoices it is currently applied against"!.
176 my $otaker = $cust_pay->otaker;
177 $otaker = '<i>auto billing</i>' if $otaker eq 'fs_daily';
178 $otaker = '<i>customer self-service</i>' if $otaker eq 'fs_selfservice';