5 %$cgi->param('tax','') unless defined $cgi->param('tax');
7 %$cgi->param('refnum', (split(/:/, ($cgi->param('refnum'))[0] ))[0] );
9 %#my $payby = $cgi->param('payby');
10 %my $payby = $cgi->param('select'); # XXX key
16 %$payby = $noauto{$payby}
17 % if ! $cgi->param('payauto') && exists $noauto{$payby};
19 %$cgi->param('payby', $payby);
22 % if ( $payby eq 'CHEK' || $payby eq 'DCHK' ) {
23 % $cgi->param('payinfo',
24 % $cgi->param('payinfo1'). '@'. $cgi->param('payinfo2') );
26 % $cgi->param('paydate',
27 % $cgi->param( 'exp_month' ). '-'. $cgi->param( 'exp_year' ) );
30 %my @invoicing_list = split( /\s*\,\s*/, $cgi->param('invoicing_list') );
31 %push @invoicing_list, 'POST' if $cgi->param('invoicing_list_POST');
32 %push @invoicing_list, 'FAX' if $cgi->param('invoicing_list_FAX');
33 %$cgi->param('invoicing_list', join(',', @invoicing_list) );
36 %#create new record object
38 %my $new = new FS::cust_main ( {
40 % $_, scalar($cgi->param($_))
41 %# } qw(custnum agentnum last first ss company address1 address2 city county
42 %# state zip daytime night fax payby payinfo paydate payname tax
44 % } fields('cust_main')
47 % delete( $new->hashref->{'agent_custid'} )
48 % unless $new->hashref->{'agent_custid'};
50 %if ( defined($cgi->param('same')) && $cgi->param('same') eq "Y" ) {
51 % $new->setfield("ship_$_", '') foreach qw(
52 % last first company address1 address2 city county state zip
53 % country daytime night fax
57 %if ( $cgi->param('birthdate') && $cgi->param('birthdate') =~ /^([ 0-9\-\/]{0,10})$/) {
58 % my $conf = new FS::Conf;
59 % my $format = $conf->config('date_format') || "%m/%d/%Y";
60 % my $parser = DateTime::Format::Strptime->new(pattern => $format,
61 % time_zone => 'floating',
63 % my $dt = $parser->parse_datetime($1);
65 % $new->setfield('birthdate', $dt->epoch);
66 % $cgi->param('birthdate', $dt->epoch);
68 %# $error ||= $cgi->param('birthdate') . " is an invalid birthdate:" . $parser->errmsg;
69 % $error ||= "Invalid birthdate: " . $cgi->param('birthdate') . ".";
70 % $cgi->param('birthdate', '');
74 %$new->setfield('paid', $cgi->param('paid') )
75 % if $cgi->param('paid');
77 %#perhaps this stuff should go to cust_main.pm
80 %if ( $new->custnum eq '' ) {
82 % if ( $cgi->param('pkgpart_svcpart') ) {
83 % my $x = $cgi->param('pkgpart_svcpart');
84 % $x =~ /^(\d+)_(\d+)$/ or die "illegal pkgpart_svcpart $x\n";
85 % my($pkgpart, $svcpart) = ($1, $2);
86 % #false laziness: copied from FS::cust_pkg::order (which should become a
87 % #FS::cust_main method)
89 % # generate %part_pkg
90 % # $part_pkg{$pkgpart} is true iff $custnum may purchase $pkgpart
91 % my $agent = qsearchs('agent',{'agentnum'=> $new->agentnum });
93 % #foreach $type_pkgs ( qsearch('type_pkgs',{'typenum'=> $agent->typenum }) ) {
94 % # my($pkgpart)=$type_pkgs->pkgpart;
95 % # $part_pkg{$pkgpart}++;
97 % # $pkgpart_href->{PKGPART} is true iff $custnum may purchase $pkgpart
98 % my $pkgpart_href = $agent->pkgpart_hashref;
101 % # this should wind up in FS::cust_pkg!
102 % $error ||= "Agent ". $new->agentnum. " (type ". $agent->typenum. ") can't ".
103 % "purchase pkgpart ". $pkgpart
104 % #unless $part_pkg{ $pkgpart };
105 % unless $pkgpart_href->{ $pkgpart };
107 % $cust_pkg = new FS::cust_pkg ( {
108 % #later 'custnum' => $custnum,
109 % 'pkgpart' => $pkgpart,
111 % #$error ||= $cust_pkg->check;
113 % #$cust_svc = new FS::cust_svc ( { 'svcpart' => $svcpart } );
115 % #$error ||= $cust_svc->check;
118 % 'svcpart' => $svcpart,
119 % 'username' => $cgi->param('username'),
120 % '_password' => $cgi->param('_password'),
121 % 'popnum' => $cgi->param('popnum'),
123 % $svc_acct{'domsvc'} = $cgi->param('domsvc')
124 % if $cgi->param('domsvc');
126 % $svc_acct = new FS::svc_acct \%svc_acct;
128 % #and just in case you were silly
129 % $svc_acct->svcpart($svcpart);
130 % $svc_acct->username($cgi->param('username'));
131 % $svc_acct->_password($cgi->param('_password'));
132 % $svc_acct->popnum($cgi->param('popnum'));
134 % #$error ||= $svc_acct->check;
136 % } elsif ( $cgi->param('username') ) { #good thing to catch
137 % $error = "Can't assign username without a package!";
141 % tie my %hash, 'Tie::RefHash';
142 % %hash = ( $cust_pkg => [ $svc_acct ] ) if $cust_pkg;
143 % $error ||= $new->insert( \%hash, \@invoicing_list );
145 % my $conf = new FS::Conf;
146 % if ( $conf->exists('backend-realtime') && ! $error ) {
148 % my $berror = $new->bill;
149 % $new->apply_payments_and_credits;
150 % $berror ||= $new->collect( 'realtime' => 1 );
151 % warn "Warning, error billing during backend-realtime: $berror" if $berror;
155 %} else { #create old record object
157 % my $old = qsearchs( 'cust_main', { 'custnum' => $new->custnum } );
158 % $error ||= "Old record not found!" unless $old;
159 % if ( defined dbdef->table('cust_main')->column('paycvv')
160 % && length($old->paycvv)
161 % && $new->paycvv =~ /^\s*\*+\s*$/ ) {
162 % $new->paycvv($old->paycvv);
164 % if ($new->ss =~ /xx/) {
165 % $new->ss($old->ss);
167 % if ($new->stateid =~ /^xxx/) {
168 % $new->stateid($old->stateid);
170 % if ($new->payby =~ /^(CARD|DCRD|CHEK|DCHK)$/ && $new->payinfo =~ /xx/) {
171 % $new->payinfo($old->payinfo);
173 % $error ||= $new->replace($old, \@invoicing_list);
178 % $cgi->param('error', $error);
179 % print $cgi->redirect(popurl(2). "cust_main.cgi?". $cgi->query_string );
181 % print $cgi->redirect(popurl(3). "view/cust_main.cgi?". $new->custnum);