1 <% $credit. ' '. $reason. $desc. $change_pkg. $apply . $unapply. $void %>
4 my( $cust_credit, %opt ) = @_;
6 my $date_format = $opt{'date_format'} || '%m/%d/%Y';
8 my @cust_credit_bill = $cust_credit->cust_credit_bill;
9 my @cust_credit_refund = $cust_credit->cust_credit_refund;
12 if ( $opt{'pkg-balances'} && $cust_credit->pkgnum ) {
13 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cust_credit->pkgnum } );
14 $desc .= ' for '. $cust_pkg->pkg_label_long;
17 my %cust_credit_bill_width = ('width' => 392);
18 my %cust_credit_bill_height = ();
19 if ( $opt{'cust_credit_bill_pkg-manual'} ) {
20 %cust_credit_bill_width = ('width' => 592);
21 %cust_credit_bill_height = ('height' => 436);
24 my( $apply, $ext ) = ( '', '', '', '' );
25 my $credit = emt("Credit by [_1]", $cust_credit->otaker );
26 if ( scalar(@cust_credit_bill) == 0
27 && scalar(@cust_credit_refund) == 0 ) {
29 $credit = '<B><FONT COLOR="#FF0000">'
30 . emt("Unapplied Credit by [_1]", $cust_credit->otaker )
32 if ( $opt{'Apply credit'} ) {
33 if ( $opt{total_owed} > 0 ) {
35 include( '/elements/popup_link.html',
36 'label' => emt('apply'),
37 'action' => "${p}edit/cust_credit_bill.cgi?".
38 $cust_credit->crednum,
39 'actionlabel' => emt('Apply credit'),
40 %cust_credit_bill_width,
41 %cust_credit_bill_height,
45 if ( $opt{total_unapplied_refunds} > 0 ) {
47 include( '/elements/popup_link.html',
48 'label' => emt('apply refund'),
49 'style' => 'white-space: nowrap',
50 'action' => "${p}edit/cust_credit_refund.cgi?".
51 $cust_credit->crednum,
52 'actionlabel' => emt('Apply credit to refund'),
58 } elsif ( scalar(@cust_credit_bill) == 1
59 && scalar(@cust_credit_refund) == 0
60 && $cust_credit->credited == 0 ) {
61 #applied to one invoice, the usual situation
62 $desc .= ' '. $cust_credit_bill[0]->applied_to_invoice;
63 } elsif ( scalar(@cust_credit_bill) == 0
64 && scalar(@cust_credit_refund) == 1
65 && $cust_credit->credited == 0 ) {
66 #applied to one refund
67 $desc .= emt(" refunded on [_1]", time2str($date_format, $cust_credit_refund[0]->_date) );
71 foreach my $app ( sort { $a->_date <=> $b->_date }
72 ( @cust_credit_bill, @cust_credit_refund ) ) {
73 if ( $app->isa('FS::cust_credit_bill') ) {
74 $desc .= ' ' . $opt{money_char} . $app->amount . ' '
75 . $app->applied_to_invoice . '<BR>';
76 } elsif ( $app->isa('FS::cust_credit_refund') ) {
77 $desc .= ' ' .
78 emt("[_1][_2] refunded on [_3]", $opt{money_char}, $app->amount,
79 time2str($date_format, $app->_date) ) . '<BR>';
81 die "$app is not a FS::cust_credit_bill or a FS::cust_credit_refund";
84 if ( $cust_credit->credited > 0 ) {
85 $desc .= ' <B><FONT COLOR="#FF0000">'.
86 emt("[_1][_2] unapplied",$opt{money_char},$cust_credit->credited).
88 if ( $opt{'Apply credit'} ) {
89 if ( $opt{total_owed} > 0 ) {
91 include( '/elements/popup_link.html',
92 'label' => emt('apply'),
93 'action' => "${p}edit/cust_credit_bill.cgi?".
94 $cust_credit->crednum,
95 'actionlabel' => emt('Apply credit'),
96 %cust_credit_bill_width,
97 %cust_credit_bill_height,
101 if ( $opt{total_unapplied_refunds} > 0 ) {
103 include( '/elements/popup_link.html',
104 'label' => emt('apply refund'),
105 'style' => 'white-space: nowrap',
106 'action' => "${p}edit/cust_credit_refund.cgi?".
107 $cust_credit->crednum,
108 'actionlabel' => emt('Apply credit to refund'),
119 if ( $apply && $opt{'pkg-balances'} && $cust_credit->pkgnum ) {
121 ' ('. include('/elements/popup_link.html',
122 'label' => emt('change package'),
123 'action' => "${p}edit/cust_credit-pkgnum.html?crednum=".
124 $cust_credit->crednum,
125 'actionlabel' => emt('Change credit package'),
133 include( '/elements/popup_link.html',
134 'label' => emt('void'),
135 'action' => "${p}misc/void-cust_credit.html?".
136 $cust_credit->crednum,
137 'actionlabel' => emt('Void credit'),
140 if $cust_credit->closed !~ /^Y/i
141 && $opt{'Void credit'};
145 if ($opt{'Unapply credit'} && !$cust_credit->closed) {
146 $unapply = areyousure_link("${p}misc/unapply-cust_credit.cgi?".$cust_credit->crednum,
147 emt('Are you sure you want to unapply this credit from invoices?'),
148 emt('Keep this credit, but dissociate it from the invoices it is currently applied against'),
151 if @cust_credit_bill;
152 $unapply .= areyousure_link("${p}misc/unapply-cust_credit_refund.cgi?".$cust_credit->crednum,
153 emt('Are you sure you want to unapply this credit from refunds?'),
154 emt('Keep this credit, but dissociate it from the refunds it is currently applied to'),
155 emt('unapply refunds')
157 if $cust_credit->refund_to_unapply;
160 my $reason = $cust_credit->reason;
161 $reason = $reason ? " ($reason)" : '';