d1dd65d659b5727ee1752c402f9c67d9abe6f970
[freeside.git] / httemplate / search / cust_bill_event.cgi
1 %
2 %
3 %my $title = $cgi->param('failed') ? 'Failed invoice events' : 'Invoice events';
4 %
5 %my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
6 %
7 %##tie my %hash, 'Tie::DxHash', 
8 %#my %hash = (
9 %#      _date => { op=> '>=', value=>$beginning },
10 %## i wish...
11 %##      _date => { op=> '<=', value=>$ending },
12 %#);
13 %#$hash{'statustext'} = { op=> '!=', value=>'' }
14 %#  if $cgi->param('failed');
15 %
16 %my $where = " WHERE cust_bill_event._date >= $beginning".
17 %            "   AND cust_bill_event._date <= $ending";
18 %
19 %if ( $cgi->param('failed') ) {
20 %  $where .= " AND statustext != '' ".
21 %            " AND statustext IS NOT NULL ".
22 %            " AND statustext != 'N/A' "
23 %}
24 %
25 %if ( $cgi->param('part_bill_event.payby') =~ /^(\w+)$/ ) {
26 %  $where .= " AND part_bill_event.payby = '$1' ";
27 %}
28 %
29 %my $sql_query = {
30 %  'table'     => 'cust_bill_event',
31 %  #'hashref'   => \%hash,
32 %  'hashref'   => {}, 
33 %  'select'    => join(', ',
34 %                   'cust_bill_event.*',
35 %                   'part_bill_event.event',
36 %                   'cust_bill.custnum',
37 %                   'cust_bill._date AS cust_bill_date',
38 %                   'cust_main.custnum AS cust_main_custnum',
39 %                   FS::UI::Web::cust_sql_fields(),
40 %                 ),
41 %  'extra_sql' => "$where ORDER BY _date ASC",
42 %  'addl_from' => 'LEFT JOIN part_bill_event USING ( eventpart ) '.
43 %                 'LEFT JOIN cust_bill       USING ( invnum    ) '.
44 %                 'LEFT JOIN cust_main       USING ( custnum   ) ',
45 %};
46 %
47 %my $count_sql = "SELECT COUNT(*) FROM cust_bill_event ".
48 %                "LEFT JOIN part_bill_event USING ( eventpart ) ".
49 %                $where;
50 %
51 %my $conf = new FS::Conf;
52 %
53 %my $failed = $cgi->param('failed');
54 %
55 %my $html_init = join("\n", map {
56 %  ( my $action = $_ ) =~ s/_$//;
57 %  include('/elements/progress-init.html',
58 %            $_.'form',
59 %            [ 'action', 'beginning', 'ending', 'failed' ],
60 %            "../misc/${_}invoice_events.cgi",
61 %            { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
62 %            $_, #key
63 %         ),
64 %  qq!<FORM NAME="${_}form">!,
65 %  qq!<INPUT TYPE="hidden" NAME="action" VALUE="$_">!, #not used though
66 %  qq!<INPUT TYPE="hidden" NAME="beginning" VALUE="$beginning">!,
67 %  qq!<INPUT TYPE="hidden" NAME="ending"    VALUE="$ending">!,
68 %  qq!<INPUT TYPE="hidden" NAME="failed"    VALUE="$failed">!,
69 %  qq!</FORM>!
70 %} qw( print_ email_ fax_ ) );
71 %
72 %my $menubar =  [
73 %                 'Main menu' => $p,
74 %                 'Re-print these events' =>
75 %                   "javascript:print_process()",
76 %                 'Re-email these events' =>
77 %                   "javascript:email_process()",
78 %               ];
79 %
80 %push @$menubar, 'Re-fax these events' =>
81 %                  "javascript:fax_process()"
82 %  if $conf->exists('hylafax');
83 %
84 %my $link_cust = sub {
85 %  my $cust_bill_event = shift;
86 %  $cust_bill_event->cust_main_custnum
87 %    ? [ "${p}view/cust_main.cgi?", 'custnum' ]
88 %    : '';
89 %};
90 %
91 %
92 <% include( 'elements/search.html',
93                  'title'       => $title,
94                  'html_init'   => $html_init,
95                  'menubar'     => $menubar,
96                  'name'        => 'billing events',
97                  'query'       => $sql_query,
98                  'count_query' => $count_sql,
99                  'header'      => [ 'Event',
100                                     'Date',
101                                     'Status',
102                                     #'Inv #', 'Inv Date', 'Cust #',
103                                     'Invoice',
104                                     FS::UI::Web::cust_header(),
105                                   ],
106                  'fields' => [
107                                'event',
108                                sub { time2str("%b %d %Y %T", $_[0]->_date) },
109                                sub { 
110                                      #my $cust_bill_event = shift;
111                                      my $status = $_[0]->status;
112                                      $status .= ': '.$_[0]->statustext
113                                        if $_[0]->statustext;
114                                      $status;
115                                    },
116                                sub {
117                                      #my $cust_bill_event = shift;
118                                      'Invoice #'. $_[0]->invnum.
119                                      ' ('.
120                                        time2str("%D", $_[0]->cust_bill_date).
121                                      ')';
122                                    },
123                                \&FS::UI::Web::cust_fields,
124                              ],
125                  'links' => [
126                               '',
127                               '',
128                               '',
129                               sub {
130                                 my $part_bill_event = shift;
131                                 my $template = $part_bill_event->templatename;
132                                 $template .= '-' if $template;
133                                 [ "${p}view/cust_bill.cgi?$template", 'invnum'];
134                               },
135                               ( map { $link_cust } FS::UI::Web::cust_header() ),
136                             ],
137              )
138 %>