X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fsvc_phone.pm;h=65a98d25ae7cb3d7a44b1e4aa4d2f1f051fd912e;hb=4109791a9b80df968edaf2e71da8ebcfb8882be3;hp=bf610c62bbce209208c374ae51cdfb1049d7f5bd;hpb=66eaa4a82b7fc52e711ecdefc95feedf629f71b1;p=freeside.git diff --git a/FS/FS/svc_phone.pm b/FS/FS/svc_phone.pm index bf610c62b..65a98d25a 100644 --- a/FS/FS/svc_phone.pm +++ b/FS/FS/svc_phone.pm @@ -173,6 +173,15 @@ sub table_info { select_label => 'domain', disable_inventory => 1, }, + 'sms_carrierid' => { label => 'SMS Carrier', + type => 'select', + select_table => 'cdr_carrier', + select_key => 'carrierid', + select_label => 'carriername', + disable_inventory => 1, + }, + 'sms_account' => { label => 'SMS Carrier Account', }, + 'max_simultaneous' => { label=>'Maximum number of simultaneous users' }, 'locationnum' => { label => 'E911 location', disable_inventory => 1, @@ -288,9 +297,8 @@ sub insert { #false laziness w/cust_pkg.pm... move this to location_Mixin? that would #make it more of a base class than a mixin... :) - if ( $options{'cust_location'} - && ( ! $self->locationnum || $self->locationnum == -1 ) ) { - my $error = $options{'cust_location'}->insert; + if ( $options{'cust_location'} ) { + my $error = $options{'cust_location'}->find_or_insert; if ( $error ) { $dbh->rollback if $oldAutoCommit; return "inserting cust_location (transaction rolled back): $error"; @@ -359,8 +367,6 @@ sub delete { } -# 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, @@ -478,6 +484,9 @@ sub check { || $self->ut_textn('phone_name') || $self->ut_foreign_keyn('pbxsvc', 'svc_pbx', 'svcnum' ) || $self->ut_foreign_keyn('domsvc', 'svc_domain', 'svcnum' ) + || $self->ut_foreign_keyn('sms_carrierid', 'cdr_carrier', 'carrierid' ) + || $self->ut_alphan('sms_account') + || $self->ut_numbern('max_simultaneous') || $self->ut_foreign_keyn('locationnum', 'cust_location', 'locationnum') || $self->ut_numbern('forwarddst') || $self->ut_textn('email') @@ -638,6 +647,26 @@ sub radius_groups { (); } +=item sms_cdr_carrier + +=cut + +sub sms_cdr_carrier { + my $self = shift; + return '' unless $self->sms_carrierid; + qsearchs('cdr_carrier', { 'carrierid' => $self->sms_carrierid } ); +} + +=item sms_carriername + +=cut + +sub sms_carriername { + my $self = shift; + my $cdr_carrier = $self->sms_cdr_carrier or return ''; + $cdr_carrier->carriername; +} + =item phone_device Returns any FS::phone_device records associated with this service. @@ -684,10 +713,14 @@ with the chosen prefix. =item begin, end: Start and end of a date range, as unix timestamp. -=item cdrtypenum: Only return CDRs with this type number. +=item cdrtypenum: Only return CDRs with this type. + +=item calltypenum: Only return CDRs with this call type. =item disable_src => 1: Only match on "charged_party", not "src". +=item nonzero: Only return CDRs where duration > 0. + =item by_svcnum: not supported for svc_phone =item billsec_sum: Instead of returning all of the CDRs, return a single @@ -733,6 +766,9 @@ sub psearch_cdrs { if ($options{'cdrtypenum'}) { $hash{'cdrtypenum'} = $options{'cdrtypenum'}; } + if ($options{'calltypenum'}) { + $hash{'calltypenum'} = $options{'calltypenum'}; + } my $for_update = $options{'for_update'} ? 'FOR UPDATE' : ''; @@ -755,6 +791,9 @@ sub psearch_cdrs { if ( $options{'end'} ) { push @where, 'startdate < '. $options{'end'}; } + if ( $options{'nonzero'} ) { + push @where, 'duration > 0'; + } my $extra_sql = ( keys(%hash) ? ' AND ' : ' WHERE ' ). join(' AND ', @where ); @@ -781,6 +820,30 @@ sub get_cdrs { qsearch ( $psearch->{query} ) } +=item sum_cdrs + +Takes the same options as psearch_cdrs, but returns a single row containing +"count" (the number of CDRs) and the sums of the following fields: duration, +billsec, rated_price, rated_seconds, rated_minutes. + +Note that if any calls are not rated, their rated_* fields will be null. +If you want to use those fields, pass the 'status' option to limit to +calls that have been rated. This is intentional; please don't "fix" it. + +=cut + +sub sum_cdrs { + my $self = shift; + my $psearch = $self->psearch_cdrs(@_); + $psearch->{query}->{'select'} = join(',', + 'COUNT(*) AS count', + map { "SUM($_) AS $_" } + qw(duration billsec rated_price rated_seconds rated_minutes) + ); + # hack + $psearch->{query}->{'extra_sql'} =~ s/ ORDER BY.*$//; + qsearchs ( $psearch->{query} ); +} =back