Merge branch 'patch-19' of https://github.com/gjones2/Freeside
[freeside.git] / httemplate / misc / xmlhttp-cust_main-email_search.html
1 <% encode_json(\@result) %>\
2 <%init>
3 die 'access denied'
4   unless $FS::CurrentUser::CurrentUser->access_right('Edit customer');
5
6 my $sub = $cgi->param('sub');
7 my $email = $cgi->param('arg');
8 my @where = (
9   "cust_main_invoice.dest != 'POST'",
10   "cust_main_invoice.dest LIKE ".dbh->quote('%'.$email.'%'),
11   $FS::CurrentUser::CurrentUser->agentnums_sql(table => 'cust_main'),
12 );
13 my @cust_main = qsearch({
14   'table'     => 'cust_main',
15   'select'    => 'cust_main.*, cust_main_invoice.dest',
16   'addl_from' => 'JOIN cust_main_invoice USING (custnum)',
17   'extra_sql' => 'WHERE '.join(' AND ', @where),
18 });
19
20 my @result = map {
21   [ $_->custnum,
22     $_->name,
23     $_->dest,
24     $_->invoice_noemail,
25     $_->message_noemail,
26   ]
27 } @cust_main;
28
29 </%init>