3 # $Id: cust_main.cgi,v 1.9 1999-04-07 15:22:19 ivan Exp $
6 # http://server.name/path/cust_main.cgi
8 # ivan@voicenet.com 96-dec-04
10 # added referral check
11 # ivan@voicenet.com 97-jun-4
14 # ivan@voicenet.com 97-jul-28
16 # same as above (again) and clean up some stuff ivan@sisd.com 98-feb-23
18 # Changes to allow page to work at a relative position in server
19 # Changed 'day' to 'daytime' because Pg6.3 reserves the day word
20 # bmccane@maxbaud.net 98-apr-3
22 # $Log: cust_main.cgi,v $
23 # Revision 1.9 1999-04-07 15:22:19 ivan
24 # don't use anchor in redirect
26 # Revision 1.8 1999/03/25 13:55:10 ivan
27 # one-screen new customer entry (including package and service) for simple
28 # packages with one svc_acct service
30 # Revision 1.7 1999/02/28 00:03:42 ivan
31 # removed misleading comments
33 # Revision 1.6 1999/01/25 12:10:00 ivan
34 # yet more mod_perl stuff
36 # Revision 1.5 1999/01/19 05:13:50 ivan
37 # for mod_perl: no more top-level my() variables; use vars instead
38 # also the last s/create/new/;
40 # Revision 1.4 1999/01/18 09:22:32 ivan
41 # changes to track email addresses for email invoicing
43 # Revision 1.3 1998/12/17 08:40:19 ivan
44 # s/CGI::Request/CGI.pm/; etc
46 # Revision 1.2 1998/11/18 08:57:36 ivan
47 # i18n, s/CGI-modules/CGI.pm/, FS::CGI::idiot instead of inline, FS::CGI::popurl
51 use vars qw( $cgi $payby @invoicing_list $new $custnum $error );
52 use vars qw( $cust_pkg $cust_svc $svc_acct );
54 use CGI::Carp qw(fatalsToBrowser);
55 use FS::UID qw(cgisuidsetup getotaker);
56 use FS::CGI qw( popurl );
57 use FS::Record qw( qsearch qsearchs fields );
67 $cgi->param('tax','') unless defined($cgi->param('tax'));
69 $cgi->param('refnum', (split(/:/, ($cgi->param('refnum'))[0] ))[0] );
71 $cgi->param('state') =~ /^(\w+)( \((\w+)\))? \/ (\w+)$/;
72 $cgi->param('state', $1);
73 $cgi->param('county', $3 || '');
74 $cgi->param('country', $4);
76 if ( $payby = $cgi->param('payby') ) {
77 $cgi->param('payinfo', $cgi->param( $payby. '_payinfo' ) );
78 $cgi->param('paydate',
79 $cgi->param( $payby. '_month' ). '-'. $cgi->param( $payby. '_year' ) );
80 $cgi->param('payname', $cgi->param( $payby. '_payname' ) );
83 $cgi->param('otaker', &getotaker );
85 @invoicing_list = split( /\s*\,\s*/, $cgi->param('invoicing_list') );
86 push @invoicing_list, 'POST' if $cgi->param('invoicing_list_POST');
88 #create new record object
90 $new = new FS::cust_main ( {
92 $_, scalar($cgi->param($_))
93 # } qw(custnum agentnum last first ss company address1 address2 city county
94 # state zip daytime night fax payby payinfo paydate payname tax
99 #perhaps the invocing_list magic should move to cust_main.pm?
100 $error = $new->check_invoicing_list( \@invoicing_list );
102 #perhaps this stuff should go to cust_main.pm as well
105 if ( $new->custnum eq '' ) {
107 if ( $cgi->param('pkgpart_svcpart') ) {
108 my $x = $cgi->param('pkgpart_svcpart');
109 $x =~ /^(\d+)_(\d+)$/;
110 my($pkgpart, $svcpart) = ($1, $2);
111 #false laziness: copied from FS::cust_pkg::order (which should become a
112 #FS::cust_main method)
115 # $part_pkg{$pkgpart} is true iff $custnum may purchase $pkgpart
116 my $agent = qsearchs('agent',{'agentnum'=> $new->agentnum });
118 foreach $type_pkgs ( qsearch('type_pkgs',{'typenum'=> $agent->typenum }) ) {
119 my($pkgpart)=$type_pkgs->pkgpart;
120 $part_pkg{$pkgpart}++;
124 $error ||= "Agent ". $new->agentnum. " (type ". $agent->typenum. ") can't".
125 "purchase pkgpart ". $pkgpart
126 unless $part_pkg{ $pkgpart };
128 $cust_pkg = new FS::cust_pkg ( {
129 #later 'custnum' => $custnum,
130 'pkgpart' => $pkgpart,
132 $error ||= $cust_pkg->check;
134 #$cust_svc = new FS::cust_svc ( { 'svcpart' => $svcpart } );
136 #$error ||= $cust_svc->check;
138 $svc_acct = new FS::svc_acct ( {
139 'svcpart' => $svcpart,
140 'username' => $cgi->param('username'),
141 '_password' => $cgi->param('_password'),
142 'popnum' => $cgi->param('popnum'),
145 my $y = $svc_acct->setdefault; # arguably should be in new method
146 $error ||= $y unless ref($y);
147 #and just in case you were silly
148 $svc_acct->svcpart($svcpart);
149 $svc_acct->username($cgi->param('username'));
150 $svc_acct->_password($cgi->param('_password'));
151 $svc_acct->popnum($cgi->param('popnum'));
153 $error ||= $svc_acct->check;
155 } elsif ( $cgi->param('username') ) { #good thing to catch
156 $error = "Can't assign username without a package!";
159 $error ||= $new->insert;
160 if ( $cust_pkg && ! $error ) {
161 $cust_pkg->custnum( $new->custnum );
162 $error ||= $cust_pkg->insert;
163 warn "WARNING: $error on pre-checked cust_pkg record!" if $error;
164 $svc_acct->pkgnum( $cust_pkg->pkgnum );
165 $error ||= $svc_acct->insert;
166 warn "WARNING: $error on pre-checked svc_acct record!" if $error;
168 } else { #create old record object
169 my $old = qsearchs( 'cust_main', { 'custnum' => $new->custnum } );
170 $error ||= "Old record not found!" unless $old;
171 $error ||= $new->replace($old);
175 $cgi->param('error', $error);
176 print $cgi->redirect(popurl(2). "cust_main.cgi?". $cgi->query_string );
178 $new->invoicing_list( \@invoicing_list );
179 $custnum = $new->custnum;
180 print $cgi->redirect(popurl(3). "view/cust_main.cgi?$custnum");