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 $money_char = $conf->config('money_char') || '$';
11 my $curuser = $FS::CurrentUser::CurrentUser;
13 my @cust_bill_pay = $cust_pay->cust_bill_pay;
14 my @cust_pay_refund = $cust_pay->cust_pay_refund;
16 my ($payby,$payinfo) = translate_payinfo($cust_pay);
17 my $target = "$payby$payinfo";
18 $payby = translate_payby($payby,$payinfo);
19 my $info = $payby ? "($payby$payinfo)" : '';
22 if ( $opt{'pkg-balances'} && $cust_pay->pkgnum ) {
23 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cust_pay->pkgnum } );
24 $desc .= ' for '. $cust_pkg->pkg_label_long;
27 my %cust_bill_pay_width = ('width' => 392);
28 my %cust_bill_pay_height = ();
29 if ($conf->exists('cust_bill_pay_pkg-manual')) {
30 %cust_bill_pay_width = ('width' => 592);
31 %cust_bill_pay_height = ('height' => 436);
36 my $italicize_otaker = 0;
37 my $otaker = $cust_pay->otaker;
38 if ( $otaker eq 'fs_daily' ) {
39 $otaker = 'auto billing';
40 $italicize_otaker = 1;
42 if ( $otaker eq 'fs_selfservice' ) {
43 $otaker = 'customer self-service';
44 $italicize_otaker = 1;
47 my $payment = emt("Payment by [_1]",$otaker);
48 $payment =~ s/$otaker/<i>$otaker<\/i>/ if $italicize_otaker;
50 if ( scalar(@cust_bill_pay) == 0
51 && scalar(@cust_pay_refund) == 0 ) {
53 $payment = emt("Unapplied Payment by [_1]",$otaker);
54 $payment =~ s/$otaker/<i>$otaker<\/i>/ if $italicize_otaker;
55 $payment = '<B><FONT COLOR="#FF0000">'.$payment.'</FONT></B>';
56 if ( $curuser->access_right('Apply payment') ) {
57 if ( $cust_pay->cust_main->total_owed > 0 ) {
59 include( '/elements/popup_link.html',
60 'label' => emt('apply'),
61 'action' => "${p}edit/cust_bill_pay.cgi?".
63 'actionlabel' => emt('Apply payment'),
65 %cust_bill_pay_height,
69 if ( $cust_pay->cust_main->total_unapplied_refunds > 0 ) {
71 include( '/elements/popup_link.html',
72 'label' => emt('apply to refund'),
73 'action' => "${p}edit/cust_pay_refund.cgi?".
75 'actionlabel' => emt('Apply payment to refund'),
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 .= emt(" refunded on [_1]", time2str($date_format, $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 .= ' ' . $money_char . $app->amount . ' ' .
98 $app->applied_to_invoice . '<BR>';
99 } elsif ( $app->isa('FS::cust_pay_refund') ) {
100 $desc .= ' ' .
101 emt("[_1][_2] refunded on [_3]", $money_char, $app->amount,
102 time2str($date_format, $app->_date) ) . '<BR>';
104 die "$app is not a FS::cust_bill_pay or FS::cust_pay_refund";
107 if ( $cust_pay->unapplied > 0 ) {
108 $desc .= ' '.
109 '<B><FONT COLOR="#FF0000">' .
110 emt("[_1][_2] unapplied", $money_char, $cust_pay->unapplied) .
112 if ( $curuser->access_right('Apply payment') ) {
113 if ( $cust_pay->cust_main->total_owed > 0 ) {
115 include( '/elements/popup_link.html',
116 'label' => emt('apply'),
117 'action' => "${p}edit/cust_bill_pay.cgi?".
119 'actionlabel' => emt('Apply payment'),
120 %cust_bill_pay_width,
121 %cust_bill_pay_height,
125 if ( $cust_pay->cust_main->total_unapplied_refunds > 0 ) {
127 include( '/elements/popup_link.html',
128 'label' => emt('apply to refund'),
129 'action' => "${p}edit/cust_pay_refund.cgi?".
131 'actionlabel' => emt('Apply payment to refund'),
142 ' ('. include('/elements/popup_link.html',
143 'label' => emt('view receipt'),
144 'action' => "${p}view/cust_pay.html?link=popup;paynum=".
146 'actionlabel' => emt('Payment Receipt'),
151 my $refund_days = $opt{'card_refund-days'} || 120;
152 my @rights = ('Refund payment');
153 push @rights, 'Refund credit card payment' if $payby eq 'CARD';
154 push @rights, 'Refund Echeck payment' if $payby eq 'CHEK';
155 if ( $cust_pay->closed !~ /^Y/i
156 && $cust_pay->payby =~ /^(CARD|CHEK)$/
157 && time-$cust_pay->_date < $refund_days*86400
158 && $cust_pay->unrefunded > 0
159 && $curuser->access_right(\@rights)
161 $refund = qq! (<A HREF="${p}edit/cust_refund.cgi?payby=$1;!.
162 qq!paynum=!. $cust_pay->paynum. '"'.
163 qq! TITLE="! .emt('Send a refund for this payment to the payment gateway')
164 . '">' . emt('refund') . '</A>)';
168 my $voidmsg = $cust_pay->payby =~ /^(CARD|CHEK)$/
169 ? ' (' . emt('do not send anything to the payment gateway').')'
171 $void = areyousure_link("${p}misc/void-cust_pay.cgi?".$cust_pay->paynum,
172 emt('Are you sure you want to void this payment?'),
173 emt('Void this payment from the database') . $voidmsg,
176 if ( $cust_pay->closed !~ /^Y/i
177 && ( ( $cust_pay->payby eq 'CARD'
178 && $curuser->access_right('Credit card void')
180 || ( $cust_pay->payby eq 'CHEK'
181 && $curuser->access_right('Echeck void')
183 || ( $cust_pay->payby !~ /^(CARD|CHEK)$/
184 && $curuser->access_right('Void payments')
190 $delete = areyousure_link("${p}misc/delete-cust_pay.cgi?".$cust_pay->paynum,
191 emt('Are you sure you want to delete this payment?'),
192 emt('Delete this payment from the database completely - not recommended'),
195 if ( $cust_pay->closed !~ /^Y/i && $opt{'deletepayments'}
196 && $curuser->access_right('Delete payment') );
199 $unapply = areyousure_link("${p}misc/unapply-cust_pay.cgi?".$cust_pay->paynum,
200 emt('Are you sure you want to unapply this payment?'),
201 emt('Keep this payment, but dissociate it from the invoices it is currently applied against'),
204 if ( $cust_pay->closed !~ /^Y/i && scalar(@cust_bill_pay)
205 && $curuser->access_right('Unapply payment') );