Diff -- /var/www/vhosts/3dshawn.com/crm.3dshawn.com/MODS/ContactForge/Onboarding.pm
Diff

/var/www/vhosts/3dshawn.com/crm.3dshawn.com/MODS/ContactForge/Onboarding.pm

added on local at 2026-07-01 15:02:54

Added
+104
lines
Removed
-0
lines
Context
0
unchanged
Blobs
from
to 3a40ba96215a
Restore this content →
Unified diff
Naive LCS-based line diff. Additions in emerald, deletions in rose. Both sides decompressed live from BLOB_STORE.
1package MODS::ContactForge::Onboarding;
2#======================================================================
3# ContactForge -- new-user sample data seeder
4#
5# Called from signup.cgi after a successful signup. Creates a sample
6# pipeline + 3 stages + 3 companies + 5 contacts + 2 deals so the
7# dashboard isn't empty on first login. Idempotent.
8#======================================================================
9use strict; use warnings;
10
11sub new { return bless {}, shift }
12
13sub seed_sample_data {
14 my ($self, $db, $dbh, $DB, $user_id) = @_;
15 return unless $user_id;
16
17 # Skip if user already has contacts
18 my $r = $db->db_readwrite($dbh, qq~
19 SELECT COUNT(*) AS n FROM `${DB}`.contacts WHERE owner_user_id='$user_id'
20 ~, $ENV{SCRIPT_NAME}, __LINE__);
21 return if $r && $r->{n};
22
23 # 1. Pipeline + 3 stages
24 my $pl = $db->db_readwrite($dbh, qq~
25 INSERT INTO `${DB}`.pipelines SET owner_user_id='$user_id', name='Sales Pipeline (example)', is_active=1
26 ~, $ENV{SCRIPT_NAME}, __LINE__);
27 my $pid = ($pl && $pl->{mysql_insertid}) ? $pl->{mysql_insertid} : 0;
28 return unless $pid;
29
30 my @stage_ids;
31 foreach my $s (
32 { name => 'Qualified', sort_order => 0, win_probability => 25 },
33 { name => 'Proposal', sort_order => 1, win_probability => 60 },
34 { name => 'Closed Won', sort_order => 2, win_probability => 100 },
35 ) {
36 my $r2 = $db->db_readwrite($dbh, qq~
37 INSERT INTO `${DB}`.deal_stages
38 SET pipeline_id='$pid', name='$s->{name}', sort_order='$s->{sort_order}', win_probability='$s->{win_probability}'
39 ~, $ENV{SCRIPT_NAME}, __LINE__);
40 push @stage_ids, ($r2 && $r2->{mysql_insertid}) ? $r2->{mysql_insertid} : 0;
41 }
42
43 # 2. Companies
44 my @companies = (
45 { name => 'Acme Robotics', domain => 'acme-robotics.example' },
46 { name => 'Northwind Logistics', domain => 'northwind.example' },
47 { name => 'Globex Industries', domain => 'globex.example' },
48 );
49 my @co_ids;
50 foreach my $c (@companies) {
51 my $n_q = $c->{name}; $n_q =~ s/'/''/g;
52 my $d_q = $c->{domain}; $d_q =~ s/'/''/g;
53 my $r2 = $db->db_readwrite($dbh, qq~
54 INSERT INTO `${DB}`.companies
55 SET owner_user_id='$user_id', name='$n_q', domain='$d_q'
56 ~, $ENV{SCRIPT_NAME}, __LINE__);
57 push @co_ids, ($r2 && $r2->{mysql_insertid}) ? $r2->{mysql_insertid} : 0;
58 }
59
60 # 3. Contacts
61 my @contacts = (
62 { first => 'Ada', last => 'Lovelace', email => 'ada@acme-robotics.example', title => 'VP Engineering', co => $co_ids[0] },
63 { first => 'Grace', last => 'Hopper', email => 'grace@acme-robotics.example', title => 'Director of Ops', co => $co_ids[0] },
64 { first => 'Linus', last => 'Pauling', email => 'linus@northwind.example', title => 'Founder', co => $co_ids[1] },
65 { first => 'Marie', last => 'Curie', email => 'marie@globex.example', title => 'Chief Scientist', co => $co_ids[2] },
66 { first => 'Alan', last => 'Turing', email => 'alan@globex.example', title => 'Head of Research', co => $co_ids[2] },
67 );
68 my @contact_ids;
69 foreach my $c (@contacts) {
70 my $co_sql = $c->{co} ? "'$c->{co}'" : 'NULL';
71 my $r2 = $db->db_readwrite($dbh, qq~
72 INSERT INTO `${DB}`.contacts
73 SET owner_user_id='$user_id',
74 company_id=$co_sql,
75 first_name='$c->{first}', last_name='$c->{last}',
76 email='$c->{email}', title='$c->{title}'
77 ~, $ENV{SCRIPT_NAME}, __LINE__);
78 push @contact_ids, ($r2 && $r2->{mysql_insertid}) ? $r2->{mysql_insertid} : 0;
79 }
80
81 # 4. Two sample deals so the pipeline kanban shows something
82 if (scalar(@stage_ids) >= 2 && scalar(@contact_ids) >= 2) {
83 $db->db_readwrite($dbh, qq~
84 INSERT INTO `${DB}`.deals
85 SET owner_user_id='$user_id', pipeline_id='$pid', stage_id='$stage_ids[0]',
86 contact_id='$contact_ids[0]', company_id='$co_ids[0]',
87 title='Acme robotics expansion (example)',
88 description='Example deal -- delete or edit. Acme is evaluating an expansion of their fleet.',
89 amount_cents=4500000, currency='usd'
90 ~, $ENV{SCRIPT_NAME}, __LINE__);
91 $db->db_readwrite($dbh, qq~
92 INSERT INTO `${DB}`.deals
93 SET owner_user_id='$user_id', pipeline_id='$pid', stage_id='$stage_ids[1]',
94 contact_id='$contact_ids[3]', company_id='$co_ids[2]',
95 title='Globex pilot program (example)',
96 description='Example deal -- delete or edit. Globex wants a 30-day pilot with 50 users.',
97 amount_cents=1200000, currency='usd'
98 ~, $ENV{SCRIPT_NAME}, __LINE__);
99 }
100
101 return 1;
102}
103
1041;
Keyboard: j next diff k previous diff g top G bottom r restore c compile-check ? help