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 $conf = new FS::Conf;
10 my $curuser = $FS::CurrentUser::CurrentUser;
12 my @cust_credit_bill = $cust_credit->cust_credit_bill;
13 my @cust_credit_refund = $cust_credit->cust_credit_refund;
16 if ( $opt{'pkg-balances'} && $cust_credit->pkgnum ) {
17 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cust_credit->pkgnum } );
18 $desc .= ' for '. $cust_pkg->pkg_label_long;
21 my %cust_credit_bill_width = ('width' => 392);
22 my %cust_credit_bill_height = ();
23 if ($conf->exists('cust_credit_bill_pkg-manual')) {
24 %cust_credit_bill_width = ('width' => 592);
25 %cust_credit_bill_height = ('height' => 436);
28 my( $pre, $post, $apply, $ext ) = ( '', '', '', '' );
29 if ( scalar(@cust_credit_bill) == 0
30 && scalar(@cust_credit_refund) == 0 ) {
32 $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
33 $post = '</FONT></B>';
34 if ( $curuser->access_right('Apply credit') ) {
35 if ( $cust_credit->cust_main->total_owed > 0 ) {
37 include( '/elements/popup_link.html',
39 'action' => "${p}edit/cust_credit_bill.cgi?".
40 $cust_credit->crednum,
41 'actionlabel' => 'Apply credit',
42 %cust_credit_bill_width,
43 %cust_credit_bill_height,
47 if ( $cust_credit->cust_main->total_unapplied_refunds > 0 ) {
49 include( '/elements/popup_link.html',
50 'label' => 'apply to refund',
51 'action' => "${p}edit/cust_credit_refund.cgi?".
52 $cust_credit->crednum,
53 'actionlabel' => 'Apply credit to refund',
55 #default# 'height' => 336,
60 } elsif ( scalar(@cust_credit_bill) == 1
61 && scalar(@cust_credit_refund) == 0
62 && $cust_credit->credited == 0 ) {
63 #applied to one invoice, the usual situation
64 $desc .= ' '. $cust_credit_bill[0]->applied_to_invoice;
65 } elsif ( scalar(@cust_credit_bill) == 0
66 && scalar(@cust_credit_refund) == 1
67 && $cust_credit->credited == 0 ) {
68 #applied to one refund
69 $desc .= ' refunded on '. time2str($date_format, $cust_credit_refund[0]->_date);
73 foreach my $app ( sort { $a->_date <=> $b->_date }
74 ( @cust_credit_bill, @cust_credit_refund ) ) {
75 if ( $app->isa('FS::cust_credit_bill') ) {
76 $desc .= ' '.
78 ' '. $app->applied_to_invoice.
80 #' on '. time2str($date_format, $app->_date).
81 } elsif ( $app->isa('FS::cust_credit_refund') ) {
82 $desc .= ' '.
84 ' refunded on '. time2str($date_format, $app->_date).
87 die "$app is not a FS::cust_credit_bill or a FS::cust_credit_refund";
90 if ( $cust_credit->credited > 0 ) {
91 $desc .= ' <B><FONT COLOR="#FF0000">$'.
92 $cust_credit->credited. ' unapplied</FONT></B>';
93 if ( $curuser->access_right('Apply credit') ) {
94 if ( $cust_credit->cust_main->total_owed > 0 ) {
96 include( '/elements/popup_link.html',
98 'action' => "${p}edit/cust_credit_bill.cgi?".
99 $cust_credit->crednum,
100 'actionlabel' => 'Apply credit',
101 %cust_credit_bill_width,
102 %cust_credit_bill_height,
106 if ( $cust_credit->cust_main->total_unapplied_refunds > 0 ) {
108 include( '/elements/popup_link.html',
109 'label' => 'apply to refund',
110 'action' => "${p}edit/cust_credit_refund.cgi?".
111 $cust_credit->crednum,
112 'actionlabel' => 'Apply credit to refund',
114 #default# 'height' => 336,
124 if ( $cust_credit->closed !~ /^Y/i
126 #s'pose deleting a credit isn't bad like deleting a payment
127 # and this needs to be generally available until we have credit voiding..
128 #&& $conf->exists('deletecredits')
130 && $curuser->access_right('Delete credit')
133 $delete = qq! (<A HREF="javascript:areyousure('!.
134 qq!${p}misc/delete-cust_credit.cgi?!. $cust_credit->crednum.
135 qq!', 'Are you sure you want to delete this credit?')">!.
140 if ( $cust_credit->closed !~ /^Y/i
141 && scalar(@cust_credit_bill)
142 && $curuser->access_right('Unapply credit')
145 $unapply = qq! (<A HREF="javascript:areyousure('!.
146 qq!${p}misc/unapply-cust_credit.cgi?!. $cust_credit->crednum.
147 qq!', 'Are you sure you want to unapply this credit?')">!.
151 my $reason = $cust_credit->reason
152 ? ' ('. $cust_credit->reason. ')'