1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
<% $credit. ' '. $reason. $desc. $change_pkg. $apply . $unapply. $void %>
<%init>
my( $cust_credit, %opt ) = @_;
my $date_format = $opt{'date_format'} || '%m/%d/%Y';
my @cust_credit_bill = $cust_credit->cust_credit_bill;
my @cust_credit_refund = $cust_credit->cust_credit_refund;
my $desc = '';
if ( $opt{'pkg-balances'} && $cust_credit->pkgnum ) {
my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cust_credit->pkgnum } );
$desc .= ' for '. $cust_pkg->pkg_label_long;
}
my %cust_credit_bill_width = ('width' => 392);
my %cust_credit_bill_height = ();
if ( $opt{'cust_credit_bill_pkg-manual'} ) {
%cust_credit_bill_width = ('width' => 592);
%cust_credit_bill_height = ('height' => 436);
}
my( $apply, $ext ) = ( '', '', '', '' );
my $credit = emt("Credit by [_1]", $cust_credit->otaker );
if ( scalar(@cust_credit_bill) == 0
&& scalar(@cust_credit_refund) == 0 ) {
#completely unapplied
$credit = '<B><FONT COLOR="#FF0000">'
. emt("Unapplied Credit by [_1]", $cust_credit->otaker )
. '</FONT></B>';
if ( $opt{'Apply credit'} ) {
if ( $opt{total_owed} > 0 ) {
$apply = ' ('.
include( '/elements/popup_link.html',
'label' => emt('apply'),
'action' => "${p}edit/cust_credit_bill.cgi?".
$cust_credit->crednum,
'actionlabel' => emt('Apply credit'),
%cust_credit_bill_width,
%cust_credit_bill_height,
).
')';
}
if ( $opt{total_unapplied_refunds} > 0 ) {
$apply.= ' ('.
include( '/elements/popup_link.html',
'label' => emt('apply to refund'),
'action' => "${p}edit/cust_credit_refund.cgi?".
$cust_credit->crednum,
'actionlabel' => emt('Apply credit to refund'),
'width' => 392,
).
')';
}
}
} elsif ( scalar(@cust_credit_bill) == 1
&& scalar(@cust_credit_refund) == 0
&& $cust_credit->credited == 0 ) {
#applied to one invoice, the usual situation
$desc .= ' '. $cust_credit_bill[0]->applied_to_invoice;
} elsif ( scalar(@cust_credit_bill) == 0
&& scalar(@cust_credit_refund) == 1
&& $cust_credit->credited == 0 ) {
#applied to one refund
$desc .= emt(" refunded on [_1]", time2str($date_format, $cust_credit_refund[0]->_date) );
} else {
#complicated
$desc .= '<BR>';
foreach my $app ( sort { $a->_date <=> $b->_date }
( @cust_credit_bill, @cust_credit_refund ) ) {
if ( $app->isa('FS::cust_credit_bill') ) {
$desc .= ' ' . $opt{money_char} . $app->amount . ' '
. $app->applied_to_invoice . '<BR>';
} elsif ( $app->isa('FS::cust_credit_refund') ) {
$desc .= ' ' .
emt("[_1][_2] refunded on [_3]", $opt{money_char}, $app->amount,
time2str($date_format, $app->_date) ) . '<BR>';
} else {
die "$app is not a FS::cust_credit_bill or a FS::cust_credit_refund";
}
}
if ( $cust_credit->credited > 0 ) {
$desc .= ' <B><FONT COLOR="#FF0000">'.
emt("[_1][_2] unapplied",$opt{money_char},$cust_credit->credited).
'</FONT></B>';
if ( $opt{'Apply credit'} ) {
if ( $opt{total_owed} > 0 ) {
$apply = ' ('.
include( '/elements/popup_link.html',
'label' => emt('apply'),
'action' => "${p}edit/cust_credit_bill.cgi?".
$cust_credit->crednum,
'actionlabel' => emt('Apply credit'),
%cust_credit_bill_width,
%cust_credit_bill_height,
).
')';
}
if ( $opt{total_unapplied_refunds} > 0 ) {
$apply.= ' ('.
include( '/elements/popup_link.html',
'label' => emt('apply to refund'),
'action' => "${p}edit/cust_credit_refund.cgi?".
$cust_credit->crednum,
'actionlabel' => emt('Apply credit to refund'),
'width' => 392,
).
')';
}
}
$desc .= '<BR>';
}
}
my $change_pkg = '';
if ( $apply && $opt{'pkg-balances'} && $cust_credit->pkgnum ) {
$change_pkg =
' ('. include('/elements/popup_link.html',
'label' => emt('change package'),
'action' => "${p}edit/cust_credit-pkgnum.html?crednum=".
$cust_credit->crednum,
'actionlabel' => emt('Change credit package'),
'width' => 763,
).
')';
}
my $void = '';
$void = ' ('.
include( '/elements/popup_link.html',
'label' => emt('void'),
'action' => "${p}misc/void-cust_credit.html?".
$cust_credit->crednum,
'actionlabel' => emt('Void credit'),
).
')'
if $cust_credit->closed !~ /^Y/i
&& $opt{'Void credit'};
my $unapply = '';
$unapply = areyousure_link("${p}misc/unapply-cust_credit.cgi?".$cust_credit->crednum,
emt('Are you sure you want to unapply this credit?'),
'',
emt('unapply')
)
if $cust_credit->closed !~ /^Y/i
&& scalar(@cust_credit_bill)
&& $opt{'Unapply credit'};
my $reason = $cust_credit->reason;
$reason = $reason ? " ($reason)" : '';
</%init>
|