[freeside-commits] freeside/httemplate/view cust_pkg.cgi, NONE, 1.16.2.2 part_event-targets.html, NONE, 1.1.2.1
Mark Wells
mark at wavetail.420.am
Tue Feb 14 17:31:33 PST 2012
Update of /home/cvs/cvsroot/freeside/httemplate/view
In directory wavetail.420.am:/tmp/cvs-serv27336/httemplate/view
Added Files:
Tag: FREESIDE_2_3_BRANCH
cust_pkg.cgi part_event-targets.html
Log Message:
query billing events to see affected objects, #15142
--- NEW FILE: cust_pkg.cgi ---
<% $cgi->redirect($path) %>
<%init>
# since cust_pkgs can't be viewed directly, just throw a redirect
my ($pkgnum) = $cgi->keywords;
$pkgnum =~ /^\d+$/ or die "invalid pkgnum '$pkgnum'";
my $show = $FS::CurrentUser::CurrentUser->default_customer_view =~ /^(jumbo|packages)$/ ? '' : ';show=packages';
my $self = FS::cust_pkg->by_key($pkgnum) or die "pkgnum $pkgnum not found";
my $frag = 'cust_pkg'. $self->pkgnum;
my $path = $p.'view/cust_main.cgi?custnum='.$self->custnum.";$show#$frag";
</%init>
--- NEW FILE: part_event-targets.html ---
<& /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) %>
% }
<BR><BR>
<TABLE class="grid" cellspacing=0 width="100%" style="font-size:80%">
<TR style='background-color:#cccccc'>
% foreach my $header ('Trigger', @cust_header, @header) {
<TH><% $header %></TH>
% }
</TR>
% my @rowcolors = ('ffffff','eeeeee');
% my $row = 0;
<TR style="background-color:#<% $rowcolors[$row++ % 2] %>">
% foreach my $object (@targets) {
% # now works for all eventtables, including cust_pkg
% my $link = $p . 'view/' . $part_event->eventtable . '.cgi?' .
% $object->$pkey;
<TD><A target="_blank" href="<% $link %>">
<% ucfirst $label %> #<% $object->$pkey %></A></TD>
% 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') {
<TD style="text-align:center;
font-weight:bold;
color:#<% $cust_main->cust_statuscolor %>"><% $_->($cust_main) %></TD>
% }
% else {
<TD><% $_->($cust_main) %></TD>
% }
% $i++;
% } #foreach @cust_fields
% foreach (@fields) {
<TD><% ref($_) eq 'CODE' ? $_->($object) : $object->$_ %></TD>
% }
</TR>
% } #foreach $object
</TABLE>
% } #object > 0
% else {
<% emt("No matching ${label}s found.") %>
%}
<& /elements/footer.html &>
<%once>
use List::MoreUtils qw(uniq);
</%once>
<%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->keywords;
$eventpart =~ /^\d+$/ or die 'illegal eventpart';
my $part_event = FS::part_event->by_key($eventpart)
or die "Event definition $eventpart not found.\n";
my @targets = $part_event->targets;
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';
}
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 {$_->custnum} @targets);
sub date_format {
my $column = shift;
sub { my $obj = shift;
my $value = $obj->get($column);
$value ? time2str('%b %d %Y', $value) : '';
};
}
</%init>
More information about the freeside-commits
mailing list