1 <% $pre %>Credit<% $post %>
2 by <% $cust_credit->otaker %><% "$reason$desc$apply$delete$unapply" %>
5 my( $cust_credit, %opt ) = @_;
7 my $date_format = $opt{'date_format'} || '%m/%d/%Y';
9 my $curuser = $FS::CurrentUser::CurrentUser;
11 my @cust_credit_bill = $cust_credit->cust_credit_bill;
12 my @cust_credit_refund = $cust_credit->cust_credit_refund;
15 if ( $opt{'pkg-balances'} && $cust_credit->pkgnum ) {
16 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cust_credit->pkgnum } );
17 $desc .= ' for '. $cust_pkg->pkg_label_long;
20 my( $pre, $post, $apply, $ext ) = ( '', '', '', '' );
21 if ( scalar(@cust_credit_bill) == 0
22 && scalar(@cust_credit_refund) == 0 ) {
24 $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
25 $post = '</FONT></B>';
26 if ( $curuser->access_right('Apply credit') ) {
27 if ( $cust_credit->cust_main->total_owed > 0 ) {
29 include( '/elements/popup_link.html',
31 'action' => "${p}edit/cust_credit_bill.cgi?".
32 $cust_credit->crednum,
33 'actionlabel' => 'Apply credit',
35 #default# 'height' => 336,
39 if ( $cust_credit->cust_main->total_unapplied_refunds > 0 ) {
41 include( '/elements/popup_link.html',
42 'label' => 'apply to refund',
43 'action' => "${p}edit/cust_credit_refund.cgi?".
44 $cust_credit->crednum,
45 'actionlabel' => 'Apply credit to refund',
47 #default# 'height' => 336,
52 } elsif ( scalar(@cust_credit_bill) == 1
53 && scalar(@cust_credit_refund) == 0
54 && $cust_credit->credited == 0 ) {
55 #applied to one invoice, the usual situation
56 $desc .= ' '. $cust_credit_bill[0]->applied_to_invoice;
57 } elsif ( scalar(@cust_credit_bill) == 0
58 && scalar(@cust_credit_refund) == 1
59 && $cust_credit->credited == 0 ) {
60 #applied to one refund
61 $desc .= ' refunded on '. time2str($date_format, $cust_credit_refund[0]->_date);
65 foreach my $app ( sort { $a->_date <=> $b->_date }
66 ( @cust_credit_bill, @cust_credit_refund ) ) {
67 if ( $app->isa('FS::cust_credit_bill') ) {
68 $desc .= ' '.
70 ' '. $app->applied_to_invoice.
72 #' on '. time2str($date_format, $app->_date).
73 } elsif ( $app->isa('FS::cust_credit_refund') ) {
74 $desc .= ' '.
76 ' refunded on '. time2str($date_format, $app->_date).
79 die "$app is not a FS::cust_credit_bill or a FS::cust_credit_refund";
82 if ( $cust_credit->credited > 0 ) {
83 $desc .= ' <B><FONT COLOR="#FF0000">$'.
84 $cust_credit->credited. ' unapplied</FONT></B>';
85 if ( $curuser->access_right('Apply credit') ) {
86 if ( $cust_credit->cust_main->total_owed > 0 ) {
88 include( '/elements/popup_link.html',
90 'action' => "${p}edit/cust_credit_bill.cgi?".
91 $cust_credit->crednum,
92 'actionlabel' => 'Apply credit',
94 #default# 'height' => 336,
98 if ( $cust_credit->cust_main->total_unapplied_refunds > 0 ) {
100 include( '/elements/popup_link.html',
101 'label' => 'apply to refund',
102 'action' => "${p}edit/cust_credit_refund.cgi?".
103 $cust_credit->crednum,
104 'actionlabel' => 'Apply credit to refund',
106 #default# 'height' => 336,
116 if ( $cust_credit->closed !~ /^Y/i
118 #s'pose deleting a credit isn't bad like deleting a payment
119 # and this needs to be generally available until we have credit voiding..
120 #&& $conf->exists('deletecredits')
122 && $curuser->access_right('Delete credit')
125 $delete = qq! (<A HREF="javascript:areyousure('!.
126 qq!${p}misc/delete-cust_credit.cgi?!. $cust_credit->crednum.
127 qq!', 'Are you sure you want to delete this credit?')">!.
132 if ( $cust_credit->closed !~ /^Y/i
133 && scalar(@cust_credit_bill)
134 && $curuser->access_right('Unapply credit')
137 $unapply = qq! (<A HREF="javascript:areyousure('!.
138 qq!${p}misc/unapply-cust_credit.cgi?!. $cust_credit->crednum.
139 qq!', 'Are you sure you want to unapply this credit?')">!.
143 my $reason = $cust_credit->reason
144 ? ' ('. $cust_credit->reason. ')'