summaryrefslogtreecommitdiff
path: root/httemplate/search/477_cust_pkg.html
blob: b8df9fd0ff2916d78b568ea0cfae7190abacb921 (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<& elements/search.html,
                  'html_init'   => $html_init,
                  'html_form'   => $html_form,
                  'html_foot'   => '</FORM>',
                  'title'       => emt('Package Search Results'), 
                  'name'        => 'packages',
                  'query'       => $query,
                  'count_query' => $count_query,
                  'header'      => [ emt('#'),
                                     emt('Quan.'),
                                     emt('Package'),
                                     emt('Class'),
                                     emt('Status'),
                                     emt('Freq.'),
                                     emt('Setup'),
                                     emt('Next bill'),
                                     emt('Susp.'),
                                     emt('Changed'),
                                     emt('Cancel'),
                                     FS::UI::Web::cust_header(),
                                     emt('Census tract'),
                                     emt('Package options'),
                                   ],
                  'fields'      => [
                    'pkgnum',
                    'quantity',
                    sub { $_[0]->pkg; },
                    'classname',
                    sub { ucfirst(shift->status); },
                    sub { FS::part_pkg::freq_pretty(shift); },

                    ( map { time_or_blank($_) }
                      qw( setup bill susp change_date cancel ) ),

                    \&FS::UI::Web::cust_fields,

                    sub { # census tract
                      my $cust_pkg = shift;
                      my $cust_location = $cust_pkg->cust_location;
                      ($cust_location->censustract || '<b>unknown</b>').
                        '<font size="-1"> (edit)</font>';
                    },

                    # a hidden input in each row with the pkgnum, so that
                    # we can refresh back to this list of pkgnums
                    sub {
                      my $cust_pkg = shift;
                      my $part_pkg = $cust_pkg->part_pkg;
                      my %hash = $part_pkg->fcc_options;
                      '<INPUT NAME="pkgnum" TYPE="hidden" VALUE="' .
                        $cust_pkg->pkgnum . '">' .
                      include('/elements/input-fcc_options.html',
                        id          => 'pkgnum'.$cust_pkg->pkgnum.
                                       'pkgpart'.$part_pkg->pkgpart,
                        curr_value  => encode_json(\%hash),
                        html_only   => 1
                      )
                    },
                  ],
                  'color' => [
                    '',
                    '',
                    '',
                    '',
                    sub { shift->statuscolor; },
                    '', '', '', '', '', '',
                    FS::UI::Web::cust_colors(),
                    '',
                    '',
                  ],
                  'style' => [ '', '', '', '', 'b', 
                               '', '', '', '', '', '',
                               FS::UI::Web::cust_styles() ],
                  'size'  => [ '', '', '', '', '-1' ],
                  'align' => 'rrlcccrrrrr'. FS::UI::Web::cust_aligns(). 'cl',
                  'links' => [
                    $link,
                    $link,
                    $link,
                    '', '', '', '', '', '', '', '',
                    ( map { $_ ne 'Cust. Status' ? $clink : '' }
                          FS::UI::Web::cust_header()
                    ),
                    '',
                    '',
                  ],
                  'link_onclicks' => [
                    (('') x 11),
                    (map { '' } FS::UI::Web::cust_header()),
                    $pkg_edit_location_link,
                    '',
                  ],

&>
<%init>

my $curuser = $FS::CurrentUser::CurrentUser;
my $edit        = 'Edit FCC report configuration';
my $edit_global = 'Edit FCC report configuration for all agents';
my $acl_edit        = $curuser->access_right($edit);
my $acl_edit_global = $curuser->access_right($edit_global);

die "access denied"
  unless $acl_edit || $acl_edit_global;

my $conf = new FS::Conf;

my $session;

my ($query, $count_query);

if ( $cgi->param('redirect') ) { # then restore the pkgnum list
  $session = $cgi->param('redirect');
  my $pref = $curuser->option("redirect$session"); # contains a list of pkgnums
  die "unknown redirect session $session\n" unless length($pref);
  my @pkgnums = grep /^\d+$/, split(',', $pref);
  
  $query = FS::cust_pkg->search({});
  $count_query = delete($query->{count_query});

  my $where = "cust_pkg.pkgnum IN (".join(',', @pkgnums).")";
  if ( $count_query =~ /WHERE/i ) {
    $where = " AND ($where) ";
  } else {
    $where = " WHERE ($where) ";
  }
  $query->{extra_sql} .= $where;
  $count_query .= $where;
} else {
  # build and run the query right now, and then cache the pkgnums it returned
  my %search_hash = ();
    
  #scalars
  for (qw( agentnum 477part 477rownum date )) {
    $search_hash{$_} = $cgi->param($_) if length($cgi->param($_));
  }

  $query = FS::cust_pkg->search(\%search_hash);
  $count_query = delete($query->{'count_query'});

  my @cust_pkg = qsearch($query);

  my $pkgnums = join(',', map { $_->pkgnum } @cust_pkg);
  $session = int(rand(4294967296)); #XXX
  my $pref = new FS::access_user_pref({
    'usernum'    => $FS::CurrentUser::CurrentUser->usernum,
    'prefname'   => "redirect$session",
    'prefvalue'  => $pkgnums,
    'expiration' => time + 3600, #1h?  1m?
  });
  my $pref_error = $pref->insert;
  if ($pref_error) {
    die "couldn't even set redirect cookie: $pref_error\n";
  }

  # and then bail out and reload using the redirect cookie
  $cgi->delete_all();
  $cgi->param("redirect", $session);
  $m->clear_buffer;
  $m->print( $cgi->redirect($cgi->self_url) );
  $m->abort;
}

my $show = $curuser->default_customer_view =~ /^(jumbo|packages)$/
             ? ''
             : ';show=packages';

my $link = sub {
  my $self = shift;
  my $frag = 'cust_pkg'. $self->pkgnum; #hack for IE ignoring real #fragment
  [ "${p}view/cust_main.cgi?custnum=".$self->custnum.
                           "$show;fragment=$frag#cust_pkg",
    'pkgnum'
  ];
};

my $html_init =
  include('/elements/init_overlib.html') .
  include('/elements/input-fcc_options.html', js_only => 1) .
  include('.style') .
  include('.script');

my $clink = sub {
  my $cust_pkg = shift;
  $cust_pkg->cust_main_custnum
    ? [ "${p}view/cust_main.cgi?", 'custnum' ] 
    : '';
};

my $html_form = qq!
  <FORM ACTION="${p}edit/process/bulk-477_cust_pkg.html" METHOD="POST" NAME="477_cust_pkg">
  <INPUT NAME="redirect" TYPE="hidden" VALUE="$session">
!;

my $pkg_edit_location_link = sub {
  my $cust_pkg = shift;
  my $locationnum = $cust_pkg->locationnum;
  include('/elements/popup_link_onclick.html',
    'action'      => $p. "edit/cust_location-censustract.html?locationnum=$locationnum",
    'actionlabel' => emt('Edit census tract'),
    'width'       => 700,
    'height'      => 355,
  );
};

sub time_or_blank {
   my $column = shift;
   return sub {
     my $record = shift;
     my $value = $record->get($column); #mmm closures
     $value ? time2str('%b %d %Y', $value ) : '';
   };
}

</%init>
<%def .style>
<style>
  button.edit_fcc_button { float: right; }
</style>
</%def>
<%def .script>
<script type="text/javascript">
  function finish_edit_fcc(id) {
    cClick();
    document.forms['477_cust_pkg'].submit(); //immediately save/refresh
  }
</script>
</%def>