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');
12 %my $payby = $cgi->param('select'); # XXX key
18 %$payby = $noauto{$payby}
19 % if ! $cgi->param('payauto') && exists $noauto{$payby};
21 %$cgi->param('payby', $payby);
24 % if ( $payby eq 'CHEK' || $payby eq 'DCHK' ) {
25 % $cgi->param('payinfo',
26 % $cgi->param('payinfo1'). '@'. $cgi->param('payinfo2') );
28 % $cgi->param('paydate',
29 % $cgi->param( 'exp_month' ). '-'. $cgi->param( 'exp_year' ) );
32 %my @invoicing_list = split( /\s*\,\s*/, $cgi->param('invoicing_list') );
33 %push @invoicing_list, 'POST' if $cgi->param('invoicing_list_POST');
34 %push @invoicing_list, 'FAX' if $cgi->param('invoicing_list_FAX');
35 %$cgi->param('invoicing_list', join(',', @invoicing_list) );
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
46 % } fields('cust_main')
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 %$new->setfield('paid', $cgi->param('paid') )
57 % if $cgi->param('paid');
59 %#perhaps this stuff should go to cust_main.pm
62 %if ( $new->custnum eq '' ) {
64 % if ( $cgi->param('pkgpart_svcpart') ) {
65 % my $x = $cgi->param('pkgpart_svcpart');
66 % $x =~ /^(\d+)_(\d+)$/ or die "illegal pkgpart_svcpart $x\n";
67 % my($pkgpart, $svcpart) = ($1, $2);
68 % #false laziness: copied from FS::cust_pkg::order (which should become a
69 % #FS::cust_main method)
71 % # generate %part_pkg
72 % # $part_pkg{$pkgpart} is true iff $custnum may purchase $pkgpart
73 % my $agent = qsearchs('agent',{'agentnum'=> $new->agentnum });
75 % #foreach $type_pkgs ( qsearch('type_pkgs',{'typenum'=> $agent->typenum }) ) {
76 % # my($pkgpart)=$type_pkgs->pkgpart;
77 % # $part_pkg{$pkgpart}++;
79 % # $pkgpart_href->{PKGPART} is true iff $custnum may purchase $pkgpart
80 % my $pkgpart_href = $agent->pkgpart_hashref;
83 % # this should wind up in FS::cust_pkg!
84 % $error ||= "Agent ". $new->agentnum. " (type ". $agent->typenum. ") can't ".
85 % "purchase pkgpart ". $pkgpart
86 % #unless $part_pkg{ $pkgpart };
87 % unless $pkgpart_href->{ $pkgpart };
89 % $cust_pkg = new FS::cust_pkg ( {
90 % #later 'custnum' => $custnum,
91 % 'pkgpart' => $pkgpart,
93 % #$error ||= $cust_pkg->check;
95 % #$cust_svc = new FS::cust_svc ( { 'svcpart' => $svcpart } );
97 % #$error ||= $cust_svc->check;
99 % $svc_acct = new FS::svc_acct ( {
100 % 'svcpart' => $svcpart,
101 % 'username' => $cgi->param('username'),
102 % '_password' => $cgi->param('_password'),
103 % 'popnum' => $cgi->param('popnum'),
106 % #and just in case you were silly
107 % $svc_acct->svcpart($svcpart);
108 % $svc_acct->username($cgi->param('username'));
109 % $svc_acct->_password($cgi->param('_password'));
110 % $svc_acct->popnum($cgi->param('popnum'));
112 % #$error ||= $svc_acct->check;
114 % } elsif ( $cgi->param('username') ) { #good thing to catch
115 % $error = "Can't assign username without a package!";
119 % tie my %hash, 'Tie::RefHash';
120 % %hash = ( $cust_pkg => [ $svc_acct ] ) if $cust_pkg;
121 % $error ||= $new->insert( \%hash, \@invoicing_list );
123 % my $conf = new FS::Conf;
124 % if ( $conf->exists('backend-realtime') && ! $error ) {
126 % my $berror = $new->bill;
127 % $new->apply_payments;
128 % $new->apply_credits;
129 % $berror ||= $new->collect( 'realtime' => 1 );
130 % warn "Warning, error billing during backend-realtime: $berror" if $berror;
134 %} else { #create old record object
136 % my $old = qsearchs( 'cust_main', { 'custnum' => $new->custnum } );
137 % $error ||= "Old record not found!" unless $old;
138 % if ( defined dbdef->table('cust_main')->column('paycvv')
139 % && length($old->paycvv)
140 % && $new->paycvv =~ /^\s*\*+\s*$/ ) {
141 % $new->paycvv($old->paycvv);
143 % $error ||= $new->replace($old, \@invoicing_list);
148 % $cgi->param('error', $error);
149 % print $cgi->redirect(popurl(2). "cust_main.cgi?". $cgi->query_string );
151 % print $cgi->redirect(popurl(3). "view/cust_main.cgi?". $new->custnum);