[freeside-commits] freeside/FS/FS cdr.pm, 1.3, 1.4 AccessRight.pm,
1.3, 1.4 svc_phone.pm, NONE, 1.1 Schema.pm, 1.17,
1.18 part_svc.pm, 1.27, 1.28 cust_svc.pm, 1.63,
1.64 h_svc_phone.pm, NONE, 1.1 Record.pm, 1.117, 1.118
Ivan,,,
ivan at wavetail.420.am
Tue Jul 11 17:20:23 PDT 2006
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail:/tmp/cvs-serv17459/FS/FS
Modified Files:
cdr.pm AccessRight.pm Schema.pm part_svc.pm cust_svc.pm
Record.pm
Added Files:
svc_phone.pm h_svc_phone.pm
Log Message:
svc_phone service and CDR billing from imported CDRs
Index: cdr.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cdr.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cdr.pm 6 Jun 2006 10:30:09 -0000 1.3
+++ cdr.pm 12 Jul 2006 00:20:21 -0000 1.4
@@ -4,6 +4,7 @@
use vars qw( @ISA );
use Date::Parse;
use Date::Format;
+use Time::Local;
use FS::UID qw( dbh );
use FS::Record qw( qsearch qsearchs );
use FS::cdr_type;
@@ -224,6 +225,17 @@
# ;
# return $error if $error;
+ $self->calldate( $self->startdate_sql )
+ if !$self->calldate && $self->startdate;
+
+ unless ( $self->charged_party ) {
+ if ( $self->dst =~ /^(\+?1)?8[02-8]{2}/ ) {
+ $self->charged_party($self->dst);
+ } else {
+ $self->charged_party($self->src);
+ }
+ }
+
#check the foreign keys even?
#do we want to outright *reject* the CDR?
my $error =
@@ -252,7 +264,7 @@
sub set_status_and_rated_price {
my($self, $status, $rated_price) = @_;
- $self->status($status);
+ $self->freesidestatus($status);
$self->rated_price($rated_price);
$self->replace();
}
@@ -267,6 +279,20 @@
str2time(shift->calldate);
}
+=item startdate_sql
+
+Parses the startdate in UNIX timestamp format and returns a string in SQL
+format.
+
+=cut
+
+sub startdate_sql {
+ my($sec,$min,$hour,$mday,$mon,$year) = localtime(shift->startdate);
+ $mon++;
+ $year += 1900;
+ "$year-$mon-$mday $hour:$min:$sec";
+}
+
=item cdr_carrier
Returns the FS::cdr_carrier object associated with this CDR, or false if no
@@ -420,6 +446,8 @@
=cut
+my($tmp_mday, $tmp_mon, $tmp_year);
+
my %import_formats = (
'asterisk' => [
'accountcode',
@@ -465,7 +493,42 @@
'quantity',
'carrierid',
'upstream_rateid',
- ]
+ ],
+ 'ams' => [
+
+ # Date
+ sub { my($cdr, $date) = @_;
+ $date =~ /^(\d{1,2})\/(\d{1,2})\/(\d\d(\d\d)?)$/
+ or die "unparsable date: $date"; #maybe we shouldn't die...
+ #$cdr->startdate( timelocal(0, 0, 0 ,$2, $1-1, $3) );
+ ($tmp_mday, $tmp_mon, $tmp_year) = ( $2, $1-1, $3 );
+ },
+
+ # Time
+ sub { my($cdr, $time) = @_;
+ #my($sec, $min, $hour, $mday, $mon, $year)= localtime($cdr->startdate);
+ $time =~ /^(\d{1,2}):(\d{1,2}):(\d{1,2})$/
+ or die "unparsable time: $time"; #maybe we shouldn't die...
+ #$cdr->startdate( timelocal($3, $2, $1 ,$mday, $mon, $year) );
+ $cdr->startdate(
+ timelocal($3, $2, $1 ,$tmp_mday, $tmp_mon, $tmp_year)
+ );
+ },
+
+ # Source_Number
+ 'src',
+
+ # Terminating_Number
+ 'dst',
+
+ # Duration
+ sub { my($cdr, $min) = @_;
+ my $sec = sprintf('%.0f', $min * 60 );
+ $cdr->billsec( $sec );
+ $cdr->duration( $sec );
+ },
+
+ ],
);
sub batch_import {
@@ -494,10 +557,20 @@
my $oldAutoCommit = $FS::UID::AutoCommit;
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
-
+
+ if ( $format eq 'ams' ) { # and other formats with a header too?
+
+ }
+
+ my $body = 0;
my $line;
while ( defined($line=<$fh>) ) {
+ #skip header...
+ if ( ! $body++ && $format eq 'ams' && $line =~ /^[\w\, ]+$/ ) {
+ next;
+ }
+
$csv->parse($line) or do {
$dbh->rollback if $oldAutoCommit;
return "can't parse: ". $csv->error_input();
@@ -506,6 +579,10 @@
my @columns = $csv->fields();
#warn join('-', at columns);
+ if ( $format eq 'ams' ) {
+ @columns = map { s/^ +//; $_; } @columns;
+ }
+
my @later = ();
my %cdr =
map {
Index: cust_svc.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_svc.pm,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -d -r1.63 -r1.64
--- cust_svc.pm 20 Mar 2006 19:13:26 -0000 1.63
+++ cust_svc.pm 12 Jul 2006 00:20:21 -0000 1.64
@@ -13,6 +13,7 @@
use FS::svc_domain;
use FS::svc_forward;
use FS::svc_broadband;
+use FS::svc_phone;
use FS::svc_external;
use FS::domain_record;
use FS::part_export;
@@ -277,6 +278,10 @@
- The table name (i.e. svc_domain) for this service
- svcnum
+Usage example:
+
+ my($label, $value, $svcdb) = $cust_svc->label;
+
=cut
sub label {
@@ -315,6 +320,8 @@
$tag = $domain_record->zone;
} elsif ( $svcdb eq 'svc_broadband' ) {
$tag = $svc_x->ip_addr;
+ } elsif ( $svcdb eq 'svc_phone' ) {
+ $tag = $svc_x->phonenum; #XXX format it better
} elsif ( $svcdb eq 'svc_external' ) {
my $conf = new FS::Conf;
if ( $conf->config('svc_external-display_type') eq 'artera_turbo' ) {
@@ -586,30 +593,29 @@
my $default_prefix = $options{'default_prefix'};
- #Currently CDRs are associated with svc_acct services via a DID in the
- #username. This part is rather tenative and still subject to change...
- #return () unless $self->svc_x->isa('FS::svc_acct');
- return () unless $self->part_svc->svcdb eq 'svc_acct';
- my $number = $self->svc_x->username;
+ #CDRs are now associated with svc_phone services via svc_phone.phonenum
+ #return () unless $self->svc_x->isa('FS::svc_phone');
+ return () unless $self->part_svc->svcdb eq 'svc_phone';
+ my $number = $self->svc_x->phonenum;
my @cdrs =
- qsearch(
+ qsearch( {
'table' => 'cdr',
'hashref' => { 'freesidestatus' => '',
'charged_party' => $number
},
'extra_sql' => 'FOR UPDATE',
- );
+ } );
if ( length($default_prefix) ) {
push @cdrs,
- qsearch(
+ qsearch( {
'table' => 'cdr',
'hashref' => { 'freesidestatus' => '',
'charged_party' => "$default_prefix$number",
},
'extra_sql' => 'FOR UPDATE',
- );
+ } );
}
@cdrs;
Index: part_svc.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_svc.pm,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- part_svc.pm 24 Jun 2006 16:41:44 -0000 1.27
+++ part_svc.pm 12 Jul 2006 00:20:21 -0000 1.28
@@ -347,7 +347,6 @@
sub check {
my $self = shift;
- my $recref = $self->hashref;
my $error;
$error=
@@ -358,8 +357,9 @@
;
return $error if $error;
- my @fields = eval { fields( $recref->{svcdb} ) }; #might die
- return "Unknown svcdb!" unless @fields;
+ my @fields = eval { fields( $self->svcdb ) }; #might die
+ return "Unknown svcdb: ". $self->svcdb. " (Error: $@)"
+ unless @fields;
$self->SUPER::check;
}
@@ -549,7 +549,9 @@
@fields;
} grep defined( dbdef->table($_) ),
- qw( svc_acct svc_domain svc_forward svc_www svc_broadband )
+ qw( svc_acct svc_domain svc_forward svc_www svc_broadband
+ svc_phone svc_external
+ )
)
} );
--- NEW FILE: svc_phone.pm ---
package FS::svc_phone;
use strict;
use vars qw( @ISA );
#use FS::Record qw( qsearch qsearchs );
use FS::svc_Common;
@ISA = qw( FS::svc_Common );
=head1 NAME
FS::svc_phone - Object methods for svc_phone records
=head1 SYNOPSIS
use FS::svc_phone;
$record = new FS::svc_phone \%hash;
$record = new FS::svc_phone { 'column' => 'value' };
$error = $record->insert;
$error = $new_record->replace($old_record);
$error = $record->delete;
$error = $record->check;
$error = $record->suspend;
$error = $record->unsuspend;
$error = $record->cancel;
=head1 DESCRIPTION
An FS::svc_phone object represents a phone number. FS::svc_phone inherits
from FS::Record. The following fields are currently supported:
=over 4
=item svcnum - primary key
=item countrycode -
=item phonenum -
=item pin -
=back
=head1 METHODS
=over 4
=item new HASHREF
Creates a new phone number. To add the number 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 { 'svc_phone'; }
=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 suspend
Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
=item unsuspend
Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
=item cancel
Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
=item check
Checks all fields to make sure this is a valid phone number. 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('svcnum')
|| $self->ut_numbern('countrycode')
|| $self->ut_number('phonenum')
|| $self->ut_numbern('pin')
;
return $error if $error;
$self->countrycode(1) unless $self->countrycode;
$self->SUPER::check;
}
=back
=head1 BUGS
=head1 SEE ALSO
L<FS::svc_Common>, L<FS::Record>, L<FS::cust_svc>, L<FS::part_svc>,
L<FS::cust_pkg>, schema.html from the base documentation.
=cut
1;
Index: Record.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Record.pm,v
retrieving revision 1.117
retrieving revision 1.118
diff -u -d -r1.117 -r1.118
--- Record.pm 1 Jul 2006 11:26:06 -0000 1.117
+++ Record.pm 12 Jul 2006 00:20:21 -0000 1.118
@@ -1727,7 +1727,7 @@
( $nullable ? ' NULL' : ' NOT NULL' ).
")\n" if $DEBUG > 2;
- if ( $value eq '' && $column_type =~ /^int/ ) {
+ if ( $value eq '' && $column_type =~ /^(int|numeric)/ ) {
if ( $nullable ) {
'NULL';
} else {
Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- Schema.pm 19 Jun 2006 02:33:52 -0000 1.17
+++ Schema.pm 12 Jul 2006 00:20:21 -0000 1.18
@@ -1538,6 +1538,18 @@
'index' => [],
},
+ 'svc_phone' => {
+ 'columns' => [
+ 'svcnum', 'int', '', '', '', '',
+ 'countrycode', 'varchar', '', 3, '', '',
+ 'phonenum', 'varchar', '', 15, '', '', #12 ?
+ 'pin', 'varchar', 'NULL', $char_d, '', '',
+ ],
+ 'primary_key' => 'svcnum',
+ 'unique' => [],
+ 'index' => [ [ 'countrycode', 'phonenum' ] ],
+ },
+
};
#'new_table' => {
--- NEW FILE: h_svc_phone.pm ---
package FS::h_svc_phone;
use strict;
use vars qw( @ISA );
use FS::h_Common;
use FS::svc_phone;
@ISA = qw( FS::h_Common FS::svc_phone );
sub table { 'h_svc_phone' };
=head1 NAME
FS::h_svc_phone - Historical phone number objects
=head1 SYNOPSIS
=head1 DESCRIPTION
An FS::h_svc_phone object represents a historical phone number.
FS::h_svc_phone inherits from FS::h_Common and FS::svc_phone.
=head1 BUGS
=head1 SEE ALSO
L<FS::h_Common>, L<FS::svc_phone>, L<FS::Record>, schema.html from the base
documentation.
=cut
1;
Index: AccessRight.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/AccessRight.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- AccessRight.pm 19 Jun 2006 11:25:13 -0000 1.3
+++ AccessRight.pm 12 Jul 2006 00:20:21 -0000 1.4
@@ -128,6 +128,8 @@
'List packages',
'List services',
+ 'List rating data',
+
'Financial reports',
'Job queue', # these are not currently agent-virtualized
More information about the freeside-commits
mailing list