this should fix credits pushing typeset invoices off the right
[freeside.git] / FS / FS / svc_Common.pm
index 65b34c7..869ab58 100644 (file)
@@ -151,6 +151,11 @@ sub label {
   $self->svcnum;
 }
 
+sub label_long {
+  my $self = shift;
+  $self->label(@_);
+}
+
 =item check
 
 Checks the validity of fields in this record.
@@ -249,6 +254,7 @@ sub insert {
 
   my $error =    $self->set_auto_inventory
               || $self->check
+              || $self->_check_duplicate
               || $self->SUPER::insert;
   if ( $error ) {
     $dbh->rollback if $oldAutoCommit;
@@ -314,6 +320,10 @@ sub insert {
   '';
 }
 
+#fallbacks
+sub _check_duplcate { ''; }
+sub table_dupcheck_fields { (); }
+
 =item delete [ , OPTION => VALUE ... ]
 
 Deletes this account from the database.  If there is an error, returns the
@@ -390,6 +400,25 @@ sub replace {
     return $error;
   }
 
+  #redundant, but so any duplicate fields are maniuplated as appropriate
+  # (svc_phone.phonenum)
+  $error = $new->check;
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  }
+
+  #if ( $old->username ne $new->username || $old->domsvc != $new->domsvc ) {
+  if ( grep { $old->$_ ne $new->$_ } $new->table_dupcheck_fields ) {
+
+    $new->svcpart( $new->cust_svc->svcpart ) unless $new->svcpart;
+    $error = $new->_check_duplicate;
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $error;
+    }
+  }
+
   $error = $new->SUPER::replace($old);
   if ($error) {
     $dbh->rollback if $oldAutoCommit;
@@ -511,7 +540,7 @@ sub setx {
   return $error if $error;
 
   my $part_svc = $self->part_svc;
-  return "Unkonwn svcpart" unless $part_svc;
+  return "Unknown svcpart" unless $part_svc;
 
   #set default/fixed/whatever fields from part_svc