1 <% $pre %>Credit<% $post %>
2 by <% $cust_credit->otaker %><% "$reason$desc$apply$delete$unapply" %>
5 my( $cust_credit, %opt ) = @_;
7 my $curuser = $FS::CurrentUser::CurrentUser;
9 my @cust_credit_bill = $cust_credit->cust_credit_bill;
10 my @cust_credit_refund = $cust_credit->cust_credit_refund;
12 my( $pre, $post, $desc, $apply, $ext ) = ( '', '', '', '', '' );
13 if ( scalar(@cust_credit_bill) == 0
14 && scalar(@cust_credit_refund) == 0 ) {
16 $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
17 $post = '</FONT></B>';
18 if ( $curuser->access_right('Apply credit') ) {
19 $apply = ' ('. include( '/elements/popup_link.html',
21 'action' => "${p}edit/cust_credit_bill.cgi?".
22 $cust_credit->crednum,
23 'actionlabel' => 'Apply credit',
25 #default# 'height' => 336,
29 } elsif ( scalar(@cust_credit_bill) == 1
30 && scalar(@cust_credit_refund) == 0
31 && $cust_credit->credited == 0 ) {
32 #applied to one invoice, the usual situation
33 $desc = ' '. $cust_credit_bill[0]->applied_to_invoice;
34 } elsif ( scalar(@cust_credit_bill) == 0
35 && scalar(@cust_credit_refund) == 1
36 && $cust_credit->credited == 0 ) {
37 #applied to one refund
38 $desc = ' refunded on '. time2str("%D", $cust_credit_refund[0]->_date);
42 foreach my $app ( sort { $a->_date <=> $b->_date }
43 ( @cust_credit_bill, @cust_credit_refund ) ) {
44 if ( $app->isa('FS::cust_credit_bill') ) {
45 $desc .= ' '.
47 ' '. $app->applied_to_invoice.
49 #' on '. time2str("%D", $app->_date).
50 } elsif ( $app->isa('FS::cust_credit_refund') ) {
51 $desc .= ' '.
53 ' refunded on '. time2str("%D", $app->_date).
56 die "$app is not a FS::cust_credit_bill or a FS::cust_credit_refund";
59 if ( $cust_credit->credited > 0 ) {
60 $desc .= ' <B><FONT COLOR="#FF0000">$'.
61 $cust_credit->credited. ' unapplied</FONT></B>';
62 if ( $curuser->access_right('Apply credit') ) {
63 $desc = ' ('. include( '/elements/popup_link.html',
65 'action' => "${p}edit/cust_credit_bill.cgi?".
66 $cust_credit->crednum,
67 'actionlabel' => 'Apply credit',
69 #default# 'height' => 336,
78 if ( $cust_credit->closed !~ /^Y/i
80 #s'pose deleting a credit isn't bad like deleting a payment
81 # and this needs to be generally available until we have credit voiding..
82 #&& $conf->exists('deletecredits')
84 && $curuser->access_right('Delete credit')
87 $delete = qq! (<A HREF="javascript:areyousure('!.
88 qq!${p}misc/delete-cust_credit.cgi?!. $cust_credit->crednum.
89 qq!', 'Are you sure you want to delete this credit?')">!.
94 if ( $cust_credit->closed !~ /^Y/i
95 && scalar(@cust_credit_bill)
96 && $curuser->access_right('Unapply credit')
99 $unapply = qq! (<A HREF="javascript:areyousure('!.
100 qq!${p}misc/unapply-cust_credit.cgi?!. $cust_credit->crednum.
101 qq!', 'Are you sure you want to unapply this credit?')">!.
105 my $reason = $cust_credit->reason
106 ? ' ('. $cust_credit->reason. ')'