[freeside-commits] branch FREESIDE_2_3_BRANCH updated. cab5ea90e9e5516540b09803325bd2f447c52086

Ivan ivan at 420.am
Tue Aug 21 18:45:22 PDT 2012


The branch, FREESIDE_2_3_BRANCH has been updated
       via  cab5ea90e9e5516540b09803325bd2f447c52086 (commit)
      from  864d4c0a473856c9d9dcb81d60297476c6a25a03 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit cab5ea90e9e5516540b09803325bd2f447c52086
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Tue Aug 21 18:45:17 2012 -0700

    add agent email, RT#18231

diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index e441a74..6a151aa 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -5138,6 +5138,13 @@ and customer address. Include units.',
     ],
   },
 
+  {
+    'key'         => 'agent-email_day',
+    'section'     => '',
+    'description' => 'On this day of each month, agents with master customer records containing email addresses will be emailed a list of their customers and balances.',
+    'type'        => 'text',
+  },
+
   { key => "apacheroot", section => "deprecated", description => "<b>DEPRECATED</b>", type => "text" },
   { key => "apachemachine", section => "deprecated", description => "<b>DEPRECATED</b>", type => "text" },
   { key => "apachemachines", section => "deprecated", description => "<b>DEPRECATED</b>", type => "text" },
diff --git a/FS/FS/Cron/agent_email.pm b/FS/FS/Cron/agent_email.pm
new file mode 100644
index 0000000..f3fb945
--- /dev/null
+++ b/FS/FS/Cron/agent_email.pm
@@ -0,0 +1,79 @@
+package FS::Cron::agent_email;
+use base qw( Exporter );
+
+use strict;
+use vars qw( @EXPORT_OK $DEBUG );
+use Date::Simple qw(today);
+use URI::Escape;
+use FS::Mason qw( mason_interps );
+use FS::Conf;
+use FS::Misc qw(send_email);
+use FS::Record qw(qsearch);# qsearchs);
+use FS::agent;
+
+ at EXPORT_OK = qw ( agent_email );
+$DEBUG = 1;
+
+sub agent_email {
+  my %opt = @_;
+
+  my $conf = new FS::Conf;
+
+  my $day = $conf->config('agent-email_day') or return;
+  return unless $day == today->day;
+
+  if ( 1 ) { #XXX if ( %%%RT_ENABLED%%% ) {
+    require RT;
+    RT::LoadConfig();
+    RT::Init();
+    RT::ConnectToDatabase();
+  }
+
+  my $from = $conf->config('invoice_from');
+
+  my $outbuf = '';;
+  my( $fs_interp, $rt_interp ) = mason_interps('standalone', 'outbuf'=>\$outbuf);
+
+  my $comp = '/search/cust_main.html';
+  my %args = (
+    'cust_fields' => 'Cust# | Cust. Status | Customer | Current Balance',
+    '_type'       => 'html-print',
+  );
+  my $query = join('&', map "$_=".uri_escape($args{$_}), keys %args );
+
+  my $extra_sql = $opt{a} ? " AND agentnum IN ( $opt{a} ) " : '';
+
+  foreach my $agent ( qsearch({
+                        'table'     => 'agent',
+                        'hashref'   => {
+                          'disabled'      => '',
+                          'agent_custnum' => { op=>'!=', value=>'' },
+                        },
+                        'extra_sql' => $extra_sql,
+                      })
+                    )
+  {
+
+    $FS::Mason::Request::QUERY_STRING = $query. '&agentnum='. $agent->agentnum;
+    $fs_interp->exec($comp);
+
+    my @email = $agent->agent_cust_main->invoicing_list or next;
+
+    warn "emailing ". join(',', at email). " for agent ". $agent->agent. "\n"
+      if $DEBUG;
+    send_email(
+      'from'         => $from,
+      'to'           => \@email,
+      'subject'      => 'Customer report',
+      'body'         => $outbuf,
+      'content-type' => 'text/html',
+      #'content-encoding'
+    ); 
+
+    $outbuf = '';
+
+  }
+
+}
+
+1;
diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily
index b73d0b1..0efe2ad 100755
--- a/FS/bin/freeside-daily
+++ b/FS/bin/freeside-daily
@@ -7,7 +7,7 @@ use FS::Conf;
 
 &untaint_argv;	#what it sounds like  (eww)
 use vars qw(%opt);
-getopts("p:a:d:vl:sy:nmrkg:uo", \%opt);
+getopts("p:a:d:vl:sy:nmrkg:o", \%opt);
 
 my $user = shift or die &usage;
 adminsuidsetup $user;
@@ -51,25 +51,24 @@ unless ( $opt{k} ) {
   notify_flat_delay(%opt);
 }
 
-#debian Pg 8.1+ auto-vaccums, 7.4 w/postgresql-contrib
-if ( $opt{u} ) {
-  use FS::Cron::vacuum qw(vacuum);
-  vacuum();
-}
-
-#you can skip this just by not having the config
-use FS::Cron::backup qw(backup);
-backup();
-
 #same
 use FS::Cron::rt_tasks qw(rt_daily);
 rt_daily(%opt);
 
+#you can skip this by not having the config
+use FS::Cron::agent_email qw(agent_email);
+agent_email(%opt);
+
 my $deldir = "$FS::UID::cache_dir/cache.$FS::UID::datasrc/";
 unlink <${deldir}.invoice*>;
 unlink <${deldir}.letter*>;
 unlink <${deldir}.CGItemp*>;
 
+#backup should be last
+#you can skip this just by not having the config
+use FS::Cron::backup qw(backup);
+backup();
+
 ###
 # subroutines
 ###
@@ -140,8 +139,6 @@ the bill and collect methods of a cust_main object.  See L<FS::cust_main>.
 
   -k: skip notify_flat_delay
 
-  -u: Do a vacuum (starting with version 1.9, this is not run by default).
-
 user: From the mapsecrets file - see config.html from the base documentation
 
 custnum: if one or more customer numbers are specified, only bills those
diff --git a/bin/agent_email b/bin/agent_email
new file mode 100755
index 0000000..2fe47c4
--- /dev/null
+++ b/bin/agent_email
@@ -0,0 +1,30 @@
+#!/usr/bin/perl
+
+use strict;
+use Getopt::Std;
+use FS::UID qw(adminsuidsetup);
+
+&untaint_argv;	#what it sounds like  (eww)
+use vars qw(%opt);
+getopts("a:", \%opt);
+
+my $user = shift or die &usage;
+adminsuidsetup $user;
+
+use FS::Cron::agent_email qw(agent_email);
+agent_email(%opt);
+
+###
+# subroutines
+###
+
+sub untaint_argv {
+  foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
+    #$ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
+    # Date::Parse
+    $ARGV[$_] =~ /^(.*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
+    $ARGV[$_]=$1;
+  }
+}
+
+1;

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Conf.pm             |    7 ++++
 FS/FS/Cron/agent_email.pm |   79 +++++++++++++++++++++++++++++++++++++++++++++
 FS/bin/freeside-daily     |   23 ++++++-------
 bin/agent_email           |   30 +++++++++++++++++
 4 files changed, 126 insertions(+), 13 deletions(-)
 create mode 100644 FS/FS/Cron/agent_email.pm
 create mode 100755 bin/agent_email




More information about the freeside-commits mailing list