This commit was generated by cvs2svn to compensate for changes in r4407,
[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                    'cust_main.custnum AS cust_main_custnum',
31                    FS::UI::Web::cust_sql_fields(),
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 my $link_cust = sub {
75   my $cust_bill_event = shift;
76   $cust_bill_event->cust_main_custnum
77     ? [ "${p}view/cust_main.cgi?", 'custnum' ]
78     : '';
79 };
80
81 %><%= include( 'elements/search.html',
82                  'title'       => $title,
83                  'html_init'   => $html_init,
84                  'menubar'     => $menubar,
85                  'name'        => 'billing events',
86                  'query'       => $sql_query,
87                  'count_query' => $count_sql,
88                  'header'      => [ 'Event',
89                                     'Date',
90                                     'Status',
91                                     #'Inv #', 'Inv Date', 'Cust #',
92                                     'Invoice',
93                                     FS::UI::Web::cust_header(),
94                                   ],
95                  'fields' => [
96                                'event',
97                                sub { time2str("%b %d %Y %T", $_[0]->_date) },
98                                sub { 
99                                      #my $cust_bill_event = shift;
100                                      my $status = $_[0]->status;
101                                      $status .= ': '.$_[0]->statustext
102                                        if $_[0]->statustext;
103                                      $status;
104                                    },
105                                sub {
106                                      #my $cust_bill_event = shift;
107                                      'Invoice #'. $_[0]->invnum.
108                                      ' ('.
109                                        time2str("%D", $_[0]->cust_bill_date).
110                                      ')';
111                                    },
112                                \&FS::UI::Web::cust_fields,
113                              ],
114                  'links' => [
115                               '',
116                               '',
117                               '',
118                               sub {
119                                 my $part_bill_event = shift;
120                                 my $template = $part_bill_event->templatename;
121                                 $template .= '-' if $template;
122                                 [ "${p}view/cust_bill.cgi?$template", 'invnum'];
123                               },
124                               ( map { $link_cust } FS::UI::Web::cust_header() ),
125                             ],
126              )
127 %>