prevent customer payment type changes from skewing payment report
[freeside.git] / FS / FS / UI / Web.pm
index 6655f27..136c8e6 100644 (file)
@@ -15,11 +15,13 @@ use FS::cust_main;  # are sql_balance and sql_date_balance in the right module?
 #@ISA = qw( FS::UI );
 @ISA = qw( Exporter );
 
-@EXPORT_OK = qw( svc_url );
+@EXPORT_OK = qw( svc_url random_id );
 
 $DEBUG = 0;
 $me = '[FS::UID::Web]';
 
+our $NO_RANDOM_IDS;
+
 ###
 # date parsing
 ###
@@ -271,7 +273,7 @@ sub cust_header {
     '(service) Latitude'       => 'ship_latitude',
     '(service) Longitude'      => 'ship_longitude',
     'Invoicing email(s)'       => 'invoicing_list_emailonly_scalar',
-    'Payment Type'             => 'payby',
+    'Payment Type'             => 'cust_payby',
     'Current Balance'          => 'current_balance',
     'Agent Cust#'              => 'agent_custid',
   );
@@ -371,9 +373,11 @@ sub cust_sql_fields {
     }
   }
 
-  foreach my $field (qw(daytime night mobile fax payby)) {
+  foreach my $field (qw(daytime night mobile fax )) {
     push @fields, $field if (grep { $_ eq $field } @cust_fields);
   }
+  push @fields, "payby AS cust_payby"
+    if grep { $_ eq 'cust_payby' } @cust_fields;
   push @fields, 'agent_custid';
 
   my @extra_fields = ();
@@ -608,6 +612,36 @@ sub is_mobile {
   return 0;
 }
 
+=item random_id [ DIGITS ]
+
+Returns a random number of length DIGITS, or if unspecified, a long random 
+identifier consisting of the timestamp, process ID, and a random number.
+Anything in the UI that needs a random identifier should use this.
+
+=cut
+
+sub random_id {
+  my $digits = shift;
+  if (!defined $NO_RANDOM_IDS) {
+    my $conf = FS::Conf->new;
+    $NO_RANDOM_IDS = $conf->exists('no_random_ids') ? 1 : 0;
+    warn "TEST MODE--RANDOM ID NUMBERS DISABLED\n" if $NO_RANDOM_IDS;
+  }
+  if ( $NO_RANDOM_IDS ) {
+    if ( $digits > 0 ) {
+      return 0;
+    } else {
+      return '0000000000-0000-000000000.000000';
+    }
+  } else {
+    if ($digits > 0) {
+      return int(rand(10 ** $digits));
+    } else {
+      return time . "-$$-" . rand() * 2**32;
+    }
+  }
+}
+
 =back
 
 =cut
@@ -623,7 +657,7 @@ use vars qw($DEBUG);
 use Carp;
 use Storable qw(nfreeze);
 use MIME::Base64;
-use JSON::XS;
+use Cpanel::JSON::XS;
 use FS::CurrentUser;
 use FS::Record qw(qsearchs);
 use FS::queue;