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,
28 #XXX if there are any open refunds
29 $apply.= ' ('. include( '/elements/popup_link.html',
30 'label' => 'apply to refund',
31 'action' => "${p}edit/cust_credit_refund.cgi?".
32 $cust_credit->crednum,
33 'actionlabel' => 'Apply credit to refund',
35 #default# 'height' => 336,
39 } elsif ( scalar(@cust_credit_bill) == 1
40 && scalar(@cust_credit_refund) == 0
41 && $cust_credit->credited == 0 ) {
42 #applied to one invoice, the usual situation
43 $desc = ' '. $cust_credit_bill[0]->applied_to_invoice;
44 } elsif ( scalar(@cust_credit_bill) == 0
45 && scalar(@cust_credit_refund) == 1
46 && $cust_credit->credited == 0 ) {
47 #applied to one refund
48 $desc = ' refunded on '. time2str("%D", $cust_credit_refund[0]->_date);
52 foreach my $app ( sort { $a->_date <=> $b->_date }
53 ( @cust_credit_bill, @cust_credit_refund ) ) {
54 if ( $app->isa('FS::cust_credit_bill') ) {
55 $desc .= ' '.
57 ' '. $app->applied_to_invoice.
59 #' on '. time2str("%D", $app->_date).
60 } elsif ( $app->isa('FS::cust_credit_refund') ) {
61 $desc .= ' '.
63 ' refunded on '. time2str("%D", $app->_date).
66 die "$app is not a FS::cust_credit_bill or a FS::cust_credit_refund";
69 if ( $cust_credit->credited > 0 ) {
70 $desc .= ' <B><FONT COLOR="#FF0000">$'.
71 $cust_credit->credited. ' unapplied</FONT></B>';
72 if ( $curuser->access_right('Apply credit') ) {
73 $apply = ' ('. include( '/elements/popup_link.html',
75 'action' => "${p}edit/cust_credit_bill.cgi?".
76 $cust_credit->crednum,
77 'actionlabel' => 'Apply credit',
79 #default# 'height' => 336,
82 #XXX if there are any open refunds
83 $apply.= ' ('. include( '/elements/popup_link.html',
84 'label' => 'apply to refund',
85 'action' => "${p}edit/cust_credit_refund.cgi?".
86 $cust_credit->crednum,
87 'actionlabel' => 'Apply credit to refund',
89 #default# 'height' => 336,
98 if ( $cust_credit->closed !~ /^Y/i
100 #s'pose deleting a credit isn't bad like deleting a payment
101 # and this needs to be generally available until we have credit voiding..
102 #&& $conf->exists('deletecredits')
104 && $curuser->access_right('Delete credit')
107 $delete = qq! (<A HREF="javascript:areyousure('!.
108 qq!${p}misc/delete-cust_credit.cgi?!. $cust_credit->crednum.
109 qq!', 'Are you sure you want to delete this credit?')">!.
114 if ( $cust_credit->closed !~ /^Y/i
115 && scalar(@cust_credit_bill)
116 && $curuser->access_right('Unapply credit')
119 $unapply = qq! (<A HREF="javascript:areyousure('!.
120 qq!${p}misc/unapply-cust_credit.cgi?!. $cust_credit->crednum.
121 qq!', 'Are you sure you want to unapply this credit?')">!.
125 my $reason = $cust_credit->reason
126 ? ' ('. $cust_credit->reason. ')'