svcpart changes now trigger all necessary export actions, manual svcpart changing...
authorivan <ivan>
Fri, 30 Jul 2004 04:54:41 +0000 (04:54 +0000)
committerivan <ivan>
Fri, 30 Jul 2004 04:54:41 +0000 (04:54 +0000)
FS/FS/Conf.pm
FS/FS/cust_svc.pm
FS/FS/svc_Common.pm
conf/cust_pkg-change_svcpart [new file with mode: 0644]
httemplate/edit/process/cust_svc.cgi [new file with mode: 0644]
httemplate/misc/process/link.cgi
httemplate/view/svc_acct.cgi

index c4b2148..bfef628 100644 (file)
@@ -1237,7 +1237,7 @@ httemplate/docs/config.html
   {
     'key'         => 'cust_pkg-change_svcpart',
     'section'     => '',
-    'description' => "When changing packages, move services even if svcparts don't match between old and new pacakge definitions.  Use with caution!  No provision is made for export differences between the old and new service definitions.  Probably only should be used when your exports for all service definitions of a given svcdb are identical.",
+    'description' => "When changing packages, move services even if svcparts don't match between old and new pacakge definitions.",
     'type'        => 'checkbox',
   },
 
index 7ee9b3f..118ab79 100644 (file)
@@ -172,15 +172,9 @@ sub replace {
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
 
-  my $error = $new->SUPER::replace($old);
-  if ( $error ) {
-    $dbh->rollback if $oldAutoCommit;
-    return $error if $error;
-  }
-
   if ( $new->svcpart != $old->svcpart ) {
     my $svc_x = $new->svc_x;
-    my $new_svc_x = ref($svc_x)->new({$svc_x->hash});
+    my $new_svc_x = ref($svc_x)->new({$svc_x->hash, svcpart=>$new->svcpart });
     my $error = $new_svc_x->replace($svc_x);
     if ( $error ) {
       $dbh->rollback if $oldAutoCommit;
@@ -188,6 +182,12 @@ sub replace {
     }
   }
 
+  my $error = $new->SUPER::replace($old);
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error if $error;
+  }
+
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
   ''; #no error
 
index a223266..38e656c 100644 (file)
@@ -302,14 +302,52 @@ sub replace {
 
   #new-style exports!
   unless ( $noexport_hack ) {
-    foreach my $part_export ( $new->cust_svc->part_svc->part_export ) {
-      my $error = $part_export->export_replace($new,$old);
+
+    #not quite false laziness, but same pattern as FS::svc_acct::replace and
+    #FS::part_export::sqlradius::_export_replace.  List::Compare or something
+    #would be useful but too much of a pain in the ass to deploy
+
+    my @old_part_export = $old->cust_svc->part_svc->part_export;
+    my %old_exportnum = map { $_->exportnum => 1 } @old_part_export;
+    my @new_part_export = 
+      $new->svcpart
+        ? qsearchs('part_svc', { svcpart=>$new->svcpart } )->part_export
+        : $new->cust_svc->part_svc->part_export;
+    my %new_exportnum = map { $_->exportnum => 1 } @new_part_export;
+
+    foreach my $delete_part_export (
+      grep { ! $new_exportnum{$_->exportnum} } @old_part_export
+    ) {
+      my $error = $delete_part_export->export_delete($old);
       if ( $error ) {
         $dbh->rollback if $oldAutoCommit;
-        return "error exporting to ". $part_export->exporttype.
+        return "error deleting, export to ". $delete_part_export->exporttype.
+               " (transaction rolled back): $error";
+      }
+    }
+
+    foreach my $replace_part_export (
+      grep { $old_exportnum{$_->exportnum} } @new_part_export
+    ) {
+      my $error = $replace_part_export->export_replace($new,$old);
+      if ( $error ) {
+        $dbh->rollback if $oldAutoCommit;
+        return "error exporting to ". $replace_part_export->exporttype.
                " (transaction rolled back): $error";
       }
     }
+
+    foreach my $insert_part_export (
+      grep { ! $old_exportnum{$_->exportnum} } @new_part_export
+    ) {
+      my $error = $insert_part_export->export_insert($new);
+      if ( $error ) {
+        $dbh->rollback if $oldAutoCommit;
+        return "error inserting export to ". $insert_part_export->exporttype.
+               " (transaction rolled back): $error";
+      }
+    }
+
   }
 
   $dbh->commit or die $dbh->errstr if $oldAutoCommit;
diff --git a/conf/cust_pkg-change_svcpart b/conf/cust_pkg-change_svcpart
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/httemplate/edit/process/cust_svc.cgi b/httemplate/edit/process/cust_svc.cgi
new file mode 100644 (file)
index 0000000..187ede5
--- /dev/null
@@ -0,0 +1,30 @@
+<%
+
+my $svcnum = $cgi->param('svcnum');
+
+my $old = qsearchs('cust_svc',{'svcnum'=>$svcnum}) if $svcnum;
+
+my $new = new FS::cust_svc ( {
+  map {
+    $_, scalar($cgi->param($_));
+  } fields('cust_svc')
+} );
+
+my $error;
+if ( $svcnum ) {
+  $error=$new->replace($old);
+} else {
+  $error=$new->insert;
+  $svcnum=$new->getfield('svcnum');
+}
+
+if ( $error ) {
+  #$cgi->param('error', $error);
+  #print $cgi->redirect(popurl(2). "cust_svc.cgi?". $cgi->query_string );
+  eidiot($error);
+} else { 
+  my $svcdb = $new->part_svc->svcdb;
+  print $cgi->redirect(popurl(3). "view/$svcdb.cgi?$svcnum");
+}
+
+
index 32a5360..acdd1ad 100755 (executable)
@@ -16,8 +16,11 @@ unless ( $svcnum ) {
   if ( $cgi->param('link_field2') =~ /^(\w+)$/ ) {
     $search{$1} = $cgi->param('link_value2');
   }
-  my $svc_x = ( grep { $_->cust_svc->svcpart == $svcpart } 
-                  qsearch( $svcdb, \%search )
+  my $svc_x = ( sort { ($b->cust_svc->pkgnum > 0) <=> ($a->cust_svc->pkgnum > 0)
+                       or ($b->cust_svc->svcpart == $svcpart)
+                            <=> ($a->cust_svc->svcpart == $svcpart)
+                     }
+                     qsearch( $svcdb, \%search )
               )[0];
   eidiot("$link_field not found!") unless $svc_x;
   $svcnum = $svc_x->svcnum;
index 14d2745..be58e4e 100755 (executable)
@@ -108,6 +108,48 @@ if (    $part_svc->part_export('sqlradius')
 
 #print qq!<BR><A HREF="../misc/sendconfig.cgi?$svcnum">Send account information</A>!;
 
+%>
+
+<% 
+  my @part_svc = ();
+  if ( $pkgnum ) { 
+    @part_svc = grep {    $_->svcdb   eq 'svc_acct'
+                       && $_->svcpart != $part_svc->svcpart }
+                $cust_pkg->available_part_svc;
+  } else {
+    @part_svc = qsearch('part_svc', {
+      svcdb    => 'svc_acct',
+      disabled => '',
+      svcpart  => { op=>'!=', value=>$part_svc->svcpart },
+    } );
+  }
+  if ( @part_svc ) {
+%>
+  <SCRIPT TYPE="text/javascript">
+  function enable_change () {
+    if ( document.OneTrueForm.svcpart.selectedIndex > 1 ) {
+      document.OneTrueForm.submit.disabled = false;
+    } else {
+      document.OneTrueForm.submit.disabled = true;
+    }
+  }
+  </SCRIPT>
+  <FORM NAME="OneTrueForm" ACTION="<%=$p%>edit/process/cust_svc.cgi">
+  <INPUT TYPE="hidden" NAME="svcnum" VALUE="<%= $svcnum %>">
+  <INPUT TYPE="hidden" NAME="pkgnum" VALUE="<%= $pkgnum %>">
+  <SELECT NAME="svcpart" onChange="enable_change()">
+    <OPTION VALUE="">Change service</OPTION>
+    <OPTION VALUE="">--------------</OPTION>
+    <% foreach my $part_svc ( @part_svc ) { %>
+      <OPTION VALUE="<%= $part_svc->svcpart %>"><%= $part_svc->svc %></OPTION>
+    <% } %>
+  </SELECT>
+  <INPUT NAME="submit" TYPE="submit" VALUE="Change" disabled>
+  </FORM>
+<% } %>
+
+<%
+
 print qq!<A HREF="${p}edit/svc_acct.cgi?$svcnum">Edit this information</A><BR>!.
       &ntable("#cccccc"). '<TR><TD>'. &ntable("#cccccc",2).
       "<TR><TD ALIGN=\"right\">Service number</TD>".