advanced invoice serach, groundwork to add reprint/fax/email links to invoice search...
[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 $where .= " AND statustext != '' AND statustext IS NOT NULL"
19   if $cgi->param('failed');
20
21 my $sql_query = {
22   'table'     => 'cust_bill_event',
23   #'hashref'   => \%hash,
24   'hashref'   => {}, 
25   'select'    => join(', ',
26                    'cust_bill_event.*',
27                    'part_bill_event.event',
28                    'cust_bill.custnum',
29                    'cust_bill._date AS cust_bill_date',
30                    map "cust_main.$_", qw(last first company)
31
32                  ),
33   'extra_sql' => "$where ORDER BY _date ASC",
34   'addl_from' => 'LEFT JOIN part_bill_event USING ( eventpart ) '.
35                  'LEFT JOIN cust_bill       USING ( invnum    ) '.
36                  'LEFT JOIN cust_main       USING ( custnum   ) ',
37 };
38
39 my $count_sql = "select count(*) from cust_bill_event $where";
40
41 my $conf = new FS::Conf;
42
43 my $failed = $cgi->param('failed');
44
45 my $html_init = join("\n", map {
46   ( my $action = $_ ) =~ s/_$//;
47   include('/elements/progress-init.html',
48             $_.'form',
49             [ 'action', 'beginning', 'ending', 'failed' ],
50             "../misc/${_}invoice_events.cgi",
51             { 'message' => "Invoices re-${action}ed" }, #would be nice to show the number of them, but...
52             $_, #key
53          ),
54   qq!<FORM NAME="${_}form">!,
55   qq!<INPUT TYPE="hidden" NAME="action" VALUE="$_">!, #not used though
56   qq!<INPUT TYPE="hidden" NAME="beginning" VALUE="$beginning">!,
57   qq!<INPUT TYPE="hidden" NAME="ending"    VALUE="$ending">!,
58   qq!<INPUT TYPE="hidden" NAME="failed"    VALUE="$failed">!,
59   qq!</FORM>!
60 } qw( print_ email_ fax_ ) );
61
62 my $menubar =  [
63                  'Main menu' => $p,
64                  'Re-print these events' =>
65                    "javascript:print_process()",
66                  'Re-email these events' =>
67                    "javascript:email_process()",
68                ];
69
70 push @$menubar, 'Re-fax these events' =>
71                   "javascript:fax_process()"
72   if $conf->exists('hylafax');
73
74 %><%= include( 'elements/search.html',
75                  'title'       => $title,
76                  'html_init'   => $html_init,
77                  'menubar'     => $menubar,
78                  'name'        => 'billing events',
79                  'query'       => $sql_query,
80                  'count_query' => $count_sql,
81                  'header'      => [ qw( Event Date Status ),
82                                     #'Inv #', 'Inv Date', 'Cust #',
83                                     'Invoice', 'Cust #',
84                                   ],
85                  'fields' => [
86                                'event',
87                                sub { time2str("%b %d %Y %T", $_[0]->_date) },
88                                sub { 
89                                      #my $cust_bill_event = shift;
90                                      my $status = $_[0]->status;
91                                      $status .= ': '.$_[0]->statustext
92                                        if $_[0]->statustext;
93                                      $status;
94                                    },
95                                sub {
96                                      #my $cust_bill_event = shift;
97                                      'Invoice #'. $_[0]->invnum.
98                                      ' ('.
99                                        time2str("%D", $_[0]->cust_bill_date).
100                                      ')';
101                                    },
102                                sub { FS::cust_main::name($_[0]) },
103
104
105                              ],
106                  'links' => [
107                               '',
108                               '',
109                               '',
110                               sub {
111                                 my $part_bill_event = shift;
112                                 my $template = $part_bill_event->templatename;
113                                 $template .= '-' if $template;
114                                 [ "${p}view/cust_bill.cgi?$template", 'invnum'];
115                               },
116                               [ "${p}view/cust_main.cgi?", 'custnum' ],
117                               [ "${p}view/cust_main.cgi?", 'custnum' ],
118                             ],
119              )
120 %>