From: ivan Date: Tue, 28 Aug 2001 14:34:14 +0000 (+0000) Subject: customer-to-customer referrals! X-Git-Tag: freeside_1_4_0pre11~406 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=aa7b51c0794f6a61e522fbba978f6c64446d8696 customer-to-customer referrals! --- diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index ba4b94c7d..682b43d95 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -502,6 +502,7 @@ sub check { || $self->ut_textn('state') || $self->ut_country('country') || $self->ut_anything('comments') + || $self->ut_numbern('referral_custnum') ; #barf. need message catalogs. i18n. etc. $error .= "Please select a referral." @@ -514,6 +515,10 @@ sub check { return "Unknown referral" unless qsearchs( 'part_referral', { 'refnum' => $self->refnum } ); + return "Unknown referring custnum ". $self->referral_custnum + unless ! $self->referral_custnum + || qsearchs( 'cust_main', { 'custnum' => $self->referral_custnum } ); + if ( $self->ss eq '' ) { $self->ss(''); } else { @@ -1342,6 +1347,34 @@ sub check_invoicing_list { ''; } +=item referral_cust_main [ DEPTH [ EXCLUDE_HASHREF ] ] + +Returns an array of customers referred by this customer (referral_custnum set +to this custnum). If DEPTH is given, recurses up to the given depth, returning +customers referred by customers referred by this customer and so on, inclusive. +The default behavior is DEPTH 1 (no recursion). + +=cut + +sub referral_cust_main { + my $self = shift; + my $depth = @_ ? shift : 1; + my $exclude = @_ ? shift : {}; + + my @cust_main = + map { $exclude->{$_->custnum}++; $_; } + grep { ! $exclude->{ $_->custnum } } + qsearch( 'cust_main', { 'referral_custnum' => $self->custnum } ); + + if ( $depth > 1 ) { + push @cust_main, + map { $_->referral_cust_main($depth-1, $exclude) } + @cust_main; + } + + @cust_main; +} + =back =head1 SUBROUTINES @@ -1365,7 +1398,7 @@ sub rebuild_fuzzyfiles { =head1 VERSION -$Id: cust_main.pm,v 1.21 2001-08-26 05:06:19 ivan Exp $ +$Id: cust_main.pm,v 1.22 2001-08-28 14:34:14 ivan Exp $ =head1 BUGS diff --git a/httemplate/docs/config.html b/httemplate/docs/config.html index 64dbcfe3f..f26ff0f78 100644 --- a/httemplate/docs/config.html +++ b/httemplate/docs/config.html @@ -44,6 +44,7 @@ All further configuration files and directories are located in
  • cybercash2 - CyberCash v2 support, four lines: paymentserverhost, paymentserverport, paymentserversecret, and transaction type (`mauthonly' or `mauthcapture'). CCLib.pm is required.
  • cybercash3.2 - CyberCash v3.2 support. Two lines: the full path and name of your merchant_conf file, and the transaction type (`mauthonly' or `mauthcapture'). CCMckLib3_2.pm, CCMckDirectLib3_2.pm and CCMckErrno3_2 are required.
  • deletecustomers - The existance of this file will enable customer deletions. Be very careful! Deleting a customer will remove all traces that this customer ever existed! It should probably only be used when auditing a legacy database. Normally, you cancel all of a customers' packages if they cancel service. +
  • disable_customer_referrals - The existance of this file will disable new customer-to-customer referrals in the web interface.
  • domain - Your domain name.
  • editreferrals - The existance of this file will allow you to change the referral of existing customers.
  • erpcdmachines - Your ERPCD authenticaion machines, one per line. This enables export of `/usr/annex/acp_passwd' and `/usr/annex/acp_dialup'. diff --git a/httemplate/docs/upgrade8.html b/httemplate/docs/upgrade8.html index 60f8f1593..e2bb333d6 100644 --- a/httemplate/docs/upgrade8.html +++ b/httemplate/docs/upgrade8.html @@ -82,7 +82,8 @@ ALTER TABLE part_svc ADD svc_forward__dstsvc integer NULL; ALTER TABLE part_svc ADD svc_forward__dstsvc_flag char(1) NULL; ALTER TABLE part_svc ADD svc_forward__dst integer NULL; ALTER TABLE part_svc ADD svc_forward__dst_flag char(1) NULL; - +ALTER TABLE cust_main ADD referral_custnum integer NULL; +CREATE INDEX cust_main3 ON cust_main ( referral_custnum );
  • If you are using PostgreSQL, apply the following changes to your database: diff --git a/httemplate/edit/cust_main.cgi b/httemplate/edit/cust_main.cgi index f331e5321..47e18d789 100755 --- a/httemplate/edit/cust_main.cgi +++ b/httemplate/edit/cust_main.cgi @@ -1,5 +1,5 @@ <% -# +# use vars qw( $cgi $custnum $action $cust_main $p1 @agents $agentnum $last $first $ss $company $address1 $address2 $city $zip @@ -61,7 +61,8 @@ if ( $cgi->param('error') ) { } else { $custnum=''; $cust_main = new FS::cust_main ( {} ); - $cust_main->setfield('otaker',&getotaker); + $cust_main->otaker( &getotaker ); + $cust_main->referral_custnum( $cgi->param('referral_custnum') ); $saved_pkgpart = 0; $username = ''; $password = ''; @@ -130,6 +131,22 @@ if ( $custnum && ! $conf->exists('editreferrals') ) { } } +#referring customer + +print qq!

    Referring Customer: !; +if ( $cust_main->referral_custnum ) { + my $referring_cust_main = + qsearchs('cust_main', { custnum => $cust_main->referral_custnum } ); + print ''. + $cust_main->referral_custnum. ': '. + ( $referring_cust_main->company + || $referring_cust_main->last. ', '. $referring_cust_main->first ). + ''; +} else { + print '(none)'; +} # contact info diff --git a/httemplate/search/cust_main.cgi b/httemplate/search/cust_main.cgi index 86bca1fcf..d038896f6 100755 --- a/httemplate/search/cust_main.cgi +++ b/httemplate/search/cust_main.cgi @@ -1,5 +1,5 @@ <% -# +# use strict; #use vars qw( $conf %ncancelled_pkgs %all_pkgs $cgi @cust_main $sortby ); @@ -35,9 +35,10 @@ if ( $cgi->keywords ) { } } else { @cust_main=(); - &cardsearch if ( $cgi->param('card_on') && $cgi->param('card') ); - &lastsearch if ( $cgi->param('last_on') && $cgi->param('last_text') ); - &companysearch if ( $cgi->param('company_on') && $cgi->param('company_text') ); + &cardsearch if $cgi->param('card_on') && $cgi->param('card'); + &lastsearch if $cgi->param('last_on') && $cgi->param('last_text'); + &companysearch if $cgi->param('company_on') && $cgi->param('company_text'); + &referralsearch if $cgi->param('referral_custnum'); } @cust_main = grep { $_->ncancelled_pkgs || ! $_->all_pkgs } @cust_main @@ -48,7 +49,7 @@ if ( $conf->exists('hidecancelledpackages' ) ) { %all_pkgs = map { $_->custnum => [ $_->all_pkgs ] } @cust_main; } -if ( scalar(@cust_main) == 1 ) { +if ( scalar(@cust_main) == 1 && ! $cgi->param('referral_custnum') ) { print $cgi->redirect(popurl(2). "view/cust_main.cgi?". $cust_main[0]->custnum); exit; } elsif ( scalar(@cust_main) == 0 ) { @@ -58,7 +59,42 @@ if ( scalar(@cust_main) == 1 ) { my($total)=scalar(@cust_main); print $cgi->header( '-expires' => 'now' ), header("Customer Search Results",menubar( 'Main Menu', popurl(2) - )), "$total matching customers found
    ", &table(), <param('referral_custnum') ) { + $cgi->param('referral_custnum') =~ /^(\d+)$/ + or eidiot "Illegal referral_custnum\n"; + my $referral_custnum = $1; + my $cust_main = qsearchs('cust_main', { custnum => $referral_custnum } ); + print '
    '. + qq!!. + 'referrals of $referral_custnum: ". + ( $cust_main->company + || $cust_main->last. ', '. $cust_main->first ). + ''; + print "\n",< + function changed(what) { + what.form.submit(); + } + +END + print ' levels deep". + ''. + ''; + } + print "
    ", &table(), < (bill) name @@ -175,7 +211,24 @@ sub cardsearch { my($payinfo)=$1; push @cust_main, qsearch('cust_main',{'payinfo'=>$payinfo, 'payby'=>'CARD'}); + $sortby=\*last_sort; +} +sub referralsearch { + $cgi->param('referral_custnum') =~ /^(\d+)$/ + or eidiot "Illegal referral_custnum"; + my $cust_main = qsearchs('cust_main', { 'custnum' => $1 } ) + or eidiot "Customer $1 not found"; + my $depth; + if ( $cgi->param('referral_depth') ) { + $cgi->param('referral_depth') =~ /^(\d+)$/ + or eidiot "Illegal referral_depth"; + $depth = $1; + } else { + $depth = 1; + } + push @cust_main, $cust_main->referral_cust_main($depth); + $sortby=\*last_sort; } sub lastsearch { diff --git a/httemplate/view/cust_main.cgi b/httemplate/view/cust_main.cgi index 088e2bb2f..cba702670 100755 --- a/httemplate/view/cust_main.cgi +++ b/httemplate/view/cust_main.cgi @@ -1,5 +1,5 @@ <% -# +# use strict; use vars qw ( $cgi $query $custnum $cust_main $hashref $agent $referral @@ -43,8 +43,18 @@ print qq! Delete this customer! if $conf->exists('deletecustomers'); -print '

    '; +unless ( $conf->exists('disable_customer_referrals') ) { + print qq! | !, + qq!Refer a new customer!; + + print qq! | !, + qq!View this customer's referrals!; +} + +print '

    '; print '
    '; print &itable(), ''; @@ -158,6 +168,22 @@ print ''; print 'Order taker', $cust_main->otaker, ''; + print 'Referring Customer'; + my $referring_cust_main = ''; + if ( $cust_main->referral_custnum + && ( $referring_cust_main = + qsearchs('cust_main', { custnum => $cust_main->referral_custnum } ) + ) + ) { + print ''. + $cust_main->referral_custnum. ': '. + ( $referring_cust_main->company + || $referring_cust_main->last. ', '. $referring_cust_main->first ). + ''; + } + print ''; + print ''; print '
    ';