X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fsvc_phone.pm;h=525025f4b8e5d8ea445a1c2288e0ba59571c9433;hb=00a60cd6783c5bf541a49ed41e945151773f130f;hp=eb06dc15e6cbb793c8f67bb3dbfc22ed002e472c;hpb=697ce57e2b1f31adb3b938dead83e160e8d115c0;p=freeside.git diff --git a/FS/FS/svc_phone.pm b/FS/FS/svc_phone.pm index eb06dc15e..525025f4b 100644 --- a/FS/FS/svc_phone.pm +++ b/FS/FS/svc_phone.pm @@ -1,19 +1,22 @@ package FS::svc_phone; +use base qw( FS::svc_Domain_Mixin FS::svc_PBX_Mixin + FS::location_Mixin + FS::svc_Common + ); use strict; -use base qw( FS::svc_Domain_Mixin FS::location_Mixin FS::svc_Common ); use vars qw( $DEBUG $me @pw_set $conf $phone_name_max $passwordmin $passwordmax ); use Data::Dumper; use Scalar::Util qw( blessed ); use List::Util qw( min ); +use Tie::IxHash; use FS::Conf; use FS::Record qw( qsearch qsearchs dbh ); use FS::PagedSearch qw( psearch ); use FS::Msgcat qw(gettext); use FS::part_svc; -use FS::phone_device; use FS::svc_pbx; use FS::svc_domain; use FS::cust_location; @@ -125,6 +128,23 @@ Account number of other provider. See lnp_other_provider. See lnp_status. If lnp_status is portin-reject or portout-reject, this is an optional reject reason. +=item e911_class + +Class of Service for E911 service (per the NENA 2.1 standard). + +=item e911_type + +Type of Service for E911 service. + +=item circuit_svcnum + +The L record for the physical circuit that transports this +phone line. + +=item sip_server + +The hostname of the SIP server that this phone number is routed to. + =back =head1 METHODS @@ -176,8 +196,17 @@ sub table_info { select_table => 'svc_domain', select_key => 'svcnum', select_label => 'domain', + select_allow_empty => 1, disable_inventory => 1, }, + 'circuit_svcnum' => { label => 'Circuit', + type => 'select', + select_table => 'svc_domain', + select_key => 'svcnum', + select_label => 'circuit_label', + disable_inventory => 1, + }, + 'sms_carrierid' => { label => 'SMS Carrier', type => 'select', select_table => 'cdr_carrier', @@ -222,6 +251,22 @@ sub table_info { { label => 'LNP Other Provider Account #', %dis2 }, + 'e911_class' => { + label => 'E911 Service Class', + type => 'select-e911_class', + disable_inventory => 1, + multiple => 1, + }, + 'e911_type' => { + label => 'E911 Service Type', + type => 'select-e911_type', + disable_inventory => 1, + multiple => 1, + }, + 'sip_server' => { + label => 'SIP Host', + %dis2, + }, }, }; } @@ -303,6 +348,7 @@ 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'} ) { + $options{'cust_location'}->custnum( $self->cust_svc->cust_pkg->custnum ); my $error = $options{'cust_location'}->find_or_insert; if ( $error ) { $dbh->rollback if $oldAutoCommit; @@ -429,11 +475,20 @@ sub replace { ); my $error = $new->SUPER::replace($old, %options); + + # if this changed the e911 location, notify exports + if ($new->locationnum ne $old->locationnum) { + my $new_location = $new->cust_location_or_main; + my $old_location = $new->cust_location_or_main; + $error ||= $new->export('relocate', $new_location, $old_location); + } + if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error if $error; } + $dbh->commit or die $dbh->errstr if $oldAutoCommit; ''; #no error } @@ -508,6 +563,7 @@ sub check { 'native', 'portin-reject', 'portout-reject']) || $self->ut_enumn('portable', ['','Y']) || $self->ut_textn('lnp_reject_reason') + || $self->ut_domainn('sip_server') ; return $error if $error; @@ -559,6 +615,13 @@ sub check { } + if ($self->e911_class and !exists(e911_classes()->{$self->e911_class})) { + return "undefined e911 class '".$self->e911_class."'"; + } + if ($self->e911_type and !exists(e911_types()->{$self->e911_type})) { + return "undefined e911 type '".$self->e911_type."'"; + } + $self->SUPER::check; } @@ -672,6 +735,8 @@ sub radius_groups { =item sms_cdr_carrier +Returns the L assigned as the SMS carrier for this phone. + =cut sub sms_cdr_carrier { @@ -682,6 +747,8 @@ sub sms_cdr_carrier { =item sms_carriername +Returns the name of the SMS carrier, or an empty string if there isn't one. + =cut sub sms_carriername { @@ -690,17 +757,35 @@ sub sms_carriername { $cdr_carrier->carriername; } -=item phone_device +=item svc_circuit -Returns any FS::phone_device records associated with this service. +Returns the L assigned as the trunk for this phone line. + +=item circuit_label + +Returns the label of the circuit (the part_svc label followed by the +circuit ID), or an empty string if there isn't one. =cut -sub phone_device { +sub svc_circuit { my $self = shift; - qsearch('phone_device', { 'svcnum' => $self->svcnum } ); + my $svcnum = $self->get('circuit_svcnum') or return ''; + return FS::svc_circuit->by_key($svcnum); } +sub circuit_label { + my $self = shift; + my $svc_circuit = $self->svc_circuit or return ''; + return join(' ', $svc_circuit->part_svc->svc, $svc_circuit->circuit_id); +} + +=item phone_device + +Returns any FS::phone_device records associated with this service. + +=cut + #override location_Mixin version cause we want to try the cust_pkg location #in between us and cust_main # XXX what to do in the unlinked case??? return a pseudo-object that returns @@ -712,6 +797,26 @@ sub cust_location_or_main { $cust_pkg ? $cust_pkg->cust_location_or_main : ''; } +=item phone_name_or_cust + +Returns the C field if it has a value, or the package contact +name if there is one, or the customer contact name. + +=cut + +sub phone_name_or_cust { + my $self = shift; + if ( $self->phone_name ) { + return $self->phone_name; + } + my $cust_pkg = $self->cust_svc->cust_pkg or return ''; + if ( $cust_pkg->contactnum ) { + return $cust_pkg->contact->firstlast; + } else { + return $cust_pkg->cust_main->name_short; + } +} + =item psearch_cdrs OPTIONS Returns a paged search (L) for Call Detail Records @@ -728,8 +833,8 @@ Accepts the following options: =item status => "" (or "processing-tiered", "done"): Return only CDRs with that processing status. -=item inbound => 1: Return CDRs for inbound calls. With "status", will filter -on inbound processing status. +=item inbound => 1: Return CDRs for inbound calls (that is, those that match +on 'dst'). With "status", will filter on inbound processing status. =item default_prefix => "XXX": Also accept the phone number of the service prepended with the chosen prefix. @@ -740,7 +845,9 @@ with the chosen prefix. =item calltypenum: Only return CDRs with this call type. -=item disable_src => 1: Only match on "charged_party", not "src". +=item disable_src => 1: Only match on 'charged_party', not 'src'. + +=item disable_charged_party => 1: Only match on 'src', not 'charged_party'. =item nonzero: Only return CDRs where duration > 0. @@ -780,8 +887,8 @@ sub psearch_cdrs { } else { - @fields = ( 'charged_party' ); - push @fields, 'src' if !$options{'disable_src'}; + push @fields, 'charged_party' unless $options{'disable_charged_party'}; + push @fields, 'src' unless $options{'disable_src'}; $hash{'freesidestatus'} = $options{'status'} if exists($options{'status'}); } @@ -870,6 +977,67 @@ sub sum_cdrs { =back +=head1 CLASS METHODS + +=over 4 + +=item e911_classes + +Returns a hashref of allowed values and descriptions for the C +field. + +=item e911_types + +Returns a hashref of allowed values and descriptions for the C +field. + +=cut + +sub e911_classes { + tie my %x, 'Tie::IxHash', ( + 1 => 'Residence', + 2 => 'Business', + 3 => 'Residence PBX', + 4 => 'Business PBX', + 5 => 'Centrex', + 6 => 'Coin 1 Way out', + 7 => 'Coin 2 Way', + 8 => 'Mobile', + 9 => 'Residence OPX', + 0 => 'Business OPX', + A => 'Customer Operated Coin Telephone', + #B => not available + G => 'Wireless Phase I', + H => 'Wireless Phase II', + I => 'Wireless Phase II with Phase I information', + V => 'VoIP Services Default', + C => 'VoIP Residence', + D => 'VoIP Business', + E => 'VoIP Coin/Pay Phone', + F => 'VoIP Wireless', + J => 'VoIP Nomadic', + K => 'VoIP Enterprise Services', + T => 'Telematics', + ); + \%x; +} + +sub e911_types { + tie my %x, 'Tie::IxHash', ( + 0 => 'Not FX nor Non-Published', + 1 => 'FX in 911 serving area', + 2 => 'FX outside 911 serving area', + 3 => 'Non-Published', + 4 => 'Non-Published FX in serving area', + 5 => 'Non-Published FX outside serving area', + 6 => 'Local Ported Number', + 7 => 'Interim Ported Number', + ); + \%x; +} + +=back + =head1 BUGS =head1 SEE ALSO