[freeside-commits] branch FREESIDE_3_BRANCH updated. 15cca75dbf7fba140fbf7b6ea1566165f921978c
Ivan
ivan at 420.am
Sat Aug 30 17:57:16 PDT 2014
The branch, FREESIDE_3_BRANCH has been updated
via 15cca75dbf7fba140fbf7b6ea1566165f921978c (commit)
from 38f381389a48a37a7ed6d6ea5e963166adb47318 (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 15cca75dbf7fba140fbf7b6ea1566165f921978c
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:
bin/sales2agent | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
create mode 100644 bin/sales2agent
More information about the freeside-commits
mailing list