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 $otaker = $cust_pay->otaker;
37 $otaker = '<i>auto billing</i>' if $otaker eq 'fs_daily';
38 $otaker = '<i>customer self-service</i>' if $otaker eq 'fs_selfservice';
40 my $payment = emt("Payment by [_1]",$otaker);
42 if ( scalar(@cust_bill_pay) == 0
43 && scalar(@cust_pay_refund) == 0 ) {
45 $payment = '<B><FONT COLOR="#FF0000">'
46 . emt("Unapplied Payment by [_1]",$otaker)
48 if ( $curuser->access_right('Apply payment') ) {
49 if ( $cust_pay->cust_main->total_owed > 0 ) {
51 include( '/elements/popup_link.html',
52 'label' => emt('apply'),
53 'action' => "${p}edit/cust_bill_pay.cgi?".
55 'actionlabel' => emt('Apply payment'),
57 %cust_bill_pay_height,
61 if ( $cust_pay->cust_main->total_unapplied_refunds > 0 ) {
63 include( '/elements/popup_link.html',
64 'label' => emt('apply to refund'),
65 'action' => "${p}edit/cust_pay_refund.cgi?".
67 'actionlabel' => emt('Apply payment to refund'),
73 } elsif ( scalar(@cust_bill_pay) == 1
74 && scalar(@cust_pay_refund) == 0
75 && $cust_pay->unapplied == 0 ) {
76 #applied to one invoice, the usual situation
77 $desc .= ' '. $cust_bill_pay[0]->applied_to_invoice;
78 } elsif ( scalar(@cust_bill_pay) == 0
79 && scalar(@cust_pay_refund) == 1
80 && $cust_pay->unapplied == 0 ) {
81 #applied to one refund
82 $desc .= emt(" refunded on [_1]", time2str($date_format, $cust_pay_refund[0]->_date) );
86 foreach my $app ( sort { $a->_date <=> $b->_date }
87 ( @cust_bill_pay, @cust_pay_refund ) ) {
88 if ( $app->isa('FS::cust_bill_pay') ) {
89 $desc .= ' ' . $money_char . $app->amount . ' ' .
90 $app->applied_to_invoice . '<BR>';
91 } elsif ( $app->isa('FS::cust_pay_refund') ) {
92 $desc .= ' ' .
93 emt("[_1][_2] refunded on [_3]", $money_char, $app->amount,
94 time2str($date_format, $app->_date) ) . '<BR>';
96 die "$app is not a FS::cust_bill_pay or FS::cust_pay_refund";
99 if ( $cust_pay->unapplied > 0 ) {
100 $desc .= ' '.
101 '<B><FONT COLOR="#FF0000">' .
102 emt("[_1][_2] unapplied", $money_char, $cust_pay->unapplied) .
104 if ( $curuser->access_right('Apply payment') ) {
105 if ( $cust_pay->cust_main->total_owed > 0 ) {
107 include( '/elements/popup_link.html',
108 'label' => emt('apply'),
109 'action' => "${p}edit/cust_bill_pay.cgi?".
111 'actionlabel' => emt('Apply payment'),
112 %cust_bill_pay_width,
113 %cust_bill_pay_height,
117 if ( $cust_pay->cust_main->total_unapplied_refunds > 0 ) {
119 include( '/elements/popup_link.html',
120 'label' => emt('apply to refund'),
121 'action' => "${p}edit/cust_pay_refund.cgi?".
123 'actionlabel' => emt('Apply payment to refund'),
134 ' ('. include('/elements/popup_link.html',
135 'label' => emt('view receipt'),
136 'action' => "${p}view/cust_pay.html?link=popup;paynum=".
138 'actionlabel' => emt('Payment Receipt'),
143 my $refund_days = $opt{'card_refund-days'} || 120;
144 my @rights = ('Refund payment');
145 push @rights, 'Refund credit card payment' if $payby eq 'CARD';
146 push @rights, 'Refund Echeck payment' if $payby eq 'CHEK';
147 if ( $cust_pay->closed !~ /^Y/i
148 && $cust_pay->payby =~ /^(CARD|CHEK)$/
149 && time-$cust_pay->_date < $refund_days*86400
150 && $cust_pay->unrefunded > 0
151 && $curuser->access_right(\@rights)
153 $refund = qq! (<A HREF="${p}edit/cust_refund.cgi?payby=$1;!.
154 qq!paynum=!. $cust_pay->paynum. '"'.
155 qq! TITLE="! .emt('Send a refund for this payment to the payment gateway')
156 . '">' . emt('refund') . '</A>)';
160 my $voidmsg = $cust_pay->payby =~ /^(CARD|CHEK)$/
161 ? ' (' . emt('do not send anything to the payment gateway').')'
163 $void = areyousure_link("${p}misc/void-cust_pay.cgi?".$cust_pay->paynum,
164 emt('Are you sure you want to void this payment?'),
165 emt('Void this payment from the database') . $voidmsg,
168 if ( $cust_pay->closed !~ /^Y/i
169 && ( ( $cust_pay->payby eq 'CARD'
170 && $curuser->access_right('Credit card void')
172 || ( $cust_pay->payby eq 'CHEK'
173 && $curuser->access_right('Echeck void')
175 || ( $cust_pay->payby !~ /^(CARD|CHEK)$/
176 && $curuser->access_right('Regular void')
182 $delete = areyousure_link("${p}misc/delete-cust_pay.cgi?".$cust_pay->paynum,
183 emt('Are you sure you want to delete this payment?'),
184 emt('Delete this payment from the database completely - not recommended'),
187 if ( $cust_pay->closed !~ /^Y/i && $opt{'deletepayments'}
188 && $curuser->access_right('Delete payment') );
191 $unapply = areyousure_link("${p}misc/unapply-cust_pay.cgi?".$cust_pay->paynum,
192 emt('Are you sure you want to unapply this payment?'),
193 emt('Keep this payment, but dissociate it from the invoices it is currently applied against'),
196 if ( $cust_pay->closed !~ /^Y/i && scalar(@cust_bill_pay)
197 && $curuser->access_right('Unapply payment') );