7 $cgi->param('tax','') unless defined $cgi->param('tax');
9 $cgi->param('refnum', (split(/:/, ($cgi->param('refnum'))[0] ))[0] );
11 my $payby = $cgi->param('payby');
13 $cgi->param('payinfo', $cgi->param( $payby. '_payinfo' ) );
14 $cgi->param('paydate',
15 $cgi->param( $payby. '_month' ). '-'. $cgi->param( $payby. '_year' ) );
16 $cgi->param('payname', $cgi->param( $payby. '_payname' ) );
19 $cgi->param('otaker', &getotaker );
21 my @invoicing_list = split( /\s*\,\s*/, $cgi->param('invoicing_list') );
22 push @invoicing_list, 'POST' if $cgi->param('invoicing_list_POST');
24 #create new record object
26 my $new = new FS::cust_main ( {
28 $_, scalar($cgi->param($_))
29 # } qw(custnum agentnum last first ss company address1 address2 city county
30 # state zip daytime night fax payby payinfo paydate payname tax
35 if ( defined($cgi->param('same')) && $cgi->param('same') eq "Y" ) {
36 $new->setfield("ship_$_", '') foreach qw(
37 last first company address1 address2 city county state zip
38 country daytime night fax
42 #perhaps this stuff should go to cust_main.pm
45 if ( $new->custnum eq '' ) {
47 if ( $cgi->param('pkgpart_svcpart') ) {
48 my $x = $cgi->param('pkgpart_svcpart');
49 $x =~ /^(\d+)_(\d+)$/;
50 my($pkgpart, $svcpart) = ($1, $2);
51 #false laziness: copied from FS::cust_pkg::order (which should become a
52 #FS::cust_main method)
55 # $part_pkg{$pkgpart} is true iff $custnum may purchase $pkgpart
56 my $agent = qsearchs('agent',{'agentnum'=> $new->agentnum });
58 #foreach $type_pkgs ( qsearch('type_pkgs',{'typenum'=> $agent->typenum }) ) {
59 # my($pkgpart)=$type_pkgs->pkgpart;
60 # $part_pkg{$pkgpart}++;
62 # $pkgpart_href->{PKGPART} is true iff $custnum may purchase $pkgpart
63 my $pkgpart_href = $agent->pkgpart_hashref;
66 # this should wind up in FS::cust_pkg!
67 $error ||= "Agent ". $new->agentnum. " (type ". $agent->typenum. ") can't".
68 "purchase pkgpart ". $pkgpart
69 #unless $part_pkg{ $pkgpart };
70 unless $pkgpart_href->{ $pkgpart };
72 $cust_pkg = new FS::cust_pkg ( {
73 #later 'custnum' => $custnum,
74 'pkgpart' => $pkgpart,
76 $error ||= $cust_pkg->check;
78 #$cust_svc = new FS::cust_svc ( { 'svcpart' => $svcpart } );
80 #$error ||= $cust_svc->check;
82 $svc_acct = new FS::svc_acct ( {
83 'svcpart' => $svcpart,
84 'username' => $cgi->param('username'),
85 '_password' => $cgi->param('_password'),
86 'popnum' => $cgi->param('popnum'),
89 my $y = $svc_acct->setdefault; # arguably should be in new method
90 $error ||= $y unless ref($y);
91 #and just in case you were silly
92 $svc_acct->svcpart($svcpart);
93 $svc_acct->username($cgi->param('username'));
94 $svc_acct->_password($cgi->param('_password'));
95 $svc_acct->popnum($cgi->param('popnum'));
97 $error ||= $svc_acct->check;
99 } elsif ( $cgi->param('username') ) { #good thing to catch
100 $error = "Can't assign username without a package!";
104 tie my %hash, 'Tie::RefHash';
105 %hash = ( $cust_pkg => [ $svc_acct ] ) if $cust_pkg;
106 $error ||= $new->insert( \%hash, \@invoicing_list );
107 } else { #create old record object
108 my $old = qsearchs( 'cust_main', { 'custnum' => $new->custnum } );
109 $error ||= "Old record not found!" unless $old;
110 $error ||= $new->replace($old, \@invoicing_list);
114 $cgi->param('error', $error);
115 print $cgi->redirect(popurl(2). "cust_main.cgi?". $cgi->query_string );
117 print $cgi->redirect(popurl(3). "view/cust_main.cgi?". $new->custnum);