correct internal reason searching, prevent interleaved suspend/cancel/expire/adjourn...
[freeside.git] / FS / FS / svc_phone.pm
index fca3369..04d5960 100644 (file)
@@ -39,13 +39,19 @@ from FS::Record.  The following fields are currently supported:
 
 =over 4
 
-=item svcnum - primary key
+=item svcnum
 
-=item countrycode - 
+primary key
 
-=item phonenum - 
+=item countrycode
 
-=item pin - 
+=item phonenum
+
+=item sip_password
+
+=item pin
+
+Voicemail PIN
 
 =back
 
@@ -63,9 +69,54 @@ 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_info {
+  {
+    'name' => 'Phone number',
+    'sorts' => 'phonenum',
+    'display_weight' => 60,
+    'cancel_weight'  => 80,
+    'fields' => {
+        'countrycode'  => { label => 'Country code',
+                            type  => 'text',
+                            disable_inventory => 1,
+                            disable_select => 1,
+                          },
+        'phonenum'     => 'Phone number',
+        'pin'          => { label => 'Personal Identification Number',
+                            type  => 'text',
+                            disable_inventory => 1,
+                            disable_select => 1,
+                          },
+        'sip_password' => 'SIP password',
+    },
+  };
+}
 
 sub table { 'svc_phone'; }
 
+=item search_sql STRING
+
+Class method which returns an SQL fragment to search for the given string.
+
+=cut
+
+sub search_sql {
+  my( $class, $string ) = @_;
+  $class->search_sql_field('phonenum', $string );
+}
+
+=item label
+
+Returns the phone number.
+
+=cut
+
+sub label {
+  my $self = shift;
+  $self->phonenum; #XXX format it better
+}
+
 =item insert
 
 Adds this record to the database.  If there is an error, returns the error,
@@ -118,10 +169,15 @@ and replace methods.
 sub check {
   my $self = shift;
 
+  my $phonenum = $self->phonenum;
+  $phonenum =~ s/\D//g;
+  $self->phonenum($phonenum);
+
   my $error = 
     $self->ut_numbern('svcnum')
     || $self->ut_numbern('countrycode')
     || $self->ut_number('phonenum')
+    || $self->ut_anything('sip_password')
     || $self->ut_numbern('pin')
   ;
   return $error if $error;
@@ -131,6 +187,18 @@ sub check {
   $self->SUPER::check;
 }
 
+=item check_pin
+
+Checks the supplied PIN against the PIN in the database.  Returns true for a
+sucessful authentication, false if no match.
+
+=cut
+
+sub check_pin {
+  my($self, $check_pin) = @_;
+  $check_pin eq $self->pin;
+}
+
 =back
 
 =head1 BUGS