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 @cust_bill_pay = $cust_pay->cust_bill_pay;
10 my @cust_pay_refund = $cust_pay->cust_pay_refund;
12 my ($payby,$payinfo) = translate_payinfo($cust_pay);
13 my $target = "$payby$payinfo";
14 $payby = translate_payby($payby,$payinfo);
15 my $info = $payby ? "($payby$payinfo)" : '';
18 if ( $opt{'pkg-balances'} && $cust_pay->pkgnum ) {
19 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cust_pay->pkgnum } );
20 $desc .= ' for '. $cust_pkg->pkg_label_long;
23 my %cust_bill_pay_width = ('width' => 392);
24 my %cust_bill_pay_height = ();
25 if ( $opt{'cust_bill_pay_pkg-manual'} ) {
26 %cust_bill_pay_width = ('width' => 592);
27 %cust_bill_pay_height = ('height' => 436);
32 my $italicize_otaker = 0;
33 my $otaker = $cust_pay->otaker;
34 if ( $otaker eq 'fs_daily' ) {
35 $otaker = 'auto billing';
36 $italicize_otaker = 1;
38 if ( $otaker eq 'fs_selfservice' ) {
39 $otaker = 'customer self-service';
40 $italicize_otaker = 1;
43 my $payment = emt("Payment by [_1]",$otaker);
44 $payment =~ s/$otaker/<i>$otaker<\/i>/ if $italicize_otaker;
46 if ( scalar(@cust_bill_pay) == 0
47 && scalar(@cust_pay_refund) == 0 ) {
49 $payment = emt("Unapplied Payment by [_1]",$otaker);
50 $payment =~ s/$otaker/<i>$otaker<\/i>/ if $italicize_otaker;
51 $payment = '<B><FONT COLOR="#FF0000">'.$payment.'</FONT></B>';
52 if ( $opt{'Apply payment'} ) {
53 if ( $opt{total_owed} > 0 ) {
55 include( '/elements/popup_link.html',
56 'label' => emt('apply'),
57 'action' => "${p}edit/cust_bill_pay.cgi?".
59 'actionlabel' => emt('Apply payment'),
61 %cust_bill_pay_height,
65 if ( $opt{total_unapplied_refunds} > 0 ) {
67 include( '/elements/popup_link.html',
68 'label' => emt('apply to refund'),
69 'action' => "${p}edit/cust_pay_refund.cgi?".
71 'actionlabel' => emt('Apply payment to refund'),
77 } elsif ( scalar(@cust_bill_pay) == 1
78 && scalar(@cust_pay_refund) == 0
79 && $cust_pay->unapplied == 0 ) {
80 #applied to one invoice, the usual situation
81 $desc .= ' '. $cust_bill_pay[0]->applied_to_invoice;
82 } elsif ( scalar(@cust_bill_pay) == 0
83 && scalar(@cust_pay_refund) == 1
84 && $cust_pay->unapplied == 0 ) {
85 #applied to one refund
86 $desc .= emt(" refunded on [_1]", time2str($date_format, $cust_pay_refund[0]->_date) );
90 foreach my $app ( sort { $a->_date <=> $b->_date }
91 ( @cust_bill_pay, @cust_pay_refund ) ) {
92 if ( $app->isa('FS::cust_bill_pay') ) {
93 $desc .= ' ' . $opt{money_char} . $app->amount . ' ' .
94 $app->applied_to_invoice . '<BR>';
95 } elsif ( $app->isa('FS::cust_pay_refund') ) {
96 $desc .= ' ' .
97 emt("[_1][_2] refunded on [_3]", $opt{money_char}, $app->amount,
98 time2str($date_format, $app->_date) ) . '<BR>';
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 emt("[_1][_2] unapplied", $opt{money_char}, $cust_pay->unapplied).
108 if ( $opt{'Apply payment'} ) {
109 if ( $opt{total_owed} > 0 ) {
111 include( '/elements/popup_link.html',
112 'label' => emt('apply'),
113 'action' => "${p}edit/cust_bill_pay.cgi?".
115 'actionlabel' => emt('Apply payment'),
116 %cust_bill_pay_width,
117 %cust_bill_pay_height,
121 if ( $opt{total_unapplied_refunds} > 0 ) {
123 include( '/elements/popup_link.html',
124 'label' => emt('apply to refund'),
125 'action' => "${p}edit/cust_pay_refund.cgi?".
127 'actionlabel' => emt('Apply payment to refund'),
138 ' ('. include('/elements/popup_link.html',
139 'label' => emt('view receipt'),
140 'action' => "${p}view/cust_pay.html?link=popup;paynum=".
142 'actionlabel' => emt('Payment Receipt'),
147 my $refund_days = $opt{'card_refund-days'} || 120;
148 my $refund_right = '';
149 $refund_right = 'Refund credit card payment' if $cust_pay->payby eq 'CARD';
150 $refund_right = 'Refund Echeck payment' if $cust_pay->payby eq 'CHEK';
151 if ( $cust_pay->closed !~ /^Y/i
152 && $cust_pay->payby =~ /^(CARD|CHEK)$/
153 && time-$cust_pay->_date < $refund_days*86400
154 && $cust_pay->unrefunded > 0
155 && $opt{$refund_right}
157 $refund = qq! (<A HREF="${p}edit/cust_refund.cgi?payby=$1;!.
158 qq!paynum=!. $cust_pay->paynum. '"'.
159 qq! TITLE="! .emt('Send a refund for this payment to the payment gateway')
160 . '">' . emt('refund') . '</A>)';
164 my $voidmsg = $cust_pay->payby =~ /^(CARD|CHEK)$/
165 ? ' (' . emt('do not send anything to the payment gateway').')'
167 $void = areyousure_link("${p}misc/void-cust_pay.cgi?".$cust_pay->paynum,
168 emt('Are you sure you want to void this payment?'),
169 emt('Void this payment from the database') . $voidmsg,
172 if $cust_pay->closed !~ /^Y/i
173 && ( ( $cust_pay->payby eq 'CARD' && $opt{'Credit card void'} )
174 || ( $cust_pay->payby eq 'CHEK' && $opt{'Echeck void'} )
175 || ( $cust_pay->payby !~ /^(CARD|CHEK)$/ && $opt{'Void payments'} )
179 $delete = areyousure_link("${p}misc/delete-cust_pay.cgi?".$cust_pay->paynum,
180 emt('Are you sure you want to delete this payment?'),
181 emt('Delete this payment from the database completely - not recommended'),
184 if $cust_pay->closed !~ /^Y/i
185 && $opt{'deletepayments'}
186 && $opt{'Delete payment'};
189 $unapply = areyousure_link("${p}misc/unapply-cust_pay.cgi?".$cust_pay->paynum,
190 emt('Are you sure you want to unapply this payment?'),
191 emt('Keep this payment, but dissociate it from the invoices it is currently applied against'),
194 if $cust_pay->closed !~ /^Y/i
195 && scalar(@cust_bill_pay)
196 && $opt{'Unapply payment'};