proper use of date_format config for international date formats, RT#7009
[freeside.git] / httemplate / view / cust_main / payment_history / credit.html
1 <% $pre %>Credit<% $post %>
2 by <% $cust_credit->otaker %><% "$reason$desc$apply$delete$unapply" %>
3 <%init>
4
5 my( $cust_credit, %opt ) = @_;
6
7 my $date_format = $opt{'date_format'} || '%m/%d/%Y';
8
9 my $curuser = $FS::CurrentUser::CurrentUser;
10
11 my @cust_credit_bill = $cust_credit->cust_credit_bill;
12 my @cust_credit_refund = $cust_credit->cust_credit_refund;
13
14 my $desc = '';
15 if ( $opt{'pkg-balances'} && $cust_credit->pkgnum ) {
16   my $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cust_credit->pkgnum } );
17   $desc .= ' for '. $cust_pkg->pkg_label_long;
18 }
19
20 my( $pre, $post, $apply, $ext ) = ( '', '', '', '' );
21 if (    scalar(@cust_credit_bill)   == 0
22      && scalar(@cust_credit_refund) == 0 ) {
23   #completely unapplied
24   $pre = '<B><FONT COLOR="#FF0000">Unapplied ';
25   $post = '</FONT></B>';
26   if ( $curuser->access_right('Apply credit') ) {
27     if ( $cust_credit->cust_main->total_owed > 0 ) {
28       $apply = ' ('.
29                include( '/elements/popup_link.html',
30                           'label'    => 'apply',
31                           'action'   => "${p}edit/cust_credit_bill.cgi?".
32                                         $cust_credit->crednum,
33                           'actionlabel' => 'Apply credit',
34                           'width'    => 392,
35                           #default# 'height' => 336,
36                       ).
37                 ')';
38     }
39     if ( $cust_credit->cust_main->total_unapplied_refunds > 0 ) {
40       $apply.= ' ('.
41                include( '/elements/popup_link.html',
42                           'label'    => 'apply to refund',
43                           'action'   => "${p}edit/cust_credit_refund.cgi?".
44                                         $cust_credit->crednum,
45                           'actionlabel' => 'Apply credit to refund',
46                           'width'    => 392,
47                           #default# 'height' => 336,
48                       ).
49                ')';
50     }
51   }
52 } elsif (    scalar(@cust_credit_bill)   == 1
53           && scalar(@cust_credit_refund) == 0
54           && $cust_credit->credited == 0      ) {
55   #applied to one invoice, the usual situation
56   $desc .= ' '. $cust_credit_bill[0]->applied_to_invoice;
57 } elsif (    scalar(@cust_credit_bill)   == 0
58           && scalar(@cust_credit_refund) == 1
59           && $cust_credit->credited == 0      ) {
60   #applied to one refund
61   $desc .= ' refunded on '.  time2str($date_format, $cust_credit_refund[0]->_date);
62 } else {
63   #complicated
64   $desc .= '<BR>';
65   foreach my $app ( sort { $a->_date <=> $b->_date }
66                          ( @cust_credit_bill, @cust_credit_refund ) ) {
67     if ( $app->isa('FS::cust_credit_bill') ) {
68       $desc .= '&nbsp;&nbsp;'.
69                '$'. $app->amount.
70                ' '. $app->applied_to_invoice.
71                '<BR>';
72                #' on '. time2str($date_format, $app->_date).
73     } elsif ( $app->isa('FS::cust_credit_refund') ) {
74       $desc .= '&nbsp;&nbsp;'.
75                '$'. $app->amount.
76                ' refunded on '. time2str($date_format, $app->_date).
77                '<BR>';
78     } else {
79       die "$app is not a FS::cust_credit_bill or a FS::cust_credit_refund";
80     }
81   }
82   if ( $cust_credit->credited > 0 ) {
83     $desc .= '&nbsp;&nbsp;<B><FONT COLOR="#FF0000">$'.
84              $cust_credit->credited. ' unapplied</FONT></B>';
85     if ( $curuser->access_right('Apply credit') ) {
86       if ( $cust_credit->cust_main->total_owed > 0 ) {
87         $apply = ' ('.
88                  include( '/elements/popup_link.html',
89                             'label'       => 'apply',
90                             'action'      => "${p}edit/cust_credit_bill.cgi?".
91                                              $cust_credit->crednum,
92                             'actionlabel' => 'Apply credit',
93                             'width'       => 392,
94                             #default# 'height' => 336,
95                         ).
96                  ')';
97       }
98       if ( $cust_credit->cust_main->total_unapplied_refunds > 0 ) {
99         $apply.= ' ('.
100                  include( '/elements/popup_link.html',
101                             'label'       => 'apply to refund',
102                             'action'      => "${p}edit/cust_credit_refund.cgi?".
103                                              $cust_credit->crednum,
104                             'actionlabel' => 'Apply credit to refund',
105                             'width'       => 392,
106                             #default# 'height' => 336,
107                         ).
108                  ')';
109       }
110     }
111     $desc .= '<BR>';
112   }
113 }
114 #
115 my $delete = '';
116 if ( $cust_credit->closed !~ /^Y/i
117
118      #s'pose deleting a credit isn't bad like deleting a payment
119      # and this needs to be generally available until we have credit voiding..
120      #&& $conf->exists('deletecredits')
121
122      && $curuser->access_right('Delete credit')
123    )
124 {
125   $delete = qq! (<A HREF="javascript:areyousure('!.
126             qq!${p}misc/delete-cust_credit.cgi?!. $cust_credit->crednum.
127             qq!', 'Are you sure you want to delete this credit?')">!.
128             qq!delete</A>)!;
129 }
130
131 my $unapply = '';
132 if (    $cust_credit->closed !~ /^Y/i
133      && scalar(@cust_credit_bill)
134      && $curuser->access_right('Unapply credit')
135    )
136 {
137   $unapply = qq! (<A HREF="javascript:areyousure('!.
138              qq!${p}misc/unapply-cust_credit.cgi?!. $cust_credit->crednum.
139              qq!', 'Are you sure you want to unapply this credit?')">!.
140              qq!unapply</A>)!;
141 }
142
143 my $reason = $cust_credit->reason
144                ? ' ('. $cust_credit->reason. ')'
145                : '';
146
147 </%init>
148