1 <% $pre %>Payment<% $post %> by <% $otaker %>
2 <% "$info$desc$view$apply$refund$void$delete$unapply" %>
5 my( $cust_pay, %opt ) = @_;
7 my $date_format = $opt{'date_format'} || '%m/%d/%Y';
9 my $curuser = $FS::CurrentUser::CurrentUser;
11 my $payby = $cust_pay->payby;
14 if ( $payby eq 'CARD' ) {
15 $payinfo = $cust_pay->paymask;
16 } elsif ( $payby eq 'CHEK' ) {
17 my( $account, $aba ) = split('@', $cust_pay->paymask );
18 $payinfo = "ABA $aba, Acct #$account";
20 $payinfo = $cust_pay->payinfo;
22 my @cust_bill_pay = $cust_pay->cust_bill_pay;
23 my @cust_pay_refund = $cust_pay->cust_pay_refund;
25 my $target = "$payby$payinfo";
26 $payby =~ s/^BILL$/Check #/ if $payinfo;
27 $payby =~ s/^CHEK$/Electronic check /;
28 $payby =~ s/^PREP$/Prepaid card /;
29 $payby =~ s/^CARD$/Credit card #/;
30 $payby =~ s/^COMP$/Complimentary by /;
31 $payby =~ s/^CASH$/Cash/;
32 $payby =~ s/^WEST$/Western Union/;
33 $payby =~ s/^MCRD$/Manual credit card/;
35 my $info = $payby ? "($payby$payinfo)" : '';
38 if ( $opt{'pkg-balances'} && $cust_pay->pkgnum ) {
39 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cust_pay->pkgnum } );
40 $desc .= ' for '. $cust_pkg->pkg_label_long;
43 my( $pre, $post, $apply, $ext ) = ( '', '', '', '' );
44 if ( scalar(@cust_bill_pay) == 0
45 && scalar(@cust_pay_refund) == 0 ) {
47 $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
48 $post = '</FONT></B>';
49 if ( $curuser->access_right('Apply payment') ) {
50 if ( $cust_pay->cust_main->total_owed > 0 ) {
52 include( '/elements/popup_link.html',
54 'action' => "${p}edit/cust_bill_pay.cgi?".
56 'actionlabel' => 'Apply payment',
58 #default# 'height' => 336,
62 if ( $cust_pay->cust_main->total_unapplied_refunds > 0 ) {
64 include( '/elements/popup_link.html',
65 'label' => 'apply to refund',
66 'action' => "${p}edit/cust_pay_refund.cgi?".
68 'actionlabel' => 'Apply payment to refund',
70 #default# 'height' => 336,
75 } elsif ( scalar(@cust_bill_pay) == 1
76 && scalar(@cust_pay_refund) == 0
77 && $cust_pay->unapplied == 0 ) {
78 #applied to one invoice, the usual situation
79 $desc .= ' '. $cust_bill_pay[0]->applied_to_invoice;
80 } elsif ( scalar(@cust_bill_pay) == 0
81 && scalar(@cust_pay_refund) == 1
82 && $cust_pay->unapplied == 0 ) {
83 #applied to one refund
84 $desc .= ' refunded on '. time2str($date_format, $cust_pay_refund[0]->_date);
88 foreach my $app ( sort { $a->_date <=> $b->_date }
89 ( @cust_bill_pay, @cust_pay_refund ) ) {
90 if ( $app->isa('FS::cust_bill_pay') ) {
91 $desc .= ' '.
93 ' '. $app->applied_to_invoice.
95 #' on '. time2str($date_format, $cust_bill_pay->_date).
96 } elsif ( $app->isa('FS::cust_pay_refund') ) {
97 $desc .= ' '.
99 ' refunded on '. time2str($date_format, $app->_date).
102 die "$app is not a FS::cust_bill_pay or FS::cust_pay_refund";
105 if ( $cust_pay->unapplied > 0 ) {
106 $desc .= ' '.
107 '<B><FONT COLOR="#FF0000">$'.
108 $cust_pay->unapplied. ' unapplied</FONT></B>';
109 if ( $curuser->access_right('Apply payment') ) {
110 if ( $cust_pay->cust_main->total_owed > 0 ) {
112 include( '/elements/popup_link.html',
114 'action' => "${p}edit/cust_bill_pay.cgi?".
116 'actionlabel' => 'Apply payment',
118 #default# 'height' => 336,
122 if ( $cust_pay->cust_main->total_unapplied_refunds > 0 ) {
124 include( '/elements/popup_link.html',
125 'label' => 'apply to refund',
126 'action' => "${p}edit/cust_pay_refund.cgi?".
128 'actionlabel' => 'Apply payment to refund',
130 #default# 'height' => 336,
140 ' ('. include('/elements/popup_link.html',
141 'label' => 'view receipt',
142 'action' => "${p}view/cust_pay.html?link=popup;paynum=".
144 'actionlabel' => 'Payment Receipt',
149 my $refund_days = $opt{'card_refund-days'} || 120;
150 if ( $cust_pay->closed !~ /^Y/i
151 && $cust_pay->payby =~ /^(CARD|CHEK)$/
152 && time-$cust_pay->_date < $refund_days*86400
153 && $cust_pay->unrefunded > 0
154 && $curuser->access_right('Refund payment')
156 $refund = qq! (<A HREF="${p}edit/cust_refund.cgi?payby=$1;!.
157 qq!paynum=!. $cust_pay->paynum. '"'.
158 qq! TITLE="Send a refund for this payment to the payment gateway"!.
163 if ( $cust_pay->closed !~ /^Y/i
164 && ( ( $cust_pay->payby eq 'CARD'
165 && $curuser->access_right('Credit card void')
167 || ( $cust_pay->payby eq 'CHEK'
168 && $curuser->access_right('Echeck void')
170 || ( $cust_pay->payby !~ /^(CARD|CHEK)$/
171 && $curuser->access_right('Regular void')
176 $void = qq! (<A HREF="javascript:areyousure('!.
177 qq!${p}misc/void-cust_pay.cgi?!. $cust_pay->paynum.
178 qq!', 'Are you sure you want to void this payment?')"!.
179 qq! TITLE="Void this payment from the database!.
180 ( $cust_pay->payby =~ /^(CARD|CHEK)$/
181 ? ' (do not send anything to the payment gateway)'
188 if ( $cust_pay->closed !~ /^Y/i
189 && $opt{'deletepayments'}
190 && $curuser->access_right('Delete payment')
193 $delete = qq! (<A HREF="javascript:areyousure('!.
194 qq!${p}misc/delete-cust_pay.cgi?!. $cust_pay->paynum.
195 qq!', 'Are you sure you want to delete this payment?')"!.
196 qq! TITLE="Delete this payment from the database completely - not recommended"!.
201 if ( $cust_pay->closed !~ /^Y/i
202 && scalar(@cust_bill_pay)
203 && $curuser->access_right('Unapply payment')
206 $unapply = qq! (<A HREF="javascript:areyousure('!.
207 qq!${p}misc/unapply-cust_pay.cgi?!. $cust_pay->paynum.
208 qq!', 'Are you sure you want to unapply this payment?')"!.
209 qq! TITLE="Keep this payment, but dissociate it from the invoices it is currently applied against"!.
213 my $otaker = $cust_pay->otaker;
214 $otaker = '<i>auto billing</i>' if $otaker eq 'fs_daily';
215 $otaker = '<i>customer self-service</i>' if $otaker eq 'fs_selfservice';