stray closing /TABLE in the no-ticket case
[freeside.git] / httemplate / elements / select-paybatch.html
1 <SELECT NAME="<% $opt{field} || 'paybatch' %>">
2
3   <OPTION VALUE="">any/none</OPTION>
4
5 % foreach my $p (@paybatch) {
6 %   my( $paybatch, $date ) = @$p;
7 %   #my @components = split('-', $paybatch);
8 %   my $pretty_date = time2str($date_format, $date);
9 %   my $pretty = "$pretty_date: $paybatch";
10
11     <OPTION VALUE="<% $paybatch |h %>"><% $pretty |h %></OPTION>
12
13 % }
14
15 </SELECT>
16 <%init>
17
18 use Date::Parse qw(str2time); #i should be in Mason.pm
19
20 my %opt = @_;
21 #my $paybatch = $opt{'curr_value'}; # || $opt{'value'} necessary?
22
23 my $conf = new FS::Conf;
24 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
25
26 my $sth = dbh->prepare('SELECT DISTINCT paybatch FROM cust_pay
27                           WHERE paybatch IS NOT NULL')
28   or die dbh->errstr;
29 $sth->execute or die $sth->errstr;
30
31 my @paybatch = #map $_->[0],
32                  sort { $a->[1] <=> $b->[1] }
33                    map { my $date = '';
34                          if ( /^\w+\-(\d+)\-/ ) {
35                            $date = $1;
36                          } elsif ( /^\w+\-([\d\/]+)\-([\d\:]+)\-/ ) {
37                            $date = str2time("$1 $2");
38                          #} else {
39                          #  warn "unparsable: $_\n";
40                          }
41                          [ $_, $date ];
42                        }
43                      grep ! /^webui-/, #don't actually want the single entries
44                        map $_->[0], @{ $sth->fetchall_arrayref };
45
46 </%init>