& /elements/header-popup.html,
{
'title' => 'Event query - '.$part_event->event,
}
&>
% if ( $objects > 0 ) {
<% emt("[quant,_1,$label]", $objects) %>
% if ( $part_event->eventtable ne 'cust_main' ) {
<% emt("belonging to [quant,_1,customer]", $customers) %>
% }
% foreach my $header ('Trigger', @cust_header, @header) {
<% $header %> |
% }
% my @rowcolors = ('ffffff','eeeeee');
% my $row = 0;
% foreach my $object (@targets) {
% # now works for all eventtables, including cust_pkg
% my $link = $p . 'view/' . $part_event->eventtable . '.cgi?' .
% $object->$pkey;
<% ucfirst $label %> #<% $object->$pkey %> |
% my $cust_main = $object->cust_main; # via Mixin
% my $i = 0; # hack to avoid messing with cust_aligns/colors/styles
% foreach (@cust_fields) {
% if ($cust_header[$i] eq 'Cust. Status') {
<% $_->($cust_main) %> |
% }
% else {
<% $_->($cust_main) %> |
% }
% $i++;
% } #foreach @cust_fields
% foreach (@fields) {
<% ref($_) eq 'CODE' ? $_->($object) : $object->$_ %> |
% }
% } #foreach $object
% } #object > 0
% else {
<% emt("No matching ${label}s found.") %>
%}
<& /elements/footer.html &>
<%init>
my $curuser = $FS::CurrentUser::CurrentUser;
die "access denied"
unless $curuser->access_right('Edit billing events')
|| $curuser->access_right('Edit global billing events');
my ($eventpart) = $cgi->param('eventpart');
$eventpart =~ /^\d+$/ or die 'illegal eventpart';
my $time = parse_datetime($cgi->param('date')) || time;
my $part_event = FS::part_event->by_key($eventpart)
or die "Event definition $eventpart not found.\n";
my @targets = $part_event->targets('time' => $time);
my $total = @targets;
# in imitation of search/elements/search-html.html
my @header;
my @fields;
my ($pkey, $label);
$pkey = dbdef->table($part_event->eventtable)->primary_key;
for ($part_event->eventtable) {
if (/^cust_main$/) {
# very likely to appear in events
my %paybys = FS::payby->cust_payby2longname;
push @header, 'Balance', 'Payment Method';
push @fields, 'balance', sub{ $paybys{$_[0]->payby} };
$label = 'customer';
}
elsif (/^cust_bill$/) {
push @header, 'Invoice Date', 'Amount', 'Balance';
push @fields, date_format('_date'), 'charged', 'owed';
$label = 'invoice';
}
elsif (/^cust_statement$/) {
push @header, 'Statement Date', 'Amount', 'Balance';
push @fields, date_format('_date'), 'charged', 'owed';
$label = 'statement';
}
elsif (/^cust_pkg$/) {
push @header, 'Package', 'Next Bill', 'Frequency';
push @fields, sub {$_[0]->part_pkg->pkg}, date_format('bill'),
sub {$_[0]->part_pkg->freq_pretty};
$label = 'package';
}
elsif (/^svc_acct$/) {
push @header, 'Username', 'Domain';
push @fields, 'username', 'domain';
$label = 'service';
}
else {}
}
my @cust_header = FS::UI::Web::cust_header();
my @cust_fields = FS::UI::Web::cust_fields_subs();
my $objects = scalar(@targets);
my $customers = uniq(map {$_->cust_main->custnum} @targets);
sub date_format {
my $column = shift;
sub { my $obj = shift;
my $value = $obj->get($column);
$value ? time2str('%b %d %Y', $value) : '';
};
}
%init>