2 <% "$reason$desc$apply$delete$unapply" %>
5 my( $cust_credit, %opt ) = @_;
7 my $date_format = $opt{'date_format'} || '%m/%d/%Y';
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 %cust_credit_bill_width = ('width' => 392);
19 my %cust_credit_bill_height = ();
20 if ( $opt{'cust_credit_bill_pkg-manual'} ) {
21 %cust_credit_bill_width = ('width' => 592);
22 %cust_credit_bill_height = ('height' => 436);
25 my( $apply, $ext ) = ( '', '', '', '' );
26 my $credit = emt("Credit by [_1]", $cust_credit->otaker );
27 if ( scalar(@cust_credit_bill) == 0
28 && scalar(@cust_credit_refund) == 0 ) {
30 $credit = '<B><FONT COLOR="#FF0000">'
31 . emt("Unapplied Credit by [_1]", $cust_credit->otaker )
33 if ( $opt{'Apply credit'} ) {
34 if ( $opt{total_owed} > 0 ) {
36 include( '/elements/popup_link.html',
37 'label' => emt('apply'),
38 'action' => "${p}edit/cust_credit_bill.cgi?".
39 $cust_credit->crednum,
40 'actionlabel' => emt('Apply credit'),
41 %cust_credit_bill_width,
42 %cust_credit_bill_height,
46 if ( $opt{total_unapplied_refunds} > 0 ) {
48 include( '/elements/popup_link.html',
49 'label' => emt('apply to refund'),
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 to refund'),
105 'action' => "${p}edit/cust_credit_refund.cgi?".
106 $cust_credit->crednum,
107 'actionlabel' => emt('Apply credit to refund'),
118 $delete = areyousure_link("${p}misc/delete-cust_credit.cgi?".$cust_credit->crednum,
119 emt('Are you sure you want to delete this credit?'),
123 if $cust_credit->closed !~ /^Y/i
124 && $opt{'Delete credit'};
127 $unapply = areyousure_link("${p}misc/unapply-cust_credit.cgi?".$cust_credit->crednum,
128 emt('Are you sure you want to unapply this credit?'),
132 if $cust_credit->closed !~ /^Y/i
133 && scalar(@cust_credit_bill)
134 && $opt{'Unapply credit'};
136 my $reason = $cust_credit->reason;
137 $reason = $reason ? " ($reason)" : '';