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 $money_char = $conf->config('money_char') || '$';
11 my $curuser = $FS::CurrentUser::CurrentUser;
13 my @cust_credit_bill = $cust_credit->cust_credit_bill;
14 my @cust_credit_refund = $cust_credit->cust_credit_refund;
17 if ( $opt{'pkg-balances'} && $cust_credit->pkgnum ) {
18 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cust_credit->pkgnum } );
19 $desc .= ' for '. $cust_pkg->pkg_label_long;
22 my %cust_credit_bill_width = ('width' => 392);
23 my %cust_credit_bill_height = ();
24 if ($conf->exists('cust_credit_bill_pkg-manual')) {
25 %cust_credit_bill_width = ('width' => 592);
26 %cust_credit_bill_height = ('height' => 436);
29 my( $apply, $ext ) = ( '', '', '', '' );
30 my $credit = emt("Credit by [_1]", $cust_credit->otaker );
31 if ( scalar(@cust_credit_bill) == 0
32 && scalar(@cust_credit_refund) == 0 ) {
34 $credit = '<B><FONT COLOR="#FF0000">'
35 . emt("Unapplied Credit by [_1]", $cust_credit->otaker )
37 if ( $curuser->access_right('Apply credit') ) {
38 if ( $cust_credit->cust_main->total_owed > 0 ) {
40 include( '/elements/popup_link.html',
41 'label' => emt('apply'),
42 'action' => "${p}edit/cust_credit_bill.cgi?".
43 $cust_credit->crednum,
44 'actionlabel' => emt('Apply credit'),
45 %cust_credit_bill_width,
46 %cust_credit_bill_height,
50 if ( $cust_credit->cust_main->total_unapplied_refunds > 0 ) {
52 include( '/elements/popup_link.html',
53 'label' => emt('apply to refund'),
54 'action' => "${p}edit/cust_credit_refund.cgi?".
55 $cust_credit->crednum,
56 'actionlabel' => emt('Apply credit to refund'),
62 } elsif ( scalar(@cust_credit_bill) == 1
63 && scalar(@cust_credit_refund) == 0
64 && $cust_credit->credited == 0 ) {
65 #applied to one invoice, the usual situation
66 $desc .= ' '. $cust_credit_bill[0]->applied_to_invoice;
67 } elsif ( scalar(@cust_credit_bill) == 0
68 && scalar(@cust_credit_refund) == 1
69 && $cust_credit->credited == 0 ) {
70 #applied to one refund
71 $desc .= emt(" refunded on [_1]", time2str($date_format, $cust_credit_refund[0]->_date) );
75 foreach my $app ( sort { $a->_date <=> $b->_date }
76 ( @cust_credit_bill, @cust_credit_refund ) ) {
77 if ( $app->isa('FS::cust_credit_bill') ) {
78 $desc .= ' ' . $money_char . $app->amount . ' '
79 . $app->applied_to_invoice . '<BR>';
80 } elsif ( $app->isa('FS::cust_credit_refund') ) {
81 $desc .= ' ' .
82 emt("[_1][_2] refunded on [_3]", $money_char, $app->amount,
83 time2str($date_format, $app->_date) ) . '<BR>';
85 die "$app is not a FS::cust_credit_bill or a FS::cust_credit_refund";
88 if ( $cust_credit->credited > 0 ) {
89 $desc .= ' <B><FONT COLOR="#FF0000">' .
90 emt("[_1][_2] unapplied", $money_char, $cust_credit->credited) .
92 if ( $curuser->access_right('Apply credit') ) {
93 if ( $cust_credit->cust_main->total_owed > 0 ) {
95 include( '/elements/popup_link.html',
96 'label' => emt('apply'),
97 'action' => "${p}edit/cust_credit_bill.cgi?".
98 $cust_credit->crednum,
99 'actionlabel' => emt('Apply credit'),
100 %cust_credit_bill_width,
101 %cust_credit_bill_height,
105 if ( $cust_credit->cust_main->total_unapplied_refunds > 0 ) {
107 include( '/elements/popup_link.html',
108 'label' => emt('apply to refund'),
109 'action' => "${p}edit/cust_credit_refund.cgi?".
110 $cust_credit->crednum,
111 'actionlabel' => emt('Apply credit to refund'),
122 $delete = areyousure_link("${p}misc/delete-cust_credit.cgi?".$cust_credit->crednum,
123 emt('Are you sure you want to delete this credit?'),
127 if ( $cust_credit->closed !~ /^Y/i && $curuser->access_right('Delete credit') );
130 $unapply = areyousure_link("${p}misc/unapply-cust_credit.cgi?".$cust_credit->crednum,
131 emt('Are you sure you want to unapply this credit?'),
135 if ( $cust_credit->closed !~ /^Y/i && scalar(@cust_credit_bill)
136 && $curuser->access_right('Unapply credit') );
138 my $reason = $cust_credit->reason
139 ? ' ('. $cust_credit->reason. ')'