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