enable CardFortress in test database, #71513
[freeside.git] / httemplate / search / h_cust_pkg.html
1 <& elements/search.html,
2                   'html_init'   => $html_init, 
3                   'title'       => $title,
4                   'name'        => 'packages',
5                   'query'       => $query,
6                   'count_query' => $count_query,
7                   'header'      => [ emt('#'),
8                                      emt('Quan.'),
9                                      emt('Package'),
10                                      emt('Class'),
11                                      emt('Status'),
12                                      emt('Ordered by'),
13                                      emt('Setup'),
14                                      emt('Base Recur'),
15                                      emt('Freq.'),
16                                      emt('Setup'),
17                                      emt('Last bill'),
18                                      emt('Next bill'),
19                                      emt('Adjourn'),
20                                      emt('Susp.'),
21                                      emt('Susp. delay'),
22                                      emt('Expire'),
23                                      emt('Contract end'),
24                                      emt('Changed'),
25                                      emt('Cancel'),
26                                      emt('Reason'),
27                                      FS::UI::Web::cust_header(
28                                        $cgi->param('cust_fields')
29                                      ),
30                                      emt('As of'),
31                                    ],
32                   'fields'      => [
33                     'pkgnum',
34                     'quantity',
35                     'pkg',
36                     'classname',
37                     sub { ucfirst(shift->status); },
38                     'otaker',
39                     sub { sprintf( $money_char.'%.2f',
40                                    shift->part_pkg->option('setup_fee'),
41                                  );
42                         },
43                     sub { my $c = shift;
44                           sprintf( $money_char.'%.2f',
45                                    $c->part_pkg->base_recur($c)
46                                  );
47                         },
48                     sub { FS::part_pkg::freq_pretty(shift); },
49
50                     ( map { time_or_blank($_) }
51           qw( setup last_bill bill adjourn susp dundate expire contract_end change_date cancel ) ),
52
53                     sub { my $self = shift;
54                           my $return = '';
55                           foreach my $action ( qw ( cancel susp ) ) {
56                             my $reason = $self->last_reason($action);
57                             $return = $reason->reason if $reason;
58                             last if $return;
59                           }
60                           $return;
61                         },
62
63                     \&FS::UI::Web::cust_fields,
64                     # in cust_pkg.cgi, service labels would go here
65                     time_or_blank('history_date'),
66                   ],
67                   'color' => [
68                     '',
69                     '',
70                     '',
71                     '',
72                     sub { shift->statuscolor; },
73                     '',
74                     '',
75                     '',
76                     '',
77                     '',
78                     '',
79                     '',
80                     '',
81                     '',
82                     '',
83                     '',
84                     '',
85                     '',
86                     '',
87                     '',
88                     FS::UI::Web::cust_colors(),
89                     '',
90                   ],
91                   'style' => [ '', '', '', '', 'b', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
92                                FS::UI::Web::cust_styles() ],
93                   'size'  => [ '', '', '', '', '-1' ],
94                   'align' => 'rrlcccrrlrrrrrrrrrrl'. FS::UI::Web::cust_aligns(). 'r',
95                   'links' => [
96                     $link,
97                     $link,
98                     $link,
99                     '',
100                     '',
101                     '',
102                     '',
103                     '',
104                     '',
105                     '',
106                     '',
107                     '',
108                     '',
109                     '',
110                     '',
111                     '',
112                     '', # link to changed-from package?
113                     '',
114                     '',
115                     '',
116                     ( map { $_ ne 'Cust. Status' ? $clink : '' }
117                           FS::UI::Web::cust_header(
118                                                     $cgi->param('cust_fields')
119                                                   )
120                     ),
121                     '',
122                   ],
123 &>
124 <%init>
125
126 # shamelessly cloned from cust_pkg.cgi, with minimal changes to make it work
127
128 my $curuser = $FS::CurrentUser::CurrentUser;
129
130 die "access denied"
131   unless $curuser->access_right('List packages');
132
133 my $conf = new FS::Conf;
134 my $money_char = $conf->config('money_char') || '$';
135
136 my %search_hash = ();
137
138 #some false laziness w/misc/bulk_change_pkg.cgi
139   
140 $search_hash{'query'} = $cgi->keywords;
141
142 #scalars
143 for (qw( agentnum custnum magic status custom cust_fields pkgbatch )) {
144   $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
145 }
146
147 #arrays
148 for my $param (qw( pkgpart classnum )) {
149   $search_hash{$param} = [ $cgi->param($param) ]
150     if grep { $_ eq $param } $cgi->param;
151 }
152
153 #scalars that need to be passed if empty
154 for my $param (qw( censustract censustract2 )) {
155   $search_hash{$param} = $cgi->param($param) || ''
156     if grep { $_ eq $param } $cgi->param;
157 }
158
159 my $report_option = $cgi->param('report_option');
160 $search_hash{report_option} = $report_option if $report_option;
161
162 for my $param (grep /^report_option_any/, $cgi->param) {
163   $search_hash{$param} = $cgi->param($param);
164 }
165
166 ###
167 # parse dates
168 ###
169
170 #false laziness w/report_cust_pkg.html
171 my %disable = (
172   'all'             => {},
173   'one-time charge' => { 'last_bill'=>1, 'bill'=>1, 'adjourn'=>1, 'susp'=>1, 'expire'=>1, 'cancel'=>1, 'contract_end'=>1, 'dundate'=>1, },
174   'active'          => { 'susp'=>1, 'cancel'=>1 },
175   'suspended'       => { 'cancel' =>1, 'dundate'=>1, },
176   'cancelled'       => {},
177   ''                => {},
178 );
179
180 foreach my $field (qw( setup last_bill bill adjourn susp expire contract_end change_date cancel active )) {
181
182   my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, $field);
183
184   next if $beginning == 0 && $ending == 4294967295
185        or $disable{$cgi->param('status')}->{$field};
186
187   $search_hash{$field} = [ $beginning, $ending ];
188
189 }
190
191 my $date;
192 if ( $cgi->param('date') =~ /^(\d+)$/ ) {
193   $date = $1;
194   $search_hash{'date'} = $date;
195 }
196
197 my $query = FS::h_cust_pkg->search(\%search_hash);
198 my $count_query = delete($query->{'count_query'});
199
200 my $show = $curuser->default_customer_view =~ /^(jumbo|packages)$/
201              ? ''
202              : ';show=packages';
203
204 my $link = sub {
205   my $self = shift;
206   my $frag = 'cust_pkg'. $self->pkgnum; #hack for IE ignoring real #fragment
207   [ "${p}view/cust_main.cgi?custnum=".$self->custnum.
208                            "$show;fragment=$frag#cust_pkg",
209     'pkgnum'
210   ];
211 };
212
213 my $clink = sub {
214   my $cust_pkg = shift;
215   $cust_pkg->cust_main_custnum
216     ? [ "${p}view/cust_main.cgi?", 'custnum' ] 
217     : '';
218 };
219
220 sub time_or_blank {
221    my $column = shift;
222    return sub {
223      my $record = shift;
224      my $value = $record->get($column); #mmm closures
225      $value ? time2str('%b %d %Y', $value ) : '';
226    };
227 }
228
229 my $html_init = '';
230
231 my $title = 'Historical Package View - ';
232 if ( $date == 0 ) {
233   $title .= 'start';
234 } elsif ( $date == 4294967295 ) {
235   $title .= 'present';
236 } else {
237   $title .= time2str('%h %o %Y', $date);
238 }
239 </%init>