freeside/FS/FS rate.pm,NONE,1.1 rate_detail.pm,NONE,1.1 rate_region.pm,NONE,1.1 rate_prefix.pm,NONE,1.1 cust_svc.pm,1.45,1.46
ivan
ivan at pouncequick.420.am
Sat Nov 20 09:26:57 PST 2004
- Previous message: freeside/httemplate/edit part_pkg.cgi,1.46,1.47
- Next message: freeside/FS/t rate.t,NONE,1.1 rate_detail.t,NONE,1.1 rate_region.t,NONE,1.1 rate_prefix.t,NONE,1.1 part_pkg-voip_sqlradacct.t,NONE,1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory pouncequick:/tmp/cvs-serv3612/FS/FS
Modified Files:
cust_svc.pm
Added Files:
rate.pm rate_detail.pm rate_region.pm rate_prefix.pm
Log Message:
first pass at VoIP rating
--- NEW FILE: rate.pm ---
package FS::rate;
use strict;
use vars qw( @ISA );
use FS::Record qw( qsearch qsearchs dbh );
use FS::rate_detail;
@ISA = qw(FS::Record);
=head1 NAME
FS::rate - Object methods for rate records
=head1 SYNOPSIS
use FS::rate;
$record = new FS::rate \%hash;
$record = new FS::rate { 'column' => 'value' };
$error = $record->insert;
$error = $new_record->replace($old_record);
$error = $record->delete;
$error = $record->check;
=head1 DESCRIPTION
An FS::rate object represents an rate plan. FS::rate inherits from
FS::Record. The following fields are currently supported:
=over 4
=item ratenum - primary key
=item ratename
=back
=head1 METHODS
=over 4
=item new HASHREF
Creates a new rate plan. To add the rate plan to the database, see L<"insert">.
Note that this stores the hash reference, not a distinct copy of the hash it
points to. You can ask the object for a copy with the I<hash> method.
=cut
# the new method can be inherited from FS::Record, if a table method is defined
sub table { 'rate'; }
=item insert [ , OPTION => VALUE ... ]
Adds this record to the database. If there is an error, returns the error,
otherwise returns false.
Currently available options are: I<rate_detail>
If I<rate_detail> is set to an array reference of FS::rate_detail objects, the
objects will have their ratenum field set and will be inserted after this
record.
=cut
sub insert {
my $self = shift;
my %options = @_;
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 $error = $self->check;
return $error if $error;
$error = $self->SUPER::insert;
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
}
if ( $options{'rate_detail'} ) {
foreach my $rate_detail ( @{$options{'rate_detail'}} ) {
$rate_detail->ratenum($self->ratenum);
$error = $rate_detail->insert;
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
}
}
}
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
'';
}
=item delete
Delete this record from the database.
=cut
# the delete method can be inherited from FS::Record
=item replace OLD_RECORD [ , OPTION => VALUE ... ]
Replaces the OLD_RECORD with this one in the database. If there is an error,
returns the error, otherwise returns false.
Currently available options are: I<rate_detail>
If I<rate_detail> is set to an array reference of FS::rate_detail objects, the
objects will have their ratenum field set and will be inserted after this
record. Any existing rate_detail records associated with this record will be
deleted.
=cut
sub replace {
my ($new, $old) = (shift, shift);
my %options = @_;
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 @old_rate_detail = ();
@old_rate_detail = $old->rate_detail if $options{'rate_detail'};
my $error = $new->SUPER::replace($old);
if ($error) {
$dbh->rollback if $oldAutoCommit;
return $error;
}
foreach my $old_rate_detail ( @old_rate_detail ) {
my $error = $old_rate_detail->delete;
if ($error) {
$dbh->rollback if $oldAutoCommit;
return $error;
}
}
foreach my $rate_detail ( @{$options{'rate_detail'}} ) {
$rate_detail->ratenum($new->ratenum);
$error = $rate_detail->insert;
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
}
}
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
'';
}
=item check
Checks all fields to make sure this is a valid rate plan. If there is
an error, returns the error, otherwise returns false. Called by the insert
and replace methods.
=cut
# the check method should currently be supplied - FS::Record contains some
# data checking routines
sub check {
my $self = shift;
my $error =
$self->ut_numbern('ratenum')
|| $self->ut_text('ratename')
;
return $error if $error;
$self->SUPER::check;
}
=item dest_detail REGIONNUM | RATE_REGION_OBJECTD
Returns the rate detail (see L<FS::rate_detail>) for this rate to the
specificed destination.
=cut
sub dest_detail {
my $self = shift;
my $regionnum = ref($_[0]) ? shift->regionnum : shift;
qsearchs( 'rate_detail', { 'ratenum' => $self->ratenum,
'dest_regionnum' => $regionnum, } );
}
=item rate_detail
Returns all region-specific details (see L<FS::rate_detail>) for this rate.
=cut
sub rate_detail {
my $self = shift;
qsearch( 'rate_detail', { 'ratenum' => $self->ratenum } );
}
=back
=head1 BUGS
=head1 SEE ALSO
L<FS::Record>, schema.html from the base documentation.
=cut
1;
Index: cust_svc.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_svc.pm,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- cust_svc.pm 17 Oct 2004 09:19:22 -0000 1.45
+++ cust_svc.pm 20 Nov 2004 17:26:53 -0000 1.46
@@ -555,6 +555,7 @@
#$attrib ???
+ #my @part_export = $cust_svc->part_svc->part_export->can('usage_sessions');
my @part_export = $self->part_svc->part_export('sqlradius');
push @part_export, $self->part_svc->part_export('sqlradius_withdomain');
die "no sqlradius or sqlradius_withdomain export configured for this".
--- NEW FILE: rate_prefix.pm ---
package FS::rate_prefix;
use strict;
use vars qw( @ISA );
use FS::Record qw( qsearch qsearchs );
use FS::rate_region;
@ISA = qw(FS::Record);
=head1 NAME
FS::rate_prefix - Object methods for rate_prefix records
=head1 SYNOPSIS
use FS::rate_prefix;
$record = new FS::rate_prefix \%hash;
$record = new FS::rate_prefix { 'column' => 'value' };
$error = $record->insert;
$error = $new_record->replace($old_record);
$error = $record->delete;
$error = $record->check;
=head1 DESCRIPTION
An FS::rate_prefix object represents an call rating prefix. FS::rate_prefix
inherits from FS::Record. The following fields are currently supported:
=over 4
=item prefixnum - primary key
=item regionnum - call ration region (see L<FS::rate_region>)
=item countrycode
=item npa
=item nxx
=back
=head1 METHODS
=over 4
=item new HASHREF
Creates a new prefix. To add the prefix to the database, see L<"insert">.
Note that this stores the hash reference, not a distinct copy of the hash it
points to. You can ask the object for a copy with the I<hash> method.
=cut
# the new method can be inherited from FS::Record, if a table method is defined
sub table { 'rate_prefix'; }
=item insert
Adds this record to the database. If there is an error, returns the error,
otherwise returns false.
=cut
# the insert method can be inherited from FS::Record
=item delete
Delete this record from the database.
=cut
# the delete method can be inherited from FS::Record
=item replace OLD_RECORD
Replaces the OLD_RECORD with this one in the database. If there is an error,
returns the error, otherwise returns false.
=cut
# the replace method can be inherited from FS::Record
=item check
Checks all fields to make sure this is a valid prefix. If there is
an error, returns the error, otherwise returns false. Called by the insert
and replace methods.
=cut
# the check method should currently be supplied - FS::Record contains some
# data checking routines
sub check {
my $self = shift;
my $error =
$self->ut_numbern('prefixnum')
|| $self->ut_foreign_key('regionnum', 'rate_region', 'regionnum' )
|| $self->ut_number('countrycode')
|| $self->ut_numbern('npa')
|| $self->ut_numbern('nxx')
;
return $error if $error;
$self->SUPER::check;
}
=item rate_region
Returns the rate region (see L<FS::rate_region>) for this prefix.
=cut
sub rate_region {
my $self = shift;
qsearch('rate_region', { 'regionnum' => $self->regionnum } );
}
=back
=head1 BUGS
=head1 SEE ALSO
L<FS::rate_region>, L<FS::Record>, schema.html from the base documentation.
=cut
1;
--- NEW FILE: rate_detail.pm ---
package FS::rate_detail;
use strict;
use vars qw( @ISA );
use FS::Record qw( qsearch qsearchs );
@ISA = qw(FS::Record);
=head1 NAME
FS::rate_detail - Object methods for rate_detail records
=head1 SYNOPSIS
use FS::rate_detail;
$record = new FS::rate_detail \%hash;
$record = new FS::rate_detail { 'column' => 'value' };
$error = $record->insert;
$error = $new_record->replace($old_record);
$error = $record->delete;
$error = $record->check;
=head1 DESCRIPTION
An FS::rate_detail object represents an call plan rate. FS::rate_detail
inherits from FS::Record. The following fields are currently supported:
=over 4
=item ratenum - rate plan (see L<FS::rate>)
=item orig_regionnum - call origination region
=item dest_regionnum - call destination region
=item min_included - included minutes
=item min_charge - charge per minute
=item sec_granularity - granularity in seconds, i.e. 6 or 60
=back
=head1 METHODS
=over 4
=item new HASHREF
Creates a new example. To add the example to the database, see L<"insert">.
Note that this stores the hash reference, not a distinct copy of the hash it
points to. You can ask the object for a copy with the I<hash> method.
=cut
# the new method can be inherited from FS::Record, if a table method is defined
sub table { 'rate_detail'; }
=item insert
Adds this record to the database. If there is an error, returns the error,
otherwise returns false.
=cut
# the insert method can be inherited from FS::Record
=item delete
Delete this record from the database.
=cut
# the delete method can be inherited from FS::Record
=item replace OLD_RECORD
Replaces the OLD_RECORD with this one in the database. If there is an error,
returns the error, otherwise returns false.
=cut
# the replace method can be inherited from FS::Record
=item check
Checks all fields to make sure this is a valid example. If there is
an error, returns the error, otherwise returns false. Called by the insert
and replace methods.
=cut
# the check method should currently be supplied - FS::Record contains some
# data checking routines
sub check {
my $self = shift;
my $error =
$self->ut_foreign_key('ratenum', 'rate', 'ratenum')
|| $self->ut_foreign_keyn('orig_regionnum', 'rate_region', 'regionnum' )
|| $self->ut_foreign_key('dest_regionnum', 'rate_region', 'regionnum' )
|| $self->ut_number('min_included')
|| $self->ut_money('min_charge')
|| $self->ut_number('sec_granularity')
;
return $error if $error;
$self->SUPER::check;
}
=back
=head1 BUGS
=head1 SEE ALSO
L<FS::rate>, L<FS::rate_region>, L<FS::Record>,
schema.html from the base documentation.
=cut
1;
--- NEW FILE: rate_region.pm ---
package FS::rate_region;
use strict;
use vars qw( @ISA );
use FS::Record qw( qsearch qsearchs dbh );
use FS::rate_prefix;
use FS::rate_detail;
@ISA = qw(FS::Record);
=head1 NAME
FS::rate_region - Object methods for rate_region records
=head1 SYNOPSIS
use FS::rate_region;
$record = new FS::rate_region \%hash;
$record = new FS::rate_region { 'column' => 'value' };
$error = $record->insert;
$error = $new_record->replace($old_record);
$error = $record->delete;
$error = $record->check;
=head1 DESCRIPTION
An FS::rate_region object represents an call rating region. FS::rate_region
inherits from FS::Record. The following fields are currently supported:
=over 4
=item regionnum - primary key
=item regionname
=back
=head1 METHODS
=over 4
=item new HASHREF
Creates a new region. To add the region to the database, see L<"insert">.
Note that this stores the hash reference, not a distinct copy of the hash it
points to. You can ask the object for a copy with the I<hash> method.
=cut
# the new method can be inherited from FS::Record, if a table method is defined
sub table { 'rate_region'; }
=item insert [ , OPTION => VALUE ... ]
Adds this record to the database. If there is an error, returns the error,
otherwise returns false.
Currently available options are: I<rate_prefix> and I<dest_detail>
If I<rate_prefix> is set to an array reference of FS::rate_prefix objects, the
objects will have their regionnum field set and will be inserted after this
record.
If I<dest_detail> is set to an array reference of FS::rate_detail objects, the
objects will have their dest_regionnum field set and will be inserted after
this record.
=cut
sub insert {
my $self = shift;
my %options = @_;
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 $error = $self->check;
return $error if $error;
$error = $self->SUPER::insert;
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
}
if ( $options{'rate_prefix'} ) {
foreach my $rate_prefix ( @{$options{'rate_prefix'}} ) {
$rate_prefix->regionnum($self->regionnum);
$error = $rate_prefix->insert;
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
}
}
}
if ( $options{'dest_detail'} ) {
foreach my $rate_detail ( @{$options{'dest_detail'}} ) {
$rate_detail->dest_regionnum($self->regionnum);
$error = $rate_detail->insert;
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
}
}
}
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
'';
}
=item delete
Delete this record from the database.
=cut
# the delete method can be inherited from FS::Record
=item replace OLD_RECORD [ , OPTION => VALUE ... ]
Replaces the OLD_RECORD with this one in the database. If there is an error,
returns the error, otherwise returns false.
Currently available options are: I<rate_prefix> and I<dest_detail>
If I<rate_prefix> is set to an array reference of FS::rate_prefix objects, the
objects will have their regionnum field set and will be inserted after this
record. Any existing rate_prefix records associated with this record will be
deleted.
If I<dest_detail> is set to an array reference of FS::rate_detail objects, the
objects will have their dest_regionnum field set and will be inserted after
this record. Any existing rate_detail records associated with this record will
be deleted.
=cut
sub replace {
my ($new, $old) = (shift, shift);
my %options = @_;
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 @old_rate_prefix = ();
@old_rate_prefix = $old->rate_prefix if $options{'rate_prefix'};
my @old_dest_detail = ();
@old_dest_detail = $old->dest_detail if $options{'dest_detail'};
my $error = $new->SUPER::replace($old);
if ($error) {
$dbh->rollback if $oldAutoCommit;
return $error;
}
foreach my $old_rate_prefix ( @old_rate_prefix ) {
my $error = $old_rate_prefix->delete;
if ($error) {
$dbh->rollback if $oldAutoCommit;
return $error;
}
}
foreach my $old_dest_detail ( @old_dest_detail ) {
my $error = $old_dest_detail->delete;
if ($error) {
$dbh->rollback if $oldAutoCommit;
return $error;
}
}
foreach my $rate_prefix ( @{$options{'rate_prefix'}} ) {
$rate_prefix->regionnum($new->regionnum);
$error = $rate_prefix->insert;
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
}
}
foreach my $rate_detail ( @{$options{'dest_detail'}} ) {
$rate_detail->dest_regionnum($new->regionnum);
$error = $rate_detail->insert;
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
}
}
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
'';
}
=item check
Checks all fields to make sure this is a valid region. If there is
an error, returns the error, otherwise returns false. Called by the insert
and replace methods.
=cut
# the check method should currently be supplied - FS::Record contains some
# data checking routines
sub check {
my $self = shift;
my $error =
$self->ut_numbern('regionnum')
|| $self->ut_text('regionname')
;
return $error if $error;
$self->SUPER::check;
}
=item rate_prefix
Returns all prefixes (see L<FS::rate_prefix>) for this region.
=cut
sub rate_prefix {
my $self = shift;
sort { $a->countrycode cmp $b->countrycode
or $a->npa cmp $b->npa
or $a->nxx cmp $b->nxx
}
qsearch( 'rate_prefix', { 'regionnum' => $self->regionnum } );
}
=item dest_detail
Returns all rate details (see L<FS::rate_detail>) for this region as a
destionation.
=cut
sub dest_detail {
my $self = shift;
qsearch( 'rate_detail', { 'dest_regionnum' => $self->regionnum, } );
}
=item prefixes_short
Returns a string representing all the prefixes for this region.
=cut
sub prefixes_short {
my $self = shift;
my $countrycode = '';
my $out = '';
foreach my $rate_prefix ( $self->rate_prefix ) {
if ( $countrycode ne $rate_prefix->countrycode ) {
$out =~ s/,$//;
$countrycode = $rate_prefix->countrycode;
$out.= " $countrycode-";
}
$out .= $rate_prefix->npa. ',';
}
$out =~ s/,$//;
$out;
}
=back
=head1 BUGS
=head1 SEE ALSO
L<FS::Record>, schema.html from the base documentation.
=cut
1;
- Previous message: freeside/httemplate/edit part_pkg.cgi,1.46,1.47
- Next message: freeside/FS/t rate.t,NONE,1.1 rate_detail.t,NONE,1.1 rate_region.t,NONE,1.1 rate_prefix.t,NONE,1.1 part_pkg-voip_sqlradacct.t,NONE,1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the freeside-commits
mailing list