4.x+ self-service API: list and remove cards on file, RT#38919
[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     'Suspension 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 $feepart = $reason->feepart;
82       my ($href, $text, $detail);
83       if ( $feepart ) {
84         my $part_fee = FS::part_fee->by_key($feepart) or return '';
85         $text = $part_fee->itemdesc . ': ' . $part_fee->explanation;
86         $detail = $reason->fee_on_unsuspend ? 'unsuspension' : 'suspension';
87         if ( $reason->fee_hold ) {
88           $detail = "next bill after $detail";
89         }
90         $detail = "(on $detail)";
91         $href = $p."edit/part_fee.html?$feepart";
92       } else {
93         my $pkgpart = $reason->unsuspend_pkgpart;
94         my $part_pkg = FS::part_pkg->by_key($pkgpart) or return '';
95         $text = $part_pkg->pkg_comment;
96         $href = $p."edit/part_pkg.cgi?$pkgpart";
97         $detail = $reason->unsuspend_hold ?
98           '(on next bill after unsuspension)' : '(on unsuspension)';
99       }
100       return '' unless length($text);
101
102       $text = qq!<A HREF="$href">! . encode_entities($text) . "</A> ".
103               "<FONT SIZE=-1>$detail</FONT>";
104       $text .= '</FONT>';
105     }
106   ;
107   $align .= 'cl';
108 }
109
110
111 </%init>