1 <!-- $Id: cust_main.cgi,v 1.6 2002-01-30 14:18:09 ivan Exp $ -->
8 $cgi->param('tax','') unless defined $cgi->param('tax');
10 $cgi->param('refnum', (split(/:/, ($cgi->param('refnum'))[0] ))[0] );
12 $cgi->param('state') =~ /^(\w*)( \(([\w ]+)\))? ?\/ ?(\w+)$/
13 or die "Oops, illegal \"state\" param: ". $cgi->param('state');
14 $cgi->param('state', $1);
15 $cgi->param('county', $3 || '');
16 $cgi->param('country', $4);
18 $cgi->param('ship_state') =~ /^(\w*)( \(([\w ]+)\))? ?\/ ?(\w+)$/
19 or $cgi->param('ship_state') =~ /^(((())))$/
20 or die "Oops, illegal \"ship_state\" param: ". $cgi->param('ship_state');
21 $cgi->param('ship_state', $1);
22 $cgi->param('ship_county', $3 || '');
23 $cgi->param('ship_country', $4);
25 my $payby = $cgi->param('payby');
27 $cgi->param('payinfo', $cgi->param( $payby. '_payinfo' ) );
28 $cgi->param('paydate',
29 $cgi->param( $payby. '_month' ). '-'. $cgi->param( $payby. '_year' ) );
30 $cgi->param('payname', $cgi->param( $payby. '_payname' ) );
33 $cgi->param('otaker', &getotaker );
35 my @invoicing_list = split( /\s*\,\s*/, $cgi->param('invoicing_list') );
36 push @invoicing_list, 'POST' if $cgi->param('invoicing_list_POST');
38 #create new record object
40 my $new = new FS::cust_main ( {
42 $_, scalar($cgi->param($_))
43 # } qw(custnum agentnum last first ss company address1 address2 city county
44 # state zip daytime night fax payby payinfo paydate payname tax
49 if ( defined($cgi->param('same')) && $cgi->param('same') eq "Y" ) {
50 $new->setfield("ship_$_", '') foreach qw(
51 last first company address1 address2 city county state zip
52 country daytime night fax
56 #perhaps this stuff should go to cust_main.pm
59 if ( $new->custnum eq '' ) {
61 if ( $cgi->param('pkgpart_svcpart') ) {
62 my $x = $cgi->param('pkgpart_svcpart');
63 $x =~ /^(\d+)_(\d+)$/;
64 my($pkgpart, $svcpart) = ($1, $2);
65 #false laziness: copied from FS::cust_pkg::order (which should become a
66 #FS::cust_main method)
69 # $part_pkg{$pkgpart} is true iff $custnum may purchase $pkgpart
70 my $agent = qsearchs('agent',{'agentnum'=> $new->agentnum });
72 #foreach $type_pkgs ( qsearch('type_pkgs',{'typenum'=> $agent->typenum }) ) {
73 # my($pkgpart)=$type_pkgs->pkgpart;
74 # $part_pkg{$pkgpart}++;
76 # $pkgpart_href->{PKGPART} is true iff $custnum may purchase $pkgpart
77 my $pkgpart_href = $agent->pkgpart_hashref;
80 # this should wind up in FS::cust_pkg!
81 $error ||= "Agent ". $new->agentnum. " (type ". $agent->typenum. ") can't".
82 "purchase pkgpart ". $pkgpart
83 #unless $part_pkg{ $pkgpart };
84 unless $pkgpart_href->{ $pkgpart };
86 $cust_pkg = new FS::cust_pkg ( {
87 #later 'custnum' => $custnum,
88 'pkgpart' => $pkgpart,
90 $error ||= $cust_pkg->check;
92 #$cust_svc = new FS::cust_svc ( { 'svcpart' => $svcpart } );
94 #$error ||= $cust_svc->check;
96 $svc_acct = new FS::svc_acct ( {
97 'svcpart' => $svcpart,
98 'username' => $cgi->param('username'),
99 '_password' => $cgi->param('_password'),
100 'popnum' => $cgi->param('popnum'),
103 my $y = $svc_acct->setdefault; # arguably should be in new method
104 $error ||= $y unless ref($y);
105 #and just in case you were silly
106 $svc_acct->svcpart($svcpart);
107 $svc_acct->username($cgi->param('username'));
108 $svc_acct->_password($cgi->param('_password'));
109 $svc_acct->popnum($cgi->param('popnum'));
111 $error ||= $svc_acct->check;
113 } elsif ( $cgi->param('username') ) { #good thing to catch
114 $error = "Can't assign username without a package!";
118 tie my %hash, 'Tie::RefHash';
119 %hash = ( $cust_pkg => [ $svc_acct ] ) if $cust_pkg;
120 $error ||= $new->insert( \%hash, \@invoicing_list );
121 } else { #create old record object
122 my $old = qsearchs( 'cust_main', { 'custnum' => $new->custnum } );
123 $error ||= "Old record not found!" unless $old;
124 $error ||= $new->replace($old, \@invoicing_list);
128 $cgi->param('error', $error);
129 print $cgi->redirect(popurl(2). "cust_main.cgi?". $cgi->query_string );
131 print $cgi->redirect(popurl(3). "view/cust_main.cgi?". $new->custnum);