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 $conf = new FS::Conf;
10 my $curuser = $FS::CurrentUser::CurrentUser;
12 my $payby = $cust_pay->payby;
15 if ( $payby eq 'CARD' ) {
16 $payinfo = $cust_pay->paymask;
17 } elsif ( $payby eq 'CHEK' ) {
18 my( $account, $aba ) = split('@', $cust_pay->paymask );
19 $payinfo = "ABA $aba, Acct #$account";
21 $payinfo = $cust_pay->payinfo;
23 my @cust_bill_pay = $cust_pay->cust_bill_pay;
24 my @cust_pay_refund = $cust_pay->cust_pay_refund;
26 my $target = "$payby$payinfo";
27 $payby =~ s/^BILL$/Check #/ if $payinfo;
28 $payby =~ s/^CHEK$/Electronic check /;
29 $payby =~ s/^PREP$/Prepaid card /;
30 $payby =~ s/^CARD$/Credit card #/;
31 $payby =~ s/^COMP$/Complimentary by /;
32 $payby =~ s/^CASH$/Cash/;
33 $payby =~ s/^WEST$/Western Union/;
34 $payby =~ s/^MCRD$/Manual credit card/;
36 my $info = $payby ? "($payby$payinfo)" : '';
39 if ( $opt{'pkg-balances'} && $cust_pay->pkgnum ) {
40 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cust_pay->pkgnum } );
41 $desc .= ' for '. $cust_pkg->pkg_label_long;
44 my %cust_bill_pay_width = ('width' => 392);
45 my %cust_bill_pay_height = ();
46 if ($conf->exists('cust_bill_pay_pkg-manual')) {
47 %cust_bill_pay_width = ('width' => 592);
48 %cust_bill_pay_height = ('height' => 436);
51 my( $pre, $post, $apply, $ext ) = ( '', '', '', '' );
52 if ( scalar(@cust_bill_pay) == 0
53 && scalar(@cust_pay_refund) == 0 ) {
55 $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
56 $post = '</FONT></B>';
57 if ( $curuser->access_right('Apply payment') ) {
58 if ( $cust_pay->cust_main->total_owed > 0 ) {
60 include( '/elements/popup_link.html',
62 'action' => "${p}edit/cust_bill_pay.cgi?".
64 'actionlabel' => 'Apply payment',
66 %cust_bill_pay_height,
70 if ( $cust_pay->cust_main->total_unapplied_refunds > 0 ) {
72 include( '/elements/popup_link.html',
73 'label' => 'apply to refund',
74 'action' => "${p}edit/cust_pay_refund.cgi?".
76 'actionlabel' => 'Apply payment to refund',
78 #default# 'height' => 336,
83 } elsif ( scalar(@cust_bill_pay) == 1
84 && scalar(@cust_pay_refund) == 0
85 && $cust_pay->unapplied == 0 ) {
86 #applied to one invoice, the usual situation
87 $desc .= ' '. $cust_bill_pay[0]->applied_to_invoice;
88 } elsif ( scalar(@cust_bill_pay) == 0
89 && scalar(@cust_pay_refund) == 1
90 && $cust_pay->unapplied == 0 ) {
91 #applied to one refund
92 $desc .= ' refunded on '. time2str($date_format, $cust_pay_refund[0]->_date);
96 foreach my $app ( sort { $a->_date <=> $b->_date }
97 ( @cust_bill_pay, @cust_pay_refund ) ) {
98 if ( $app->isa('FS::cust_bill_pay') ) {
99 $desc .= ' '.
101 ' '. $app->applied_to_invoice.
103 #' on '. time2str($date_format, $cust_bill_pay->_date).
104 } elsif ( $app->isa('FS::cust_pay_refund') ) {
105 $desc .= ' '.
107 ' refunded on '. time2str($date_format, $app->_date).
110 die "$app is not a FS::cust_bill_pay or FS::cust_pay_refund";
113 if ( $cust_pay->unapplied > 0 ) {
114 $desc .= ' '.
115 '<B><FONT COLOR="#FF0000">$'.
116 $cust_pay->unapplied. ' unapplied</FONT></B>';
117 if ( $curuser->access_right('Apply payment') ) {
118 if ( $cust_pay->cust_main->total_owed > 0 ) {
120 include( '/elements/popup_link.html',
122 'action' => "${p}edit/cust_bill_pay.cgi?".
124 'actionlabel' => 'Apply payment',
125 %cust_bill_pay_width,
126 %cust_bill_pay_height,
130 if ( $cust_pay->cust_main->total_unapplied_refunds > 0 ) {
132 include( '/elements/popup_link.html',
133 'label' => 'apply to refund',
134 'action' => "${p}edit/cust_pay_refund.cgi?".
136 'actionlabel' => 'Apply payment to refund',
138 #default# 'height' => 336,
148 ' ('. include('/elements/popup_link.html',
149 'label' => 'view receipt',
150 'action' => "${p}view/cust_pay.html?link=popup;paynum=".
152 'actionlabel' => 'Payment Receipt',
157 my $refund_days = $opt{'card_refund-days'} || 120;
158 if ( $cust_pay->closed !~ /^Y/i
159 && $cust_pay->payby =~ /^(CARD|CHEK)$/
160 && time-$cust_pay->_date < $refund_days*86400
161 && $cust_pay->unrefunded > 0
162 && $curuser->access_right('Refund payment')
164 $refund = qq! (<A HREF="${p}edit/cust_refund.cgi?payby=$1;!.
165 qq!paynum=!. $cust_pay->paynum. '"'.
166 qq! TITLE="Send a refund for this payment to the payment gateway"!.
171 if ( $cust_pay->closed !~ /^Y/i
172 && ( ( $cust_pay->payby eq 'CARD'
173 && $curuser->access_right('Credit card void')
175 || ( $cust_pay->payby eq 'CHEK'
176 && $curuser->access_right('Echeck void')
178 || ( $cust_pay->payby !~ /^(CARD|CHEK)$/
179 && $curuser->access_right('Regular void')
184 $void = qq! (<A HREF="javascript:areyousure('!.
185 qq!${p}misc/void-cust_pay.cgi?!. $cust_pay->paynum.
186 qq!', 'Are you sure you want to void this payment?')"!.
187 qq! TITLE="Void this payment from the database!.
188 ( $cust_pay->payby =~ /^(CARD|CHEK)$/
189 ? ' (do not send anything to the payment gateway)'
196 if ( $cust_pay->closed !~ /^Y/i
197 && $opt{'deletepayments'}
198 && $curuser->access_right('Delete payment')
201 $delete = qq! (<A HREF="javascript:areyousure('!.
202 qq!${p}misc/delete-cust_pay.cgi?!. $cust_pay->paynum.
203 qq!', 'Are you sure you want to delete this payment?')"!.
204 qq! TITLE="Delete this payment from the database completely - not recommended"!.
209 if ( $cust_pay->closed !~ /^Y/i
210 && scalar(@cust_bill_pay)
211 && $curuser->access_right('Unapply payment')
214 $unapply = qq! (<A HREF="javascript:areyousure('!.
215 qq!${p}misc/unapply-cust_pay.cgi?!. $cust_pay->paynum.
216 qq!', 'Are you sure you want to unapply this payment?')"!.
217 qq! TITLE="Keep this payment, but dissociate it from the invoices it is currently applied against"!.
221 my $otaker = $cust_pay->otaker;
222 $otaker = '<i>auto billing</i>' if $otaker eq 'fs_daily';
223 $otaker = '<i>customer self-service</i>' if $otaker eq 'fs_selfservice';