[freeside-commits] branch master updated. 5ef5203cb6da8e0a8e1f60228b9a9250605f404e

Ivan ivan at 420.am
Sat Aug 30 17:56:08 PDT 2014


The branch, master has been updated
       via  5ef5203cb6da8e0a8e1f60228b9a9250605f404e (commit)
       via  4064388ed4466966a281e7db86a374cabe22ae8c (commit)
      from  1dbab258aed2f501761d69a2afcdf6b977721dfe (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 5ef5203cb6da8e0a8e1f60228b9a9250605f404e
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Sat Aug 30 15:02:36 2014 -0700

    doc

diff --git a/FS/FS/sales.pm b/FS/FS/sales.pm
index f1b406d..d262051 100644
--- a/FS/FS/sales.pm
+++ b/FS/FS/sales.pm
@@ -38,14 +38,21 @@ FS::Record.  The following fields are currently supported:
 
 primary key
 
+=item salesperson
+
+Name
+
 =item agentnum
 
-agentnum
+Agent (see L<FS::agent)
 
 =item disabled
 
-disabled
+Disabled flag, empty or `Y'
+
+=item sales_custnum
 
+Sales person master customer (see L<FS::cust_main>)
 
 =back
 

commit 4064388ed4466966a281e7db86a374cabe22ae8c
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Sat Aug 30 15:01:08 2014 -0700

    convert sales persons to agents, R#30315

diff --git a/bin/sales2agent b/bin/sales2agent
new file mode 100644
index 0000000..e3e122a
--- /dev/null
+++ b/bin/sales2agent
@@ -0,0 +1,75 @@
+#!/usr/bin/perl
+
+use FS::UID qw(adminsuidsetup dbh);
+use FS::Record qw(qsearch);
+use FS::sales;
+use FS::agent;
+use FS::access_group;
+use FS::access_groupagent;
+use FS::cust_main;
+
+adminsuidsetup shift or die &usage;
+
+$FS::UID::AutoCommit = 0;
+
+my @sales = qsearch('sales', {'disabled'=>''});
+
+foreach my $sales (@sales) {
+
+  my $agent = new FS::agent {
+    'agent'         => $sales->salesperson,
+    'agent_custnum' => $sales->sales_custnum,
+  };
+  my $error = $agent->insert;
+  if ( $error ) {
+    dbh->rollback or die dbh->errstr;
+    die $error;
+  }
+
+  my $access_group = new FS::access_group {
+    'groupname' => $agent->agent,
+  };
+  $error = $access_group->insert;
+  if ( $error ) {
+    dbh->rollback or die dbh->errstr;
+    die $error;
+  }
+
+  my $access_groupagent = new FS::access_groupagent {
+    'groupnum' => $access_group->groupnum,
+    'agentnum' => $agent->agentnum,
+  };
+  $error = $access_groupagent->insert;
+  if ( $error ) {
+    dbh->rollback or die dbh->errstr;
+    die $error;
+  }
+
+  foreach my $cust_main (qsearch('cust_main', {'salesnum'=>$sales->salesnum})) {
+
+    $cust_main->salesnum('');
+    $cust_main->agentnum($agent->agentnum);
+    $error = $cust_main->replace;
+    if ( $error ) {
+      dbh->rollback or die dbh->errstr;
+      die $error;
+    }
+
+  }
+
+  $sales->disabled('');
+  $error = $sales->replace;
+  if ( $error ) {
+    dbh->rollback or die dbh->errstr;
+    die $error;
+  }
+  
+}
+
+dbh->commit or die dbh->errstr;
+
+1;
+
+sub usage {
+  die "Usage:\n\n  sales2agent username\n";
+}

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

Summary of changes:
 FS/FS/sales.pm  |   11 ++++++--
 bin/sales2agent |   75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 2 deletions(-)
 create mode 100644 bin/sales2agent




More information about the freeside-commits mailing list