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;
13 if ( $opt{'pkg-balances'} && $cust_credit->pkgnum ) {
14 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cust_credit->pkgnum } );
15 $desc .= ' for '. $cust_pkg->pkg_label_long;
18 my( $pre, $post, $apply, $ext ) = ( '', '', '', '' );
19 if ( scalar(@cust_credit_bill) == 0
20 && scalar(@cust_credit_refund) == 0 ) {
22 $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
23 $post = '</FONT></B>';
24 if ( $curuser->access_right('Apply credit') ) {
25 if ( $cust_credit->cust_main->total_owed > 0 ) {
27 include( '/elements/popup_link.html',
29 'action' => "${p}edit/cust_credit_bill.cgi?".
30 $cust_credit->crednum,
31 'actionlabel' => 'Apply credit',
33 #default# 'height' => 336,
37 if ( $cust_credit->cust_main->total_unapplied_refunds > 0 ) {
39 include( '/elements/popup_link.html',
40 'label' => 'apply to refund',
41 'action' => "${p}edit/cust_credit_refund.cgi?".
42 $cust_credit->crednum,
43 'actionlabel' => 'Apply credit to refund',
45 #default# 'height' => 336,
50 } elsif ( scalar(@cust_credit_bill) == 1
51 && scalar(@cust_credit_refund) == 0
52 && $cust_credit->credited == 0 ) {
53 #applied to one invoice, the usual situation
54 $desc .= ' '. $cust_credit_bill[0]->applied_to_invoice;
55 } elsif ( scalar(@cust_credit_bill) == 0
56 && scalar(@cust_credit_refund) == 1
57 && $cust_credit->credited == 0 ) {
58 #applied to one refund
59 $desc .= ' refunded on '. time2str("%D", $cust_credit_refund[0]->_date);
63 foreach my $app ( sort { $a->_date <=> $b->_date }
64 ( @cust_credit_bill, @cust_credit_refund ) ) {
65 if ( $app->isa('FS::cust_credit_bill') ) {
66 $desc .= ' '.
68 ' '. $app->applied_to_invoice.
70 #' on '. time2str("%D", $app->_date).
71 } elsif ( $app->isa('FS::cust_credit_refund') ) {
72 $desc .= ' '.
74 ' refunded on '. time2str("%D", $app->_date).
77 die "$app is not a FS::cust_credit_bill or a FS::cust_credit_refund";
80 if ( $cust_credit->credited > 0 ) {
81 $desc .= ' <B><FONT COLOR="#FF0000">$'.
82 $cust_credit->credited. ' unapplied</FONT></B>';
83 if ( $curuser->access_right('Apply credit') ) {
84 if ( $cust_credit->cust_main->total_owed > 0 ) {
86 include( '/elements/popup_link.html',
88 'action' => "${p}edit/cust_credit_bill.cgi?".
89 $cust_credit->crednum,
90 'actionlabel' => 'Apply credit',
92 #default# 'height' => 336,
96 if ( $cust_credit->cust_main->total_unapplied_refunds > 0 ) {
98 include( '/elements/popup_link.html',
99 'label' => 'apply to refund',
100 'action' => "${p}edit/cust_credit_refund.cgi?".
101 $cust_credit->crednum,
102 'actionlabel' => 'Apply credit to refund',
104 #default# 'height' => 336,
114 if ( $cust_credit->closed !~ /^Y/i
116 #s'pose deleting a credit isn't bad like deleting a payment
117 # and this needs to be generally available until we have credit voiding..
118 #&& $conf->exists('deletecredits')
120 && $curuser->access_right('Delete credit')
123 $delete = qq! (<A HREF="javascript:areyousure('!.
124 qq!${p}misc/delete-cust_credit.cgi?!. $cust_credit->crednum.
125 qq!', 'Are you sure you want to delete this credit?')">!.
130 if ( $cust_credit->closed !~ /^Y/i
131 && scalar(@cust_credit_bill)
132 && $curuser->access_right('Unapply credit')
135 $unapply = qq! (<A HREF="javascript:areyousure('!.
136 qq!${p}misc/unapply-cust_credit.cgi?!. $cust_credit->crednum.
137 qq!', 'Are you sure you want to unapply this credit?')">!.
141 my $reason = $cust_credit->reason
142 ? ' ('. $cust_credit->reason. ')'