summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FS/FS/cust_main.pm35
-rw-r--r--httemplate/docs/config.html1
-rw-r--r--httemplate/docs/upgrade8.html3
-rwxr-xr-xhttemplate/edit/cust_main.cgi21
-rwxr-xr-xhttemplate/search/cust_main.cgi65
-rwxr-xr-xhttemplate/view/cust_main.cgi30
6 files changed, 143 insertions, 12 deletions
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
<li><a name="cybercash2">cybercash2</a> - <a href="http://www.cybercash.com/cybercash/services/cashreg214.html">CyberCash v2</a> support, four lines: paymentserverhost, paymentserverport, paymentserversecret, and transaction type (`mauthonly' or `mauthcapture'). CCLib.pm is required.
<li>cybercash3.2 - <a href="http://www.cybercash.com/cybercash/services/technology.html">CyberCash v3.2</a> 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.
<li><a name="deletecustomers">deletecustomers</a> - 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.
+ <li><a name="disable_customer_referrals">disable_customer_referrals</a> - The existance of this file will disable new customer-to-customer referrals in the web interface.
<li><a name="domain">domain</a> - Your domain name.
<li><a name="editreferrals">editreferrals</a> - The existance of this file will allow you to change the referral of existing customers.
<li><a name="erpcdmachines">erpcdmachines</a> - 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 );
</pre>
<li>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 @@
<%
-#<!-- $Id: cust_main.cgi,v 1.3 2001-08-12 00:07:55 ivan Exp $ -->
+#<!-- $Id: cust_main.cgi,v 1.4 2001-08-28 14:34:14 ivan Exp $ -->
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!<BR><BR>Referring Customer: !;
+if ( $cust_main->referral_custnum ) {
+ my $referring_cust_main =
+ qsearchs('cust_main', { custnum => $cust_main->referral_custnum } );
+ print '<A HREF="'. popurl(1). '/cust_main.cgi?'.
+ $cust_main->referral_custnum. '">'.
+ $cust_main->referral_custnum. ': '.
+ ( $referring_cust_main->company
+ || $referring_cust_main->last. ', '. $referring_cust_main->first ).
+ '</A><INPUT TYPE="hidden" NAME="referral_custnum" VALUE="'.
+ $cust_main->referral_custnum. '">';
+} else {
+ print '(none)<INPUT TYPE="hidden" NAME="referral_custnum" VALUE="">';
+}
# 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 @@
<%
-#<!-- $Id: cust_main.cgi,v 1.2 2001-07-30 10:41:44 ivan Exp $ -->
+#<!-- $Id: cust_main.cgi,v 1.3 2001-08-28 14:34:14 ivan Exp $ -->
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<BR>", &table(), <<END;
+ )), "$total matching customers found";
+ if ( $cgi->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 '<FORM METHOD=POST>'.
+ qq!<INPUT TYPE="hidden" NAME="referral_custnum" VALUE="$referral_custnum">!.
+ 'referrals of <A HREF="'. popurl(2).
+ "view/cust_main.cgi?$referral_custnum\">$referral_custnum: ".
+ ( $cust_main->company
+ || $cust_main->last. ', '. $cust_main->first ).
+ '</A>';
+ print "\n",<<END;
+ <SCRIPT>
+ function changed(what) {
+ what.form.submit();
+ }
+ </SCRIPT>
+END
+ print ' <SELECT NAME="referral_depth" SIZE="1" onChange="changed(this)">';
+ my $max = 8; #config file
+ $cgi->param('referral_depth') =~ /^(\d+)$/
+ or eidiot "Illegal referral_depth";
+ my $referral_depth = $1;
+
+ foreach my $depth ( 1 .. $max ) {
+ print '<OPTION',
+ ' SELECTED'x($depth == $referral_depth),
+ ">$depth";
+ }
+ print "</SELECT> levels deep".
+ '<NOSCRIPT> <INPUT TYPE="submit" VALUE="change"></NOSCRIPT>'.
+ '</FORM>';
+ }
+ print "<BR>", &table(), <<END;
<TR>
<TH></TH>
<TH>(bill) name</TH>
@@ -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 @@
<%
-#<!-- $Id: cust_main.cgi,v 1.4 2001-08-13 23:15:35 ivan Exp $ -->
+#<!-- $Id: cust_main.cgi,v 1.5 2001-08-28 14:34:14 ivan Exp $ -->
use strict;
use vars qw ( $cgi $query $custnum $cust_main $hashref $agent $referral
@@ -43,8 +43,18 @@ print qq!<A HREF="!, popurl(2),
print qq! | <A HREF="!, popurl(2),
qq!misc/delete-customer.cgi?$custnum"> Delete this customer</A>!
if $conf->exists('deletecustomers');
-print '<BR><BR>';
+unless ( $conf->exists('disable_customer_referrals') ) {
+ print qq! | <A HREF="!, popurl(2),
+ qq!edit/cust_main.cgi?referral_custnum=$custnum">!,
+ qq!Refer a new customer</A>!;
+
+ print qq! | <A HREF="!, popurl(2),
+ qq!search/cust_main.cgi?referral_custnum=$custnum">!,
+ qq!View this customer's referrals<A>!;
+}
+
+print '<BR><BR>';
print '<A NAME="cust_main"></A>';
print &itable(), '<TR>';
@@ -158,6 +168,22 @@ print '<TD VALIGN="top">';
print '<TR><TD ALIGN="right">Order taker</TD><TD BGCOLOR="#ffffff">',
$cust_main->otaker, '</TD></TR>';
+ print '<TR><TD ALIGN="right">Referring Customer</TD><TD BGCOLOR="#ffffff">';
+ my $referring_cust_main = '';
+ if ( $cust_main->referral_custnum
+ && ( $referring_cust_main =
+ qsearchs('cust_main', { custnum => $cust_main->referral_custnum } )
+ )
+ ) {
+ print '<A HREF="'. popurl(1). 'cust_main.cgi?'.
+ $cust_main->referral_custnum. '">'.
+ $cust_main->referral_custnum. ': '.
+ ( $referring_cust_main->company
+ || $referring_cust_main->last. ', '. $referring_cust_main->first ).
+ '</A>';
+ }
+ print '</TD></TR>';
+
print '</TABLE></TD></TR></TABLE>';
print '<BR>';