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)" : '';
37 if ( $opt{'pkg-balances'} && $cust_pay->pkgnum ) {
38 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cust_pay->pkgnum } );
39 $desc .= ' for '. $cust_pkg->pkg_label_long;
42 my %cust_bill_pay_width = ('width' => 392);
43 my %cust_bill_pay_height = ();
44 if ($conf->exists('cust_bill_pay_pkg-manual')) {
45 %cust_bill_pay_width = ('width' => 592);
46 %cust_bill_pay_height = ('height' => 436);
49 my( $pre, $post, $apply, $ext ) = ( '', '', '', '' );
50 if ( scalar(@cust_bill_pay) == 0
51 && scalar(@cust_pay_refund) == 0 ) {
53 $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
54 $post = '</FONT></B>';
55 if ( $curuser->access_right('Apply payment') ) {
56 if ( $cust_pay->cust_main->total_owed > 0 ) {
58 include( '/elements/popup_link.html',
60 'action' => "${p}edit/cust_bill_pay.cgi?".
62 'actionlabel' => 'Apply payment',
64 %cust_bill_pay_height,
68 if ( $cust_pay->cust_main->total_unapplied_refunds > 0 ) {
70 include( '/elements/popup_link.html',
71 'label' => 'apply to refund',
72 'action' => "${p}edit/cust_pay_refund.cgi?".
74 'actionlabel' => 'Apply payment to refund',
76 #default# 'height' => 336,
81 } elsif ( scalar(@cust_bill_pay) == 1
82 && scalar(@cust_pay_refund) == 0
83 && $cust_pay->unapplied == 0 ) {
84 #applied to one invoice, the usual situation
85 $desc .= ' '. $cust_bill_pay[0]->applied_to_invoice;
86 } elsif ( scalar(@cust_bill_pay) == 0
87 && scalar(@cust_pay_refund) == 1
88 && $cust_pay->unapplied == 0 ) {
89 #applied to one refund
90 $desc .= ' refunded on '. time2str("%D", $cust_pay_refund[0]->_date);
94 foreach my $app ( sort { $a->_date <=> $b->_date }
95 ( @cust_bill_pay, @cust_pay_refund ) ) {
96 if ( $app->isa('FS::cust_bill_pay') ) {
97 $desc .= ' '.
99 ' '. $app->applied_to_invoice.
101 #' on '. time2str("%D", $cust_bill_pay->_date).
102 } elsif ( $app->isa('FS::cust_pay_refund') ) {
103 $desc .= ' '.
105 ' refunded on '. time2str("%D", $app->_date).
108 die "$app is not a FS::cust_bill_pay or FS::cust_pay_refund";
111 if ( $cust_pay->unapplied > 0 ) {
112 $desc .= ' '.
113 '<B><FONT COLOR="#FF0000">$'.
114 $cust_pay->unapplied. ' unapplied</FONT></B>';
115 if ( $curuser->access_right('Apply payment') ) {
116 if ( $cust_pay->cust_main->total_owed > 0 ) {
118 include( '/elements/popup_link.html',
120 'action' => "${p}edit/cust_bill_pay.cgi?".
122 'actionlabel' => 'Apply payment',
123 %cust_bill_pay_width,
124 %cust_bill_pay_height,
128 if ( $cust_pay->cust_main->total_unapplied_refunds > 0 ) {
130 include( '/elements/popup_link.html',
131 'label' => 'apply to refund',
132 'action' => "${p}edit/cust_pay_refund.cgi?".
134 'actionlabel' => 'Apply payment to refund',
136 #default# 'height' => 336,
146 ' ('. include('/elements/popup_link.html',
147 'label' => 'view receipt',
148 'action' => "${p}view/cust_pay.html?link=popup;paynum=".
150 'actionlabel' => 'Payment Receipt',
155 my $refund_days = $opt{'card_refund-days'} || 120;
156 if ( $cust_pay->closed !~ /^Y/i
157 && $cust_pay->payby =~ /^(CARD|CHEK)$/
158 && time-$cust_pay->_date < $refund_days*86400
159 && $cust_pay->unrefunded > 0
160 && $curuser->access_right('Refund payment')
162 $refund = qq! (<A HREF="${p}edit/cust_refund.cgi?payby=$1;!.
163 qq!paynum=!. $cust_pay->paynum. '"'.
164 qq! TITLE="Send a refund for this payment to the payment gateway"!.
169 if ( $cust_pay->closed !~ /^Y/i
170 && ( ( $cust_pay->payby eq 'CARD'
171 && $curuser->access_right('Credit card void')
173 || ( $cust_pay->payby eq 'CHEK'
174 && $curuser->access_right('Echeck void')
176 || ( $cust_pay->payby !~ /^(CARD|CHEK)$/
177 && $curuser->access_right('Regular void')
182 $void = qq! (<A HREF="javascript:areyousure('!.
183 qq!${p}misc/void-cust_pay.cgi?!. $cust_pay->paynum.
184 qq!', 'Are you sure you want to void this payment?')"!.
185 qq! TITLE="Void this payment from the database!.
186 ( $cust_pay->payby =~ /^(CARD|CHEK)$/
187 ? ' (do not send anything to the payment gateway)'
194 if ( $cust_pay->closed !~ /^Y/i
195 && $opt{'deletepayments'}
196 && $curuser->access_right('Delete payment')
199 $delete = qq! (<A HREF="javascript:areyousure('!.
200 qq!${p}misc/delete-cust_pay.cgi?!. $cust_pay->paynum.
201 qq!', 'Are you sure you want to delete this payment?')"!.
202 qq! TITLE="Delete this payment from the database completely - not recommended"!.
207 if ( $cust_pay->closed !~ /^Y/i
208 && scalar(@cust_bill_pay)
209 && $curuser->access_right('Unapply payment')
212 $unapply = qq! (<A HREF="javascript:areyousure('!.
213 qq!${p}misc/unapply-cust_pay.cgi?!. $cust_pay->paynum.
214 qq!', 'Are you sure you want to unapply this payment?')"!.
215 qq! TITLE="Keep this payment, but dissociate it from the invoices it is currently applied against"!.
219 my $otaker = $cust_pay->otaker;
220 $otaker = '<i>auto billing</i>' if $otaker eq 'fs_daily';
221 $otaker = '<i>customer self-service</i>' if $otaker eq 'fs_selfservice';