RT#7407, variable length prepaid card codes
authormark <mark>
Tue, 9 Mar 2010 21:58:10 +0000 (21:58 +0000)
committermark <mark>
Tue, 9 Mar 2010 21:58:10 +0000 (21:58 +0000)
FS/FS/prepay_credit.pm
httemplate/edit/prepay_credit.cgi
httemplate/edit/process/prepay_credit.cgi

index 302ba37..e5773ae 100644 (file)
@@ -136,7 +136,7 @@ sub agent {
 
 =over 4
 
-=item generate NUM TYPE HASHREF
+=item generate NUM TYPE LENGTH HASHREF
 
 Generates the specified number of prepaid cards.  Returns an array reference of
 the newly generated card identifiers, or a scalar error message.
@@ -145,11 +145,12 @@ the newly generated card identifiers, or a scalar error message.
 
 #false laziness w/agent::generate_reg_codes
 sub generate {
-  my( $num, $type, $hashref ) = @_;
+  my( $num, $type, $length, $hashref ) = @_;
 
   my @codeset = ();
   push @codeset, ( 'A'..'Z' ) if $type =~ /alpha/;
   push @codeset, ( '1'..'9' ) if $type =~ /numeric/;
+  $length ||= 8;
 
   local $SIG{HUP} = 'IGNORE';
   local $SIG{INT} = 'IGNORE';
@@ -163,11 +164,11 @@ sub generate {
   my $dbh = dbh;
 
   my $condup = 0; #don't retry forever
-
+  
   my @cards = ();
   for ( 1 ... $num ) {
 
-    my $identifier = join('', map($codeset[int(rand $#codeset)], (0..7) ) );
+    my $identifier = join('', map($codeset[int(rand $#codeset)], (1..$length) ) );
 
     redo if qsearchs('prepay_credit',{identifier=>$identifier}) && $condup++<23;
     $condup = 0;
index ed404b7..f7a1b08 100644 (file)
@@ -7,13 +7,16 @@
 Generate
 <INPUT TYPE="text" NAME="num" VALUE="<% $cgi->param('num') || '(quantity)' |h %>" SIZE=10 MAXLENGTH=10 onFocus="if ( this.value == '(quantity)' ) { this.value = ''; }">
 
+prepaid cards of
+
+<INPUT TYPE="text" NAME="length" SIZE=3 MAXLENGTH=2 VALUE=8>&nbsp;
 <SELECT NAME="type">
 % foreach (qw(alpha alphanumeric numeric)) { 
   <OPTION<% $cgi->param('type') eq $_ ? ' SELECTED' : '' %>><% $_ %>
 % } 
 </SELECT>
 
-prepaid cards
+characters each
 
 <BR>for <SELECT NAME="agentnum"><OPTION>(any agent)
 % foreach my $opt_agent ( qsearch('agent', { 'disabled' => '' } ) ) { 
index 8f2eb2b..a55522b 100644 (file)
@@ -56,6 +56,7 @@ $hashref->{totalbytes} = $cgi->param('totalbytes') * $cgi->param('totalmultiplie
 
 $error ||= FS::prepay_credit::generate( $num,
                                         scalar($cgi->param('type')), 
+                                        $cgi->param('length'),
                                         $hashref
                                       );