1 <% $payment. ' '. $info. $desc.
2 $view. $change_pkg. $apply. $refund. $void. $delete. $unapply
6 my( $cust_pay, %opt ) = @_;
8 my $date_format = $opt{'date_format'} || '%m/%d/%Y';
10 my @cust_bill_pay = $cust_pay->cust_bill_pay;
11 my @cust_pay_refund = $cust_pay->cust_pay_refund;
13 my ($payby,$payinfo) = translate_payinfo($cust_pay);
14 my $target = "$payby$payinfo";
15 $payby = translate_payby($payby,$payinfo);
16 my $info = $payby ? "($payby$payinfo)" : '';
19 if ( $opt{'pkg-balances'} && $cust_pay->pkgnum ) {
20 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cust_pay->pkgnum } );
21 $desc .= ' for '. $cust_pkg->pkg_label_long;
24 my %cust_bill_pay_width = ('width' => 392);
25 my %cust_bill_pay_height = ();
26 if ( $opt{'cust_bill_pay_pkg-manual'} ) {
27 %cust_bill_pay_width = ('width' => 592);
28 %cust_bill_pay_height = ('height' => 436);
33 my $italicize_otaker = 0;
34 my $otaker = $cust_pay->otaker;
35 if ( $otaker eq 'fs_daily' ) {
36 $otaker = 'auto billing';
37 $italicize_otaker = 1;
39 if ( $otaker eq 'fs_selfservice' ) {
40 $otaker = 'customer self-service';
41 $italicize_otaker = 1;
44 my $payment = emt("Payment by [_1]",$otaker);
45 $payment =~ s/$otaker/<i>$otaker<\/i>/ if $italicize_otaker;
47 if ( scalar(@cust_bill_pay) == 0
48 && scalar(@cust_pay_refund) == 0 ) {
50 $payment = emt("Unapplied Payment by [_1]",$otaker);
51 $payment =~ s/$otaker/<i>$otaker<\/i>/ if $italicize_otaker;
52 $payment = '<B><FONT COLOR="#FF0000">'.$payment.'</FONT></B>';
53 if ( $opt{'Apply payment'} ) {
54 if ( $opt{total_owed} > 0 ) {
56 include( '/elements/popup_link.html',
57 'label' => emt('apply'),
58 'action' => "${p}edit/cust_bill_pay.cgi?".
60 'actionlabel' => emt('Apply payment'),
62 %cust_bill_pay_height,
66 if ( $opt{total_unapplied_refunds} > 0 ) {
68 include( '/elements/popup_link.html',
69 'label' => emt('apply to refund'),
70 'action' => "${p}edit/cust_pay_refund.cgi?".
72 'actionlabel' => emt('Apply payment to refund'),
78 } elsif ( scalar(@cust_bill_pay) == 1
79 && scalar(@cust_pay_refund) == 0
80 && $cust_pay->unapplied == 0 ) {
81 #applied to one invoice, the usual situation
82 $desc .= ' '. $cust_bill_pay[0]->applied_to_invoice;
83 } elsif ( scalar(@cust_bill_pay) == 0
84 && scalar(@cust_pay_refund) == 1
85 && $cust_pay->unapplied == 0 ) {
86 #applied to one refund
87 $desc .= emt(" refunded on [_1]", time2str($date_format, $cust_pay_refund[0]->_date) );
91 foreach my $app ( sort { $a->_date <=> $b->_date }
92 ( @cust_bill_pay, @cust_pay_refund ) ) {
93 if ( $app->isa('FS::cust_bill_pay') ) {
94 $desc .= ' ' . $opt{money_char} . $app->amount . ' ' .
95 $app->applied_to_invoice . '<BR>';
96 } elsif ( $app->isa('FS::cust_pay_refund') ) {
97 $desc .= ' ' .
98 emt("[_1][_2] refunded on [_3]", $opt{money_char}, $app->amount,
99 time2str($date_format, $app->_date) ) . '<BR>';
101 die "$app is not a FS::cust_bill_pay or FS::cust_pay_refund";
104 if ( $cust_pay->unapplied > 0 ) {
105 $desc .= ' '.
106 '<B><FONT COLOR="#FF0000">'.
107 emt("[_1][_2] unapplied", $opt{money_char}, $cust_pay->unapplied).
109 if ( $opt{'Apply payment'} ) {
110 if ( $opt{total_owed} > 0 ) {
112 include( '/elements/popup_link.html',
113 'label' => emt('apply'),
114 'action' => "${p}edit/cust_bill_pay.cgi?".
116 'actionlabel' => emt('Apply payment'),
117 %cust_bill_pay_width,
118 %cust_bill_pay_height,
122 if ( $opt{total_unapplied_refunds} > 0 ) {
124 include( '/elements/popup_link.html',
125 'label' => emt('apply to refund'),
126 'action' => "${p}edit/cust_pay_refund.cgi?".
128 'actionlabel' => emt('Apply payment to refund'),
139 ' ('. include('/elements/popup_link.html',
140 'label' => emt('view receipt'),
141 'action' => "${p}view/cust_pay.html?link=popup;paynum=".
143 'actionlabel' => emt('Payment Receipt'),
148 if ( $apply && $opt{'pkg-balances'} && $cust_pay->pkgnum ) {
150 ' ('. include('/elements/popup_link.html',
151 'label' => emt('change package'),
152 'action' => "${p}edit/cust_pay-pkgnum.html?paynum=".
154 'actionlabel' => emt('Change payment package'),
161 my $refund_days = $opt{'card_refund-days'} || 120;
162 my $refund_right = '';
163 $refund_right = 'Refund credit card payment' if $cust_pay->payby eq 'CARD';
164 $refund_right = 'Refund Echeck payment' if $cust_pay->payby eq 'CHEK';
165 if ( $cust_pay->closed !~ /^Y/i
166 && $cust_pay->payby =~ /^(CARD|CHEK)$/
167 && time-$cust_pay->_date < $refund_days*86400
168 && $cust_pay->unrefunded > 0
169 && $opt{$refund_right}
171 $refund = qq! (<A HREF="${p}edit/cust_refund.cgi?payby=$1;!.
172 qq!paynum=!. $cust_pay->paynum. '"'.
173 qq! TITLE="! .emt('Send a refund for this payment to the payment gateway')
174 . '">' . emt('refund') . '</A>)';
178 my $voidmsg = $cust_pay->payby =~ /^(CARD|CHEK)$/
179 ? ' (' . emt('do not send anything to the payment gateway').')'
181 $void = areyousure_link("${p}misc/void-cust_pay.cgi?".$cust_pay->paynum,
182 emt('Are you sure you want to void this payment?'),
183 emt('Void this payment from the database') . $voidmsg,
186 if $cust_pay->closed !~ /^Y/i
187 && ( ( $cust_pay->payby eq 'CARD' && $opt{'Credit card void'} )
188 || ( $cust_pay->payby eq 'CHEK' && $opt{'Echeck void'} )
189 || ( $cust_pay->payby !~ /^(CARD|CHEK)$/ && $opt{'Void payments'} )
193 $delete = areyousure_link("${p}misc/delete-cust_pay.cgi?".$cust_pay->paynum,
194 emt('Are you sure you want to delete this payment?'),
195 emt('Delete this payment from the database completely - not recommended'),
198 if $cust_pay->closed !~ /^Y/i
199 && $opt{'deletepayments'}
200 && $opt{'Delete payment'};
203 $unapply = areyousure_link("${p}misc/unapply-cust_pay.cgi?".$cust_pay->paynum,
204 emt('Are you sure you want to unapply this payment?'),
205 emt('Keep this payment, but dissociate it from the invoices it is currently applied against'),
208 if $cust_pay->closed !~ /^Y/i
209 && scalar(@cust_bill_pay)
210 && $opt{'Unapply payment'};