X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FMisc.pm;h=a1d41e0a4ff677594f42b35a2e2ef6dd4674279a;hb=965185edd27890ea2fc00c7179dccf137b61320d;hp=6024b832aef5d4ef85cd3b36629c95dafd354247;hpb=fed0c6bf093ae154d17a4075e254a69be68f3d22;p=freeside.git diff --git a/FS/FS/Misc.pm b/FS/FS/Misc.pm index 6024b832a..a1d41e0a4 100644 --- a/FS/FS/Misc.pm +++ b/FS/FS/Misc.pm @@ -5,9 +5,15 @@ use vars qw ( @ISA @EXPORT_OK $DEBUG ); use Exporter; use Carp; use Data::Dumper; +#do NOT depend on any FS:: modules here, causes weird (sometimes unreproducable +#until on client machine) dependancy loops. put them in FS::Misc::Something +#instead @ISA = qw( Exporter ); -@EXPORT_OK = qw( send_email send_fax states_hash state_label card_types ); +@EXPORT_OK = qw( send_email send_fax + states_hash counties state_label + card_types + ); $DEBUG = 0; @@ -359,13 +365,12 @@ sub states_hash { # sort map { s/[\n\r]//g; $_; } map { $_->state; } - qsearch({ - 'select' => 'state', - 'table' => 'cust_main_county', - 'hashref' => { 'country' => $country }, - 'extra_sql' => 'GROUP BY state', - }) - ; + qsearch({ + 'select' => 'state', + 'table' => 'cust_main_county', + 'hashref' => { 'country' => $country }, + 'extra_sql' => 'GROUP BY state', + }); #it could throw a fatal "Invalid country code" error (for example "AX") my $subcountry = eval { new Locale::SubCountry($country) } @@ -378,6 +383,26 @@ sub states_hash { @states; } +=item counties STATE COUNTRY + +Returns a list of counties for this state and country. + +=cut + +sub counties { + my( $state, $country ) = @_; + + sort map { s/[\n\r]//g; $_; } + map { $_->county } + qsearch({ + 'select' => 'DISTINCT county', + 'table' => 'cust_main_county', + 'hashref' => { 'state' => $state, + 'country' => $country, + }, + }); +} + =item state_label STATE COUNTRY_OR_LOCALE_SUBCOUNRY_OBJECT =cut @@ -407,17 +432,18 @@ sub state_label { =item card_types -Returns a hash reference of the accepted credit card types. +Returns a hash reference of the accepted credit card types. Keys are shorter +identifiers and values are the longer strings used by the system (see +L). =cut #$conf from above -use Tie::IxHash; sub card_types { my $conf = new FS::Conf; - tie my %card_types, 'Tie::IxHash', + my %card_types = ( #displayname #value (Business::CreditCard) "VISA" => "VISA card", "MasterCard" => "MasterCard", @@ -429,7 +455,7 @@ sub card_types { "BankCard" => "BankCard", "Switch" => "Switch", "Solo" => "Solo", - ; + ); my @conf_card_types = grep { ! /^\s*$/ } $conf->config('card-types'); if ( @conf_card_types ) { #perhaps the hash is backwards for this, but this way works better for