& elements/search.html,
'title' => emt('Voided Invoice Search Results'),
'name' => 'voided invoices',
'query' => $sql_query,
'count_query' => $count_query,
'count_addl' => $count_addl,
'redirect' => $link,
'header' => [ emt('Invoice #'),
emt('Amount'),
emt('Date'),
FS::UI::Web::cust_header(),
emt('Voided by'),
emt('Date'),
emt('Reason'),
],
'fields' => [
'display_invnum',
sub { sprintf($money_char.'%.2f', shift->charged ) },
sub { time2str('%b %d %Y', shift->_date ) },
\&FS::UI::Web::cust_fields,
'username',
sub { time2str('%b %d %Y', shift->void_date) },
'reason',
],
'sort_fields' => [
'COALESCE( agent_invid, invnum )',
'charged',
'_date',
FS::UI::Web::cust_sort_fields(),
'username',
'void_date',
'reason',
],
'align' => 'rrl'.FS::UI::Web::cust_aligns().'lll',
'links' => [
$link,
$link,
$link,
( map { $_ ne 'Cust. Status' ? $clink : '' }
FS::UI::Web::cust_header()
),
$link,
$link,
],
'color' => [
'',
'',
'',
FS::UI::Web::cust_colors(),
],
'style' => [
'',
'',
'',
FS::UI::Web::cust_styles(),
],
&>
<%init>
die "access denied"
unless $FS::CurrentUser::CurrentUser->access_right('List invoices');
# or something else?
my $conf = new FS::Conf;
my $money_char = $conf->config('money_char') || '$';
my $addl_from =
' LEFT JOIN access_user ON (cust_bill_void.void_usernum = access_user.usernum) '.
FS::UI::Web::join_cust_main('cust_bill_void');
#here is the agent virtualization
my $agentnums_sql = $FS::CurrentUser::CurrentUser->agentnums_sql;
my( $count_query, $sql_query );
my $count_addl = '';
my %search;
if ( $cgi->param('invnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) {
my $invnum_or_invid = "( invnum = $2 OR agent_invid = $2 )";
my $where = "WHERE $invnum_or_invid AND $agentnums_sql";
$count_query = "SELECT COUNT(*) FROM cust_bill_void $addl_from $where";
$sql_query = {
'table' => 'cust_bill_void',
'addl_from' => $addl_from,
'hashref' => {},
'extra_sql' => $where,
};
} else {
#some false laziness w/cust_bill::re_X
my $orderby = 'ORDER BY cust_bill_void._date';
if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
$search{'agentnum'} = $1;
}
if ( $cgi->param('refnum') =~ /^(\d+)$/ ) {
$search{'refnum'} = $1;
}
if ( grep { $_ eq 'cust_classnum' } $cgi->param ) {
$search{'cust_classnum'} = [ $cgi->param('cust_classnum') ];
}
if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
$search{'custnum'} = $1;
}
# begin/end/beginning/ending
my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
$search{'_date'} = [ $beginning, $ending ]
unless $beginning == 0 && $ending == 4294967295;
($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, 'void_');
$search{'void_date'} = [ $beginning, $ending ]
unless $beginning == 0 && $ending == 4294967295;
if ( $cgi->param('invnum_min') =~ /^\s*(\d+)\s*$/ ) {
$search{'invnum_min'} = $1;
}
if ( $cgi->param('invnum_max') =~ /^\s*(\d+)\s*$/ ) {
$search{'invnum_max'} = $1;
}
#payby
if ( $cgi->param('payby') ) {
$search{'payby'} = [ $cgi->param('payby') ];
}
#amounts
$search{'charged'} = [ FS::UI::Web::parse_lt_gt($cgi, 'charged') ];
my $extra_sql = FS::cust_bill_void->search_sql_where( \%search );
$extra_sql = "WHERE $extra_sql" if $extra_sql;
unless ( $count_query ) {
$count_query = 'SELECT COUNT(*), SUM(charged)';
$count_addl = [ $money_char . '%.2f voided' ];
}
$count_query .= " FROM cust_bill_void $addl_from $extra_sql";
$sql_query = {
'table' => 'cust_bill_void',
'addl_from' => $addl_from,
'hashref' => {},
'select' => join(', ',
'cust_bill_void.*',
#( map "cust_main.$_", qw(custnum last first company) ),
'cust_main.custnum as cust_main_custnum',
FS::UI::Web::cust_sql_fields(),
'access_user.username',
),
'extra_sql' => $extra_sql,
'order_by' => $orderby,
};
}
my $link = [ "${p}view/cust_bill_void.html?", 'invnum', ];
my $clink = sub {
my $cust_bill = shift;
$cust_bill->cust_main_custnum
? [ "${p}view/cust_main.cgi?", 'custnum' ]
: '';
};
# really don't want the ability to print/spool/email voided invoices
%init>