+my %options = ();
+if ( $curuser->access_right('Edit customer tax exemptions') ) {
+ my @exempt_groups = grep /\S/, $conf->config('tax-cust_exempt-groups');
+ my @tax_exempt = grep { $cgi->param("tax_$_") eq 'Y' } @exempt_groups;
+ $options{'tax_exemption'} = {
+ map { $_ => scalar($cgi->param("tax_$_".'_num')) } @tax_exempt
+ };
+}
+
+$options{'cust_payby_params'} = scalar($cgi->Vars);
+
+if ( $cgi->param('residential_commercial') eq 'Residential' ) {
+
+ my $email = $cgi->param('invoice_email') || '';
+ if ( length($email) == 0 and $conf->exists('cust_main-require_invoicing_list_email', $agentnum) ) {
+ $error = 'Email address required';
+ }
+
+ $options{'invoicing_list'} = [ split(/[,\s]+/, $email) ];
+ # XXX really should include the phone numbers in here also
+
+} else {
+
+ # contact UI is enabled
+ $options{'contact_params'} = scalar($cgi->Vars);
+
+ if ($conf->exists('cust_main-require_invoicing_list_email', $agentnum)) {
+ my $has_email = 0;
+ foreach my $prefix (grep /^contactnum\d+$/, $cgi->param) {
+ if ( length($cgi->param($prefix . '_emailaddress'))
+ and $cgi->param($prefix . '_invoice_dest') ) {
+ $has_email = 1;
+ last;
+ }
+ }
+ $error = "At least one contact must receive email invoices"
+ unless $has_email;
+ }
+
+}
+
+# kind of a hack, but some tax data vendors require a status and others
+# don't.
+my $vendor = $conf->config('tax_data_vendor');
+if ( $vendor eq 'avalara' or $vendor eq 'suretax' ) {
+ if ( ! $cgi->param('taxstatusnum') ) {
+ $error ||= 'Tax status required';
+ }
+}