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 = mt("ABA [_1], Acct #[_2]",$aba,$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 = translate_payby($payby,$payinfo);
28 my $info = $payby ? "($payby$payinfo)" : '';
31 if ( $opt{'pkg-balances'} && $cust_pay->pkgnum ) {
32 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cust_pay->pkgnum } );
33 $desc .= ' for '. $cust_pkg->pkg_label_long;
36 my %cust_bill_pay_width = ('width' => 392);
37 my %cust_bill_pay_height = ();
38 if ($conf->exists('cust_bill_pay_pkg-manual')) {
39 %cust_bill_pay_width = ('width' => 592);
40 %cust_bill_pay_height = ('height' => 436);
43 my( $apply, $ext ) = ( '', '', '', '' );
45 my $otaker = $cust_pay->otaker;
46 $otaker = '<i>auto billing</i>' if $otaker eq 'fs_daily';
47 $otaker = '<i>customer self-service</i>' if $otaker eq 'fs_selfservice';
49 my $payment = mt("Payment by [_1]",$otaker);
51 if ( scalar(@cust_bill_pay) == 0
52 && scalar(@cust_pay_refund) == 0 ) {
54 $payment = '<B><FONT COLOR="#FF0000">'
55 . mt("Unapplied Payment by [_1]",$otaker)
57 if ( $curuser->access_right('Apply payment') ) {
58 if ( $cust_pay->cust_main->total_owed > 0 ) {
60 include( '/elements/popup_link.html',
61 'label' => mt('apply'),
62 'action' => "${p}edit/cust_bill_pay.cgi?".
64 'actionlabel' => mt('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' => mt('apply to refund'),
74 'action' => "${p}edit/cust_pay_refund.cgi?".
76 'actionlabel' => mt('Apply payment to refund'),
82 } elsif ( scalar(@cust_bill_pay) == 1
83 && scalar(@cust_pay_refund) == 0
84 && $cust_pay->unapplied == 0 ) {
85 #applied to one invoice, the usual situation
86 $desc .= ' '. $cust_bill_pay[0]->applied_to_invoice;
87 } elsif ( scalar(@cust_bill_pay) == 0
88 && scalar(@cust_pay_refund) == 1
89 && $cust_pay->unapplied == 0 ) {
90 #applied to one refund
91 $desc .= mt(" refunded on [_1]", time2str($date_format, $cust_pay_refund[0]->_date) );
95 foreach my $app ( sort { $a->_date <=> $b->_date }
96 ( @cust_bill_pay, @cust_pay_refund ) ) {
97 if ( $app->isa('FS::cust_bill_pay') ) {
98 $desc .= ' '.
100 ' '. $app->applied_to_invoice.
102 #' on '. time2str($date_format, $cust_bill_pay->_date).
103 } elsif ( $app->isa('FS::cust_pay_refund') ) {
104 $desc .= ' '.
106 mt(" refunded on [_1]", time2str($date_format, $app->_date) ) .
109 die "$app is not a FS::cust_bill_pay or FS::cust_pay_refund";
112 if ( $cust_pay->unapplied > 0 ) {
113 $desc .= ' '.
114 '<B><FONT COLOR="#FF0000">$'.
115 $cust_pay->unapplied. ' unapplied</FONT></B>';
116 if ( $curuser->access_right('Apply payment') ) {
117 if ( $cust_pay->cust_main->total_owed > 0 ) {
119 include( '/elements/popup_link.html',
120 'label' => mt('apply'),
121 'action' => "${p}edit/cust_bill_pay.cgi?".
123 'actionlabel' => mt('Apply payment'),
124 %cust_bill_pay_width,
125 %cust_bill_pay_height,
129 if ( $cust_pay->cust_main->total_unapplied_refunds > 0 ) {
131 include( '/elements/popup_link.html',
132 'label' => mt('apply to refund'),
133 'action' => "${p}edit/cust_pay_refund.cgi?".
135 'actionlabel' => mt('Apply payment to refund'),
146 ' ('. include('/elements/popup_link.html',
147 'label' => mt('view receipt'),
148 'action' => "${p}view/cust_pay.html?link=popup;paynum=".
150 'actionlabel' => mt('Payment Receipt'),
155 my $refund_days = $opt{'card_refund-days'} || 120;
156 my @rights = ('Refund payment');
157 push @rights, 'Refund credit card payment' if $payby eq 'CARD';
158 push @rights, 'Refund Echeck payment' if $payby eq 'CHEK';
159 if ( $cust_pay->closed !~ /^Y/i
160 && $cust_pay->payby =~ /^(CARD|CHEK)$/
161 && time-$cust_pay->_date < $refund_days*86400
162 && $cust_pay->unrefunded > 0
163 && $curuser->access_right(\@rights)
165 $refund = qq! (<A HREF="${p}edit/cust_refund.cgi?payby=$1;!.
166 qq!paynum=!. $cust_pay->paynum. '"'.
167 qq! TITLE="Send a refund for this payment to the payment gateway"!.
172 my $voidmsg = $cust_pay->payby =~ /^(CARD|CHEK)$/
173 ? ' (' . mt('do not send anything to the payment gateway').')'
175 $void = areyousure_link("${p}misc/void-cust_pay.cgi?".$cust_pay->paynum,
176 mt('Are you sure you want to void this payment?'),
177 mt('Void this payment from the database') . $voidmsg,
180 if ( $cust_pay->closed !~ /^Y/i
181 && ( ( $cust_pay->payby eq 'CARD'
182 && $curuser->access_right('Credit card void')
184 || ( $cust_pay->payby eq 'CHEK'
185 && $curuser->access_right('Echeck void')
187 || ( $cust_pay->payby !~ /^(CARD|CHEK)$/
188 && $curuser->access_right('Regular void')
194 $delete = areyousure_link("${p}misc/delete-cust_pay.cgi?".$cust_pay->paynum,
195 mt('Are you sure you want to delete this payment?'),
196 mt('Delete this payment from the database completely - not recommended'),
199 if ( $cust_pay->closed !~ /^Y/i && $opt{'deletepayments'}
200 && $curuser->access_right('Delete payment') );
203 $unapply = areyousure_link("${p}misc/unapply-cust_pay.cgi?".$cust_pay->paynum,
204 mt('Are you sure you want to unapply this payment?'),
205 mt('Keep this payment, but dissociate it from the invoices it is currently applied against'),
208 if ( $cust_pay->closed !~ /^Y/i && scalar(@cust_bill_pay)
209 && $curuser->access_right('Unapply payment') );