summaryrefslogtreecommitdiff
path: root/httemplate/search/cust_event_fee.html
blob: 230d7b3bdd2db83c35cb9e0bdeb0f48e47c221d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<& elements/search.html,
                 'title'       => 'Billing event fees',
                 'html_init'   => include('.init'),
                 'menubar'     => $menubar,
                 'name'        => 'billing events',
                 'query'       => $sql_query,
                 'count_query' => $count_sql,
                 'header'      => [ 'Event',
                                    'Event date',
                                    'Fee',
                                    'Invoice',
                                    'Invoice date',
                                    FS::UI::Web::cust_header(),
                                  ],
                 'fields' => [
                               'event',
                               sub { time2str("%b %d %Y %T", $_[0]->_date) },
                               'itemdesc',
                               $inv_sub,
                               sub { my $d = $_[0]->fee_cust_bill_date;
                                     $d ? time2str("%b %d %Y %T", $d) : '' },
                               \&FS::UI::Web::cust_fields,
                             ],
                'align' => 'lrlrr'.FS::UI::Web::cust_aligns(),
                'links' => [
                              '',
                              '',
                              '',
                              $inv_link,
                              $inv_link,
                              ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
                                    FS::UI::Web::cust_header()
                              ),
                            ],
                 'color' => [ 
                              '',
                              '',
                              '',
                              '',
                              '',
                              FS::UI::Web::cust_colors(),
                            ],
                 'style' => [ 
                              '',
                              '',
                              '',
                              '',
                              '',
                              FS::UI::Web::cust_styles(),
                            ],
&>
<%once>

my $inv_sub = sub {
  my $cust_event_fee = shift;
  my $fee_invnum = $cust_event_fee->fee_invnum;
  $fee_invnum || ( $cust_event_fee->nextbill ? '(next bill)' : '(not yet)' );
};

my $inv_link = sub {
  $_[0]->fee_invnum
    ?  [ "${p}view/cust_bill.cgi?", 'fee_invnum' ]
    : '';
};

my $link_cust = sub {
  my $cust_event_fee = shift;
  $cust_event_fee->custnum
    ? [ "${p}view/cust_main.cgi?", 'custnum' ]
    : '';
};

</%once>
<%shared>
my @scalars = qw( billpkgnum ); #qw( agentnum status custnum invnum pkgnum failed );
my @lists = qw( eventpart );
my %search;
</%shared>
<%init>

my $curuser = $FS::CurrentUser::CurrentUser;

die "access denied"
  unless $curuser->access_right('Billing event reports');

for my $param (@scalars) {
  $search{$param} = scalar( $cgi->param($param) )
    if $cgi->param($param);
}

#lists
foreach my $param (@lists) {
  $search{$param} = [ $cgi->param($param) ];
}

my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
$search{'beginning'} = $beginning;
$search{'ending'}    = $ending;

my $where = ' WHERE '. FS::cust_event_fee->search_sql_where( \%search );

my $join = FS::cust_event_fee->join_sql();

my $sql_query = {
  'table'     => 'cust_event_fee',
  'select'    => join(', ',
                    'cust_event_fee.*',
                    'cust_event.*',
                    'part_event.*',
                    'cust_bill_pkg.invnum AS fee_invnum',
                    'fee_cust_bill._date AS fee_cust_bill_date',
                    'part_fee.itemdesc',
                    'cust_main.custnum',
                    FS::UI::Web::cust_sql_fields(),
                  ),
  'hashref'   => {}, 
  'extra_sql' => $where,
  'order_by'  => 'ORDER BY eventfeenum ASC', #'ORDER BY _date ASC',
  'addl_from' => $join,
};

my $count_sql = "SELECT COUNT(*) FROM cust_event_fee $join $where";

my $conf = new FS::Conf;

my $menubar = [];
push @$menubar, 'Delete these fees' => "javascript:confirm_delete_fees()"
  if $curuser->access_right('Delete fees');

</%init>
<%def .init>
<& /elements/progress-init.html,
  'delete_fees_form',
  [ @scalars, @lists, 'beginning', 'ending' ],
  "../misc/delete_fees.cgi",
  { 'message' => 'Fees deleted', #would be nice to show the number of them...
    #what we were just displaying is gone, so where to go?
    # woudl be nice to not keep displaying the deleted data
    #'url'     => 
  },
&>
<FORM NAME="delete_fees_form">
%   foreach my $param (@scalars, 'beginning', 'ending') {
  <INPUT TYPE="hidden" NAME="<% $param %>" VALUE="<% $search{$param} |h %>">
%   }
%   foreach my $param (@lists) {
%     foreach my $value (@{ $search{$param} }) {
  <INPUT TYPE="hidden" NAME="<% $param %>" VALUE="<% $value |h %>">
%     }
%   }
</FORM>
<SCRIPT TYPE="text/javascript">

function confirm_delete_fees() {
  if ( ! confirm("Are you sure you want to delete these fees?") ) {
    return;
  }
  process();
}

</SCRIPT>
</%def>