This commit was generated by cvs2svn to compensate for changes in r9232,
[freeside.git] / httemplate / search / cust_pkg.cgi
1 <% include( 'elements/search.html',
2                   'html_init'   => $html_init, 
3                   'title'       => 'Package Search Results', 
4                   'name'        => 'packages',
5                   'query'       => $sql_query,
6                   'count_query' => $count_query,
7                   #'redirect'    => $link,
8                   'header'      => [ '#',
9                                      'Quan.',
10                                      'Package',
11                                      'Class',
12                                      'Status',
13                                      'Setup',
14                                      'Base Recur',
15                                      'Freq.',
16                                      'Setup',
17                                      'Last bill',
18                                      'Next bill',
19                                      'Adjourn',
20                                      'Susp.',
21                                      'Expire',
22                                      'Cancel',
23                                      'Reason',
24                                      FS::UI::Web::cust_header(
25                                        $cgi->param('cust_fields')
26                                      ),
27                                      'Services',
28                                    ],
29                   'fields'      => [
30                     'pkgnum',
31                     'quantity',
32                     sub { #my $part_pkg = $part_pkg{shift->pkgpart};
33                           #$part_pkg->pkg; # ' - '. $part_pkg->comment;
34                           $_[0]->pkg; # ' - '. $_[0]->comment;
35                         },
36                     'classname',
37                     sub { ucfirst(shift->status); },
38                     sub { sprintf( $money_char.'%.2f',
39                                    shift->part_pkg->option('setup_fee'),
40                                  );
41                         },
42                     sub { my $c = shift;
43                           sprintf( $money_char.'%.2f',
44                                    $c->part_pkg->base_recur($c)
45                                  );
46                         },
47                     sub { #shift->part_pkg->freq_pretty;
48
49                           #my $part_pkg = $part_pkg{shift->pkgpart};
50                           #$part_pkg->freq_pretty;
51
52                           FS::part_pkg::freq_pretty(shift);
53                         },
54
55                     #sub { time2str('%b %d %Y', shift->setup); },
56                     #sub { time2str('%b %d %Y', shift->last_bill); },
57                     #sub { time2str('%b %d %Y', shift->bill); },
58                     #sub { time2str('%b %d %Y', shift->susp); },
59                     #sub { time2str('%b %d %Y', shift->expire); },
60                     #sub { time2str('%b %d %Y', shift->get('cancel')); },
61                     ( map { time_or_blank($_) }
62                           qw( setup last_bill bill adjourn susp expire cancel ) ),
63
64                     sub { my $self = shift;
65                           my $return = '';
66                           foreach my $action ( qw ( cancel susp ) ) {
67                             my $reason = $self->last_reason($action);
68                             $return = $reason->reason if $reason;
69                             last if $return;
70                           }
71                           $return;
72                         },
73
74                     \&FS::UI::Web::cust_fields,
75                     #sub { '<table border=0 cellspacing=0 cellpadding=0 STYLE="border:none">'.
76                     #      join('', map { '<tr><td align="right" style="border:none">'. $_->[0].
77                     #                     ':</td><td style="border:none">'. $_->[1]. '</td></tr>' }
78                     #                   shift->labels
79                     #          ).
80                     #      '</table>';
81                     #    },
82                     sub {
83                           [ map {
84                                   [ 
85                                     { 'data' => $_->[0]. ':',
86                                       'align'=> 'right',
87                                     },
88                                     { 'data' => $_->[1],
89                                       'align'=> 'left',
90                                       'link' => $p. 'view/' .
91                                                 $_->[2]. '.cgi?'. $_->[3],
92                                     },
93                                   ];
94                                 } shift->labels
95                           ];
96                         },
97                   ],
98                   'color' => [
99                     '',
100                     '',
101                     '',
102                     '',
103                     sub { shift->statuscolor; },
104                     '',
105                     '',
106                     '',
107                     '',
108                     '',
109                     '',
110                     '',
111                     '',
112                     '',
113                     '',
114                     '',
115                     FS::UI::Web::cust_colors(),
116                     '',
117                   ],
118                   'style' => [ '', '', '', '', 'b', '', '', '', '', '', '', '', '', '', '', '',
119                                FS::UI::Web::cust_styles() ],
120                   'size'  => [ '', '', '', '', '-1' ],
121                   'align' => 'rrlccrrlrrrrrrrl'. FS::UI::Web::cust_aligns(). 'r',
122                   'links' => [
123                     $link,
124                     $link,
125                     $link,
126                     '',
127                     '',
128                     '',
129                     '',
130                     '',
131                     '',
132                     '',
133                     '',
134                     '',
135                     '',
136                     '',
137                     '',
138                     '',
139                     ( map { $_ ne 'Cust. Status' ? $clink : '' }
140                           FS::UI::Web::cust_header(
141                                                     $cgi->param('cust_fields')
142                                                   )
143                     ),
144                     '',
145                   ],
146               )
147 %>
148 <%init>
149
150 my $curuser = $FS::CurrentUser::CurrentUser;
151
152 die "access denied"
153   unless $curuser->access_right('List packages');
154
155 my $conf = new FS::Conf;
156 my $money_char = $conf->config('money_char') || '$';
157
158 # my %part_pkg = map { $_->pkgpart => $_ } qsearch('part_pkg', {});
159
160 my %search_hash = ();
161
162 #some false laziness w/misc/bulk_change_pkg.cgi
163   
164 $search_hash{'query'} = $cgi->keywords;
165   
166 for (qw( agentnum custnum magic status classnum custom cust_fields )) {
167   $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
168 }
169
170 $search_hash{'pkgpart'} = [ $cgi->param('pkgpart') ];
171
172 for my $param ( qw(censustract) ) {
173   $search_hash{$param} = $cgi->param($param) || ''
174     if ( grep { /$param/ } $cgi->param );
175 }
176
177 my @report_option = $cgi->param('report_option')
178   if $cgi->param('report_option');
179 $search_hash{report_option} = join(',', @report_option) if @report_option;
180
181 ###
182 # parse dates
183 ###
184
185 #false laziness w/report_cust_pkg.html
186 my %disable = (
187   'all'             => {},
188   'one-time charge' => { 'last_bill'=>1, 'bill'=>1, 'adjourn'=>1, 'susp'=>1, 'expire'=>1, 'cancel'=>1, },
189   'active'          => { 'susp'=>1, 'cancel'=>1 },
190   'suspended'       => { 'cancel' => 1 },
191   'cancelled'       => {},
192   ''                => {},
193 );
194
195 foreach my $field (qw( setup last_bill bill adjourn susp expire cancel active )) {
196
197   my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, $field);
198
199   next if $beginning == 0 && $ending == 4294967295
200        or $disable{$cgi->param('status')}->{$field};
201
202   $search_hash{$field} = [ $beginning, $ending ];
203
204 }
205
206 my $sql_query = FS::cust_pkg->search(\%search_hash);
207 my $count_query = delete($sql_query->{'count_query'});
208
209 my $show = $curuser->default_customer_view =~ /^(jumbo|packages)$/
210              ? ''
211              : ';show=packages';
212
213 my $link = sub {
214   my $self = shift;
215   my $frag = 'cust_pkg'. $self->pkgnum; #hack for IE ignoring real #fragment
216   [ "${p}view/cust_main.cgi?custnum=".$self->custnum.
217                            "$show;fragment=$frag#cust_pkg",
218     'pkgnum'
219   ];
220 };
221
222 my $clink = sub {
223   my $cust_pkg = shift;
224   $cust_pkg->cust_main_custnum
225     ? [ "${p}view/cust_main.cgi?", 'custnum' ] 
226     : '';
227 };
228
229 #if ( scalar(@cust_pkg) == 1 ) {
230 #  print $cgi->redirect("${p}view/cust_main.cgi?". $cust_pkg[0]->custnum.
231 #                       "#cust_pkg". $cust_pkg[0]->pkgnum );
232
233 #    my @cust_svc = qsearch( 'cust_svc', { 'pkgnum' => $pkgnum } );
234 #    my $rowspan = scalar(@cust_svc) || 1;
235
236 #    my $n2 = '';
237 #    foreach my $cust_svc ( @cust_svc ) {
238 #      my($label, $value, $svcdb) = $cust_svc->label;
239 #      my $svcnum = $cust_svc->svcnum;
240 #      my $sview = $p. "view";
241 #      print $n2,qq!<TD><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$label</FONT></A></TD>!,
242 #            qq!<TD><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$value</FONT></A></TD>!;
243 #      $n2="</TR><TR>";
244 #    }
245
246 sub time_or_blank {
247    my $column = shift;
248    return sub {
249      my $record = shift;
250      my $value = $record->get($column); #mmm closures
251      $value ? time2str('%b %d %Y', $value ) : '';
252    };
253 }
254
255 my $html_init = sub {
256   my $query = shift;
257   my $text = '';
258   my $curuser = $FS::CurrentUser::CurrentUser;
259
260   if ( $curuser->access_right('Bulk change customer packages') ) {
261     $text .= include('/elements/init_overlib.html').
262              include( '/elements/popup_link.html',
263                'label'       => 'Change these packages',
264                'action'      => "${p}misc/bulk_change_pkg.cgi?$query",
265                'actionlabel' => 'Change Packages',
266                'width'       => 569,
267                'height'      => 210,
268              ). '<BR>';
269
270     if ( $curuser->access_right('Edit customer package dates') ) {
271       $text .= include( '/elements/popup_link.html',
272                  'label'       => 'Increment next bill date',
273                  'action'      => "${p}misc/bulk_pkg_increment_bill.cgi?$query",
274                  'actionlabel' => 'Increment Bill Date',
275                  'width'       => 569,
276                  'height'      => 210,
277               ). '<BR>';
278     }
279   }
280   return $text;
281 };
282
283 </%init>