freeside/FS/FS agent.pm,1.6,1.7 cust_main.pm,1.154,1.155 CGI.pm,1.25,1.26

ivan ivan at pouncequick.420.am
Thu Jun 10 05:31:36 PDT 2004


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory pouncequick:/tmp/cvs-serv23020/FS/FS

Modified Files:
	agent.pm cust_main.pm CGI.pm 
Log Message:
agent interface

Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.154
retrieving revision 1.155
diff -u -d -r1.154 -r1.155
--- cust_main.pm	14 May 2004 12:25:44 -0000	1.154
+++ cust_main.pm	10 Jun 2004 12:31:31 -0000	1.155
@@ -2538,6 +2538,136 @@
   qsearch('cust_main', { 'custnum' => $self->custnum }, '*', 'FOR UPDATE' );
 }
 
+=item name
+
+Returns a name string for this customer, either "Company (Last, First)" or
+"Last, First".
+
+=cut
+
+sub name {
+  my $self = shift;
+  my $name = $self->get('last'). ', '. $self->first;
+  $name = $self->company. " ($name)" if $self->company;
+  $name;
+}
+
+=item status
+
+Returns a status string for this customer, currently:
+
+=over 4
+
+=item prospect - No packages have ever been ordered
+
+=item active - One or more recurring packages is active
+
+=item suspended - All non-cancelled recurring packages are suspended
+
+=item cancelled - All recurring packages are cancelled
+
+=back
+
+=cut
+
+sub status {
+  my $self = shift;
+  for my $status (qw( prospect active suspended cancelled )) {
+    my $method = $status.'_sql';
+    my $numnum = ( my $sql = $self->$method() ) =~ s/cust_main\.custnum/?/g;
+    my $sth = dbh->prepare("SELECT $sql") or die dbh->errstr;
+    $sth->execute( ($self->custnum) x $numnum ) or die $sth->errstr;
+    return $status if $sth->fetchrow_arrayref->[0];
+  }
+}
+
+=item statuscolor
+
+Returns a hex triplet color string for this customer's status.
+
+=cut
+
+my %statuscolor = (
+  'prospect'  => '000000',
+  'active'    => '00CC00',
+  'suspended' => 'FF9900',
+  'cancelled' => 'FF0000',
+);
+sub statuscolor {
+  my $self = shift;
+  $statuscolor{$self->status};
+}
+
+=back
+
+=head1 CLASS METHODS
+
+=over 4
+
+=item prospect_sql
+
+Returns an SQL expression identifying prospective cust_main records (customers
+with no packages ever ordered)
+
+=cut
+
+sub prospect_sql { "
+  0 = ( SELECT COUNT(*) FROM cust_pkg
+          WHERE cust_pkg.custnum = cust_main.custnum
+      )
+"; }
+
+=item active_sql
+
+Returns an SQL expression identifying active cust_main records.
+
+=cut
+
+sub active_sql { "
+  0 < ( SELECT COUNT(*) FROM cust_pkg
+          WHERE cust_pkg.custnum = cust_main.custnum
+            AND ( cust_pkg.cancel IS NULL OR cust_pkg.cancel = 0 )
+            AND ( cust_pkg.susp   IS NULL OR cust_pkg.susp   = 0 )
+      )
+"; }
+
+=item susp_sql
+=item suspended_sql
+
+Returns an SQL expression identifying suspended cust_main records.
+
+=cut
+
+sub suspended_sql { susp_sql(@_); }
+sub susp_sql { "
+    0 < ( SELECT COUNT(*) FROM cust_pkg
+            WHERE cust_pkg.custnum = cust_main.custnum
+              AND ( cust_pkg.cancel IS NULL OR cust_pkg.cancel = 0 )
+        )
+    AND 0 = ( SELECT COUNT(*) FROM cust_pkg
+                WHERE cust_pkg.custnum = cust_main.custnum
+                  AND ( cust_pkg.susp IS NULL OR cust_pkg.susp = 0 )
+            )
+"; }
+
+=item cancel_sql
+=item cancelled_sql
+
+Returns an SQL expression identifying cancelled cust_main records.
+
+=cut
+
+sub cancelled_sql { cancel_sql(@_); }
+sub cancel_sql { "
+  0 < ( SELECT COUNT(*) FROM cust_pkg
+          WHERE cust_pkg.custnum = cust_main.custnum
+      )
+  AND 0 = ( SELECT COUNT(*) FROM cust_pkg
+              WHERE cust_pkg.custnum = cust_main.custnum
+                AND ( cust_pkg.cancel IS NULL OR cust_pkg.cancel = 0 )
+          )
+"; }
+
 =back
 
 =head1 SUBROUTINES

Index: CGI.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/CGI.pm,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- CGI.pm	22 Mar 2004 19:03:03 -0000	1.25
+++ CGI.pm	10 Jun 2004 12:31:31 -0000	1.26
@@ -294,6 +294,8 @@
     or die "unknown custnum $arg";
 
   my $html = 'Customer #<B>'. $cust_main->custnum. '</B>'.
+    ' - <B><FONT COLOR="'. $cust_main->statuscolor. '">'.
+    ucfirst($cust_main->status). '</FONT></B>'.
     ntable('#e8e8e8'). '<TR><TD>'. ntable("#cccccc",2).
     '<TR><TD ALIGN="right" VALIGN="top">Billing<BR>Address</TD><TD BGCOLOR="#ffffff">'.
     $cust_main->getfield('last'). ', '. $cust_main->first. '<BR>';
@@ -305,6 +307,20 @@
   $html .= $cust_main->country. '<BR>'
     if $cust_main->country && $cust_main->country ne $countrydefault;
 
+  $html .= '</TD></TR><TR><TD></TD><TD BGCOLOR="#ffffff">';
+  if ( $cust_main->daytime && $cust_main->night ) {
+    use FS::Msgcat;
+    $html .= ( FS::Msgcat::_gettext('daytime') || 'Day' ).
+             ' '. $cust_main->daytime.
+             '<BR>'. ( FS::Msgcat::_gettext('night') || 'Night' ).
+             ' '. $cust_main->night;
+  } elsif ( $cust_main->daytime || $cust_main->night ) {
+    $html .= $cust_main->daytime || $cust_main->night;
+  }
+  if ( $cust_main->fax ) {
+    $html .= '<BR>Fax '. $cust_main->fax;
+  }
+
   $html .= '</TD></TR></TABLE></TD>';
 
   if ( defined $cust_main->dbdef_table->column('ship_last') ) {
@@ -326,6 +342,23 @@
     $html .= $cust_main->get("${pre}country"). '<BR>'
       if $cust_main->get("${pre}country")
          && $cust_main->get("${pre}country") ne $countrydefault;
+
+    $html .= '</TD></TR><TR><TD></TD><TD BGCOLOR="#ffffff">';
+
+    if ( $cust_main->get("${pre}daytime") && $cust_main->get("${pre}night") ) {
+      use FS::Msgcat;
+      $html .= ( FS::Msgcat::_gettext('daytime') || 'Day' ).
+               ' '. $cust_main->get("${pre}daytime").
+               '<BR>'. ( FS::Msgcat::_gettext('night') || 'Night' ).
+               ' '. $cust_main->get("${pre}night");
+    } elsif ( $cust_main->get("${pre}daytime")
+              || $cust_main->get("${pre}night") ) {
+      $html .= $cust_main->get("${pre}daytime")
+               || $cust_main->get("${pre}night");
+    }
+    if ( $cust_main->get("${pre}fax") ) {
+      $html .= '<BR>Fax '. $cust_main->get("${pre}fax");
+    }
 
     $html .= '</TD></TR></TABLE></TD>';
   }

Index: agent.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/agent.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- agent.pm	30 Sep 2003 15:01:46 -0000	1.6
+++ agent.pm	10 Jun 2004 12:31:31 -0000	1.7
@@ -2,7 +2,7 @@
 
 use strict;
 use vars qw( @ISA );
-use FS::Record qw( qsearch qsearchs );
+use FS::Record qw( dbh qsearch qsearchs );
 use FS::cust_main;
 use FS::agent_type;
 
@@ -164,11 +164,107 @@
   $self->agent_type->pkgpart_hashref;
 }
 
-=back
+=item num_prospect_cust_main
 
-=head1 VERSION
+Returns the number of prospects (customers with no packages ever ordered) for
+this agent.
 
-$Id$
+=cut
+
+sub num_prospect_cust_main {
+  shift->num_sql(FS::cust_main->prospect_sql);
+}
+
+sub num_sql {
+  my( $self, $sql ) = @_;
+  my $sth = dbh->prepare(
+    "SELECT COUNT(*) FROM cust_main WHERE agentnum = ? AND $sql"
+  ) or die dbh->errstr;
+  $sth->execute($self->agentnum) or die $sth->errstr;
+  $sth->fetchrow_arrayref->[0];
+}
+
+=item prospect_cust_main
+
+Returns the prospects (customers with no packages ever ordered) for this agent,
+as cust_main objects.
+
+=cut
+
+sub prospect_cust_main {
+  shift->cust_main_sql(FS::cust_main->prospect_sql);
+}
+
+sub cust_main_sql {
+  my( $self, $sql ) = @_;
+  qsearch( 'cust_main',
+           { 'agentnum' => $self->agentnum },
+           '',
+           " AND $sql"
+  );
+}
+
+=item num_active_cust_main
+
+Returns the number of active customers for this agent.
+
+=cut
+
+sub num_active_cust_main {
+  shift->num_sql(FS::cust_main->active_sql);
+}
+
+=item active_cust_main
+
+Returns the active customers for this agent, as cust_main objects.
+
+=cut
+
+sub active_cust_main {
+  shift->cust_main_sql(FS::cust_main->active_sql);
+}
+
+=item num_susp_cust_main
+
+Returns the number of suspended customers for this agent.
+
+=cut
+
+sub num_susp_cust_main {
+  shift->num_sql(FS::cust_main->susp_sql);
+}
+
+=item susp_cust_main
+
+Returns the suspended customers for this agent, as cust_main objects.
+
+=cut
+
+sub susp_cust_main {
+  shift->cust_main_sql(FS::cust_main->susp_sql);
+}
+
+=item num_cancel_cust_main
+
+Returns the number of cancelled customer for this agent.
+
+=cut
+
+sub num_cancel_cust_main {
+  shift->num_sql(FS::cust_main->cancel_sql);
+}
+
+=item cancel_cust_main
+
+Returns the cancelled customers for this agent, as cust_main objects.
+
+=cut
+
+sub cancel_cust_main {
+  shift->cust_main_sql(FS::cust_main->cancel_sql);
+}
+
+=back
 
 =head1 BUGS
 




More information about the freeside-commits mailing list