1 <% $credit. ' '. $reason. $desc. $change_pkg. $apply. $delete. $unapply %>
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 to refund'),
49 'action' => "${p}edit/cust_credit_refund.cgi?".
50 $cust_credit->crednum,
51 'actionlabel' => emt('Apply credit to refund'),
57 } elsif ( scalar(@cust_credit_bill) == 1
58 && scalar(@cust_credit_refund) == 0
59 && $cust_credit->credited == 0 ) {
60 #applied to one invoice, the usual situation
61 $desc .= ' '. $cust_credit_bill[0]->applied_to_invoice;
62 } elsif ( scalar(@cust_credit_bill) == 0
63 && scalar(@cust_credit_refund) == 1
64 && $cust_credit->credited == 0 ) {
65 #applied to one refund
66 $desc .= emt(" refunded on [_1]", time2str($date_format, $cust_credit_refund[0]->_date) );
70 foreach my $app ( sort { $a->_date <=> $b->_date }
71 ( @cust_credit_bill, @cust_credit_refund ) ) {
72 if ( $app->isa('FS::cust_credit_bill') ) {
73 $desc .= ' ' . $opt{money_char} . $app->amount . ' '
74 . $app->applied_to_invoice . '<BR>';
75 } elsif ( $app->isa('FS::cust_credit_refund') ) {
76 $desc .= ' ' .
77 emt("[_1][_2] refunded on [_3]", $opt{money_char}, $app->amount,
78 time2str($date_format, $app->_date) ) . '<BR>';
80 die "$app is not a FS::cust_credit_bill or a FS::cust_credit_refund";
83 if ( $cust_credit->credited > 0 ) {
84 $desc .= ' <B><FONT COLOR="#FF0000">'.
85 emt("[_1][_2] unapplied",$opt{money_char},$cust_credit->credited).
87 if ( $opt{'Apply credit'} ) {
88 if ( $opt{total_owed} > 0 ) {
90 include( '/elements/popup_link.html',
91 'label' => emt('apply'),
92 'action' => "${p}edit/cust_credit_bill.cgi?".
93 $cust_credit->crednum,
94 'actionlabel' => emt('Apply credit'),
95 %cust_credit_bill_width,
96 %cust_credit_bill_height,
100 if ( $opt{total_unapplied_refunds} > 0 ) {
102 include( '/elements/popup_link.html',
103 'label' => emt('apply to refund'),
104 'action' => "${p}edit/cust_credit_refund.cgi?".
105 $cust_credit->crednum,
106 'actionlabel' => emt('Apply credit to refund'),
117 if ( $apply && $opt{'pkg-balances'} && $cust_credit->pkgnum ) {
119 ' ('. include('/elements/popup_link.html',
120 'label' => emt('change package'),
121 'action' => "${p}edit/cust_credit-pkgnum.html?crednum=".
122 $cust_credit->crednum,
123 'actionlabel' => emt('Change credit package'),
130 $delete = areyousure_link("${p}misc/delete-cust_credit.cgi?".$cust_credit->crednum,
131 emt('Are you sure you want to delete this credit?'),
135 if $cust_credit->closed !~ /^Y/i
136 && $opt{'Delete credit'};
139 $unapply = areyousure_link("${p}misc/unapply-cust_credit.cgi?".$cust_credit->crednum,
140 emt('Are you sure you want to unapply this credit?'),
144 if $cust_credit->closed !~ /^Y/i
145 && scalar(@cust_credit_bill)
146 && $opt{'Unapply credit'};
148 my $reason = $cust_credit->reason;
149 $reason = $reason ? " ($reason)" : '';