summaryrefslogtreecommitdiff
path: root/httemplate/search
diff options
context:
space:
mode:
Diffstat (limited to 'httemplate/search')
-rw-r--r--httemplate/search/cdr.html6
-rwxr-xr-xhttemplate/search/cust_bill.html28
-rwxr-xr-xhttemplate/search/cust_credit.html7
-rwxr-xr-xhttemplate/search/cust_main.cgi169
-rwxr-xr-xhttemplate/search/cust_pay.cgi16
-rwxr-xr-xhttemplate/search/cust_pkg.cgi173
-rwxr-xr-xhttemplate/search/cust_pkg_report.cgi22
-rw-r--r--httemplate/search/elements/search.html9
-rw-r--r--httemplate/search/inventory_item.html62
-rw-r--r--httemplate/search/report_cdr.html2
-rwxr-xr-xhttemplate/search/report_cust_pkg.html47
-rwxr-xr-xhttemplate/search/report_receivables.cgi83
-rwxr-xr-xhttemplate/search/svc_acct.cgi25
-rwxr-xr-xhttemplate/search/svc_domain.cgi48
-rwxr-xr-xhttemplate/search/svc_forward.cgi29
-rw-r--r--httemplate/search/svc_phone.cgi94
-rwxr-xr-xhttemplate/search/svc_www.cgi4
17 files changed, 590 insertions, 234 deletions
diff --git a/httemplate/search/cdr.html b/httemplate/search/cdr.html
index ec847e41f..e3d6043e8 100644
--- a/httemplate/search/cdr.html
+++ b/httemplate/search/cdr.html
@@ -11,13 +11,15 @@ if ( $cgi->param('freesidestatus') eq 'NULL' ) {
my $title = "Unprocessed $title";
$hashref->{'freesidestatus'} = ''; # Record.pm will take care of it
- $count_query .= " AND ( freesidestatus IS NULL OR freesidestatus = '' )";
+ #$count_query .= " AND ( freesidestatus IS NULL OR freesidestatus = '' )";
+ $count_query .= " WHERE ( freesidestatus IS NULL OR freesidestatus = '' )";
} elsif ( $cgi->param('freesidestatus') =~ /^([\w ]+)$/ ) {
my $title = "Processed $title";
$hashref->{'freesidestatus'} = $1;
- $count_query .= " AND freesidestatus = '$1'";
+ #$count_query .= " AND freesidestatus = '$1'";
+ $count_query .= " WHERE freesidestatus = '$1'";
}
diff --git a/httemplate/search/cust_bill.html b/httemplate/search/cust_bill.html
index 2108653a8..79c05dc42 100755
--- a/httemplate/search/cust_bill.html
+++ b/httemplate/search/cust_bill.html
@@ -1,4 +1,9 @@
<%
+
+ my $join_cust_main = 'LEFT JOIN cust_main USING ( custnum )';
+ #here is the agent virtualization
+ my $agentnums_sql = $FS::CurrentUser::CurrentUser->agentnums_sql;
+
my( $count_query, $sql_query );
my( $count_addl ) = ( '' );
my( $distinct ) = ( '' );
@@ -6,11 +11,15 @@
my($agentnum) = ( '' );
my($open, $days) = ( '', '' );
if ( $cgi->param('invnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) {
- $count_query = "SELECT COUNT(*) FROM cust_bill WHERE invnum = $2";
+ $count_query =
+ "SELECT COUNT(*) FROM cust_bill $join_cust_main".
+ " WHERE invnum = $2 AND $agentnums_sql"; #agent virtualization
$sql_query = {
'table' => 'cust_bill',
+ 'addl_from' => $join_cust_main,
'hashref' => { 'invnum' => $2 },
#'select' => '*',
+ 'extra_sql' => " AND $agentnums_sql", #agent virtualization
};
} else {
#if ( $cgi->param('begin') || $cgi->param('end')
@@ -28,7 +37,7 @@
$begin = str2time($1);
push @where, "cust_bill._date >= $begin";
}
- if ( $cgi->param('ending')
+ if ( $cgi->param('ending')
&& $cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/ ) {
$end = str2time($1) + 86399;
push @where, "cust_bill._date < $end";
@@ -43,6 +52,13 @@
push @where, "cust_bill._date < $end";
}
+ if ( $cgi->param('invnum_min') =~ /^\s*(\d+)\s*$/ ) {
+ push @where, "cust_bill.invnum >= $1";
+ }
+ if ( $cgi->param('invnum_max') =~ /^\s*(\d+)\s*$/ ) {
+ push @where, "cust_bill.invnum <= $1";
+ }
+
if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
$agentnum = $1;
push @where, "cust_main.agentnum = $agentnum";
@@ -68,10 +84,10 @@
push @where, "cust_bill._date < ". (time-86400*$days) if $days;
}
+ #here is the agent virtualization
+ push @where, $agentnums_sql;
my $extra_sql = scalar(@where) ? 'WHERE '. join(' AND ', @where) : '';
- my $addl_from = 'left join cust_main using ( custnum )';
-
if ( $cgi->param('newest_percust') ) {
$distinct = 'DISTINCT ON ( cust_bill.custnum )';
$orderby = 'ORDER BY cust_bill.custnum ASC, cust_bill._date DESC';
@@ -85,11 +101,11 @@
'$%.2f total outstanding balance',
];
}
- $count_query .= " FROM cust_bill $addl_from $extra_sql";
+ $count_query .= " FROM cust_bill $join_cust_main $extra_sql";
$sql_query = {
'table' => 'cust_bill',
- 'addl_from' => $addl_from,
+ 'addl_from' => $join_cust_main,
'hashref' => {},
'select' => "$distinct ". join(', ',
'cust_bill.*',
diff --git a/httemplate/search/cust_credit.html b/httemplate/search/cust_credit.html
index 279d682cd..eb78db5cd 100755
--- a/httemplate/search/cust_credit.html
+++ b/httemplate/search/cust_credit.html
@@ -36,9 +36,10 @@
push @search, " _date < $1 ";
}
- my $where = scalar(@search)
- ? 'WHERE '. join(' AND ', @search)
- : '';
+ #here is the agent virtualization
+ push @search, $FS::CurrentUser::CurrentUser->agentnums_sql;
+
+ my $where = 'WHERE '. join(' AND ', @search);
my $count_query = 'SELECT COUNT(*), SUM(amount) '.
'FROM cust_credit LEFT JOIN cust_main USING ( custnum ) '.
diff --git a/httemplate/search/cust_main.cgi b/httemplate/search/cust_main.cgi
index 733e5dc15..f6841a099 100755
--- a/httemplate/search/cust_main.cgi
+++ b/httemplate/search/cust_main.cgi
@@ -109,6 +109,7 @@ if ( $cgi->param('browse')
push @qual, FS::cust_main->cancel_sql if $cgi->param('cancelled');
push @qual, FS::cust_main->prospect_sql if $cgi->param('prospect');
push @qual, FS::cust_main->active_sql if $cgi->param('active');
+ push @qual, FS::cust_main->inactive_sql if $cgi->param('inactive');
push @qual, FS::cust_main->susp_sql if $cgi->param('suspended');
#EWWWWWW
@@ -117,6 +118,10 @@ if ( $cgi->param('browse')
my $addl_qual = join(' AND ', @qual);
+ #here is the agent virtualization
+ $addl_qual .= ( $addl_qual ? ' AND ' : '' ).
+ $FS::CurrentUser::CurrentUser->agentnums_sql;
+
if ( $addl_qual ) {
$qual .= ' AND ' if $qual;
$qual .= $addl_qual;
@@ -322,32 +327,43 @@ END
print "<BR><BR>". $pager. include('/elements/table-grid.html'). <<END;
<TR>
- <TH></TH>
- <TH>(bill) name</TH>
- <TH>company</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc"></TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc">(bill) name</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc">company</TH>
END
if ( defined dbdef->table('cust_main')->column('ship_last') ) {
print <<END;
- <TH>(service) name</TH>
- <TH>company</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc">(service) name</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc">company</TH>
END
}
foreach my $addl_header ( @addl_headers ) {
- print "<TH>$addl_header</TH>";
+ print '<TH CLASS="grid" BGCOLOR="#cccccc">'. "$addl_header</TH>";
}
print <<END;
- <TH>Packages</TH>
- <TH COLSPAN=2>Services</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc">Packages</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=2>Services</TH>
</TR>
END
+ my $bgcolor1 = '#eeeeee';
+ my $bgcolor2 = '#ffffff';
+ my $bgcolor;
+
my(%saw,$cust_main);
foreach $cust_main (
sort $sortby grep(!$saw{$_->custnum}++, @cust_main)
) {
+
+ if ( $bgcolor eq $bgcolor1 ) {
+ $bgcolor = $bgcolor2;
+ } else {
+ $bgcolor = $bgcolor1;
+ }
+
my($custnum,$last,$first,$company)=(
$cust_main->custnum,
$cust_main->getfield('last'),
@@ -377,9 +393,9 @@ END
%>
<TR>
- <TD ROWSPAN=<%= $rowspan || 1 %>><A HREF="<%= $view %>"><FONT SIZE=-1><%= $custnum %></FONT></A></TD>
- <TD ROWSPAN=<%= $rowspan || 1 %>><A HREF="<%= $view %>"><FONT SIZE=-1><%= "$last, $first" %></FONT></A></TD>
- <TD ROWSPAN=<%= $rowspan || 1 %>><%= $pcompany %></TD>
+ <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>" ROWSPAN=<%= $rowspan || 1 %>><A HREF="<%= $view %>"><FONT SIZE=-1><%= $custnum %></FONT></A></TD>
+ <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>" ROWSPAN=<%= $rowspan || 1 %>><A HREF="<%= $view %>"><FONT SIZE=-1><%= "$last, $first" %></FONT></A></TD>
+ <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>" ROWSPAN=<%= $rowspan || 1 %>><%= $pcompany %></TD>
<%
if ( defined dbdef->table('cust_main')->column('ship_last') ) {
@@ -393,55 +409,85 @@ END
: '<FONT SIZE=-1>&nbsp;</FONT>';
%>
- <TD ROWSPAN=<%= $rowspan || 1 %>><A HREF="<%= $view %>"><FONT SIZE=-1><%= "$ship_last, $ship_first" %></FONT></A></TD>
- <TD ROWSPAN=<%= $rowspan || 1 %>><%= $pship_company %></A></TD>
+ <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>" ROWSPAN=<%= $rowspan || 1 %>><A HREF="<%= $view %>"><FONT SIZE=-1><%= "$ship_last, $ship_first" %></FONT></A></TD>
+ <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>" ROWSPAN=<%= $rowspan || 1 %>><%= $pship_company %></A></TD>
<% }
foreach my $addl_col ( @addl_cols ) { %>
- <TD ROWSPAN=<%= $rowspan || 1 %> ALIGN=right><FONT SIZE=-1>
-
- <% if ( $addl_col eq 'tickets' ) {
- if ( @custom_priorities ) {
- print &itable('', 0);
- foreach my $priority ( @custom_priorities, '' ) {
-
- my $num =
- FS::TicketSystem->num_customer_tickets($custnum,$priority);
- my $ahref = '';
- $ahref= '<A HREF="'.
- FS::TicketSystem->href_customer_tickets($custnum,$priority).
- '">'
- if $num;
-
- print '<TR>'.
- " <TD ALIGN=right><FONT SIZE=-1>$ahref$num</A></FONT></TD>".
- "<TD ALIGN=left><FONT SIZE=-1>$ahref".
- ( $priority || '<i>(none)</i>' ).
- "</A></FONT></TD></TR>";
-
- }
- print '<TR><TD BGCOLOR="#000000" COLSPAN=2></TD></TR>'.
- '<TR><TD ALIGN=right><FONT SIZE=-1>';
- }
-
- my $ahref = '';
- $ahref = '<A HREF="'.
- FS::TicketSystem->href_customer_tickets($custnum).
- '">'
- if $cust_main->get($addl_col);
-
- print $ahref. $cust_main->get($addl_col). '</A>';
- print "</FONT></TD><TD ALIGN=left>".
- "<FONT SIZE=-1>${ahref}Total</A><FONT>".
- "</TD></TR></TABLE>"
- if @custom_priorities;
+ <% if ( $addl_col eq 'tickets' ) { %>
- } else {
- print $cust_main->get($addl_col);
+ <% if ( @custom_priorities ) { %>
+
+ <TD CLASS="inv" BGCOLOR="<%= $bgcolor %>" ROWSPAN=<%= $rowspan || 1 %> ALIGN=right><FONT SIZE=-1>
+
+ <TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>
+
+ <% foreach my $priority ( @custom_priorities, '' ) { %>
+
+ <%
+ my $num =
+ FS::TicketSystem->num_customer_tickets($custnum,$priority);
+ my $ahref = '';
+ $ahref= '<A HREF="'.
+ FS::TicketSystem->href_customer_tickets($custnum,$priority).
+ '">'
+ if $num;
+ %>
+
+ <TR>
+ <TD ALIGN=right>
+ <FONT SIZE=-1><%= $ahref.$num %></A></FONT>
+ </TD>
+ <TD ALIGN=left>
+ <FONT SIZE=-1><%= $ahref %><%= $priority || '<i>(none)</i>' %></A></FONT>
+ </TD>
+ </TR>
+
+ <% } %>
+
+ <TR>
+ <TH ALIGN=right STYLE="border-top: dashed 1px black">
+ <FONT SIZE=-1>
+
+ <% } else { %>
+
+ <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>" ROWSPAN=<%= $rowspan || 1 %> ALIGN=right><FONT SIZE=-1>
+
+ <% } %>
+
+ <%
+ my $ahref = '';
+ $ahref = '<A HREF="'.
+ FS::TicketSystem->href_customer_tickets($custnum).
+ '">'
+ if $cust_main->get($addl_col);
+ %>
+
+ <%= $ahref %><%= $cust_main->get($addl_col) %></A>
+
+ <% if ( @custom_priorities ) { %>
+
+ </FONT></TH>
+ <TH ALIGN=left STYLE="border-top: dashed 1px black">
+ <FONT SIZE=-1><%= ${ahref} %>Total</A><FONT>
+ </TH>
+ </TR>
+ </TABLE>
+
+ <% } %>
+
+ </FONT></TD>
+
+ <% } else { %>
+
+ <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>" ROWSPAN=<%= $rowspan || 1 %> ALIGN=right><FONT SIZE=-1>
+ <%= $cust_main->get($addl_col) %>
+ </FONT></TD>
+
+<%
}
- print "</FONT></TD>";
}
my($n1)='';
@@ -457,19 +503,30 @@ END
#my(@cust_svc) = qsearch( 'cust_svc', { 'pkgnum' => $_->pkgnum } );
my $rowspan = scalar(@cust_svc) || 1;
- print $n1, qq!<TD ROWSPAN=$rowspan><A HREF="$pkgview"><FONT SIZE=-1>$pkg - $comment</FONT></A></TD>!;
+ print $n1, qq!<TD CLASS="grid" BGCOLOR="$bgcolor" ROWSPAN=$rowspan><A HREF="$pkgview"><FONT SIZE=-1>$pkg - $comment</FONT></A></TD>!;
+
my($n2)='';
foreach my $cust_svc ( @cust_svc ) {
my($label, $value, $svcdb) = $cust_svc->label;
my($svcnum) = $cust_svc->svcnum;
my($sview) = $p.'view';
- print $n2,qq!<TD><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$label</FONT></A></TD>!,
- qq!<TD><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$value</FONT></A></TD>!;
+ print $n2,qq!<TD CLASS="grid" BGCOLOR="$bgcolor" ><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$label</FONT></A></TD>!,
+ qq!<TD CLASS="grid" BGCOLOR="$bgcolor" ><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$value</FONT></A></TD>!;
$n2="</TR><TR>";
}
+
+ unless ( @cust_svc ) {
+ print qq!<TD CLASS="grid" BGCOLOR="$bgcolor" COLSPAN=2>&nbsp;</TD>!;
+ }
+
#print qq!</TR><TR>\n!;
$n1="</TR><TR>";
}
+
+ unless ( @{$all_pkgs{$custnum}} ) {
+ print qq!<TD CLASS="grid" BGCOLOR="$bgcolor" COLSPAN=3>&nbsp;</TD>!;
+ }
+
print "</TR>";
}
diff --git a/httemplate/search/cust_pay.cgi b/httemplate/search/cust_pay.cgi
index 99ffc3d20..0247b0b0d 100755
--- a/httemplate/search/cust_pay.cgi
+++ b/httemplate/search/cust_pay.cgi
@@ -96,10 +96,10 @@
die "unknown search magic: ". $cgi->param('magic');
}
- my $search = '';
- if ( @search ) {
- $search = ' WHERE '. join(' AND ', @search);
- }
+ #here is the agent virtualization
+ push @search, $FS::CurrentUser::CurrentUser->agentnums_sql;
+
+ my $search = ' WHERE '. join(' AND ', @search);
$count_query = "SELECT COUNT(*), SUM(paid) ".
"FROM cust_pay LEFT JOIN cust_main USING ( custnum )".
@@ -125,14 +125,16 @@
$cgi->param('payby') =~ /^(\w+)$/ or die "illegal payby";
my $payby = $1;
- $count_query = "SELECT COUNT(*), SUM(paid) FROM cust_pay ".
- "WHERE payinfo = '$payinfo' AND payby = '$payby'";
+ $count_query = "SELECT COUNT(*), SUM(paid) FROM cust_pay".
+ " WHERE payinfo = '$payinfo' AND payby = '$payby'".
+ " AND ". $FS::CurrentUser::CurrentUser->agentnums_sql;
$sql_query = {
'table' => 'cust_pay',
'hashref' => { 'payinfo' => $payinfo,
'payby' => $payby },
- 'extra_sql' => "ORDER BY _date",
+ 'extra_sql' => $FS::CurrentUser::CurrentUser->agentnums_sql.
+ " ORDER BY _date",
};
}
diff --git a/httemplate/search/cust_pkg.cgi b/httemplate/search/cust_pkg.cgi
index a2fb89c12..614e9b509 100755
--- a/httemplate/search/cust_pkg.cgi
+++ b/httemplate/search/cust_pkg.cgi
@@ -1,19 +1,89 @@
<%
-my %part_pkg = map { $_->pkgpart => $_ } qsearch('part_pkg', {});
+# my %part_pkg = map { $_->pkgpart => $_ } qsearch('part_pkg', {});
my($query) = $cgi->keywords;
-my $orderby;
-my @where;
-my $cjoin = '';
+my @where = ();
+
+##
+# parse agent
+##
if ( $cgi->param('agentnum') =~ /^(\d+)$/ and $1 ) {
- $cjoin = "LEFT JOIN cust_main USING ( custnum )";
push @where,
"agentnum = $1";
}
+##
+# parse status
+##
+
+if ( $cgi->param('magic') eq 'active'
+ || $cgi->param('status') eq 'active' ) {
+
+ push @where, FS::cust_pkg->active_sql();
+
+} elsif ( $cgi->param('magic') eq 'inactive'
+ || $cgi->param('status') eq 'inactive' ) {
+
+ push @where, FS::cust_pkg->inactive_sql();
+
+
+} elsif ( $cgi->param('magic') eq 'suspended'
+ || $cgi->param('status') eq 'suspended' ) {
+
+ push @where, FS::cust_pkg->suspended_sql();
+
+} elsif ( $cgi->param('magic') =~ /^cancell?ed$/
+ || $cgi->param('status') =~ /^cancell?ed$/ ) {
+
+ push @where, FS::cust_pkg->cancelled_sql();
+
+} elsif ( $cgi->param('status') =~ /^(one-time charge|inactive)$/ ) {
+
+ push @where, FS::cust_pkg->inactive_sql();
+
+}
+
+###
+# parse package class
+###
+
+#false lazinessish w/graph/cust_bill_pkg.cgi
+my $classnum = 0;
+my @pkg_class = ();
+if ( exists($cgi->Vars->{'classnum'})
+ && $cgi->param('classnum') =~ /^(\d*)$/
+ )
+{
+ $classnum = $1;
+ if ( $classnum ) { #a specific class
+ push @where, "classnum = $classnum";
+
+ #@pkg_class = ( qsearchs('pkg_class', { 'classnum' => $classnum } ) );
+ #die "classnum $classnum not found!" unless $pkg_class[0];
+ #$title .= $pkg_class[0]->classname.' ';
+
+ } elsif ( $classnum eq '' ) { #the empty class
+
+ push @where, "classnum IS NULL";
+ #$title .= 'Empty class ';
+ #@pkg_class = ( '(empty class)' );
+ } elsif ( $classnum eq '0' ) {
+ #@pkg_class = qsearch('pkg_class', {} ); # { 'disabled' => '' } );
+ #push @pkg_class, '(empty class)';
+ } else {
+ die "illegal classnum";
+ }
+}
+#eslaf
+
+###
+# parse magic, legacy, etc.
+###
+
+my $orderby;
if ( $cgi->param('magic') && $cgi->param('magic') eq 'bill' ) {
$orderby = 'ORDER BY bill';
@@ -23,40 +93,17 @@ if ( $cgi->param('magic') && $cgi->param('magic') eq 'bill' ) {
#"bill <= $ending",
"CASE WHEN bill IS NULL THEN 0 ELSE bill END >= $beginning ",
"CASE WHEN bill IS NULL THEN 0 ELSE bill END <= $ending",
- '( cancel IS NULL OR cancel = 0 )';
+ #'( cancel IS NULL OR cancel = 0 )'
+ ;
} else {
if ( $cgi->param('magic') &&
- $cgi->param('magic') =~ /^(active|suspended|cancell?ed)$/
+ $cgi->param('magic') =~ /^(active|inactive|suspended|cancell?ed)$/
) {
$orderby = 'ORDER BY pkgnum';
- if ( $cgi->param('magic') eq 'active' ) {
-
- #push @where,
- # '( susp IS NULL OR susp = 0 )',
- # '( cancel IS NULL OR cancel = 0)';
- push @where, FS::cust_pkg->active_sql();
-
- } elsif ( $cgi->param('magic') eq 'suspended' ) {
-
- push @where,
- 'susp IS NOT NULL',
- 'susp != 0',
- '( cancel IS NULL OR cancel = 0)';
-
- } elsif ( $cgi->param('magic') =~ /^cancell?ed$/ ) {
-
- push @where,
- 'cancel IS NOT NULL',
- 'cancel != 0';
-
- } else {
- die "guru meditation #420";
- }
-
if ( $cgi->param('pkgpart') =~ /^(\d+)$/ ) {
push @where, "pkgpart = $1";
}
@@ -84,21 +131,35 @@ if ( $cgi->param('magic') && $cgi->param('magic') eq 'bill' ) {
}
+##
+# setup queries, links, subs, etc. for the search
+##
+
+# here is the agent virtualization
+push @where, $FS::CurrentUser::CurrentUser->agentnums_sql;
+
my $extra_sql = scalar(@where) ? ' WHERE '. join(' AND ', @where) : '';
-my $count_query = "SELECT COUNT(*) FROM cust_pkg $cjoin $extra_sql";
+my $addl_from = 'LEFT JOIN cust_main USING ( custnum ) '.
+ 'LEFT JOIN part_pkg USING ( pkgpart ) '.
+ 'LEFT JOIN pkg_class USING ( classnum ) ';
+
+my $count_query = "SELECT COUNT(*) FROM cust_pkg $addl_from $extra_sql";
my $sql_query = {
'table' => 'cust_pkg',
'hashref' => {},
'select' => join(', ',
'cust_pkg.*',
+ ( map "part_pkg.$_", qw( pkg freq ) ),
+ 'pkg_class.classname',
'cust_main.custnum as cust_main_custnum',
- FS::UI::Web::cust_sql_fields(),
+ FS::UI::Web::cust_sql_fields(
+ $cgi->param('cust_fields')
+ ),
),
'extra_sql' => "$extra_sql $orderby",
- 'addl_from' => ' LEFT JOIN cust_main USING ( custnum ) ',
- #' LEFT JOIN part_pkg USING ( pkgpart ) '
+ 'addl_from' => $addl_from,
};
my $link = sub {
@@ -138,6 +199,10 @@ sub time_or_blank {
};
}
+###
+# and finally, include the search template
+###
+
%><%= include( 'elements/search.html',
'title' => 'Package Search Results',
'name' => 'packages',
@@ -146,6 +211,7 @@ sub time_or_blank {
#'redirect' => $link,
'header' => [ '#',
'Package',
+ 'Class',
'Status',
'Freq.',
'Setup',
@@ -154,18 +220,25 @@ sub time_or_blank {
'Susp.',
'Expire',
'Cancel',
- FS::UI::Web::cust_header(),
+ FS::UI::Web::cust_header(
+ $cgi->param('cust_fields')
+ ),
'Services',
],
'fields' => [
'pkgnum',
- sub { my $part_pkg = $part_pkg{shift->pkgpart};
- $part_pkg->pkg; # ' - '. $part_pkg->comment;
+ sub { #my $part_pkg = $part_pkg{shift->pkgpart};
+ #$part_pkg->pkg; # ' - '. $part_pkg->comment;
+ $_[0]->pkg; # ' - '. $_[0]->comment;
},
+ 'classname',
sub { ucfirst(shift->status); },
sub { #shift->part_pkg->freq_pretty;
- my $part_pkg = $part_pkg{shift->pkgpart};
- $part_pkg->freq_pretty;
+
+ #my $part_pkg = $part_pkg{shift->pkgpart};
+ #$part_pkg->freq_pretty;
+
+ FS::part_pkg::freq_pretty(shift);
},
#sub { time2str('%b %d %Y', shift->setup); },
@@ -204,6 +277,7 @@ sub time_or_blank {
'color' => [
'',
'',
+ '',
sub { shift->statuscolor; },
'',
'',
@@ -212,12 +286,16 @@ sub time_or_blank {
'',
'',
'',
- ( map { '' } FS::UI::Web::cust_header() ),
+ ( map { '' }
+ FS::UI::Web::cust_header(
+ $cgi->param('cust_fields')
+ )
+ ),
'',
],
- 'style' => [ '', '', 'b' ],
- 'size' => [ '', '', '-1', ],
- 'align' => 'rlclrrrrrr',
+ 'style' => [ '', '', '', 'b' ],
+ 'size' => [ '', '', '', '-1', ],
+ 'align' => 'rllclrrrrrr',
'links' => [
$link,
$link,
@@ -229,7 +307,12 @@ sub time_or_blank {
'',
'',
'',
- ( map { $clink } FS::UI::Web::cust_header() ),
+ '',
+ ( map { $clink }
+ FS::UI::Web::cust_header(
+ $cgi->param('cust_fields')
+ )
+ ),
'',
],
)
diff --git a/httemplate/search/cust_pkg_report.cgi b/httemplate/search/cust_pkg_report.cgi
deleted file mode 100755
index d9aada5f4..000000000
--- a/httemplate/search/cust_pkg_report.cgi
+++ /dev/null
@@ -1,22 +0,0 @@
-<%= include('/elements/header.html', 'Packages' ) %>
-
-<FORM ACTION="cust_pkg.cgi" METHOD="GET">
-<INPUT TYPE="hidden" NAME="magic" VALUE="bill">
-
-Return packages with next bill date:
-<BR><BR>
-
- <TABLE>
- <%= include( '/elements/tr-input-beginning_ending.html' ) %>
- <%= include( '/elements/tr-select-agent.html',
- $cgi->param('agentnum'),
- )
- %>
- </TABLE>
-
-<BR>
-<INPUT TYPE="submit" VALUE="Get Report">
-
-</FORM>
-
-<%= include('/elements/footer.html') %>
diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html
index 6cf574164..3e689eba1 100644
--- a/httemplate/search/elements/search.html
+++ b/httemplate/search/elements/search.html
@@ -380,8 +380,7 @@
my $tableref = $_;
- '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0'.
- ' STYLE="border:none">'.
+ '<TABLE CLASS="inv" CELLSPACING=0 CELLPADDING=0>'.
join('', map {
@@ -393,7 +392,7 @@
my $element = $_;
- '<TD STYLE="border:none"'.
+ '<TD'.
( $element->{'align'}
? ' ALIGN="'. $element->{'align'}. '"'
: ''
@@ -432,6 +431,8 @@
) {
+ my $class = ( $field =~ /^<TABLE/i ) ? 'inv' : 'grid';
+
my $align = $aligns ? shift @$aligns : '';
$align = " ALIGN=$align" if $align;
@@ -471,7 +472,7 @@
}
%>
- <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>"<%= $align %>><%= $font %><%= $a %><%= $s %><%= $field %><%= $es %><%= $a ? '</A>' : '' %><%= $font ? '</FONT>' : '' %></TD>
+ <TD CLASS="<%= $class %>" BGCOLOR="<%= $bgcolor %>"<%= $align %>><%= $font %><%= $a %><%= $s %><%= $field %><%= $es %><%= $a ? '</A>' : '' %><%= $font ? '</FONT>' : '' %></TD>
<% } %>
<% } else { %>
<% foreach ( @$row ) { %>
diff --git a/httemplate/search/inventory_item.html b/httemplate/search/inventory_item.html
index bd74f5619..7049c8841 100644
--- a/httemplate/search/inventory_item.html
+++ b/httemplate/search/inventory_item.html
@@ -24,7 +24,30 @@ if ( $cgi->param('avail') ) {
my $count_query =
"SELECT COUNT(*) FROM inventory_item WHERE classnum = $classnum $extra_sql";
+my $link = sub {
+ my $inventory_item = shift;
+ if ( $inventory_item->svcnum ) {
+ [ "${p}view/svc_acct.cgi?", 'svcnum' ];
+ } else {
+ '';
+ }
+};
+my $link_cust = sub {
+ my $inventory_item = shift;
+ if ( $inventory_item->custnum ) {
+ [ "${p}view/cust_main.cgi?", 'custnum' ];
+ } else {
+ '';
+ }
+};
+
+my $addl_from = ' LEFT JOIN cust_svc USING ( svcnum ) '.
+ ' LEFT JOIN part_svc USING ( svcpart ) '.
+ ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
+ ' LEFT JOIN cust_main USING ( custnum ) ';
+
%><%= include( 'elements/search.html',
+
'title' => $title,
#less lame to use Lingua:: something to pluralize
@@ -33,19 +56,52 @@ my $count_query =
'query' => {
'table' => 'inventory_item',
'hashref' => { 'classnum' => $classnum },
+ 'select' => join(', ',
+ 'inventory_item.*',
+ 'cust_main.custnum',
+ FS::UI::Web::cust_sql_fields(),
+ ),
'extra_sql' => $extra_sql,
+ 'addl_from' => $addl_from,
},
'count_query' => $count_query,
- # XXX proper full service/customer link ala svc_acct
- 'header' => [ '#', $inventory_class->classname, 'svcnum' ],
+ 'header' => [
+ '#',
+ $inventory_class->classname,
+ 'Service',
+ FS::UI::Web::cust_header(),
+ ],
'fields' => [
'itemnum',
'item',
- 'svcnum', #XXX proper full service customer link ala svc_acct
+ #'svcnum', #XXX proper full service customer link ala svc_acct
# "unallocated" ? "available" ?
+ sub {
+ #this could be way more efficient with a mixin
+ # like cust_main_Mixin that let us all all the methods
+ # on data we already have...
+ my $inventory_item = shift;
+ my $cust_svc = $inventory_item->cust_svc;
+ if ( $cust_svc ) {
+ my($label, $value) = $cust_svc->label;
+ "$label: $value";
+ } else {
+ '(available)';
+ }
+ },
+
+ \&FS::UI::Web::cust_fields,
+
+ ],
+
+ 'links' => [
+ '',
+ '',
+ $link,
+ ( map { $link_cust } FS::UI::Web::cust_header() ),
],
)
diff --git a/httemplate/search/report_cdr.html b/httemplate/search/report_cdr.html
index 924e28bd7..6febe6c4a 100644
--- a/httemplate/search/report_cdr.html
+++ b/httemplate/search/report_cdr.html
@@ -4,7 +4,7 @@
Status: <SELECT NAME="freesidestatus">
<OPTION VALUE="">(all)
<OPTION VALUE="NULL">unprocessed
- <OPTION VALUE="done"">processed
+ <OPTION VALUE="done">processed
</SELECT><BR>
<INPUT TYPE="submit" VALUE="Search Call Detail Records">
diff --git a/httemplate/search/report_cust_pkg.html b/httemplate/search/report_cust_pkg.html
new file mode 100755
index 000000000..98e91217f
--- /dev/null
+++ b/httemplate/search/report_cust_pkg.html
@@ -0,0 +1,47 @@
+<%= include('/elements/header.html', 'Package Report' ) %>
+
+<FORM ACTION="cust_pkg.cgi" METHOD="GET">
+<INPUT TYPE="hidden" NAME="magic" VALUE="bill">
+
+ <TABLE BGCOLOR="#cccccc" CELLSPACING=0>
+
+ <TR>
+ <TH BGCOLOR="#e8e8e8" COLSPAN=2 ALIGN="left"><FONT SIZE="+1">Search options</FONT></TH>
+ </TR>
+ <%= include( '/elements/tr-select-agent.html',
+ $cgi->param('agentnum'),
+ )
+ %>
+ <%= include( '/elements/tr-select-cust_pkg-status.html' ) %>
+ <%= include( '/elements/tr-select-pkg_class.html', '',
+ 'pre_options' => [ '0' => 'all' ],
+ 'empty_label' => '(empty class)',
+ )
+ %>
+ <% #include( '/elements/tr-selectmultiple-part_pkg.html' ) %>
+ <TR>
+ <TD ALIGN="right" VALIGN="center">Next bill date</TD>
+ <TD>
+ <TABLE>
+ <%= include( '/elements/tr-input-beginning_ending.html' ) %>
+ </TABLE>
+ </TD>
+ </TR>
+
+ <TR>
+ <TH BGCOLOR="#e8e8e8" COLSPAN=2>&nbsp;</TH>
+ </TR>
+
+ <TR>
+ <TH BGCOLOR="#e8e8e8" COLSPAN=2 ALIGN="left"><FONT SIZE="+1">Display options</FONT></TH>
+ </TR>
+ <%= include( '/elements/tr-select-cust-fields.html' ) %>
+
+ </TABLE>
+
+<BR>
+<INPUT TYPE="submit" VALUE="Get Report">
+
+</FORM>
+
+<%= include('/elements/footer.html') %>
diff --git a/httemplate/search/report_receivables.cgi b/httemplate/search/report_receivables.cgi
index ac94e1a5c..3052ea93c 100755
--- a/httemplate/search/report_receivables.cgi
+++ b/httemplate/search/report_receivables.cgi
@@ -62,26 +62,19 @@ END
my $owed_cols = join(',', map owed( @$_, 'cust'=>1 ), @ranges );
- my $recurring = <<END;
- '0' != ( select freq from part_pkg
- where cust_pkg.pkgpart = part_pkg.pkgpart )
-END
-
- my $packages_cols = <<END;
+ my $select_count_pkgs = FS::cust_main->select_count_pkgs_sql;
- ( select count(*) from cust_pkg
- where cust_main.custnum = cust_pkg.custnum
- and $recurring
- and ( cancel = 0 or cancel is null )
- ) as uncancelled_pkgs,
-
- ( select count(*) from cust_pkg
- where cust_main.custnum = cust_pkg.custnum
- and $recurring
- and ( cancel = 0 or cancel is null )
- and ( susp = 0 or susp is null )
- ) as active_pkgs
+ my $active_sql = FS::cust_pkg->active_sql;
+ my $inactive_sql = FS::cust_pkg->inactive_sql;
+ my $suspended_sql = FS::cust_pkg->inactive_sql;
+ my $cancelled_sql = FS::cust_pkg->inactive_sql;
+ my $packages_cols = <<END;
+ ( $select_count_pkgs ) AS num_pkgs_sql,
+ ( $select_count_pkgs AND $active_sql ) AS active_pkgs,
+ ( $select_count_pkgs AND $inactive_sql ) AS inactive_pkgs,
+ ( $select_count_pkgs AND $suspended_sql ) AS suspended_pkgs,
+ ( $select_count_pkgs AND $cancelled_sql ) AS cancelled_pkgs
END
my $where = "where ". owed(0, 0, 'cust'=>1, 'noas'=>1). " > 0";
@@ -92,6 +85,9 @@ END
$where .= " AND agentnum = '$agentnum' ";
}
+ #here is the agent virtualization
+ $where .= ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql;
+
my $count_sql = "select count(*) from cust_main $where";
my $sql_query = {
@@ -116,6 +112,27 @@ END
my $clink = [ "${p}view/cust_main.cgi?", 'custnum' ];
+ my $status_statuscol = sub {
+ #conceptual false laziness with cust_main::status...
+ my $row = shift;
+
+ my $status = 'unknown';
+ if ( $row->num_pkgs_sql == 0 ) {
+ $status = 'prospect';
+ } elsif ( $row->active_pkgs > 0 ) {
+ $status = 'active';
+ } elsif ( $row->inactive_pkgs > 0 ) {
+ $status = 'inactive';
+ } elsif ( $row->suspended_pkgs > 0 ) {
+ $status = 'suspended';
+ } elsif ( $row->cancelled_pkgs > 0 ) {
+ $status = 'cancelled'
+ }
+
+ ( ucfirst($status), $FS::cust_main::statuscolor{$status} );
+ };
+
+
%><%= include( 'elements/search.html',
'title' => 'Accounts Receivable Aging Summary',
'name' => 'customers',
@@ -153,20 +170,7 @@ END
],
'fields' => [
\&FS::UI::Web::cust_fields,
- sub {
- my $row = shift;
- my $status = 'Cancelled';
- my $statuscol = 'FF0000';
- if ( $row->uncancelled_pkgs ) {
- $status = 'Suspended';
- $statuscol = 'FF9900';
- if ( $row->active_pkgs ) {
- $status = 'Active';
- $statuscol = '00CC00';
- }
- }
- $status;
- },
+ sub { ( &{$status_statuscol}(shift) )[0] },
#sub { ucfirst(shift->status) },
sub { sprintf( $money_char.'%.2f',
shift->get('owed_0_30') ) },
@@ -199,20 +203,7 @@ END
'b', '', '', '', '', 'b', ],
'color' => [
( map '', FS::UI::Web::cust_header() ),
- sub {
- my $row = shift;
- my $status = 'Cancelled';
- my $statuscol = 'FF0000';
- if ( $row->uncancelled_pkgs ) {
- $status = 'Suspended';
- $statuscol = 'FF9900';
- if ( $row->active_pkgs ) {
- $status = 'Active';
- $statuscol = '00CC00';
- }
- }
- $statuscol;
- },
+ sub { ( &{$status_statuscol}(shift) )[1] },
#sub { shift->statuscolor; },
'',
'',
diff --git a/httemplate/search/svc_acct.cgi b/httemplate/search/svc_acct.cgi
index b14591958..0f2f3ef45 100755
--- a/httemplate/search/svc_acct.cgi
+++ b/httemplate/search/svc_acct.cgi
@@ -5,11 +5,9 @@ my $orderby = 'ORDER BY svcnum';
my($query)=$cgi->keywords;
$query ||= ''; #to avoid use of unitialized value errors
-my $cjoin = '';
my @extra_sql = ();
if ( $query =~ /^UN_(.*)$/ ) {
$query = $1;
- $cjoin = 'LEFT JOIN cust_svc USING ( svcnum )';
push @extra_sql, 'pkgnum IS NULL';
}
@@ -24,7 +22,6 @@ if ( $query eq 'svcnum' ) {
push @extra_sql, "popnum = $1";
$orderby = "ORDER BY LOWER(username)";
} elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
- $cjoin ||= 'LEFT JOIN cust_svc USING ( svcnum )';
push @extra_sql, "svcpart = $1";
$orderby = "ORDER BY uid";
#$orderby = "ORDER BY svcnum";
@@ -72,12 +69,20 @@ if ( $query eq 'svcnum' ) {
}
+my $addl_from = ' LEFT JOIN cust_svc USING ( svcnum ) '.
+ ' LEFT JOIN part_svc USING ( svcpart ) '.
+ ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
+ ' LEFT JOIN cust_main USING ( custnum ) ';
+
+#here is the agent virtualization
+push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql;
+
my $extra_sql =
scalar(@extra_sql)
? ' WHERE '. join(' AND ', @extra_sql )
: '';
-my $count_query = "SELECT COUNT(*) FROM svc_acct $cjoin $extra_sql";
+my $count_query = "SELECT COUNT(*) FROM svc_acct $addl_from $extra_sql";
#if ( keys %svc_acct ) {
# $count_query .= ' WHERE '.
# join(' AND ', map "$_ = ". dbh->quote($svc_acct{$_}),
@@ -90,14 +95,12 @@ my $sql_query = {
'hashref' => {}, # \%svc_acct,
'select' => join(', ',
'svc_acct.*',
+ 'part_svc.svc',
'cust_main.custnum',
FS::UI::Web::cust_sql_fields(),
),
'extra_sql' => "$extra_sql $orderby",
- 'addl_from' => ' LEFT JOIN cust_svc USING ( svcnum ) '.
- ' LEFT JOIN part_svc USING ( svcpart ) '.
- ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
- ' LEFT JOIN cust_main USING ( custnum ) ',
+ 'addl_from' => $addl_from,
};
my $link = [ "${p}view/svc_acct.cgi?", 'svcnum' ];
@@ -117,21 +120,21 @@ my $link_cust = sub {
'count_query' => $count_query,
'redirect' => $link,
'header' => [ '#',
+ 'Service',
'Account',
'UID',
- 'Service',
FS::UI::Web::cust_header(),
],
'fields' => [ 'svcnum',
+ 'svc',
'email',
'uid',
- 'svc',
\&FS::UI::Web::cust_fields,
],
'links' => [ $link,
$link,
$link,
- '',
+ $link,
( map { $link_cust }
FS::UI::Web::cust_header()
),
diff --git a/httemplate/search/svc_domain.cgi b/httemplate/search/svc_domain.cgi
index b02eea8bd..ecb77792f 100755
--- a/httemplate/search/svc_domain.cgi
+++ b/httemplate/search/svc_domain.cgi
@@ -6,51 +6,62 @@ my($query)=$cgi->keywords;
$query ||= ''; #to avoid use of unitialized value errors
my $orderby = 'ORDER BY svcnum';
-my $join = '';
my %svc_domain = ();
-my $extra_sql = '';
+my @extra_sql = ();
if ( $query eq 'svcnum' ) {
#$orderby = 'ORDER BY svcnum';
} elsif ( $query eq 'domain' ) {
$orderby = 'ORDER BY domain';
-} elsif ( $query eq 'UN_svcnum' ) {
+} elsif ( $query eq 'UN_svcnum' ) { #UN searches need to be acl'ed (and need to
+ #fix $agentnums_sql
#$orderby = 'ORDER BY svcnum';
- $join = 'LEFT JOIN cust_svc USING ( svcnum )';
- $extra_sql = ' WHERE pkgnum IS NULL';
-} elsif ( $query eq 'UN_domain' ) {
+ push @extra_sql, 'pkgnum IS NULL';
+} elsif ( $query eq 'UN_domain' ) { #UN searches need to be acl'ed (and need to
+ #fix $agentnums_sql
$orderby = 'ORDER BY domain';
- $join = 'LEFT JOIN cust_svc USING ( svcnum )';
- $extra_sql = ' WHERE pkgnum IS NULL';
+ push @extra_sql, 'pkgnum IS NULL';
} elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
#$orderby = 'ORDER BY svcnum';
- $join = 'LEFT JOIN cust_svc USING ( svcnum )';
- $extra_sql = " WHERE svcpart = $1";
+ push @extra_sql, "svcpart = $1";
} else {
$cgi->param('domain') =~ /^([\w\-\.]+)$/;
- $join = '';
$svc_domain{'domain'} = $1;
}
-my $count_query = "SELECT COUNT(*) FROM svc_domain $join $extra_sql";
+my $addl_from = ' LEFT JOIN cust_svc USING ( svcnum ) '.
+ ' LEFT JOIN part_svc USING ( svcpart ) '.
+ ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
+ ' LEFT JOIN cust_main USING ( custnum ) ';
+
+#here is the agent virtualization
+push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql;
+
+my $extra_sql = '';
+if ( @extra_sql ) {
+ $extra_sql = ( keys(%svc_domain) ? ' AND ' : ' WHERE ' ).
+ join(' AND ', @extra_sql );
+}
+
+my $count_query = "SELECT COUNT(*) FROM svc_domain $addl_from ";
if ( keys %svc_domain ) {
$count_query .= ' WHERE '.
join(' AND ', map "$_ = ". dbh->quote($svc_domain{$_}),
keys %svc_domain
);
}
+$count_query .= $extra_sql;
my $sql_query = {
'table' => 'svc_domain',
'hashref' => \%svc_domain,
'select' => join(', ',
'svc_domain.*',
- 'cust_main.custnum',
- FS::UI::Web::cust_sql_fields(),
+ 'part_svc.svc',
+ 'cust_main.custnum',
+ FS::UI::Web::cust_sql_fields(),
),
'extra_sql' => "$extra_sql $orderby",
- 'addl_from' => 'LEFT JOIN cust_svc USING ( svcnum ) '.
- 'LEFT JOIN cust_pkg USING ( pkgnum ) '.
- 'LEFT JOIN cust_main USING ( custnum ) ',
+ 'addl_from' => $addl_from,
};
my $link = [ "${p}view/svc_domain.cgi?", 'svcnum' ];
@@ -68,15 +79,18 @@ my $link_cust = sub {
'count_query' => $count_query,
'redirect' => $link,
'header' => [ '#',
+ 'Service',
'Domain',
FS::UI::Web::cust_header(),
],
'fields' => [ 'svcnum',
+ 'svc',
'domain',
\&FS::UI::Web::cust_fields,
],
'links' => [ $link,
$link,
+ $link,
( map { $link_cust }
FS::UI::Web::cust_header()
),
diff --git a/httemplate/search/svc_forward.cgi b/httemplate/search/svc_forward.cgi
index a204e345f..d391a1834 100755
--- a/httemplate/search/svc_forward.cgi
+++ b/httemplate/search/svc_forward.cgi
@@ -5,14 +5,12 @@ my $conf = new FS::Conf;
my($query)=$cgi->keywords;
$query ||= ''; #to avoid use of unitialized value errors
-
my $orderby;
-my $cjoin = '';
my @extra_sql = ();
-if ( $query =~ /^UN_(.*)$/ ) {
+if ( $query =~ /^UN_(.*)$/ ) { #UN searches need to be acl'ed (and need to
+ #fix $agentnums_sql
$query = $1;
- $cjoin = 'LEFT JOIN cust_svc USING ( svcnum )';
push @extra_sql, 'pkgnum IS NULL';
}
@@ -22,25 +20,31 @@ if ( $query eq 'svcnum' ) {
eidiot('unimplemented');
}
+my $addl_from = ' LEFT JOIN cust_svc USING ( svcnum ) '.
+ ' LEFT JOIN part_svc USING ( svcpart ) '.
+ ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
+ ' LEFT JOIN cust_main USING ( custnum ) ';
+
+#here is the agent virtualization
+push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql;
+
my $extra_sql =
scalar(@extra_sql)
? ' WHERE '. join(' AND ', @extra_sql )
: '';
-my $count_query = "SELECT COUNT(*) FROM svc_forward $cjoin $extra_sql";
+my $count_query = "SELECT COUNT(*) FROM svc_forward $addl_from $extra_sql";
my $sql_query = {
'table' => 'svc_forward',
'hashref' => {},
'select' => join(', ',
'svc_forward.*',
- 'cust_main.custnum',
- FS::UI::Web::cust_sql_fields(),
+ 'part_svc.svc',
+ 'cust_main.custnum',
+ FS::UI::Web::cust_sql_fields(),
),
'extra_sql' => "$extra_sql $orderby",
- 'addl_from' => ' LEFT JOIN cust_svc USING ( svcnum ) '.
- ' LEFT JOIN part_svc USING ( svcpart ) '.
- ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
- ' LEFT JOIN cust_main USING ( custnum ) ',
+ 'addl_from' => $addl_from,
};
# <TH>Service #<BR><FONT SIZE=-1>(click to view forward)</FONT></TH>
@@ -100,16 +104,19 @@ my $link_cust = sub {
'count_query' => $count_query,
'redirect' => $link,
'header' => [ '#',
+ 'Service',
'Mail to',
'Forwards to',
FS::UI::Web::cust_header(),
],
'fields' => [ 'svcnum',
+ 'svc',
$format_src,
$format_dst,
\&FS::UI::Web::cust_fields,
],
'links' => [ $link,
+ $link,
$link_src,
$link_dst,
( map { $link_cust }
diff --git a/httemplate/search/svc_phone.cgi b/httemplate/search/svc_phone.cgi
new file mode 100644
index 000000000..a68a13e39
--- /dev/null
+++ b/httemplate/search/svc_phone.cgi
@@ -0,0 +1,94 @@
+<%
+
+my $conf = new FS::Conf;
+
+my($query)=$cgi->keywords;
+$query ||= ''; #to avoid use of unitialized value errors
+
+my $orderby = 'ORDER BY svcnum';
+my %svc_phone = ();
+my @extra_sql = ();
+if ( $query eq 'svcnum' ) {
+ #$orderby = 'ORDER BY svcnum';
+} elsif ( $query eq 'phonenum' ) {
+ $orderby = 'ORDER BY phonenum';
+} elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) {
+ #$orderby = 'ORDER BY svcnum';
+ push @extra_sql, "svcpart = $1";
+} else {
+ $cgi->param('phonenum') =~ /^([\d\- ]+)$/;
+ ( $svc_phone{'phonenum'} = $1 ) =~ s/\D//g;
+}
+
+my $addl_from = ' LEFT JOIN cust_svc USING ( svcnum ) '.
+ ' LEFT JOIN part_svc USING ( svcpart ) '.
+ ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
+ ' LEFT JOIN cust_main USING ( custnum ) ';
+
+#here is the agent virtualization
+push @extra_sql, $FS::CurrentUser::CurrentUser->agentnums_sql;
+
+my $extra_sql = '';
+if ( @extra_sql ) {
+ $extra_sql = ( keys(%svc_phone) ? ' AND ' : ' WHERE ' ).
+ join(' AND ', @extra_sql );
+}
+
+my $count_query = "SELECT COUNT(*) FROM svc_phone $addl_from ";
+if ( keys %svc_phone ) {
+ $count_query .= ' WHERE '.
+ join(' AND ', map "$_ = ". dbh->quote($svc_phone{$_}),
+ keys %svc_phone
+ );
+}
+$count_query .= $extra_sql;
+
+my $sql_query = {
+ 'table' => 'svc_phone',
+ 'hashref' => \%svc_phone,
+ 'select' => join(', ',
+ 'svc_phone.*',
+ 'part_svc.svc',
+ 'cust_main.custnum',
+ FS::UI::Web::cust_sql_fields(),
+ ),
+ 'extra_sql' => "$extra_sql $orderby",
+ 'addl_from' => $addl_from,
+};
+
+my $link = [ "${p}view/svc_phone.cgi?", 'svcnum' ];
+
+#smaller false laziness w/svc_*.cgi here
+my $link_cust = sub {
+ my $svc_x = shift;
+ $svc_x->custnum ? [ "${p}view/cust_main.cgi?", 'custnum' ] : '';
+};
+
+%><%= include( 'elements/search.html',
+ 'title' => "Phone number search results",
+ 'name' => 'phone numbers',
+ 'query' => $sql_query,
+ 'count_query' => $count_query,
+ 'redirect' => $link,
+ 'header' => [ '#',
+ 'Service',
+ 'Country code',
+ 'Phone number',
+ FS::UI::Web::cust_header(),
+ ],
+ 'fields' => [ 'svcnum',
+ 'svc',
+ 'countrycode',
+ 'phonenum',
+ \&FS::UI::Web::cust_fields,
+ ],
+ 'links' => [ $link,
+ $link,
+ $link,
+ $link,
+ ( map { $link_cust }
+ FS::UI::Web::cust_header()
+ ),
+ ],
+ )
+%>
diff --git a/httemplate/search/svc_www.cgi b/httemplate/search/svc_www.cgi
index ae51c61fc..ef4045cf9 100755
--- a/httemplate/search/svc_www.cgi
+++ b/httemplate/search/svc_www.cgi
@@ -17,6 +17,7 @@ my $sql_query = {
'hashref' => {},
'select' => join(', ',
'svc_www.*',
+ 'part_svc.svc',
'cust_main.custnum',
FS::UI::Web::cust_sql_fields(),
),
@@ -43,11 +44,13 @@ my $link_cust = sub {
'count_query' => $count_query,
'redirect' => $link,
'header' => [ '#',
+ 'Service',
'Zone',
'User',
FS::UI::Web::cust_header(),
],
'fields' => [ 'svcnum',
+ 'svc',
sub { $_[0]->domain_record->zone },
sub {
my $svc_www = shift;
@@ -59,6 +62,7 @@ my $link_cust = sub {
\&FS::UI::Web::cust_fields,
],
'links' => [ $link,
+ $link,
'',
$ulink,
( map { $link_cust }