diff options
author | ivan <ivan> | 2005-03-12 14:31:50 +0000 |
---|---|---|
committer | ivan <ivan> | 2005-03-12 14:31:50 +0000 |
commit | b5fbaadb1cb2893660e460a1d4a3cabe02774de7 (patch) | |
tree | 0f574d67fffe967f98d0bdcac1e69e1fc1fd78c0 /FS | |
parent | 40c89f3fd0933be14693b918e045bc21d39d6f01 (diff) |
- bring prepaid support into this century (close: Bug#1124)
- finally get rid of fs_signup (everything is in fs_selfservice now) (Bug#413)
- organize main menu sysadmin section so it is slightly less confusing
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/agent.pm | 17 | ||||
-rw-r--r-- | FS/FS/cust_main.pm | 33 | ||||
-rw-r--r-- | FS/FS/cust_pay.pm | 2 | ||||
-rw-r--r-- | FS/FS/prepay_credit.pm | 72 | ||||
-rwxr-xr-x | FS/bin/freeside-setup | 1 |
5 files changed, 108 insertions, 17 deletions
diff --git a/FS/FS/agent.pm b/FS/FS/agent.pm index 3d8e67739..fc1d1a93e 100644 --- a/FS/FS/agent.pm +++ b/FS/FS/agent.pm @@ -274,6 +274,7 @@ generated codes, or a scalar error message. =cut +#false laziness w/prepay_credit::generate sub generate_reg_codes { my( $self, $num, $pkgparts ) = @_; @@ -325,6 +326,22 @@ sub num_reg_code { $sth->fetchrow_arrayref->[0]; } +=item num_prepay_credit + +Returns the number of unused prepaid cards for this agent. + +=cut + +sub num_prepay_credit { + my $self = shift; + my $sth = dbh->prepare( + "SELECT COUNT(*) FROM prepay_credit WHERE agentnum = ?" + ) or die dbh->errstr; + $sth->execute($self->agentnum) or die $sth->errstr; + $sth->fetchrow_arrayref->[0]; +} + + =back =head1 BUGS diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 60556a5a4..e5748ec3f 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -175,7 +175,7 @@ FS::Record. The following fields are currently supported: =item ship_fax - phone (optional) -=item payby - I<CARD> (credit card - automatic), I<DCRD> (credit card - on-demand), I<CHEK> (electronic check - automatic), I<DCHK> (electronic check - on-demand), I<LECB> (Phone bill billing), I<BILL> (billing), I<COMP> (free), or I<PREPAY> (special billing type: applies a credit - see L<FS::prepay_credit> and sets billing type to I<BILL>) +=item payby - I<CARD> (credit card - automatic), I<DCRD> (credit card - on-demand), I<CHEK> (electronic check - automatic), I<DCHK> (electronic check - on-demand), I<LECB> (Phone bill billing), I<BILL> (billing), I<COMP> (free), or I<PREPAY> (special billing type: applies a payment from a prepaid card - see L<FS::prepay_credit> - and sets billing type to I<BILL>) =item payinfo - card number, P.O., comp issuer (4-8 lowercase alphanumerics; think username) or prepayment identifier (see L<FS::prepay_credit>) @@ -271,20 +271,28 @@ sub insert { local $FS::UID::AutoCommit = 0; my $dbh = dbh; - my $amount = 0; + my $prepay_credit = ''; my $seconds = 0; if ( $self->payby eq 'PREPAY' ) { $self->payby('BILL'); - my $prepay_credit = qsearchs( + $prepay_credit = qsearchs( 'prepay_credit', { 'identifier' => $self->payinfo }, '', 'FOR UPDATE' ); - warn "WARNING: can't find pre-found prepay_credit: ". $self->payinfo - unless $prepay_credit; - $amount = $prepay_credit->amount; + unless ( $prepay_credit ) { + $dbh->rollback if $oldAutoCommit; + return "Invalid prepaid card: ". $self->payinfo; + } $seconds = $prepay_credit->seconds; + if ( $prepay_credit->agentnum ) { + if ( $self->agentnum && $self->agentnum != $prepay_credit->agentnum ) { + $dbh->rollback if $oldAutoCommit; + return "prepaid card not valid for agent ". $self->agentnum; + } + $self->agentnum($prepay_credit->agentnum); + } my $error = $prepay_credit->delete; if ( $error ) { $dbh->rollback if $oldAutoCommit; @@ -321,15 +329,18 @@ sub insert { return "No svc_acct record to apply pre-paid time"; } - if ( $amount ) { - my $cust_credit = new FS::cust_credit { + if ( $prepay_credit && $prepay_credit->amount ) { + my $cust_pay = new FS::cust_pay { 'custnum' => $self->custnum, - 'amount' => $amount, + 'paid' => $prepay_credit->amount, + #'_date' => #date the prepaid card was purchased??? + 'payby' => 'PREP', + 'payinfo' => $prepay_credit->identifier, }; - $error = $cust_credit->insert; + $error = $cust_pay->insert; if ( $error ) { $dbh->rollback if $oldAutoCommit; - return "inserting credit (transaction rolled back): $error"; + return "inserting prepayment (transaction rolled back): $error"; } } diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm index 1ceb599a0..80d4a140b 100644 --- a/FS/FS/cust_pay.pm +++ b/FS/FS/cust_pay.pm @@ -357,7 +357,7 @@ sub check { $self->_date(time) unless $self->_date; - $self->payby =~ /^(CARD|CHEK|LECB|BILL|COMP)$/ or return "Illegal payby"; + $self->payby =~ /^(CARD|CHEK|LECB|BILL|COMP|PREP)$/ or return "Illegal payby"; $self->payby($1); #false laziness with cust_refund::check diff --git a/FS/FS/prepay_credit.pm b/FS/FS/prepay_credit.pm index a9d26d151..cffedeb0f 100644 --- a/FS/FS/prepay_credit.pm +++ b/FS/FS/prepay_credit.pm @@ -2,8 +2,8 @@ package FS::prepay_credit; use strict; use vars qw( @ISA ); -#use FS::Record qw( qsearch qsearchs ); -use FS::Record qw(); +use FS::Record qw(qsearchs dbh); +use FS::agent; @ISA = qw(FS::Record); @@ -37,8 +37,8 @@ FS::prepay_credit - Object methods for prepay_credit records =head1 DESCRIPTION -An FS::table_name object represents an pre--paid credit, such as a pre-paid -"calling card". FS::prepay_credit inherits from FS::Record. The following +An FS::prepay_credit object represents a pre-paid card. FS::prepay_credit +inherits from FS::Record. The following fields are currently supported: =over 4 @@ -107,14 +107,76 @@ sub check { $self->ut_numbern('prepaynum') || $self->ut_alpha('identifier') || $self->ut_money('amount') - || $self->utnumbern('seconds') + || $self->ut_numbern('seconds') + || $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum') || $self->SUPER::check ; } +=item agent + +Returns the agent (see L<FS::agent>) for this prepaid card, if any. + +=cut + +sub agent { + my $self = shift; + qsearchs('agent', { 'agentnum' => $self->agentnum } ); +} + =back +=head1 SUBROUTINES + +=over 4 + +=item generate NUM TYPE HASHREF + +Generates the specified number of prepaid cards. Returns an array reference of +the newly generated card identifiers, or a scalar error message. + +=cut + +#false laziness w/agent::generate_reg_codes +sub generate { + my( $num, $type, $hashref ) = @_; + + my @codeset = (); + push @codeset, ( 'A'..'Z' ) if $type =~ /alpha/; + push @codeset, ( '1'..'9' ) if $type =~ /numeric/; + + local $SIG{HUP} = 'IGNORE'; + local $SIG{INT} = 'IGNORE'; + local $SIG{QUIT} = 'IGNORE'; + local $SIG{TERM} = 'IGNORE'; + local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; + + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + my @cards = (); + for ( 1 ... $num ) { + my $prepay_credit = new FS::prepay_credit { + 'identifier' => join('', map($codeset[int(rand $#codeset)], (0..7) ) ), + %$hashref, + }; + my $error = $prepay_credit->check || $prepay_credit->insert; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "(inserting prepay_credit) $error"; + } + push @cards, $prepay_credit->identifier; + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + + \@cards; + +} + =head1 BUGS =head1 SEE ALSO diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 5ab6eb9f3..74aa5e2f0 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -890,6 +890,7 @@ sub tables_hash_hack { 'identifier', 'varchar', '', $char_d, 'amount', @money_type, 'seconds', 'int', 'NULL', '', + 'agentnum', 'int', 'NULL', '', ], 'primary_key' => 'prepaynum', 'unique' => [ ['identifier'] ], |