2 <% "$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( $apply, $ext ) = ( '', '', '', '' );
29 my $credit = mt("Credit by [_1]", $cust_credit->otaker );
30 if ( scalar(@cust_credit_bill) == 0
31 && scalar(@cust_credit_refund) == 0 ) {
33 $credit = '<B><FONT COLOR="#FF0000">'
34 . mt("Unapplied Credit by [_1]", $cust_credit->otaker )
36 if ( $curuser->access_right('Apply credit') ) {
37 if ( $cust_credit->cust_main->total_owed > 0 ) {
39 include( '/elements/popup_link.html',
40 'label' => mt('apply'),
41 'action' => "${p}edit/cust_credit_bill.cgi?".
42 $cust_credit->crednum,
43 'actionlabel' => mt('Apply credit'),
44 %cust_credit_bill_width,
45 %cust_credit_bill_height,
49 if ( $cust_credit->cust_main->total_unapplied_refunds > 0 ) {
51 include( '/elements/popup_link.html',
52 'label' => mt('apply to refund'),
53 'action' => "${p}edit/cust_credit_refund.cgi?".
54 $cust_credit->crednum,
55 'actionlabel' => mt('Apply credit to refund'),
61 } elsif ( scalar(@cust_credit_bill) == 1
62 && scalar(@cust_credit_refund) == 0
63 && $cust_credit->credited == 0 ) {
64 #applied to one invoice, the usual situation
65 $desc .= ' '. $cust_credit_bill[0]->applied_to_invoice;
66 } elsif ( scalar(@cust_credit_bill) == 0
67 && scalar(@cust_credit_refund) == 1
68 && $cust_credit->credited == 0 ) {
69 #applied to one refund
70 $desc .= mt(" refunded on [_1]", time2str($date_format, $cust_credit_refund[0]->_date) );
74 foreach my $app ( sort { $a->_date <=> $b->_date }
75 ( @cust_credit_bill, @cust_credit_refund ) ) {
76 if ( $app->isa('FS::cust_credit_bill') ) {
77 $desc .= ' '.
79 ' '. $app->applied_to_invoice.
81 #' on '. time2str($date_format, $app->_date).
82 } elsif ( $app->isa('FS::cust_credit_refund') ) {
83 $desc .= ' '.
85 mt(" refunded on [_1]", time2str($date_format, $app->_date) ).
88 die "$app is not a FS::cust_credit_bill or a FS::cust_credit_refund";
91 if ( $cust_credit->credited > 0 ) {
92 $desc .= ' <B><FONT COLOR="#FF0000">$'.
93 $cust_credit->credited. ' unapplied</FONT></B>';
94 if ( $curuser->access_right('Apply credit') ) {
95 if ( $cust_credit->cust_main->total_owed > 0 ) {
97 include( '/elements/popup_link.html',
98 'label' => mt('apply'),
99 'action' => "${p}edit/cust_credit_bill.cgi?".
100 $cust_credit->crednum,
101 'actionlabel' => mt('Apply credit'),
102 %cust_credit_bill_width,
103 %cust_credit_bill_height,
107 if ( $cust_credit->cust_main->total_unapplied_refunds > 0 ) {
109 include( '/elements/popup_link.html',
110 'label' => mt('apply to refund'),
111 'action' => "${p}edit/cust_credit_refund.cgi?".
112 $cust_credit->crednum,
113 'actionlabel' => mt('Apply credit to refund'),
124 $delete = areyousure_link("${p}misc/delete-cust_credit.cgi?".$cust_credit->crednum,
125 mt('Are you sure you want to delete this credit?'),
129 if ( $cust_credit->closed !~ /^Y/i && $curuser->access_right('Delete credit') );
132 $unapply = areyousure_link("${p}misc/unapply-cust_credit.cgi?".$cust_credit->crednum,
133 mt('Are you sure you want to unapply this credit?'),
137 if ( $cust_credit->closed !~ /^Y/i && scalar(@cust_credit_bill)
138 && $curuser->access_right('Unapply credit') );
140 my $reason = $cust_credit->reason
141 ? ' ('. $cust_credit->reason. ')'