1 package FS::Cron::agent_email;
2 use base qw( Exporter );
5 use vars qw( @EXPORT_OK $DEBUG );
6 use Date::Simple qw(today);
8 use FS::Mason qw( mason_interps );
10 use FS::Misc qw(send_email);
11 use FS::Record qw(qsearch);# qsearchs);
14 @EXPORT_OK = qw ( agent_email );
20 my $conf = new FS::Conf;
22 my $day = $conf->config('agent-email_day') or return;
23 return unless $day == today->day;
25 if ( 1 ) { #XXX if ( %%%RT_ENABLED%%% ) {
29 RT::ConnectToDatabase();
32 my $from = $conf->config('invoice_from');
35 my( $fs_interp, $rt_interp ) = mason_interps('standalone', 'outbuf'=>\$outbuf);
37 my $comp = '/search/cust_main.html';
39 'cust_fields' => 'Cust# | Cust. Status | Customer | Current Balance',
40 '_type' => 'html-print',
42 my $query = join('&', map "$_=".uri_escape($args{$_}), keys %args );
44 my $extra_sql = $opt{a} ? " AND agentnum IN ( $opt{a} ) " : '';
46 foreach my $agent ( qsearch({
50 'agent_custnum' => { op=>'!=', value=>'' },
52 'extra_sql' => $extra_sql,
57 $FS::Mason::Request::QUERY_STRING = $query. '&agentnum='. $agent->agentnum;
58 $fs_interp->exec($comp);
60 my @email = $agent->agent_cust_main->invoicing_list or next;
62 warn "emailing ". join(',',@email). " for agent ". $agent->agent. "\n"
67 'subject' => 'Customer report',
69 'content-type' => 'text/html',