use vars qw( @ISA @EXPORT_OK $conf
@cust_main_county %cust_main_county $countyflag );
use Exporter;
-use FS::Record qw( qsearch );
+use FS::Record qw( qsearch dbh );
@ISA = qw( FS::Record );
@EXPORT_OK = qw( regionselector );
return '';
}
+=item sql_taxclass_sameregion
+
+Returns an SQL WHERE fragment or the empty string to search for entries
+with different tax classes.
+
+=cut
+
+#hmm, description above could be better...
+
+sub sql_taxclass_sameregion {
+ my $self = shift;
+
+ my $same_query = 'SELECT taxclass FROM cust_main_county '.
+ ' WHERE taxnum != ? AND country = ?';
+ my @same_param = ( 'taxnum', 'country' );
+ foreach my $opt_field (qw( state county )) {
+ if ( $self->$opt_field() ) {
+ $same_query .= " AND $opt_field = ?";
+ push @same_param, $opt_field;
+ } else {
+ $same_query .= " AND $opt_field IS NULL";
+ }
+ }
+
+ my @taxclasses = $self->_list_sql( \@same_param, $same_query );
+
+ return '' unless scalar(@taxclasses);
+
+ '( taxclass IS NULL OR ( '. #only if !$self->taxclass ??
+ join(' AND ', map { 'taxclass != '.dbh->quote($_) } @taxclasses ).
+ ' ) ) ';
+}
+
+sub _list_sql {
+ my( $self, $param, $sql ) = @_;
+ my $sth = dbh->prepare($sql) or die dbh->errstr;
+ $sth->execute( map $self->$_(), @$param )
+ or die "Unexpected error executing statement $sql: ". $sth->errstr;
+ map $_->[0], @{ $sth->fetchall_arrayref };
+}
+
=back
=head1 SUBROUTINES
foreach my $country ( sort keys %cust_main_county ) {
$script_html .= "\nif ( country == \"$country\" ) {\n";
foreach my $state ( sort keys %{$cust_main_county{$country}} ) {
- my( $dstate = $state ) =~ s/\n//g;
+ ( my $dstate = $state ) =~ s/[\n\r]//g;
my $text = $dstate || '(n/a)';
$script_html .= qq!opt(what.form.${prefix}state, "$dstate", "$text");\n!;
}
foreach my $state ( sort keys %{ $cust_main_county{$selected_country} } ) {
my $text = $state || '(n/a)';
my $selected = $state eq $selected_state ? 'SELECTED' : '';
- $state_html .= "\n<OPTION $selected VALUE=$state>$text</OPTION>"
+ $state_html .= qq(\n<OPTION $selected VALUE="$state">$text</OPTION>);
}
$state_html .= '</SELECT>';
keys %cust_main_county
) {
my $selected = $country eq $selected_country ? ' SELECTED' : '';
- $country_html .= "\n<OPTION$selected>$country</OPTION>"
+ $country_html .= qq(\n<OPTION$selected VALUE="$country">$country</OPTION>");
}
$country_html .= '</SELECT>';