Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / FS / FS / svc_phone.pm
index f28002c..65a98d2 100644 (file)
@@ -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,7 +713,9 @@ 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".
 
@@ -735,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' : '';