projects
/
freeside.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Telos XML SMS records, RT#10721
[freeside.git]
/
FS
/
FS
/
prepay_credit.pm
diff --git
a/FS/FS/prepay_credit.pm
b/FS/FS/prepay_credit.pm
index
92f2a30
..
e5773ae
100644
(file)
--- a/
FS/FS/prepay_credit.pm
+++ b/
FS/FS/prepay_credit.pm
@@
-61,7
+61,7
@@
fields are currently supported:
=item new HASHREF
=item new HASHREF
-Creates a new pre-paid credit. To add the
example
to the database, see
+Creates a new pre-paid credit. To add the
pre-paid credit
to the database, see
L<"insert">.
Note that this stores the hash reference, not a distinct copy of the hash it
L<"insert">.
Note that this stores the hash reference, not a distinct copy of the hash it
@@
-110,6
+110,9
@@
sub check {
|| $self->ut_alpha('identifier')
|| $self->ut_money('amount')
|| $self->ut_numbern('seconds')
|| $self->ut_alpha('identifier')
|| $self->ut_money('amount')
|| $self->ut_numbern('seconds')
+ || $self->ut_numbern('upbytes')
+ || $self->ut_numbern('downbytes')
+ || $self->ut_numbern('totalbytes')
|| $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum')
|| $self->SUPER::check
;
|| $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum')
|| $self->SUPER::check
;
@@
-133,7
+136,7
@@
sub agent {
=over 4
=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.
Generates the specified number of prepaid cards. Returns an array reference of
the newly generated card identifiers, or a scalar error message.
@@
-142,11
+145,12
@@
the newly generated card identifiers, or a scalar error message.
#false laziness w/agent::generate_reg_codes
sub generate {
#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/;
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';
local $SIG{HUP} = 'IGNORE';
local $SIG{INT} = 'IGNORE';
@@
-159,10
+163,18
@@
sub generate {
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
+ my $condup = 0; #don't retry forever
+
my @cards = ();
for ( 1 ... $num ) {
my @cards = ();
for ( 1 ... $num ) {
+
+ my $identifier = join('', map($codeset[int(rand $#codeset)], (1..$length) ) );
+
+ redo if qsearchs('prepay_credit',{identifier=>$identifier}) && $condup++<23;
+ $condup = 0;
+
my $prepay_credit = new FS::prepay_credit {
my $prepay_credit = new FS::prepay_credit {
- 'identifier' =>
join('', map($codeset[int(rand $#codeset)], (0..7) ) )
,
+ 'identifier' =>
$identifier
,
%$hashref,
};
my $error = $prepay_credit->check || $prepay_credit->insert;
%$hashref,
};
my $error = $prepay_credit->check || $prepay_credit->insert;