summaryrefslogtreecommitdiff
path: root/httemplate/browse/reason.html
blob: 7f62ada8476654831649ef67826484e5be5a1876 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<% include( 'elements/browse.html',
                 'title'       => ucfirst($classname) . ' Reasons',
                 'menubar'     => [ ucfirst($classname).' Reason Types' =>
				      $p."browse/reason_type.html?class=$class"
                                  ],
                 'html_init'   => $html_init,
                 'name'        => $classname . ' reasons',
                 'disableable' => 1,
                 'disabled_statuspos' => 3,
                 'query'       => { 'table'     => 'reason',
                                    'hashref'   => {},
                                    'extra_sql' => $where_clause. 
				                   ' ORDER BY reason_type', 
                                    'addl_from' => 'LEFT JOIN reason_type ON reason_type.typenum = reason.reason_type', 
                                  },
                 'count_query' => $count_query,
                 'header'      => \@header,
                 'fields'      => \@fields,
                 'links'       => \@links,
                 'align'       => $align,
                 'html_form'   => qq!<FORM ACTION="${p}misc/reason_merge.html" METHOD="POST">!,
                 'html_foot'   => $html_foot,
             )
%>
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');

$cgi->param('class') =~ /^(\w)$/ or die "illegal class";
my $class = $1;

my $classname = $FS::reason_type::class_name{$class};
my $classpurpose = $FS::reason_type::class_purpose{$class};

my $html_init = include('/elements/init_overlib.html').
ucfirst($classname).  " reasons $classpurpose.<BR><BR>".
qq!<A HREF="${p}edit/reason.html?class=$class">!.
"<I>Add a $classname reason</I></A><BR><BR>";

my $where_clause = " WHERE class='$class' ";

my $count_query = 'SELECT COUNT(*) FROM reason LEFT JOIN reason_type on ' .
                'reason_type.typenum = reason.reason_type ' . $where_clause;

my $link = [ $p."edit/reason.html?class=$class&reasonnum=", 'reasonnum' ];

my @header = (
  '#',
  ucfirst($classname) . ' reason type',
  ucfirst($classname) . ' reason',
);

my @fields = (
  'reasonnum',
  sub { shift->reasontype->type },
  'reason',
);

my @links = (
  $link,
  $link,
  '',
);

my $align = 'rll';

if ( $class eq 'S' or $class eq 'C' ) {
  push @header, 'Credit unused service';
  push @fields,
    sub {
      my $reason = shift;
      if ( $reason->unused_credit ) {
        return '<SPAN STYLE="background-color:#00ff00">YES</SPAN>';
      } else {
        return '<SPAN STYLE="background-color:#ff0000">NO</SPAN>';
      }
    };
  $align .= 'c';
}
if ( $class eq 'S' ) {
  push @header, 'Suspension fee';
  push @fields,
    sub {
      my $reason = shift;
      my $feepart = $reason->feepart;
      my ($href, $text, $detail);
      if ( $feepart ) {
        my $part_fee = FS::part_fee->by_key($feepart) or return '';
        $text = $part_fee->itemdesc . ': ' . $part_fee->explanation;
        $detail = $reason->fee_on_unsuspend ? 'unsuspension' : 'suspension';
        if ( $reason->fee_hold ) {
          $detail = "next bill after $detail";
        }
        $detail = "(on $detail)";
        $href = $p."edit/part_fee.html?$feepart";
      } else {
        my $pkgpart = $reason->unsuspend_pkgpart;
        my $part_pkg = FS::part_pkg->by_key($pkgpart) or return '';
        $text = $part_pkg->pkg_comment;
        $href = $p."edit/part_pkg.cgi?$pkgpart";
        $detail = $reason->unsuspend_hold ?
          '(on next bill after unsuspension)' : '(on unsuspension)';
      }
      return '' unless length($text);

      $text = qq!<A HREF="$href">! . encode_entities($text) . "</A> ".
              "<FONT SIZE=-1>$detail</FONT>";
      $text .= '</FONT>';
    }
  ;
  $align .= 'l';
}

# reason merge handling
push @header, '';
push @fields, sub {
  my $reason = shift;
  my $reasonnum = $reason->reasonnum;
  qq!<INPUT TYPE="checkbox" NAME="reasonnum" VALUE="$reasonnum">!;
};
push @links, '';
$align .= 'l';
my $html_foot = include('/search/elements/checkbox-foot.html',
  onclick  => include( '/elements/popup_link_onclick.html',
                js_action   => q!'! . "${p}misc/reason-merge.html?" . q!' + toCGIString()!,
                actionlabel => 'Merge reasons',
              ),
  label    => 'merge selected reasons',
  minboxes => 2,
) . '</FORM>';

</%init>