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,
52 #XXX if there are any open refunds
53 $apply.= ' ('. include( '/elements/popup_link.html',
54 'label' => 'apply to refund',
55 'action' => "${p}edit/cust_pay_refund.cgi?".
57 'actionlabel' => 'Apply payment to refund',
59 #default# 'height' => 336,
63 } elsif ( scalar(@cust_bill_pay) == 1
64 && scalar(@cust_pay_refund) == 0
65 && $cust_pay->unapplied == 0 ) {
66 #applied to one invoice, the usual situation
67 $desc = ' '. $cust_bill_pay[0]->applied_to_invoice;
68 } elsif ( scalar(@cust_bill_pay) == 0
69 && scalar(@cust_pay_refund) == 1
70 && $cust_pay->unapplied == 0 ) {
71 #applied to one refund
72 $desc = ' refunded on '. time2str("%D", $cust_pay_refund[0]->_date);
76 foreach my $app ( sort { $a->_date <=> $b->_date }
77 ( @cust_bill_pay, @cust_pay_refund ) ) {
78 if ( $app->isa('FS::cust_bill_pay') ) {
79 $desc .= ' '.
81 ' '. $app->applied_to_invoice.
83 #' on '. time2str("%D", $cust_bill_pay->_date).
84 } elsif ( $app->isa('FS::cust_pay_refund') ) {
85 $desc .= ' '.
87 ' refunded on '. time2str("%D", $app->_date).
90 die "$app is not a FS::cust_bill_pay or FS::cust_pay_refund";
93 if ( $cust_pay->unapplied > 0 ) {
94 $desc .= ' '.
95 '<B><FONT COLOR="#FF0000">$'.
96 $cust_pay->unapplied. ' unapplied</FONT></B>';
97 if ( $curuser->access_right('Apply payment') ) {
98 $apply = ' ('. include( '/elements/popup_link.html',
100 'action' => "${p}edit/cust_bill_pay.cgi?".
102 'actionlabel' => 'Apply payment',
104 #default# 'height' => 336,
107 #XXX if there are any open refunds
108 $apply.= ' ('. include( '/elements/popup_link.html',
109 'label' => 'apply to refund',
110 'action' => "${p}edit/cust_pay_refund.cgi?".
112 'actionlabel' => 'Apply payment to refund',
114 #default# 'height' => 336,
123 ' ('. include('/elements/popup_link.html',
124 'label' => 'view receipt',
125 'action' => "${p}view/cust_pay.html?link=popup;paynum=".
127 'actionlabel' => 'Payment Receipt',
132 my $refund_days = $conf->config('card_refund-days') || 120;
133 if ( $cust_pay->closed !~ /^Y/i
134 && $cust_pay->payby =~ /^(CARD|CHEK)$/
135 && time-$cust_pay->_date < $refund_days*86400
136 && $cust_pay->unrefunded > 0
137 && $curuser->access_right('Refund payment')
139 $refund = qq! (<A HREF="${p}edit/cust_refund.cgi?payby=$1;!.
140 qq!paynum=!. $cust_pay->paynum. '"'.
141 qq! TITLE="Send a refund for this payment to the payment gateway"!.
146 if ( $cust_pay->closed !~ /^Y/i
147 && ( ( $cust_pay->payby eq 'CARD'
148 && $curuser->access_right('Credit card void')
150 || ( $cust_pay->payby eq 'CHEK'
151 && $curuser->access_right('Echeck void')
153 || ( $cust_pay->payby !~ /^(CARD|CHEK)$/
154 && $curuser->access_right('Regular void')
159 $void = qq! (<A HREF="javascript:areyousure('!.
160 qq!${p}misc/void-cust_pay.cgi?!. $cust_pay->paynum.
161 qq!', 'Are you sure you want to void this payment?')"!.
162 qq! TITLE="Void this payment from the database!.
163 ( $cust_pay->payby =~ /^(CARD|CHEK)$/
164 ? ' (do not send anything to the payment gateway)'
171 if ( $cust_pay->closed !~ /^Y/i
172 && $conf->exists('deletepayments')
173 && $curuser->access_right('Delete payment')
176 $delete = qq! (<A HREF="javascript:areyousure('!.
177 qq!${p}misc/delete-cust_pay.cgi?!. $cust_pay->paynum.
178 qq!', 'Are you sure you want to delete this payment?')"!.
179 qq! TITLE="Delete this payment from the database completely - not recommended"!.
184 if ( $cust_pay->closed !~ /^Y/i
185 && scalar(@cust_bill_pay)
186 && $curuser->access_right('Unapply payment')
189 $unapply = qq! (<A HREF="javascript:areyousure('!.
190 qq!${p}misc/unapply-cust_pay.cgi?!. $cust_pay->paynum.
191 qq!', 'Are you sure you want to unapply this payment?')"!.
192 qq! TITLE="Keep this payment, but dissociate it from the invoices it is currently applied against"!.
196 my $otaker = $cust_pay->otaker;
197 $otaker = '<i>auto billing</i>' if $otaker eq 'fs_daily';
198 $otaker = '<i>customer self-service</i>' if $otaker eq 'fs_selfservice';