add unused_credit option on suspend reasons to browse and edit UI, #31702
[freeside.git] / httemplate / browse / reason.html
1 <% include( 'elements/browse.html',
2                  'title'       => ucfirst($classname) . ' Reasons',
3                  'menubar'     => [ ucfirst($classname).' Reason Types' =>
4                                       $p."browse/reason_type.html?class=$class"
5                                   ],
6                  'html_init'   => $html_init,
7                  'name'        => $classname . ' reasons',
8                  'disableable' => 1,
9                  'disabled_statuspos' => 3,
10                  'query'       => { 'table'     => 'reason',
11                                     'hashref'   => {},
12                                     'extra_sql' => $where_clause. 
13                                                    ' ORDER BY reason_type', 
14                                     'addl_from' => 'LEFT JOIN reason_type ON reason_type.typenum = reason.reason_type', 
15                                   },
16                  'count_query' => $count_query,
17                  'header'      => \@header,
18                  'fields'      => \@fields,
19                  'links'       => \@links,
20                  'align'       => $align,
21              )
22 %>
23 <%init>
24
25 die "access denied"
26   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
27
28 $cgi->param('class') =~ /^(\w)$/ or die "illegal class";
29 my $class = $1;
30
31 my $classname = $FS::reason_type::class_name{$class};
32 my $classpurpose = $FS::reason_type::class_purpose{$class};
33
34 my $html_init = ucfirst($classname).  " reasons $classpurpose.<BR><BR>".
35 qq!<A HREF="${p}edit/reason.html?class=$class">!.
36 "<I>Add a $classname reason</I></A><BR><BR>";
37
38 my $where_clause = " WHERE class='$class' ";
39
40 my $count_query = 'SELECT COUNT(*) FROM reason LEFT JOIN reason_type on ' .
41                 'reason_type.typenum = reason.reason_type ' . $where_clause;
42
43 my $link = [ $p."edit/reason.html?class=$class&reasonnum=", 'reasonnum' ];
44
45 my @header = (
46   '#',
47   ucfirst($classname) . ' reason type',
48   ucfirst($classname) . ' reason',
49 );
50
51 my @fields = (
52   'reasonnum',
53   sub { shift->reasontype->type },
54   'reason',
55 );
56
57 my @links = (
58   $link,
59   $link,
60   '',
61 );
62
63 my $align = 'rll';
64
65 if ( $class eq 'S' ) {
66   push @header,
67     'Credit unused service',
68     'Unsuspension fee',
69   ;
70   push @fields,
71     sub {
72       my $reason = shift;
73       if ( $reason->unused_credit ) {
74         return '<SPAN STYLE="background-color:#00ff00">YES</SPAN>';
75       } else {
76         return '<SPAN STYLE="background-color:#ff0000">NO</SPAN>';
77       }
78     },
79     sub {
80       my $reason = shift;
81       my $pkgpart = $reason->unsuspend_pkgpart or return '';
82       my $part_pkg = FS::part_pkg->by_key($pkgpart) or return '';
83       my $text = $part_pkg->pkg_comment;
84       my $href = $p."edit/part_pkg.cgi?$pkgpart";
85       $text = qq!<A HREF="$href">! . encode_entities($text) . "</A>".
86               "<FONT SIZE=-1>";
87       if ( $reason->unsuspend_hold ) {
88         $text .= ' (on next bill)'
89       } else {
90         $text .= ' (immediately)'
91       }
92       $text .= '</FONT>';
93     }
94   ;
95   $align .= 'cl';
96 }
97
98
99 </%init>