internationalization/localization, RT12515
[freeside.git] / httemplate / search / cust_pkg.cgi
1 <& elements/search.html,
2                   'html_init'   => $html_init, 
3                   'title'       => emt('Package Search Results'), 
4                   'name'        => 'packages',
5                   'query'       => $sql_query,
6                   'count_query' => $count_query,
7                   'header'      => [ emt('#'),
8                                      emt('Quan.'),
9                                      emt('Package'),
10                                      emt('Class'),
11                                      emt('Status'),
12                                      emt('Setup'),
13                                      emt('Base Recur'),
14                                      emt('Freq.'),
15                                      emt('Setup'),
16                                      emt('Last bill'),
17                                      emt('Next bill'),
18                                      emt('Adjourn'),
19                                      emt('Susp.'),
20                                      emt('Expire'),
21                                      emt('Contract end'),
22                                      emt('Cancel'),
23                                      emt('Reason'),
24                                      FS::UI::Web::cust_header(
25                                        $cgi->param('cust_fields')
26                                      ),
27                                      emt('Services'),
28                                    ],
29                   'fields'      => [
30                     'pkgnum',
31                     'quantity',
32                     sub { $_[0]->pkg; },
33                     'classname',
34                     sub { ucfirst(shift->status); },
35                     sub { sprintf( $money_char.'%.2f',
36                                    shift->part_pkg->option('setup_fee'),
37                                  );
38                         },
39                     sub { my $c = shift;
40                           sprintf( $money_char.'%.2f',
41                                    $c->part_pkg->base_recur($c)
42                                  );
43                         },
44                     sub { FS::part_pkg::freq_pretty(shift); },
45
46                     ( map { time_or_blank($_) }
47           qw( setup last_bill bill adjourn susp expire contract_end cancel ) ),
48
49                     sub { my $self = shift;
50                           my $return = '';
51                           foreach my $action ( qw ( cancel susp ) ) {
52                             my $reason = $self->last_reason($action);
53                             $return = $reason->reason if $reason;
54                             last if $return;
55                           }
56                           $return;
57                         },
58
59                     \&FS::UI::Web::cust_fields,
60                     sub {
61                       my $cust_pkg = shift;
62                       my $type = $cgi->param('_type') || '';
63                       if ($type =~ /xls|csv/) {
64                         my $cust_svc = $cust_pkg->primary_cust_svc;
65                         if($cust_svc) {
66                           return join ": ",($cust_svc->label)[0,1];
67                         }
68                         else {
69                           return '';
70                         }
71                       }
72                       else {
73                           [ map {
74                                   [ 
75                                     { 'data' => $_->[0]. ':',
76                                       'align'=> 'right',
77                                     },
78                                     { 'data' => $_->[1],
79                                       'align'=> 'left',
80                                       'link' => $p. 'view/' .
81                                                 $_->[2]. '.cgi?'. $_->[3],
82                                     },
83                                   ];
84                                 } $cust_pkg->labels
85                           ];
86                       }
87                     }
88                   ],
89                   'color' => [
90                     '',
91                     '',
92                     '',
93                     '',
94                     sub { shift->statuscolor; },
95                     '',
96                     '',
97                     '',
98                     '',
99                     '',
100                     '',
101                     '',
102                     '',
103                     '',
104                     '',
105                     '',
106                     '',
107                     FS::UI::Web::cust_colors(),
108                     '',
109                   ],
110                   'style' => [ '', '', '', '', 'b', '', '', '', '', '', '', '', '', '', '', '', '',
111                                FS::UI::Web::cust_styles() ],
112                   'size'  => [ '', '', '', '', '-1' ],
113                   'align' => 'rrlccrrlrrrrrrrrl'. FS::UI::Web::cust_aligns(). 'r',
114                   'links' => [
115                     $link,
116                     $link,
117                     $link,
118                     '',
119                     '',
120                     '',
121                     '',
122                     '',
123                     '',
124                     '',
125                     '',
126                     '',
127                     '',
128                     '',
129                     '',
130                     '',
131                     '',
132                     ( map { $_ ne 'Cust. Status' ? $clink : '' }
133                           FS::UI::Web::cust_header(
134                                                     $cgi->param('cust_fields')
135                                                   )
136                     ),
137                     '',
138                   ],
139 &>
140 <%init>
141
142 my $curuser = $FS::CurrentUser::CurrentUser;
143
144 die "access denied"
145   unless $curuser->access_right('List packages');
146
147 my $conf = new FS::Conf;
148 my $money_char = $conf->config('money_char') || '$';
149
150 my %search_hash = ();
151
152 #some false laziness w/misc/bulk_change_pkg.cgi
153   
154 $search_hash{'query'} = $cgi->keywords;
155
156 #scalars
157 for (qw( agentnum custnum magic status classnum custom cust_fields pkgbatch )) {
158   $search_hash{$_} = $cgi->param($_) if $cgi->param($_);
159 }
160
161 $search_hash{'pkgpart'} = [ $cgi->param('pkgpart') ];
162
163 for my $param ( qw(censustract) ) {
164   $search_hash{$param} = $cgi->param($param) || ''
165     if ( grep { /$param/ } $cgi->param );
166 }
167
168 my @report_option = $cgi->param('report_option')
169   if $cgi->param('report_option');
170 $search_hash{report_option} = join(',', @report_option) if @report_option;
171
172 ###
173 # parse dates
174 ###
175
176 #false laziness w/report_cust_pkg.html
177 my %disable = (
178   'all'             => {},
179   'one-time charge' => { 'last_bill'=>1, 'bill'=>1, 'adjourn'=>1, 'susp'=>1, 'expire'=>1, 'cancel'=>1, },
180   'active'          => { 'susp'=>1, 'cancel'=>1 },
181   'suspended'       => { 'cancel' => 1 },
182   'cancelled'       => {},
183   ''                => {},
184 );
185
186 foreach my $field (qw( setup last_bill bill adjourn susp expire contract_end cancel active )) {
187
188   my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, $field);
189
190   next if $beginning == 0 && $ending == 4294967295
191        or $disable{$cgi->param('status')}->{$field};
192
193   $search_hash{$field} = [ $beginning, $ending ];
194
195 }
196
197 my $sql_query = FS::cust_pkg->search(\%search_hash);
198 my $count_query = delete($sql_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 = sub {
230   my $query = shift;
231   my $text = '';
232   my $curuser = $FS::CurrentUser::CurrentUser;
233
234   if ( $curuser->access_right('Bulk change customer packages') ) {
235     $text .= include('/elements/init_overlib.html').
236              include( '/elements/popup_link.html',
237                'label'       => emt('Change these packages'),
238                'action'      => "${p}misc/bulk_change_pkg.cgi?$query",
239                'actionlabel' => emt('Change Packages'),
240                'width'       => 569,
241                'height'      => 210,
242              ). '<BR>';
243
244     if ( $curuser->access_right('Edit customer package dates') ) {
245       $text .= include( '/elements/popup_link.html',
246                  'label'       => emt('Increment next bill date'),
247                  'action'      => "${p}misc/bulk_pkg_increment_bill.cgi?$query",
248                  'actionlabel' => emt('Increment Bill Date'),
249                  'width'       => 569,
250                  'height'      => 210,
251               ). '<BR>';
252     }
253     $text .= include( '/elements/email-link.html',
254                 'search_hash' => \%search_hash,
255                 'table'       => 'cust_pkg',
256                 );
257   }
258   return $text;
259 };
260
261 </%init>