Merge branch 'master' of git.freeside.biz:/home/git/freeside
[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                  'html_form'   => qq!<FORM ACTION="${p}misc/reason_merge.html" METHOD="POST">!,
22                  'html_foot'   => $html_foot,
23              )
24 %>
25 <%init>
26
27 die "access denied"
28   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
29
30 $cgi->param('class') =~ /^(\w)$/ or die "illegal class";
31 my $class = $1;
32
33 my $classname = $FS::reason_type::class_name{$class};
34 my $classpurpose = $FS::reason_type::class_purpose{$class};
35
36 my $html_init = include('/elements/init_overlib.html').
37 ucfirst($classname).  " reasons $classpurpose.<BR><BR>".
38 qq!<A HREF="${p}edit/reason.html?class=$class">!.
39 "<I>Add a $classname reason</I></A><BR><BR>";
40
41 my $where_clause = " WHERE class='$class' ";
42
43 my $count_query = 'SELECT COUNT(*) FROM reason LEFT JOIN reason_type on ' .
44                 'reason_type.typenum = reason.reason_type ' . $where_clause;
45
46 my $link = [ $p."edit/reason.html?class=$class&reasonnum=", 'reasonnum' ];
47
48 my @header = (
49   '#',
50   ucfirst($classname) . ' reason type',
51   ucfirst($classname) . ' reason',
52 );
53
54 my @fields = (
55   'reasonnum',
56   sub { shift->reasontype->type },
57   'reason',
58 );
59
60 my @links = (
61   $link,
62   $link,
63   '',
64 );
65
66 my $align = 'rll';
67
68 if ( $class eq 'S' ) {
69   push @header,
70     'Credit unused service',
71     'Suspension fee',
72   ;
73   push @fields,
74     sub {
75       my $reason = shift;
76       if ( $reason->unused_credit ) {
77         return '<SPAN STYLE="background-color:#00ff00">YES</SPAN>';
78       } else {
79         return '<SPAN STYLE="background-color:#ff0000">NO</SPAN>';
80       }
81     },
82     sub {
83       my $reason = shift;
84       my $feepart = $reason->feepart;
85       my ($href, $text, $detail);
86       if ( $feepart ) {
87         my $part_fee = FS::part_fee->by_key($feepart) or return '';
88         $text = $part_fee->itemdesc . ': ' . $part_fee->explanation;
89         $detail = $reason->fee_on_unsuspend ? 'unsuspension' : 'suspension';
90         if ( $reason->fee_hold ) {
91           $detail = "next bill after $detail";
92         }
93         $detail = "(on $detail)";
94         $href = $p."edit/part_fee.html?$feepart";
95       } else {
96         my $pkgpart = $reason->unsuspend_pkgpart;
97         my $part_pkg = FS::part_pkg->by_key($pkgpart) or return '';
98         $text = $part_pkg->pkg_comment;
99         $href = $p."edit/part_pkg.cgi?$pkgpart";
100         $detail = $reason->unsuspend_hold ?
101           '(on next bill after unsuspension)' : '(on unsuspension)';
102       }
103       return '' unless length($text);
104
105       $text = qq!<A HREF="$href">! . encode_entities($text) . "</A> ".
106               "<FONT SIZE=-1>$detail</FONT>";
107       $text .= '</FONT>';
108     }
109   ;
110   $align .= 'cl';
111 }
112
113 # reason merge handling
114 push @header, '';
115 push @fields, sub {
116   my $reason = shift;
117   my $reasonnum = $reason->reasonnum;
118   qq!<INPUT TYPE="checkbox" NAME="reasonnum" VALUE="$reasonnum">!;
119 };
120 push @links, '';
121 $align .= 'l';
122 my $html_foot = include('/search/elements/checkbox-foot.html',
123   onclick  => include( '/elements/popup_link_onclick.html',
124                 js_action   => q!'! . "${p}misc/reason-merge.html?" . q!' + toCGIString()!,
125                 actionlabel => 'Merge reasons',
126               ),
127   label    => 'merge selected reasons',
128   minboxes => 2,
129 ) . '</FORM>';
130
131 </%init>