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 if ( $cust_credit->cust_main->total_owed > 0 ) {
21 include( '/elements/popup_link.html',
23 'action' => "${p}edit/cust_credit_bill.cgi?".
24 $cust_credit->crednum,
25 'actionlabel' => 'Apply credit',
27 #default# 'height' => 336,
31 if ( $cust_credit->cust_main->total_unapplied_refunds > 0 ) {
33 include( '/elements/popup_link.html',
34 'label' => 'apply to refund',
35 'action' => "${p}edit/cust_credit_refund.cgi?".
36 $cust_credit->crednum,
37 'actionlabel' => 'Apply credit to refund',
39 #default# 'height' => 336,
44 } elsif ( scalar(@cust_credit_bill) == 1
45 && scalar(@cust_credit_refund) == 0
46 && $cust_credit->credited == 0 ) {
47 #applied to one invoice, the usual situation
48 $desc = ' '. $cust_credit_bill[0]->applied_to_invoice;
49 } elsif ( scalar(@cust_credit_bill) == 0
50 && scalar(@cust_credit_refund) == 1
51 && $cust_credit->credited == 0 ) {
52 #applied to one refund
53 $desc = ' refunded on '. time2str("%D", $cust_credit_refund[0]->_date);
57 foreach my $app ( sort { $a->_date <=> $b->_date }
58 ( @cust_credit_bill, @cust_credit_refund ) ) {
59 if ( $app->isa('FS::cust_credit_bill') ) {
60 $desc .= ' '.
62 ' '. $app->applied_to_invoice.
64 #' on '. time2str("%D", $app->_date).
65 } elsif ( $app->isa('FS::cust_credit_refund') ) {
66 $desc .= ' '.
68 ' refunded on '. time2str("%D", $app->_date).
71 die "$app is not a FS::cust_credit_bill or a FS::cust_credit_refund";
74 if ( $cust_credit->credited > 0 ) {
75 $desc .= ' <B><FONT COLOR="#FF0000">$'.
76 $cust_credit->credited. ' unapplied</FONT></B>';
77 if ( $curuser->access_right('Apply credit') ) {
78 if ( $cust_credit->cust_main->total_owed > 0 ) {
80 include( '/elements/popup_link.html',
82 'action' => "${p}edit/cust_credit_bill.cgi?".
83 $cust_credit->crednum,
84 'actionlabel' => 'Apply credit',
86 #default# 'height' => 336,
90 if ( $cust_credit->cust_main->total_unapplied_refunds > 0 ) {
92 include( '/elements/popup_link.html',
93 'label' => 'apply to refund',
94 'action' => "${p}edit/cust_credit_refund.cgi?".
95 $cust_credit->crednum,
96 'actionlabel' => 'Apply credit to refund',
98 #default# 'height' => 336,
108 if ( $cust_credit->closed !~ /^Y/i
110 #s'pose deleting a credit isn't bad like deleting a payment
111 # and this needs to be generally available until we have credit voiding..
112 #&& $conf->exists('deletecredits')
114 && $curuser->access_right('Delete credit')
117 $delete = qq! (<A HREF="javascript:areyousure('!.
118 qq!${p}misc/delete-cust_credit.cgi?!. $cust_credit->crednum.
119 qq!', 'Are you sure you want to delete this credit?')">!.
124 if ( $cust_credit->closed !~ /^Y/i
125 && scalar(@cust_credit_bill)
126 && $curuser->access_right('Unapply credit')
129 $unapply = qq! (<A HREF="javascript:areyousure('!.
130 qq!${p}misc/unapply-cust_credit.cgi?!. $cust_credit->crednum.
131 qq!', 'Are you sure you want to unapply this credit?')">!.
135 my $reason = $cust_credit->reason
136 ? ' ('. $cust_credit->reason. ')'