1 <% $pre %>Credit<% $post %>
2 by <% $cust_credit->otaker %><% "$reason$desc$apply$delete$unapply" %>
5 my( $cust_credit, %opt ) = @_;
7 my $conf = new FS::Conf;
8 my $curuser = $FS::CurrentUser::CurrentUser;
10 my @cust_credit_bill = $cust_credit->cust_credit_bill;
11 my @cust_credit_refund = $cust_credit->cust_credit_refund;
14 if ( $opt{'pkg-balances'} && $cust_credit->pkgnum ) {
15 my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cust_credit->pkgnum } );
16 $desc .= ' for '. $cust_pkg->pkg_label_long;
19 my %cust_credit_bill_width = ('width' => 392);
20 my %cust_credit_bill_height = ();
21 if ($conf->exists('cust_credit_bill_pkg-manual')) {
22 %cust_credit_bill_width = ('width' => 592);
23 %cust_credit_bill_height = ('height' => 436);
26 my( $pre, $post, $apply, $ext ) = ( '', '', '', '' );
27 if ( scalar(@cust_credit_bill) == 0
28 && scalar(@cust_credit_refund) == 0 ) {
30 $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
31 $post = '</FONT></B>';
32 if ( $curuser->access_right('Apply credit') ) {
33 if ( $cust_credit->cust_main->total_owed > 0 ) {
35 include( '/elements/popup_link.html',
37 'action' => "${p}edit/cust_credit_bill.cgi?".
38 $cust_credit->crednum,
39 'actionlabel' => 'Apply credit',
40 %cust_credit_bill_width,
41 %cust_credit_bill_height,
45 if ( $cust_credit->cust_main->total_unapplied_refunds > 0 ) {
47 include( '/elements/popup_link.html',
48 'label' => 'apply to refund',
49 'action' => "${p}edit/cust_credit_refund.cgi?".
50 $cust_credit->crednum,
51 'actionlabel' => 'Apply credit to refund',
53 #default# 'height' => 336,
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 .= ' refunded on '. time2str("%D", $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 .= ' '.
76 ' '. $app->applied_to_invoice.
78 #' on '. time2str("%D", $app->_date).
79 } elsif ( $app->isa('FS::cust_credit_refund') ) {
80 $desc .= ' '.
82 ' refunded on '. time2str("%D", $app->_date).
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 $cust_credit->credited. ' unapplied</FONT></B>';
91 if ( $curuser->access_right('Apply credit') ) {
92 if ( $cust_credit->cust_main->total_owed > 0 ) {
94 include( '/elements/popup_link.html',
96 'action' => "${p}edit/cust_credit_bill.cgi?".
97 $cust_credit->crednum,
98 'actionlabel' => 'Apply credit',
99 %cust_credit_bill_width,
100 %cust_credit_bill_height,
104 if ( $cust_credit->cust_main->total_unapplied_refunds > 0 ) {
106 include( '/elements/popup_link.html',
107 'label' => 'apply to refund',
108 'action' => "${p}edit/cust_credit_refund.cgi?".
109 $cust_credit->crednum,
110 'actionlabel' => 'Apply credit to refund',
112 #default# 'height' => 336,
122 if ( $cust_credit->closed !~ /^Y/i
124 #s'pose deleting a credit isn't bad like deleting a payment
125 # and this needs to be generally available until we have credit voiding..
126 #&& $conf->exists('deletecredits')
128 && $curuser->access_right('Delete credit')
131 $delete = qq! (<A HREF="javascript:areyousure('!.
132 qq!${p}misc/delete-cust_credit.cgi?!. $cust_credit->crednum.
133 qq!', 'Are you sure you want to delete this credit?')">!.
138 if ( $cust_credit->closed !~ /^Y/i
139 && scalar(@cust_credit_bill)
140 && $curuser->access_right('Unapply credit')
143 $unapply = qq! (<A HREF="javascript:areyousure('!.
144 qq!${p}misc/unapply-cust_credit.cgi?!. $cust_credit->crednum.
145 qq!', 'Are you sure you want to unapply this credit?')">!.
149 my $reason = $cust_credit->reason
150 ? ' ('. $cust_credit->reason. ')'