1 <% $pre %>Payment<% $post %> by <% $otaker %>
2 <% "$info$desc$view$apply$refund$void$delete$unapply" %>
5 my( $cust_pay, %opt ) = @_;
7 my $curuser = $FS::CurrentUser::CurrentUser;
9 my $payby = $cust_pay->payby;
12 if ( $payby eq 'CARD' ) {
13 $payinfo = $cust_pay->paymask;
14 } elsif ( $payby eq 'CHEK' ) {
15 my( $account, $aba ) = split('@', $cust_pay->paymask );
16 $payinfo = "ABA $aba, Acct #$account";
18 $payinfo = $cust_pay->payinfo;
20 my @cust_bill_pay = $cust_pay->cust_bill_pay;
21 my @cust_pay_refund = $cust_pay->cust_pay_refund;
23 my $target = "$payby$payinfo";
24 $payby =~ s/^BILL$/Check #/ if $payinfo;
25 $payby =~ s/^CHEK$/Electronic check /;
26 $payby =~ s/^PREP$/Prepaid card /;
27 $payby =~ s/^CARD$/Credit card #/;
28 $payby =~ s/^COMP$/Complimentary by /;
29 $payby =~ s/^CASH$/Cash/;
30 $payby =~ s/^WEST$/Western Union/;
31 $payby =~ s/^MCRD$/Manual credit card/;
33 my $info = $payby ? "($payby$payinfo)" : '';
36 if ( $opt{'pkg-balances'} && $cust_pay->pkgnum ) {
37 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cust_pay->pkgnum } );
38 $desc .= ' for '. $cust_pkg->pkg_label_long;
41 my( $pre, $post, $apply, $ext ) = ( '', '', '', '' );
42 if ( scalar(@cust_bill_pay) == 0
43 && scalar(@cust_pay_refund) == 0 ) {
45 $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
46 $post = '</FONT></B>';
47 if ( $curuser->access_right('Apply payment') ) {
48 if ( $cust_pay->cust_main->total_owed > 0 ) {
50 include( '/elements/popup_link.html',
52 'action' => "${p}edit/cust_bill_pay.cgi?".
54 'actionlabel' => 'Apply payment',
56 #default# 'height' => 336,
60 if ( $cust_pay->cust_main->total_unapplied_refunds > 0 ) {
62 include( '/elements/popup_link.html',
63 'label' => 'apply to refund',
64 'action' => "${p}edit/cust_pay_refund.cgi?".
66 'actionlabel' => 'Apply payment to refund',
68 #default# 'height' => 336,
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 .= ' refunded on '. time2str("%D", $cust_pay_refund[0]->_date);
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 .= ' '.
91 ' '. $app->applied_to_invoice.
93 #' on '. time2str("%D", $cust_bill_pay->_date).
94 } elsif ( $app->isa('FS::cust_pay_refund') ) {
95 $desc .= ' '.
97 ' refunded on '. time2str("%D", $app->_date).
100 die "$app is not a FS::cust_bill_pay or FS::cust_pay_refund";
103 if ( $cust_pay->unapplied > 0 ) {
104 $desc .= ' '.
105 '<B><FONT COLOR="#FF0000">$'.
106 $cust_pay->unapplied. ' unapplied</FONT></B>';
107 if ( $curuser->access_right('Apply payment') ) {
108 if ( $cust_pay->cust_main->total_owed > 0 ) {
110 include( '/elements/popup_link.html',
112 'action' => "${p}edit/cust_bill_pay.cgi?".
114 'actionlabel' => 'Apply payment',
116 #default# 'height' => 336,
120 if ( $cust_pay->cust_main->total_unapplied_refunds > 0 ) {
122 include( '/elements/popup_link.html',
123 'label' => 'apply to refund',
124 'action' => "${p}edit/cust_pay_refund.cgi?".
126 'actionlabel' => 'Apply payment to refund',
128 #default# 'height' => 336,
138 ' ('. include('/elements/popup_link.html',
139 'label' => 'view receipt',
140 'action' => "${p}view/cust_pay.html?link=popup;paynum=".
142 'actionlabel' => 'Payment Receipt',
147 my $refund_days = $opt{'card_refund-days'} || 120;
148 if ( $cust_pay->closed !~ /^Y/i
149 && $cust_pay->payby =~ /^(CARD|CHEK)$/
150 && time-$cust_pay->_date < $refund_days*86400
151 && $cust_pay->unrefunded > 0
152 && $curuser->access_right('Refund payment')
154 $refund = qq! (<A HREF="${p}edit/cust_refund.cgi?payby=$1;!.
155 qq!paynum=!. $cust_pay->paynum. '"'.
156 qq! TITLE="Send a refund for this payment to the payment gateway"!.
161 if ( $cust_pay->closed !~ /^Y/i
162 && ( ( $cust_pay->payby eq 'CARD'
163 && $curuser->access_right('Credit card void')
165 || ( $cust_pay->payby eq 'CHEK'
166 && $curuser->access_right('Echeck void')
168 || ( $cust_pay->payby !~ /^(CARD|CHEK)$/
169 && $curuser->access_right('Regular void')
174 $void = qq! (<A HREF="javascript:areyousure('!.
175 qq!${p}misc/void-cust_pay.cgi?!. $cust_pay->paynum.
176 qq!', 'Are you sure you want to void this payment?')"!.
177 qq! TITLE="Void this payment from the database!.
178 ( $cust_pay->payby =~ /^(CARD|CHEK)$/
179 ? ' (do not send anything to the payment gateway)'
186 if ( $cust_pay->closed !~ /^Y/i
187 && $opt{'deletepayments'}
188 && $curuser->access_right('Delete payment')
191 $delete = qq! (<A HREF="javascript:areyousure('!.
192 qq!${p}misc/delete-cust_pay.cgi?!. $cust_pay->paynum.
193 qq!', 'Are you sure you want to delete this payment?')"!.
194 qq! TITLE="Delete this payment from the database completely - not recommended"!.
199 if ( $cust_pay->closed !~ /^Y/i
200 && scalar(@cust_bill_pay)
201 && $curuser->access_right('Unapply payment')
204 $unapply = qq! (<A HREF="javascript:areyousure('!.
205 qq!${p}misc/unapply-cust_pay.cgi?!. $cust_pay->paynum.
206 qq!', 'Are you sure you want to unapply this payment?')"!.
207 qq! TITLE="Keep this payment, but dissociate it from the invoices it is currently applied against"!.
211 my $otaker = $cust_pay->otaker;
212 $otaker = '<i>auto billing</i>' if $otaker eq 'fs_daily';
213 $otaker = '<i>customer self-service</i>' if $otaker eq 'fs_selfservice';